Re: [PATCH v2] Makefile: Fix detection of clang when cross-compiling
From: Michal Marek
Date: Wed Aug 19 2015 - 11:41:47 EST
On Mon, Jul 13, 2015 at 08:59:33PM +1000, Anton Blanchard wrote:
> Hi,
>
> > > 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.
> > >
> > > v2: Move the detection of clang after the inclusion of the
> > > arch/*/Makefile (as they might set $(CROSS_COMPILE))
> > >
> > > Signed-off-by: Paul Cercueil <paul@xxxxxxxxxxxxxxx
> > <mailto:paul@xxxxxxxxxxxxxxx>>
> >
> > Applied to kbuild.git#kbuild. I will push it after v4.1-rc1
> > becomes available, though.
> >
> > Drat. I wish I saw this earlier.
> >
> > This breaks patches which check for the value of COMPILER in
> > arch/*/Makefile. This detection must be performed before the
> > inclusion of the arch Makefile.
> >
> > Can I move this to after the initialization of CC but before the
> > include?
> >
> > I'm not sure that being able to define the default compiler per arch
> > is necessary. But I know I need to be able to add arch specific flags
> > for clang.
>
> I can confirm the patch breaks ppc64le clang builds.
Can you try the (untested) patch below?