xref: /optee_os/mk/clang.mk (revision 787d273744e8defaf7956b5c2e0af19f4cc9d6e5)
198d863a5SJerome Forissier# CROSS_COMPILE_$(sm) is derived from CROSS_COMPILE/CROSS_COMPILE32/
298d863a5SJerome Forissier# CROSS_COMPILE64 and indicates the target that should be passed to clang. Path
398d863a5SJerome Forissier# components are ignored, as well as any command before the compiler name (for
498d863a5SJerome Forissier# instance "/some/path/ccache /other/path/arm-linux-gnueabihf-").
598d863a5SJerome Forissier# We try to extract any ccache command if present.
698d863a5SJerome Forissierclang-target	:= $(patsubst %-,%,$(notdir $(lastword $(CROSS_COMPILE_$(sm)))))
798d863a5SJerome Forissierccache-cmd	:= $(if $(findstring ccache,$(CROSS_COMPILE_$(sm))),$(firstword $(CROSS_COMPILE_$(sm))) ,)
898d863a5SJerome Forissier
998d863a5SJerome ForissierCC$(sm)		:= $(ccache-cmd)clang --target=$(clang-target)
1098d863a5SJerome ForissierCPP$(sm)	:= $(ccache-cmd)clang-cpp --target=$(clang-target)
1198d863a5SJerome ForissierLD$(sm)		:= $(ccache-cmd)ld.lld
1298d863a5SJerome Forissier
1398d863a5SJerome Forissierifeq ($(sm)-$(CFG_WITH_PAGER),core-y)
1498d863a5SJerome Forissier# Workaround an issue with all_objs.o and unpaged.o when CFG_WITH_PAGER=y:
1598d863a5SJerome Forissier# ld.ldd merges .text.* sections into .text, even though the linker script does
1698d863a5SJerome Forissier# not tell to do so. --relocatable would avoid that, but is not compatible with
1798d863a5SJerome Forissier# --gc-sections. A trivial patch to ld.lld can fix the issue (in
1898d863a5SJerome Forissier# lld/ELF/Writer.cpp, change elf::getOutputSectionName() to always return
1998d863a5SJerome Forissier# s->name) so perhaps a new command line option could be proposed upstream?
2098d863a5SJerome Forissier# Anyway, use GNU.ld for the moment.
2198d863a5SJerome ForissierLDcore		:= $(CROSS_COMPILE_$(sm))ld
2298d863a5SJerome Forissierendif
2398d863a5SJerome Forissier
2498d863a5SJerome ForissierAR$(sm)		:= $(ccache-cmd)llvm-ar
2598d863a5SJerome ForissierNM$(sm)		:= llvm-nm
2633017d85SJerome ForissierOBJCOPY$(sm)	:= llvm-objcopy
27*787d2737SJerome ForissierOBJDUMP$(sm)	:= llvm-objdump
2898d863a5SJerome ForissierREADELF$(sm)	:= llvm-readelf
2998d863a5SJerome Forissier
3098d863a5SJerome Forissiernostdinc$(sm)	:= -nostdinc -isystem $(shell $(CC$(sm)) \
3198d863a5SJerome Forissier			-print-file-name=include 2> /dev/null)
3298d863a5SJerome Forissier
3398d863a5SJerome Forissiercomp-cflags-warns-clang := -Wno-language-extension-token \
3498d863a5SJerome Forissier			 -Wno-gnu-zero-variadic-macro-arguments
3598d863a5SJerome Forissier
3698d863a5SJerome Forissierlibgcc$(sm)  	:=
3798d863a5SJerome Forissier
3898d863a5SJerome Forissier# Define these to something to discover accidental use
3998d863a5SJerome ForissierCC		:= false
4098d863a5SJerome ForissierCPP		:= false
4198d863a5SJerome ForissierLD		:= false
4298d863a5SJerome ForissierAR		:= false
4398d863a5SJerome ForissierNM		:= false
4498d863a5SJerome ForissierOBJCOPY		:= false
4598d863a5SJerome ForissierOBJDUMP		:= false
4698d863a5SJerome ForissierREADELF		:= false
4798d863a5SJerome Forissiernostdinc	:= --bad-nostdinc-variable
4898d863a5SJerome Forissierlibgcc  	:= --bad-libgcc-variable
4998d863a5SJerome Forissier
50