Re: [PATCH] kbuild: Support clang-$ver builds

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Oct 28, 2021 at 10:44 PM Peter Zijlstra <peterz@xxxxxxxxxxxxx> wrote:
>
> Hi,
>
> Debian (and derived) distros ship their compilers as -$ver suffixed
> binaries. For gcc it is sufficent to use:
>
>  $ make CC=gcc-12
>
> However, clang builds (esp. clang-lto) need a whole array of tools to be
> exactly right, leading to unweildy stuff like:
>
>  $ make CC=clang-13 LD=ld.lld=14 AR=llvm-ar-13 NM=llvm-nm-13 OBJCOPY=llvm-objcopy-13 OBJDUMP=llvm-objdump-13 READELF=llvm-readelf-13 STRIP=llvm-strip-13 LLVM=1
>
> which is, quite franktly, totally insane and unusable. Instead use the
> already mandatory LLVM variable to convey this, enabling one such as
> myself to use:
>
>  $ make LLVM=-13
>
> This also lets one quickly test different clang versions.


Please read the commit log of
a0d1c951ef08ed24f35129267e3595d86f57f5d3






> Signed-off-by: Peter Zijlstra (Intel) <peterz@xxxxxxxxxxxxx>
> ---
>  Makefile                       | 27 +++++++++++++++++----------
>  tools/scripts/Makefile.include | 23 +++++++++++++++--------
>  2 files changed, 32 insertions(+), 18 deletions(-)
>
> diff --git a/Makefile b/Makefile
> index 30c7c81d0437..a38f38f7f190 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -423,9 +423,16 @@ HOST_LFS_CFLAGS := $(shell getconf LFS_CFLAGS 2>/dev/null)
>  HOST_LFS_LDFLAGS := $(shell getconf LFS_LDFLAGS 2>/dev/null)
>  HOST_LFS_LIBS := $(shell getconf LFS_LIBS 2>/dev/null)
>
> +# When LLVM=-ver use clang-ver binaries, useful for Debian and other
> +# multi-version setups
> +ifeq ($(shell test $(LLVM) -lt 0; echo $$?),0)
> +LLVM_SFX=$(LLVM)
> +export LLVM_SFX
> +endif
> +
>  ifneq ($(LLVM),)
> -HOSTCC = clang
> -HOSTCXX        = clang++
> +HOSTCC = clang$(LLVM_SFX)
> +HOSTCXX        = clang++$(LLVM_SFX)
>  else
>  HOSTCC = gcc
>  HOSTCXX        = g++
> @@ -443,14 +450,14 @@ KBUILD_HOSTLDLIBS   := $(HOST_LFS_LIBS) $(HOSTLDLIBS)
>  # Make variables (CC, etc...)
>  CPP            = $(CC) -E
>  ifneq ($(LLVM),)
> -CC             = clang
> -LD             = ld.lld
> -AR             = llvm-ar
> -NM             = llvm-nm
> -OBJCOPY                = llvm-objcopy
> -OBJDUMP                = llvm-objdump
> -READELF                = llvm-readelf
> -STRIP          = llvm-strip
> +CC             = clang$(LLVM_SFX)
> +LD             = ld.lld$(LLVM_SFX)
> +AR             = llvm-ar$(LLVM_SFX)
> +NM             = llvm-nm$(LLVM_SFX)
> +OBJCOPY                = llvm-objcopy$(LLVM_SFX)
> +OBJDUMP                = llvm-objdump$(LLVM_SFX)
> +READELF                = llvm-readelf$(LLVM_SFX)
> +STRIP          = llvm-strip$(LLVM_SFX)
>  else
>  CC             = $(CROSS_COMPILE)gcc
>  LD             = $(CROSS_COMPILE)ld
> diff --git a/tools/scripts/Makefile.include b/tools/scripts/Makefile.include
> index 071312f5eb92..a2b53cc91378 100644
> --- a/tools/scripts/Makefile.include
> +++ b/tools/scripts/Makefile.include
> @@ -51,12 +51,19 @@ define allow-override
>      $(eval $(1) = $(2)))
>  endef
>
> +# When LLVM=-ver use clang-ver binaries, useful for Debian and other
> +# multi-version setups
> +ifeq ($(shell test $(LLVM) -lt 0; echo $$?),0)
> +LLVM_SFX=$(LLVM)
> +export LLVM_SFX
> +endif
> +
>  ifneq ($(LLVM),)
> -$(call allow-override,CC,clang)
> -$(call allow-override,AR,llvm-ar)
> -$(call allow-override,LD,ld.lld)
> -$(call allow-override,CXX,clang++)
> -$(call allow-override,STRIP,llvm-strip)
> +$(call allow-override,CC,clang$(LLVM_SFX))
> +$(call allow-override,AR,llvm-ar$(LLVM_SFX))
> +$(call allow-override,LD,ld.lld$(LLVM_SFX))
> +$(call allow-override,CXX,clang++$(LLVM_SFX))
> +$(call allow-override,STRIP,llvm-strip$(LLVM_SFX))
>  else
>  # Allow setting various cross-compile vars or setting CROSS_COMPILE as a prefix.
>  $(call allow-override,CC,$(CROSS_COMPILE)gcc)
> @@ -69,9 +76,9 @@ endif
>  CC_NO_CLANG := $(shell $(CC) -dM -E -x c /dev/null | grep -Fq "__clang__"; echo $$?)
>
>  ifneq ($(LLVM),)
> -HOSTAR  ?= llvm-ar
> -HOSTCC  ?= clang
> -HOSTLD  ?= ld.lld
> +HOSTAR  ?= llvm-ar$(LLVM_SFX)
> +HOSTCC  ?= clang$(LLVM_SFX)
> +HOSTLD  ?= ld.lld$(LLVM_SFX)
>  else
>  HOSTAR  ?= ar
>  HOSTCC  ?= gcc



-- 
Best Regards
Masahiro Yamada



[Index of Archives]     [Linux&nblp;USB Development]     [Linux Media]     [Video for Linux]     [Linux Audio Users]     [Yosemite Secrets]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux