[Skiboot] [PATCH v2 02/11] Makefile: Add additional flags when using clang

Joel Stanley joel at jms.id.au
Fri May 4 12:10:27 AEST 2018


Clang needs to be told which target it's building for, as unlike GCC the
one binary targets many architectures.

Signed-off-by: Joel Stanley <joel at jms.id.au>
---
 Makefile.main | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/Makefile.main b/Makefile.main
index 72b68219e9ac..05222a1acc62 100644
--- a/Makefile.main
+++ b/Makefile.main
@@ -21,6 +21,8 @@ try = $(shell set -e; if ($(1)) >/dev/null 2>&1; \
 try-cflag = $(call try,$(1) $(2) -x c -c /dev/null -o /dev/null,$(2))
 test_cflag = $(call try,$(1) $(2) -x c -c /dev/null -o /dev/null,1,0)
 
+cc-name := $(shell $(CC) -v 2>&1 | grep -q "clang version" && echo clang || echo gcc)
+
 # Base warnings
 CWARNS := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
 	  -Werror-implicit-function-declaration -Wdeclaration-after-statement \
@@ -142,6 +144,27 @@ else
 AFLAGS += $(call try-cflag,$(CC),-mabi=elfv1)
 endif
 
+ifeq ($(cc-name),clang)
+ifneq ($(CROSS),)
+CLANG_TARGET    := --target=$(notdir $(CROSS:%-=%))
+GCC_TOOLCHAIN   := $(realpath $(dir $(shell which $(LD)))/..)
+endif
+ifneq ($(GCC_TOOLCHAIN),)
+CLANG_GCC_TC    := --gcc-toolchain=$(GCC_TOOLCHAIN)
+endif
+CFLAGS += $(CLANG_TARGET) $(CLANG_GCC_TC)
+AFLAGS += $(CLANG_TARGET) $(CLANG_GCC_TC)
+CFLAGS += $(call cc-option, -no-integrated-as)
+AFLAGS += $(call cc-option, -no-integrated-as)
+
+LDFLAGS += $(CLANG_TARGET) $(CLANG_GCC_TC)
+
+CFLAGS += -mcpu=pwr8
+LDFLAGS += -mcpu=pwr8
+ASFLAGS += -mcpu=pwr8
+
+endif
+
 # Special tool flags:
 # Do not use the floating point unit
 CFLAGS += -msoft-float
-- 
2.17.0



More information about the Skiboot mailing list