All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Makefile: Fix detection of clang when cross-compiling
@ 2015-04-09 14:34 ` Paul Cercueil
  0 siblings, 0 replies; 3+ messages in thread
From: Paul Cercueil @ 2015-04-09 14:34 UTC (permalink / raw)
  To: Michal Marek; +Cc: linux-kbuild, linux-kernel, Paul Cercueil

When the host's C compiler is clang, and when attempting to
cross-compile Linux e.g. to MIPS with mipsel-linux-gcc, the Makefile
would incorrectly detect the use of clang, which resulted in
clang-specific flags being passed to mipsel-linux-gcc.

This can be verified under Debian by installing the "clang" package,
and then using it as the default compiler with:
sudo update-alternatives --config cc

This patch moves the detection of clang after the $(CC) variable is
initialized to the name of the cross-compiler, so that the check applies
to the cross-compiler and not the host's C compiler.

Signed-off-by: Paul Cercueil <paul@crapouillou.net>
---
 Makefile | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/Makefile b/Makefile
index 54430f9..5fff1b2 100644
--- a/Makefile
+++ b/Makefile
@@ -335,15 +335,6 @@ endif
 export KBUILD_MODULES KBUILD_BUILTIN
 export KBUILD_CHECKSRC KBUILD_SRC KBUILD_EXTMOD
 
-ifneq ($(CC),)
-ifeq ($(shell $(CC) -v 2>&1 | grep -c "clang version"), 1)
-COMPILER := clang
-else
-COMPILER := gcc
-endif
-export COMPILER
-endif
-
 # Look for make include files relative to root of kernel src
 MAKEFLAGS += --include-dir=$(srctree)
 
@@ -369,6 +360,13 @@ PERL		= perl
 PYTHON		= python
 CHECK		= sparse
 
+ifeq ($(shell $(CC) -v 2>&1 | grep -c "clang version"), 1)
+COMPILER := clang
+else
+COMPILER := gcc
+endif
+export COMPILER
+
 CHECKFLAGS     := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ \
 		  -Wbitwise -Wno-return-void $(CF)
 CFLAGS_MODULE   =
-- 
2.1.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH] Makefile: Fix detection of clang when cross-compiling
@ 2015-04-09 14:34 ` Paul Cercueil
  0 siblings, 0 replies; 3+ messages in thread
From: Paul Cercueil @ 2015-04-09 14:34 UTC (permalink / raw)
  To: Michal Marek; +Cc: linux-kbuild, linux-kernel, Paul Cercueil

When the host's C compiler is clang, and when attempting to
cross-compile Linux e.g. to MIPS with mipsel-linux-gcc, the Makefile
would incorrectly detect the use of clang, which resulted in
clang-specific flags being passed to mipsel-linux-gcc.

This can be verified under Debian by installing the "clang" package,
and then using it as the default compiler with:
sudo update-alternatives --config cc

This patch moves the detection of clang after the $(CC) variable is
initialized to the name of the cross-compiler, so that the check applies
to the cross-compiler and not the host's C compiler.

Signed-off-by: Paul Cercueil <paul@crapouillou.net>
---
 Makefile | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/Makefile b/Makefile
index 54430f9..5fff1b2 100644
--- a/Makefile
+++ b/Makefile
@@ -335,15 +335,6 @@ endif
 export KBUILD_MODULES KBUILD_BUILTIN
 export KBUILD_CHECKSRC KBUILD_SRC KBUILD_EXTMOD
 
-ifneq ($(CC),)
-ifeq ($(shell $(CC) -v 2>&1 | grep -c "clang version"), 1)
-COMPILER := clang
-else
-COMPILER := gcc
-endif
-export COMPILER
-endif
-
 # Look for make include files relative to root of kernel src
 MAKEFLAGS += --include-dir=$(srctree)
 
@@ -369,6 +360,13 @@ PERL		= perl
 PYTHON		= python
 CHECK		= sparse
 
+ifeq ($(shell $(CC) -v 2>&1 | grep -c "clang version"), 1)
+COMPILER := clang
+else
+COMPILER := gcc
+endif
+export COMPILER
+
 CHECKFLAGS     := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ \
 		  -Wbitwise -Wno-return-void $(CF)
 CFLAGS_MODULE   =
-- 
2.1.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] Makefile: Fix detection of clang when cross-compiling
  2015-04-09 14:34 ` Paul Cercueil
  (?)
@ 2015-04-11 19:34 ` Michal Marek
  -1 siblings, 0 replies; 3+ messages in thread
From: Michal Marek @ 2015-04-11 19:34 UTC (permalink / raw)
  To: Paul Cercueil; +Cc: linux-kbuild, linux-kernel

On Thu, Apr 09, 2015 at 04:34:54PM +0200, Paul Cercueil wrote:
> When the host's C compiler is clang, and when attempting to
> cross-compile Linux e.g. to MIPS with mipsel-linux-gcc, the Makefile
> would incorrectly detect the use of clang, which resulted in
> clang-specific flags being passed to mipsel-linux-gcc.
> 
> This can be verified under Debian by installing the "clang" package,
> and then using it as the default compiler with:
> sudo update-alternatives --config cc
> 
> This patch moves the detection of clang after the $(CC) variable is
> initialized to the name of the cross-compiler, so that the check applies
> to the cross-compiler and not the host's C compiler.
> 
> Signed-off-by: Paul Cercueil <paul@crapouillou.net>
> ---
>  Makefile | 16 +++++++---------
>  1 file changed, 7 insertions(+), 9 deletions(-)
> 
> diff --git a/Makefile b/Makefile
> index 54430f9..5fff1b2 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -335,15 +335,6 @@ endif
>  export KBUILD_MODULES KBUILD_BUILTIN
>  export KBUILD_CHECKSRC KBUILD_SRC KBUILD_EXTMOD
>  
> -ifneq ($(CC),)
> -ifeq ($(shell $(CC) -v 2>&1 | grep -c "clang version"), 1)
> -COMPILER := clang
> -else
> -COMPILER := gcc
> -endif
> -export COMPILER
> -endif
> -
>  # Look for make include files relative to root of kernel src
>  MAKEFLAGS += --include-dir=$(srctree)
>  
> @@ -369,6 +360,13 @@ PERL		= perl
>  PYTHON		= python
>  CHECK		= sparse
>  
> +ifeq ($(shell $(CC) -v 2>&1 | grep -c "clang version"), 1)
> +COMPILER := clang
> +else
> +COMPILER := gcc
> +endif
> +export COMPILER

It should be moved even deeper, after the inclusion of arch/*/Makefile.
There are architectures which set $(CROSS_COMPILE) by default, as a
convenience.

Michal

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-04-11 19:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-09 14:34 [PATCH] Makefile: Fix detection of clang when cross-compiling Paul Cercueil
2015-04-09 14:34 ` Paul Cercueil
2015-04-11 19:34 ` Michal Marek

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.