diff mbox series

[4/4] powerpc/Makefile: Auto detect cross compiler

Message ID 20231206115548.1466874-4-mpe@ellerman.id.au (mailing list archive)
State Accepted
Commit 402928b58ec62b42b11992a7b51ff2f56ed65a18
Headers show
Series [1/4] powerpc/Makefile: Don't use $(ARCH) unnecessarily | expand

Checks

Context Check Description
snowpatch_ozlabs/github-powerpc_selftests success Successfully ran 8 jobs.
snowpatch_ozlabs/github-powerpc_ppctests success Successfully ran 8 jobs.
snowpatch_ozlabs/github-powerpc_sparse success Successfully ran 4 jobs.
snowpatch_ozlabs/github-powerpc_clang success Successfully ran 6 jobs.
snowpatch_ozlabs/github-powerpc_kernel_qemu success Successfully ran 23 jobs.

Commit Message

Michael Ellerman Dec. 6, 2023, 11:55 a.m. UTC
If no cross compiler is specified, try to auto detect one.

Look for various combinations, matching:
  powerpc(64(le)?)?(-unknown)?-linux(-gnu)?-

There are more possibilities, but the above is known to find a compiler
on Fedora and Ubuntu (which use linux-gnu-), and also detects the
kernel.org cross compilers (which use linux-).

This allows cross compiling with simply:

 # Ubuntu
 $ sudo apt install gcc-powerpc-linux-gnu
 # Fedora
 $ sudo dnf install gcc-powerpc64-linux-gnu

 $ make ARCH=powerpc defconfig
 $ make ARCH=powerpc -j 4

Inspired by arch/parisc/Makefile.

Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
---
 arch/powerpc/Makefile | 11 +++++++++++
 1 file changed, 11 insertions(+)

Comments

Segher Boessenkool Dec. 6, 2023, 4:25 p.m. UTC | #1
On Wed, Dec 06, 2023 at 10:55:48PM +1100, Michael Ellerman wrote:
> Look for various combinations, matching:
>   powerpc(64(le)?)?(-unknown)?-linux(-gnu)?-
> 
> There are more possibilities, but the above is known to find a compiler
> on Fedora and Ubuntu (which use linux-gnu-), and also detects the
> kernel.org cross compilers (which use linux-).

$ sh ../config.sub powerpc64-linux
powerpc64-unknown-linux-gnu

I am very very lazy, so buildall uses short names everywhere :-)

Btw, can you build the kernel for a config that differs in 32/64 or
BE/LE with the default your compiler uses?  There is no reason this
shouldn't work (you don't use any system libraries), but you need to
use the correct compiler command-line flags for that always.

Acked-by: Segher Boessenkool <segher@kernel.crashing.org>


Segher
Michael Ellerman Dec. 7, 2023, 4:48 a.m. UTC | #2
Segher Boessenkool <segher@kernel.crashing.org> writes:
> On Wed, Dec 06, 2023 at 10:55:48PM +1100, Michael Ellerman wrote:
>> Look for various combinations, matching:
>>   powerpc(64(le)?)?(-unknown)?-linux(-gnu)?-
>> 
>> There are more possibilities, but the above is known to find a compiler
>> on Fedora and Ubuntu (which use linux-gnu-), and also detects the
>> kernel.org cross compilers (which use linux-).
>
> $ sh ../config.sub powerpc64-linux
> powerpc64-unknown-linux-gnu
>
> I am very very lazy, so buildall uses short names everywhere :-)

I used to use just ppc64-gcc :)

I can add more variants but didn't want to add too many unless someone
is actually using them.

> Btw, can you build the kernel for a config that differs in 32/64 or
> BE/LE with the default your compiler uses?  There is no reason this
> shouldn't work (you don't use any system libraries), but you need to
> use the correct compiler command-line flags for that always.

Yes it should work. I've tested at least ppc64le/ppc64/ppc defconfigs.

There have been bugs in the past but AFAIK we have fixed all of them,
though there's probably some still lurking for more obscure configs.

> Acked-by: Segher Boessenkool <segher@kernel.crashing.org>

Thanks.

cheers
diff mbox series

Patch

diff --git a/arch/powerpc/Makefile b/arch/powerpc/Makefile
index 48c06f5a0dc1..051247027da0 100644
--- a/arch/powerpc/Makefile
+++ b/arch/powerpc/Makefile
@@ -10,6 +10,17 @@ 
 # Rewritten by Cort Dougan and Paul Mackerras
 #
 
+ifdef cross_compiling
+  ifeq ($(CROSS_COMPILE),)
+    # Auto detect cross compiler prefix.
+    # Look for: (powerpc(64(le)?)?)(-unknown)?-linux(-gnu)?-
+    CC_ARCHES := powerpc powerpc64 powerpc64le
+    CC_SUFFIXES := linux linux-gnu unknown-linux-gnu
+    CROSS_COMPILE := $(call cc-cross-prefix, $(foreach a,$(CC_ARCHES), \
+                       $(foreach s,$(CC_SUFFIXES),$(a)-$(s)-)))
+  endif
+endif
+
 HAS_BIARCH	:= $(call cc-option-yn, -m32)
 
 # Set default 32 bits cross compilers for vdso and boot wrapper