具有此makefile:
# If KERNELRELEASE is defined, we've been invoked from the
# kernel build system and can use its language.
ifneq ($(KERNELRELEASE),)
obj-m := module.o
# Otherwise we were called directly from the command
# line; invoke the kernel build system.
else
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
default:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
endif
我只有一个问题。此makefile被读取两次。首次设置$KERNELDIR
和PWD
-else
分支。在二读时-出现了我的问题-它仅设置$obj-m
,但如何设置?到“第二”读时,脚本应在源目录中调用Makefile(如-C
选项所调用),因此无法从当前目录中设置obj-m
变量(之前的目录已更改为源目录)通过-C
)。还是第二次通过$(MAKE)
调用会继承变量?
注意传递给子品牌的选项:M=$(PWD)
这意味着子make知道makefile所在的工作目录(在其$(M)
变量中,然后可以执行类似include $(M)/Makefile
的操作来设置您的obj-m
变量。