aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichal Marek <mmarek@suse.com>2015-08-19 11:36:41 -0400
committerMichal Marek <mmarek@suse.com>2015-09-04 07:14:10 -0400
commit5631d9c429857194bd55d7bcd8fa5bdd1a9899a3 (patch)
treef0424c4fe42eb83bf35a0cda4204aff097a8b192
parentd179e22762fd38414c4108acedd5feca4cf7e0d8 (diff)
kbuild: Fix clang detection
We cannot detect clang before including the arch Makefile, because that can set the default cross compiler. We also cannot detect clang after including the arch Makefile, because powerpc wants to know about clang. Solve this by using an deferred variable. This costs us a few shell invocations, but this is only a constant number. Reported-by: Behan Webster <behanw@converseincode.com> Reported-by: Anton Blanchard <anton@samba.org> Signed-off-by: Michal Marek <mmarek@suse.com>
-rw-r--r--Makefile9
-rw-r--r--arch/powerpc/Makefile8
-rw-r--r--scripts/Kbuild.include4
-rw-r--r--scripts/Makefile.extrawarn2
4 files changed, 10 insertions, 13 deletions
diff --git a/Makefile b/Makefile
index 13270c0a9336..5ccbb58553ab 100644
--- a/Makefile
+++ b/Makefile
@@ -661,14 +661,7 @@ endif
661endif 661endif
662KBUILD_CFLAGS += $(stackp-flag) 662KBUILD_CFLAGS += $(stackp-flag)
663 663
664ifeq ($(shell $(CC) -v 2>&1 | grep -c "clang version"), 1) 664ifeq ($(cc-name),clang)
665COMPILER := clang
666else
667COMPILER := gcc
668endif
669export COMPILER
670
671ifeq ($(COMPILER),clang)
672KBUILD_CPPFLAGS += $(call cc-option,-Qunused-arguments,) 665KBUILD_CPPFLAGS += $(call cc-option,-Qunused-arguments,)
673KBUILD_CPPFLAGS += $(call cc-option,-Wno-unknown-warning-option,) 666KBUILD_CPPFLAGS += $(call cc-option,-Wno-unknown-warning-option,)
674KBUILD_CFLAGS += $(call cc-disable-warning, unused-variable) 667KBUILD_CFLAGS += $(call cc-disable-warning, unused-variable)
diff --git a/arch/powerpc/Makefile b/arch/powerpc/Makefile
index 05f464eb6952..dfe88896b06c 100644
--- a/arch/powerpc/Makefile
+++ b/arch/powerpc/Makefile
@@ -67,7 +67,7 @@ UTS_MACHINE := $(OLDARCH)
67 67
68ifeq ($(CONFIG_CPU_LITTLE_ENDIAN),y) 68ifeq ($(CONFIG_CPU_LITTLE_ENDIAN),y)
69override CC += -mlittle-endian 69override CC += -mlittle-endian
70ifneq ($(COMPILER),clang) 70ifneq ($(cc-name),clang)
71override CC += -mno-strict-align 71override CC += -mno-strict-align
72endif 72endif
73override AS += -mlittle-endian 73override AS += -mlittle-endian
@@ -333,7 +333,7 @@ TOUT := .tmp_gas_check
333# - Require gcc 4.0 or above on 64-bit 333# - Require gcc 4.0 or above on 64-bit
334# - gcc-4.2.0 has issues compiling modules on 64-bit 334# - gcc-4.2.0 has issues compiling modules on 64-bit
335checkbin: 335checkbin:
336 @if test "${COMPILER}" != "clang" \ 336 @if test "$(cc-name)" != "clang" \
337 && test "$(cc-version)" = "0304" ; then \ 337 && test "$(cc-version)" = "0304" ; then \
338 if ! /bin/echo mftb 5 | $(AS) -v -mppc -many -o $(TOUT) >/dev/null 2>&1 ; then \ 338 if ! /bin/echo mftb 5 | $(AS) -v -mppc -many -o $(TOUT) >/dev/null 2>&1 ; then \
339 echo -n '*** ${VERSION}.${PATCHLEVEL} kernels no longer build '; \ 339 echo -n '*** ${VERSION}.${PATCHLEVEL} kernels no longer build '; \
@@ -342,14 +342,14 @@ checkbin:
342 false; \ 342 false; \
343 fi ; \ 343 fi ; \
344 fi 344 fi
345 @if test "${COMPILER}" != "clang" \ 345 @if test "$(cc-name)" != "clang" \
346 && test "$(cc-version)" -lt "0400" \ 346 && test "$(cc-version)" -lt "0400" \
347 && test "x${CONFIG_PPC64}" = "xy" ; then \ 347 && test "x${CONFIG_PPC64}" = "xy" ; then \
348 echo -n "Sorry, GCC v4.0 or above is required to build " ; \ 348 echo -n "Sorry, GCC v4.0 or above is required to build " ; \
349 echo "the 64-bit powerpc kernel." ; \ 349 echo "the 64-bit powerpc kernel." ; \
350 false ; \ 350 false ; \
351 fi 351 fi
352 @if test "${COMPILER}" != "clang" \ 352 @if test "$(cc-name)" != "clang" \
353 && test "$(cc-fullversion)" = "040200" \ 353 && test "$(cc-fullversion)" = "040200" \
354 && test "x${CONFIG_MODULES}${CONFIG_PPC64}" = "xyy" ; then \ 354 && test "x${CONFIG_MODULES}${CONFIG_PPC64}" = "xyy" ; then \
355 echo -n '*** GCC-4.2.0 cannot compile the 64-bit powerpc ' ; \ 355 echo -n '*** GCC-4.2.0 cannot compile the 64-bit powerpc ' ; \
diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include
index d3437b82ac25..3523df613391 100644
--- a/scripts/Kbuild.include
+++ b/scripts/Kbuild.include
@@ -128,6 +128,10 @@ cc-option-align = $(subst -functions=0,,\
128cc-disable-warning = $(call try-run,\ 128cc-disable-warning = $(call try-run,\
129 $(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) -W$(strip $(1)) -c -x c /dev/null -o "$$TMP",-Wno-$(strip $(1))) 129 $(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) -W$(strip $(1)) -c -x c /dev/null -o "$$TMP",-Wno-$(strip $(1)))
130 130
131# cc-name
132# Expands to either gcc or clang
133cc-name = $(shell $(CC) -v 2>&1 | grep -q "clang version" && echo clang || echo gcc)
134
131# cc-version 135# cc-version
132cc-version = $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-version.sh $(CC)) 136cc-version = $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-version.sh $(CC))
133 137
diff --git a/scripts/Makefile.extrawarn b/scripts/Makefile.extrawarn
index f734033af219..4efedcbe4165 100644
--- a/scripts/Makefile.extrawarn
+++ b/scripts/Makefile.extrawarn
@@ -56,7 +56,7 @@ endif
56KBUILD_CFLAGS += $(warning) 56KBUILD_CFLAGS += $(warning)
57else 57else
58 58
59ifeq ($(COMPILER),clang) 59ifeq ($(cc-name),clang)
60KBUILD_CFLAGS += $(call cc-disable-warning, initializer-overrides) 60KBUILD_CFLAGS += $(call cc-disable-warning, initializer-overrides)
61KBUILD_CFLAGS += $(call cc-disable-warning, unused-value) 61KBUILD_CFLAGS += $(call cc-disable-warning, unused-value)
62KBUILD_CFLAGS += $(call cc-disable-warning, format) 62KBUILD_CFLAGS += $(call cc-disable-warning, format)