Skip to contentSkip to conversation

Makefile: Add HOST_GCC_SUFFIX and CROSS_GCC_SUFFIX

PATCH In review Palmer Dabbelt 2 participants 2 messages Jan 18, 2024 – Jan 19, 2024 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Makefile: Add HOST_GCC_SUFFIX and CROSS_GCC_SUFFIX

From: Palmer Dabbelt <[email protected]>

I was just trying to track down a build bug with an old toolchain. Turns out Ubuntu installs old GCCs as something like riscv64-linux-gnu-gcc-10, which is a bit clunky to point the build at without a way to append a suffix to CC.

There's already LLVM_SUFFIX, but nothing similar for GCC. I've split out the host and target suffixes as users probably don't have the same version of for both (unlike LLVM, where the cross compiler is likely to support the host target).

---
I've only given this some very minimal testing, but it at least works for my simple use case.

---
 Makefile | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
Makefile +3 -3
index f1b2fd977275..36ce336cda3b 100644
@@ -433,8 +433,8 @@ endif
 HOSTCC	= $(LLVM_PREFIX)clang$(LLVM_SUFFIX)
 HOSTCXX	= $(LLVM_PREFIX)clang++$(LLVM_SUFFIX)
 else
-HOSTCC	= gcc
-HOSTCXX	= g++
+HOSTCC	= gcc$(HOST_GCC_SUFFIX)
+HOSTCXX	= g++$(HOST_GCC_SUFFIX)
 endif
 HOSTRUSTC = rustc
 HOSTPKG_CONFIG	= pkg-config
@@ -480,7 +480,7 @@ OBJDUMP		= $(LLVM_PREFIX)llvm-objdump$(LLVM_SUFFIX)
 READELF		= $(LLVM_PREFIX)llvm-readelf$(LLVM_SUFFIX)
 STRIP		= $(LLVM_PREFIX)llvm-strip$(LLVM_SUFFIX)
 else
-CC		= $(CROSS_COMPILE)gcc
+CC		= $(CROSS_COMPILE)gcc$(CROSS_GCC_SUFFIX)
 LD		= $(CROSS_COMPILE)ld
 AR		= $(CROSS_COMPILE)ar
 NM		= $(CROSS_COMPILE)nm
Signature · 1 line
2.43.0
#1 lore raw
Quoted 7 lines · Palmer Dabbelt

From: Palmer Dabbelt <[email protected]>

I was just trying to track down a build bug with an old toolchain. Turns out Ubuntu installs old GCCs as something like riscv64-linux-gnu-gcc-10, which is a bit clunky to point the build at without a way to append a suffix to CC.

You can do:

make CROSS_COMPILE=riscv64-linux-gnu- CC=riscv64-linux-gnu-gcc-10

Quoted 42 lines

There's already LLVM_SUFFIX, but nothing similar for GCC. I've split out the host and target suffixes as users probably don't have the same version of for both (unlike LLVM, where the cross compiler is likely to support the host target).

---
I've only given this some very minimal testing, but it at least works for my simple use case.

---
 Makefile | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
Makefile +3 -4
index f1b2fd977275..36ce336cda3b 100644
@@ -433,8 +433,8 @@ endif
 HOSTCC = $(LLVM_PREFIX)clang$(LLVM_SUFFIX)
 HOSTCXX        = $(LLVM_PREFIX)clang++$(LLVM_SUFFIX)
 else
-HOSTCC = gcc
-HOSTCXX        = g++
+HOSTCC = gcc$(HOST_GCC_SUFFIX)
+HOSTCXX        = g++$(HOST_GCC_SUFFIX)
 endif
 HOSTRUSTC = rustc
 HOSTPKG_CONFIG = pkg-config
@@ -480,7 +480,7 @@ OBJDUMP             = $(LLVM_PREFIX)llvm-objdump$(LLVM_SUFFIX)
 READELF                = $(LLVM_PREFIX)llvm-readelf$(LLVM_SUFFIX)
 STRIP          = $(LLVM_PREFIX)llvm-strip$(LLVM_SUFFIX)
 else
-CC             = $(CROSS_COMPILE)gcc
+CC             = $(CROSS_COMPILE)gcc$(CROSS_GCC_SUFFIX)
 LD             = $(CROSS_COMPILE)ld
 AR             = $(CROSS_COMPILE)ar
 NM             = $(CROSS_COMPILE)nm
--

2.43.0

Signature · 2 lines
Best Regards
Masahiro Yamada