Skip to content

Commit

Permalink
Makefile: Add additional flags when using clang
Browse files Browse the repository at this point in the history
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@jms.id.au>
Signed-off-by: Stewart Smith <stewart@linux.ibm.com>
  • Loading branch information
shenki authored and stewartsmith committed May 4, 2018
1 parent 1f1b3b4 commit 97cb325
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions Makefile.main
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 97cb325

Please sign in to comment.