Skip to contentSkip to conversation

kbuild, LLVMLinux: Add better clang cross build support

PATCH New [email protected] 1 participant 1 message Sep 6, 2014 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kbuild, LLVMLinux: Add better clang cross build support

From: Behan Webster <[email protected]>

Add cross target to CC if using clang. Also add custom gcc toolchain path for fallback gcc tools.

COMPILER is previously set to "clang" if CC=clang was set from the make command line. So -target and -gcc-toolchain can be added to CC, since we already know that it is set.

Clang will fallback to using things like ld, as, and libgcc if (respectively) one of the llvm linkers isn't available, the integrated assembler is turned off, or an appropriately cross-compiled version of compiler-rt isn't available. To this end, you can specify the path to this fallback gcc toolchain with GCC_TOOLCHAIN.

---
 Makefile | 9 +++++++++
 1 file changed, 9 insertions(+)
Makefile +9 -0
index 2893d7f..c772619 100644
@@ -360,7 +360,16 @@ include $(srctree)/scripts/Kbuild.include
 # Make variables (CC, etc...)
 AS		= $(CROSS_COMPILE)as
 LD		= $(CROSS_COMPILE)ld
+ifeq ($(COMPILER),clang)
+ifneq ($(CROSS_COMPILE),)
+CC		+= -target $(CROSS_COMPILE:%-=%)
+endif
+ifneq ($(GCC_TOOLCHAIN),)
+CC		+= -gcc-toolchain $(GCC_TOOLCHAIN)
+endif
+else
 CC		= $(CROSS_COMPILE)gcc
+endif
 CPP		= $(CC) -E
 AR		= $(CROSS_COMPILE)ar
 NM		= $(CROSS_COMPILE)nm
Signature · 1 line
1.9.1