On Tue, Jul 20, 2021 at 2:54 PM Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx> wrote: > > But there are other things that stick around. In particular, I have > considered simply using git config variables for that. > > Something like this in the main Makefile: A slightly more fleshed-out patch to do this just to see if somebody wants to work on something like this. It really would seem to make it very easy to set up any random build environment, and not have to remember it once it's done. There are probably better ways to do this, I normally try to avoid doing Makefile magic, since others have taken it over. Masahiro? Linus
Makefile | 50 +++++++++++++++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 19 deletions(-) diff --git a/Makefile b/Makefile index e4f5895badb5..221eb205b475 100644 --- a/Makefile +++ b/Makefile @@ -436,27 +436,39 @@ KBUILD_HOSTCXXFLAGS := -Wall -O2 $(HOST_LFS_CFLAGS) $(HOSTCXXFLAGS) KBUILD_HOSTLDFLAGS := $(HOST_LFS_LDFLAGS) $(HOSTLDFLAGS) KBUILD_HOSTLDLIBS := $(HOST_LFS_LIBS) $(HOSTLDLIBS) -# Make variables (CC, etc...) -CPP = $(CC) -E +# default build environment ('git config' can override) 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 +DEF_CC = clang +DEF_LD = ld.lld +DEF_AR = llvm-ar +DEF_NM = llvm-nm +DEF_OBJCOPY = llvm-objcopy +DEF_OBJDUMP = llvm-objdump +DEF_READELF = llvm-readelf +DEF_STRIP = llvm-strip else -CC = $(CROSS_COMPILE)gcc -LD = $(CROSS_COMPILE)ld -AR = $(CROSS_COMPILE)ar -NM = $(CROSS_COMPILE)nm -OBJCOPY = $(CROSS_COMPILE)objcopy -OBJDUMP = $(CROSS_COMPILE)objdump -READELF = $(CROSS_COMPILE)readelf -STRIP = $(CROSS_COMPILE)strip -endif +DEF_CC = $(CROSS_COMPILE)gcc +DEF_LD = $(CROSS_COMPILE)ld +DEF_AR = $(CROSS_COMPILE)ar +DEF_NM = $(CROSS_COMPILE)nm +DEF_OBJCOPY = $(CROSS_COMPILE)objcopy +DEF_OBJDUMP = $(CROSS_COMPILE)objdump +DEF_READELF = $(CROSS_COMPILE)readelf +DEF_STRIP = $(CROSS_COMPILE)strip +endif + +build-option = $(shell git config --default "$(2)" --get $(1) || echo "$(2)") +CC = $(call build-option,build.cc,$(DEF_CC)) +LD = $(call build-option,build.ld,$(DEF_LD)) +AR = $(call build-option,build.ar,$(DEF_AR)) +NM = $(call build-option,build.nm,$(DEF_NM)) +OBJCOPY = $(call build-option,build.objcopy,$(DEF_OBJCOPY)) +OBJDUMP = $(call build-option,build.objdump,$(DEF_OBJDUMP)) +READELF = $(call build-option,build.readelf,$(DEF_READELF)) +STRIP = $(call build-option,build.strip,$(DEF_STRIP)) + +# Make variables (CC, etc...) +CPP = $(CC) -E PAHOLE = pahole RESOLVE_BTFIDS = $(objtree)/tools/bpf/resolve_btfids/resolve_btfids LEX = flex