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)))))
7ifeq ($(clang-target),aarch64-linux)
8clang-target	:= aarch64-linux-gnu
9endif
10ccache-cmd	:= $(if $(findstring ccache,$(CROSS_COMPILE_$(sm))),$(firstword $(CROSS_COMPILE_$(sm))) ,)
11
12CC$(sm)		:= $(ccache-cmd)$(OPTEE_CLANG_COMPILER_PATH)clang --target=$(clang-target)
13CXX$(sm)	:= false # Untested yet
14# Due to the absence of clang-cpp in AOSP's prebuilt version of clang,
15# use the equivalent command of 'clang -E'
16CPP$(sm)	:= $(ccache-cmd)$(OPTEE_CLANG_COMPILER_PATH)clang --target=$(clang-target) -E
17LD$(sm)		:= $(ccache-cmd)$(OPTEE_CLANG_COMPILER_PATH)ld.lld
18
19AR$(sm)		:= $(ccache-cmd)$(OPTEE_CLANG_COMPILER_PATH)llvm-ar
20NM$(sm)		:= $(OPTEE_CLANG_COMPILER_PATH)llvm-nm
21OBJCOPY$(sm)	:= $(OPTEE_CLANG_COMPILER_PATH)llvm-objcopy
22OBJDUMP$(sm)	:= $(OPTEE_CLANG_COMPILER_PATH)llvm-objdump
23READELF$(sm)	:= $(OPTEE_CLANG_COMPILER_PATH)llvm-readelf
24
25nostdinc$(sm)	:= -nostdinc -isystem $(shell $(CC$(sm)) \
26			-print-file-name=include 2> /dev/null)
27
28comp-cflags-warns-clang := -Wno-language-extension-token \
29			 -Wno-gnu-zero-variadic-macro-arguments
30
31# Note, use the compiler runtime library (libclang_rt.builtins.*.a) instead of
32# libgcc for clang
33libgcc$(sm)	:= $(shell $(CC$(sm)) $(CFLAGS$(arch-bits-$(sm))) \
34			-rtlib=compiler-rt -print-libgcc-file-name 2> /dev/null)
35
36# Core ASLR relies on the executable being ready to run from its preferred load
37# address, because some symbols are used before the MMU is enabled and the
38# relocations are applied.
39ldflag-apply-dynamic-relocs := --apply-dynamic-relocs
40
41# Define these to something to discover accidental use
42CC		:= false
43CXX		:= false
44CPP		:= false
45LD		:= false
46AR		:= false
47NM		:= false
48OBJCOPY		:= false
49OBJDUMP		:= false
50READELF		:= false
51nostdinc	:= --bad-nostdinc-variable
52libgcc  	:= --bad-libgcc-variable
53
54