xref: /optee_os/mk/clang.mk (revision df24e6517b6454cf906c16979ea0e7546c5c99d5)
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)
10CPP$(sm)	:= $(ccache-cmd)clang-cpp --target=$(clang-target)
11LD$(sm)		:= $(ccache-cmd)ld.lld
12
13ifeq ($(sm)-$(CFG_WITH_PAGER),core-y)
14# Workaround an issue with all_objs.o and unpaged.o when CFG_WITH_PAGER=y:
15# ld.ldd merges .text.* sections into .text, even though the linker script does
16# not tell to do so. --relocatable would avoid that, but is not compatible with
17# --gc-sections. A trivial patch to ld.lld can fix the issue (in
18# lld/ELF/Writer.cpp, change elf::getOutputSectionName() to always return
19# s->name) so perhaps a new command line option could be proposed upstream?
20# Anyway, use GNU.ld for the moment.
21LDcore		:= $(CROSS_COMPILE_$(sm))ld
22endif
23
24AR$(sm)		:= $(ccache-cmd)llvm-ar
25NM$(sm)		:= llvm-nm
26OBJCOPY$(sm)	:= llvm-objcopy
27
28# llvm-objdump:
29# - Does not support mixed 32-bit ARM and Thumb instructions
30# - Has a poorer output than the binutils version (static functions not shown,
31#   for instance).
32# Rely on the GNU binutils version instead (if available).
33binutils-objdump = $(CROSS_COMPILE_$(sm))objdump
34ifneq (,$(filter GNU,$(shell $(binutils-objdump) -v 2>&1)))
35OBJDUMP$(sm)	:= $(binutils-objdump)
36else
37OBJDUMP$(sm)	:= echo "Warning: binutils objdump not found, file will be empty" >&2; true
38endif
39
40READELF$(sm)	:= llvm-readelf
41
42nostdinc$(sm)	:= -nostdinc -isystem $(shell $(CC$(sm)) \
43			-print-file-name=include 2> /dev/null)
44
45comp-cflags-warns-clang := -Wno-language-extension-token \
46			 -Wno-gnu-zero-variadic-macro-arguments
47
48libgcc$(sm)  	:=
49
50# Define these to something to discover accidental use
51CC		:= false
52CPP		:= false
53LD		:= false
54AR		:= false
55NM		:= false
56OBJCOPY		:= false
57OBJDUMP		:= false
58READELF		:= false
59nostdinc	:= --bad-nostdinc-variable
60libgcc  	:= --bad-libgcc-variable
61
62