xref: /optee_os/mk/clang.mk (revision 8182792a91f49b750ff196abdf038cb9d1827cc6)
1# CROSS_COMPILE_$(sm) is derived from CROSS_COMPILE/CROSS_COMPILE32/
2# CROSS_COMPILE64 and indicates the target that should be passed to clang. Path
3# components are ignored, as well as any command before the compiler name (for
4# instance "/some/path/ccache /other/path/arm-linux-gnueabihf-").
5# We try to extract any ccache command if present.
6clang-target	:= $(patsubst %-,%,$(notdir $(lastword $(CROSS_COMPILE_$(sm)))))
7ccache-cmd	:= $(if $(findstring ccache,$(CROSS_COMPILE_$(sm))),$(firstword $(CROSS_COMPILE_$(sm))) ,)
8
9CC$(sm)		:= $(ccache-cmd)clang --target=$(clang-target)
10# Due to the absence of clang-cpp in AOSP's prebuilt version of clang,
11# use the equivalent command of 'clang -E'
12CPP$(sm)	:= $(ccache-cmd)clang --target=$(clang-target) -E
13LD$(sm)		:= $(ccache-cmd)ld.lld
14
15ifeq ($(sm)-$(CFG_WITH_PAGER),core-y)
16# Workaround an issue with all_objs.o and unpaged.o when CFG_WITH_PAGER=y:
17# ld.ldd merges .text.* sections into .text, even though the linker script does
18# not tell to do so. --relocatable would avoid that, but is not compatible with
19# --gc-sections. A trivial patch to ld.lld can fix the issue (in
20# lld/ELF/Writer.cpp, change elf::getOutputSectionName() to always return
21# s->name) so perhaps a new command line option could be proposed upstream?
22# Anyway, use GNU.ld for the moment.
23LDcore		:= $(CROSS_COMPILE_$(sm))ld
24endif
25
26AR$(sm)		:= $(ccache-cmd)llvm-ar
27NM$(sm)		:= llvm-nm
28OBJCOPY$(sm)	:= llvm-objcopy
29OBJDUMP$(sm)	:= llvm-objdump
30READELF$(sm)	:= llvm-readelf
31
32nostdinc$(sm)	:= -nostdinc -isystem $(shell $(CC$(sm)) \
33			-print-file-name=include 2> /dev/null)
34
35comp-cflags-warns-clang := -Wno-language-extension-token \
36			 -Wno-gnu-zero-variadic-macro-arguments
37
38# Note, the currently used compiler runtime library may be libgcc.a or
39# libclang_rt.builtins.*.a depending on the compiler build-time configuration.
40libgcc$(sm)  	:= $(shell $(CC$(sm)) $(CFLAGS$(arch-bits-$(sm))) $(comp-cflags$(sm)) \
41			-print-libgcc-file-name 2> /dev/null)
42
43# Define these to something to discover accidental use
44CC		:= false
45CPP		:= false
46LD		:= false
47AR		:= false
48NM		:= false
49OBJCOPY		:= false
50OBJDUMP		:= false
51READELF		:= false
52nostdinc	:= --bad-nostdinc-variable
53libgcc  	:= --bad-libgcc-variable
54
55