[PATCH] Makefile: Add HOST_GCC_SUFFIX and CROSS_GCC_SUFFIX

Palmer Dabbelt posted 1 patch 1 year, 11 months ago
Makefile | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
[PATCH] Makefile: Add HOST_GCC_SUFFIX and CROSS_GCC_SUFFIX
Posted by Palmer Dabbelt 1 year, 11 months ago
From: Palmer Dabbelt <palmer@rivosinc.com>

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).

Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
---
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(-)

diff --git a/Makefile b/Makefile
index f1b2fd977275..36ce336cda3b 100644
--- a/Makefile
+++ b/Makefile
@@ -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
Re: [PATCH] Makefile: Add HOST_GCC_SUFFIX and CROSS_GCC_SUFFIX
Posted by Masahiro Yamada 1 year, 11 months ago
On Fri, Jan 19, 2024 at 4:20 AM Palmer Dabbelt <palmer@rivosinc.com> wrote:
>
> From: Palmer Dabbelt <palmer@rivosinc.com>
>
> 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





>
> 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).
>
> Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
> ---
> 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(-)
>
> diff --git a/Makefile b/Makefile
> index f1b2fd977275..36ce336cda3b 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -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
>
>


-- 
Best Regards
Masahiro Yamada