Skip to content

Commit fe106f5

Browse files
nickdesaulniersTashar02
authored andcommitted
Makefile: infer --target from ARCH for CC=clang
We get constant feedback that the command line invocation of make is too long when compiling with LLVM. CROSS_COMPILE is helpful when a toolchain has a prefix of the target triple, or is an absolute path outside of $PATH. Since a Clang binary is generally multi-targeted, we can infer a given target from SRCARCH/ARCH. If CROSS_COMPILE is not set, simply set --target= for CLANG_FLAGS, KBUILD_CFLAGS, and KBUILD_AFLAGS based on $SRCARCH. Previously, we'd cross compile via: $ ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- make LLVM=1 LLVM_IAS=1 Now: $ ARCH=arm64 make LLVM=1 LLVM_IAS=1 For native builds (not involving cross compilation) we now explicitly specify a target triple rather than rely on the implicit host triple. Link: ClangBuiltLinux/linux#1399 Suggested-by: Arnd Bergmann <[email protected]> Suggested-by: Linus Torvalds <[email protected]> Suggested-by: Masahiro Yamada <[email protected]> Suggested-by: Nathan Chancellor <[email protected]> Acked-by: Arnd Bergmann <[email protected]> Reviewed-by: Nathan Chancellor <[email protected]> Signed-off-by: Nick Desaulniers <[email protected]> Acked-by: Miguel Ojeda <[email protected]> Signed-off-by: Masahiro Yamada <[email protected]> Signed-off-by: Divyanshu-Modi <[email protected]> Change-Id: I0915f6da8aeb9582df6d3556bf5c1482bc62d257 Signed-off-by: Divyanshu-Modi <[email protected]> Signed-off-by: Tashfin Shakeer Rhythm <[email protected]>
1 parent af5c94a commit fe106f5

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

scripts/Makefile.clang

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,27 @@
1-
ifneq ($(CROSS_COMPILE),)
1+
# Individual arch/{arch}/Makefiles should use -EL/-EB to set intended
2+
# endianness and -m32/-m64 to set word size based on Kconfigs instead of
3+
# relying on the target triple.
4+
CLANG_TARGET_FLAGS_arm := arm-linux-gnueabi
5+
CLANG_TARGET_FLAGS_arm64 := aarch64-linux-gnu
6+
CLANG_TARGET_FLAGS_hexagon := hexagon-linux-musl
7+
CLANG_TARGET_FLAGS_m68k := m68k-linux-gnu
8+
CLANG_TARGET_FLAGS_mips := mipsel-linux-gnu
9+
CLANG_TARGET_FLAGS_powerpc := powerpc64le-linux-gnu
10+
CLANG_TARGET_FLAGS_riscv := riscv64-linux-gnu
11+
CLANG_TARGET_FLAGS_s390 := s390x-linux-gnu
12+
CLANG_TARGET_FLAGS_x86 := x86_64-linux-gnu
13+
CLANG_TARGET_FLAGS := $(CLANG_TARGET_FLAGS_$(SRCARCH))
14+
15+
ifeq ($(CROSS_COMPILE),)
16+
ifeq ($(CLANG_TARGET_FLAGS),)
17+
$(error Specify CROSS_COMPILE or add '--target=' option to scripts/Makefile.clang)
18+
else
19+
CLANG_FLAGS += --target=$(CLANG_TARGET_FLAGS)
20+
endif # CLANG_TARGET_FLAGS
21+
else
222
CLANG_FLAGS += --target=$(notdir $(CROSS_COMPILE:%-=%))
3-
endif
23+
endif # CROSS_COMPILE
24+
425
ifneq ($(LLVM_IAS),1)
526
CLANG_FLAGS += -no-integrated-as
627
GCC_TOOLCHAIN_DIR := $(dir $(shell which $(CROSS_COMPILE)elfedit))

0 commit comments

Comments
 (0)