linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Michael Ellerman <mpe@ellerman.id.au>
To: <linuxppc-dev@lists.ozlabs.org>
Subject: [PATCH 4/4] powerpc/Makefile: Auto detect cross compiler
Date: Wed,  6 Dec 2023 22:55:48 +1100	[thread overview]
Message-ID: <20231206115548.1466874-4-mpe@ellerman.id.au> (raw)
In-Reply-To: <20231206115548.1466874-1-mpe@ellerman.id.au>

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(+)

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
-- 
2.43.0


  parent reply	other threads:[~2023-12-06 11:59 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-06 11:55 [PATCH 1/4] powerpc/Makefile: Don't use $(ARCH) unnecessarily Michael Ellerman
2023-12-06 11:55 ` [PATCH 2/4] powerpc/vdso: No need to undef powerpc for 64-bit build Michael Ellerman
2023-12-06 16:18   ` Segher Boessenkool
2023-12-06 11:55 ` [PATCH 3/4] powerpc/Makefile: Default to ppc64le_defconfig when cross building Michael Ellerman
2023-12-06 11:55 ` Michael Ellerman [this message]
2023-12-06 16:25   ` [PATCH 4/4] powerpc/Makefile: Auto detect cross compiler Segher Boessenkool
2023-12-07  4:48     ` Michael Ellerman
2023-12-21 10:38 ` [PATCH 1/4] powerpc/Makefile: Don't use $(ARCH) unnecessarily Michael Ellerman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231206115548.1466874-4-mpe@ellerman.id.au \
    --to=mpe@ellerman.id.au \
    --cc=linuxppc-dev@lists.ozlabs.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).