Skip to content

Commit

Permalink
kbuild: Fix clang detection
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reported-by: Anton Blanchard <[email protected]>
Signed-off-by: Michal Marek <[email protected]>
  • Loading branch information
Michal Marek committed Sep 4, 2015
1 parent d179e22 commit 5631d9c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 13 deletions.
9 changes: 1 addition & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -661,14 +661,7 @@ endif
endif
KBUILD_CFLAGS += $(stackp-flag)

ifeq ($(shell $(CC) -v 2>&1 | grep -c "clang version"), 1)
COMPILER := clang
else
COMPILER := gcc
endif
export COMPILER

ifeq ($(COMPILER),clang)
ifeq ($(cc-name),clang)
KBUILD_CPPFLAGS += $(call cc-option,-Qunused-arguments,)
KBUILD_CPPFLAGS += $(call cc-option,-Wno-unknown-warning-option,)
KBUILD_CFLAGS += $(call cc-disable-warning, unused-variable)
Expand Down
8 changes: 4 additions & 4 deletions arch/powerpc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ UTS_MACHINE := $(OLDARCH)

ifeq ($(CONFIG_CPU_LITTLE_ENDIAN),y)
override CC += -mlittle-endian
ifneq ($(COMPILER),clang)
ifneq ($(cc-name),clang)
override CC += -mno-strict-align
endif
override AS += -mlittle-endian
Expand Down Expand Up @@ -333,7 +333,7 @@ TOUT := .tmp_gas_check
# - Require gcc 4.0 or above on 64-bit
# - gcc-4.2.0 has issues compiling modules on 64-bit
checkbin:
@if test "${COMPILER}" != "clang" \
@if test "$(cc-name)" != "clang" \
&& test "$(cc-version)" = "0304" ; then \
if ! /bin/echo mftb 5 | $(AS) -v -mppc -many -o $(TOUT) >/dev/null 2>&1 ; then \
echo -n '*** ${VERSION}.${PATCHLEVEL} kernels no longer build '; \
Expand All @@ -342,14 +342,14 @@ checkbin:
false; \
fi ; \
fi
@if test "${COMPILER}" != "clang" \
@if test "$(cc-name)" != "clang" \
&& test "$(cc-version)" -lt "0400" \
&& test "x${CONFIG_PPC64}" = "xy" ; then \
echo -n "Sorry, GCC v4.0 or above is required to build " ; \
echo "the 64-bit powerpc kernel." ; \
false ; \
fi
@if test "${COMPILER}" != "clang" \
@if test "$(cc-name)" != "clang" \
&& test "$(cc-fullversion)" = "040200" \
&& test "x${CONFIG_MODULES}${CONFIG_PPC64}" = "xyy" ; then \
echo -n '*** GCC-4.2.0 cannot compile the 64-bit powerpc ' ; \
Expand Down
4 changes: 4 additions & 0 deletions scripts/Kbuild.include
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ cc-option-align = $(subst -functions=0,,\
cc-disable-warning = $(call try-run,\
$(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) -W$(strip $(1)) -c -x c /dev/null -o "$$TMP",-Wno-$(strip $(1)))

# cc-name
# Expands to either gcc or clang
cc-name = $(shell $(CC) -v 2>&1 | grep -q "clang version" && echo clang || echo gcc)

# cc-version
cc-version = $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-version.sh $(CC))

Expand Down
2 changes: 1 addition & 1 deletion scripts/Makefile.extrawarn
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ endif
KBUILD_CFLAGS += $(warning)
else

ifeq ($(COMPILER),clang)
ifeq ($(cc-name),clang)
KBUILD_CFLAGS += $(call cc-disable-warning, initializer-overrides)
KBUILD_CFLAGS += $(call cc-disable-warning, unused-value)
KBUILD_CFLAGS += $(call cc-disable-warning, format)
Expand Down

0 comments on commit 5631d9c

Please sign in to comment.