On Thu, 9 Sept 2021 at 05:20, Masahiro Yamada <masahiroy@xxxxxxxxxx> wrote: > > I sometimes test GNU make 3.81 for kernel builds, but I have not tested > the -e option. > > Now I tested the -e option, and it worked for me. > Both $(M) and $(KBUILD_EXTMOD) were correctly set. > > So, I did not observe anything you claim. Thanks for trying it out. See below for a summary of my test comparing GNUmake 3.81 and 4.1. All the tests have been performed on Ubuntu 14.04. (Yes, I know that's old.) > I ran this Makefile with GNU Make 3.81 > > masahiro@oscar:~/workspace/hello$ cat Makefile > obj-m += hello.o > > KERNEL_DIR := $(HOME)/ref/linux > > all: > ${MAKE} -C $(KERNEL_DIR) -e M=$(PWD) modules > > clean: > make -C $(KERNEL_DIR) M=$(PWD) clean > masahiro@oscar:~/workspace/hello$ make-3.81 --version > GNU Make 3.81 > Copyright (C) 2006 Free Software Foundation, Inc. > This is free software; see the source for copying conditions. > There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A > PARTICULAR PURPOSE. > > This program built for x86_64-unknown-linux-gnu > masahiro@oscar:~/workspace/hello$ make-3.81 > make-3.81 -C /home/masahiro/ref/linux -e > M=/home/masahiro/workspace/hello modules > make-3.81[1]: Entering directory `/home/masahiro/ref/linux' > make-3.81[2]: Entering directory `/home/masahiro/ref/linux' > CC [M] /home/masahiro/workspace/hello/hello.o > MODPOST /home/masahiro/workspace/hello/Module.symvers > CC [M] /home/masahiro/workspace/hello/hello.mod.o > LD [M] /home/masahiro/workspace/hello/hello.ko > make-3.81[2]: Leaving directory `/home/masahiro/ref/linux' > make-3.81[1]: Leaving directory `/home/masahiro/ref/linux' > masahiro@oscar:~/workspace/hello$ ls hello* > hello.c hello.ko hello.mod hello.mod.c hello.mod.o hello.o > > hello.ko was successfully built. > > Entering/Leaving directory is eye-sores, > but presumably it is because MAKEFLAGS is overridden > by the environment since you gave -e. Here is what I have. $ cat Makefile export KERNEL_DIR = /local/users/mmayer/linux-5.4 export CFLAGS_MODULE = -DGREETING_NAME='"Linux"' obj-m += hello-1.o all: ${MAKE} -C $(KERNEL_DIR) -e -r M=$(PWD) modules clean: make -C $(KERNEL_DIR) M=$(PWD) clean $ cat hello-1.c /* * hello-1.c - The simplest kernel module. */ #include <linux/module.h> /* Needed by all modules */ #include <linux/kernel.h> /* Needed for KERN_INFO */ int init_module(void) { printk(KERN_INFO "Hello " GREETING_NAME ".\n"); return 0; } void cleanup_module(void) { printk(KERN_INFO "Goodbye " GREETING_NAME ".\n"); } MODULE_LICENSE("GPL"); Now, if I run make 3.81, this happens. Please note that I added some extra output to the top-level Linux Makefile, which is where some of the extra output is coming from. $ make --version GNU Make 3.81 Copyright (C) 2006 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. This program built for x86_64-pc-linux-gnu $ make hello: CFLAGS_MODULE=-DGREETING_NAME='"Linux"' hello: KBUILD_EXTMOD= make -C /local/users/mmayer/linux-5.4 -e -r M=/local/users/mmayer/hello modules need-sub-make make[1]: Entering directory `/local/users/mmayer/linux-5.4' 1) CFLAGS_MODULE=-DGREETING_NAME='Linux' KBUILD_CFLAGS_MODULE= CFLAGS_MODULE[make]=-DGREETING_NAME='Linux' CFLAGS_MODULE[env]=-DGREETING_NAME='"Linux"' Invoking sub-make... abs_srctree=/local/users/mmayer/linux-5.4 MAKECMDGOALS=modules make -C /local/users/mmayer/linux-5.4 -f /local/users/mmayer/linux-5.4/Makefile modules make[2]: Entering directory `/local/users/mmayer/linux-5.4' KBUILD_CFLAGS_MODULE=-DMODULE CFLAGS_MODULE= KBUILD_CFLAGS_MODULE=-DMODULE CFLAGS_MODULE= KBUILD_CFLAGS_MODULE=-DMODULE CFLAGS_MODULE= CALL scripts/checksyscalls.sh CALL scripts/atomic/check-atomics.sh warning: Cannot use CONFIG_STACK_VALIDATION=y, please install libelf-dev, libelf-devel or elfutils-libelf-devel 2) KBUILD_CFLAGS_MODULE=-DMODULE 2) CFLAGS_MODULE= build=-f ./scripts/Makefile.build obj, @=init 2) KBUILD_CFLAGS_MODULE=-DMODULE 2) CFLAGS_MODULE= build=-f ./scripts/Makefile.build obj, @=usr 2) KBUILD_CFLAGS_MODULE=-DMODULE 2) CFLAGS_MODULE= build=-f ./scripts/Makefile.build obj, @=arch/x86 [...] As you can see, it doesn't pass the value of $(M). Instead, it is running "make modules" because it sees $(M) as empty. If I use make 4.1, it works, even though nothing has changed except for "make" itself. $ ../make-4.2.1/make --version GNU Make 4.2.1 Built for x86_64-pc-linux-gnu Copyright (C) 1988-2016 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. $ ../make-4.2.1/make hello: CFLAGS_MODULE=-DGREETING_NAME='"Linux"' hello: KBUILD_EXTMOD= M=/local/users/mmayer/hello modules /local/users/mmayer/hello/../make-4.2.1/make -C /local/users/mmayer/linux-5.4 -e -r M=/local/users/mmayer/hello modules make[1]: Entering directory '/local/users/mmayer/linux-5.4' KBUILD_CFLAGS_MODULE=-DMODULE CFLAGS_MODULE[make]=-DGREETING_NAME='Linux' CFLAGS_MODULE[env]=-DGREETING_NAME='"Linux"' 2) KBUILD_CFLAGS_MODULE=-DMODULE 2) CFLAGS_MODULE=-DGREETING_NAME='Linux' build=-f ./scripts/Makefile.build obj, @=/local/users/mmayer/hello make[2]: Entering directory '/local/users/mmayer/linux-5.4' hello: CFLAGS_MODULE=-DGREETING_NAME='"Linux"' hello: KBUILD_EXTMOD=/local/users/mmayer/hello CC [M] /local/users/mmayer/hello/hello-1.o make[2]: Leaving directory '/local/users/mmayer/linux-5.4' make[2]: Entering directory '/local/users/mmayer/linux-5.4' hello: CFLAGS_MODULE=-DGREETING_NAME='"Linux"' hello: KBUILD_EXTMOD=/local/users/mmayer/hello Building modules, stage 2. MODPOST 1 modules make[3]: Entering directory '/local/users/mmayer/linux-5.4' CC [M] /local/users/mmayer/hello/hello-1.mod.o LD [M] /local/users/mmayer/hello/hello-1.ko make[3]: Leaving directory '/local/users/mmayer/linux-5.4' make[2]: Leaving directory '/local/users/mmayer/linux-5.4' make[1]: Leaving directory '/local/users/mmayer/linux-5.4' $ lsb_release -d Description: Ubuntu 14.04.5 LTS > I do not understand your motivation for using -e, though. I am not entirely clear on that either, but I have been told it is needed in that particular build environment. Regards, -Markus