[U-Boot] [PATCH 1/2] kbuild: Add clang detection

Adapted from:
From 5631d9c429857194bd55d7bcd8fa5bdd1a9899a3 Mon Sep 17 00:00:00 2001
From: Michal Marek mmarek@suse.com Date: Wed, 19 Aug 2015 17:36:41 +0200 Subject: [PATCH 1/1] 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
in the Linux kernel.
This will allow us to make better decisions about when to run tests later on for gcc features.
Signed-off-by: Tom Rini trini@konsulko.com --- scripts/Kbuild.include | 4 ++++ 1 file changed, 4 insertions(+)
diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include index 98e09ce..30e6e31 100644 --- a/scripts/Kbuild.include +++ b/scripts/Kbuild.include @@ -130,6 +130,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))

For compatibility clang will report some gcc version. However since we are checking gcc versions in order to then fail to build, we should limit these tests only to when we are using gcc and not clang.
Signed-off-by: Tom Rini trini@konsulko.com --- arch/arm/config.mk | 3 ++- arch/powerpc/config.mk | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/arch/arm/config.mk b/arch/arm/config.mk index 0550225..a3e14a8 100644 --- a/arch/arm/config.mk +++ b/arch/arm/config.mk @@ -40,7 +40,8 @@ ifeq ($(CONFIG_SYS_THUMB_BUILD),y) archprepare: checkthumb
checkthumb: - @if test "$(call cc-version)" -lt "0404"; then \ + @if test "$(call cc-name)" = "gcc" -a \ + "$(call cc-version)" -lt "0404"; then \ echo -n '*** Your GCC does not produce working '; \ echo 'binaries in THUMB mode.'; \ echo '*** Your board is configured for THUMB mode.'; \ diff --git a/arch/powerpc/config.mk b/arch/powerpc/config.mk index 6b44a37..b0ed374 100644 --- a/arch/powerpc/config.mk +++ b/arch/powerpc/config.mk @@ -41,7 +41,8 @@ archprepare: checkgcc4 # that U-Boot wants. # See http://lists.denx.de/pipermail/u-boot/2012-September/135156.html checkgcc4: - @if test $(call cc-version) -lt 0400; then \ + @if test "$(call cc-name)" = "gcc" -a \ + $(call cc-version) -lt 0400; then \ echo -n '*** Your GCC is too old, please upgrade to GCC 4.x or newer'; \ false; \ fi

On Tue, Jan 19, 2016 at 08:39:02PM -0500, Tom Rini wrote:
For compatibility clang will report some gcc version. However since we are checking gcc versions in order to then fail to build, we should limit these tests only to when we are using gcc and not clang.
Signed-off-by: Tom Rini trini@konsulko.com
Applied to u-boot/master, thanks!

On Tue, Jan 19, 2016 at 08:39:01PM -0500, Tom Rini wrote:
Adapted from:
From 5631d9c429857194bd55d7bcd8fa5bdd1a9899a3 Mon Sep 17 00:00:00 2001
From: Michal Marek mmarek@suse.com Date: Wed, 19 Aug 2015 17:36:41 +0200 Subject: [PATCH 1/1] 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
in the Linux kernel.
This will allow us to make better decisions about when to run tests later on for gcc features.
Signed-off-by: Tom Rini trini@konsulko.com
Applied to u-boot/master, thanks!
participants (1)
-
Tom Rini