makefile递归调用的优先级是多少?

What is the precedence of recursive invoking of makefile?

拥有这个 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 被读取 2 次。第一次,它设置 $KERNELDIRPWD - else 分支。在第二次阅读时——我的问题来了——它只设置了 $obj-m,但如何设置?在读取 'second' 时,脚本应该调用源目录中的 Makefile(使用 -C 选项调用),因此无法从我的当前目录(之前的目录)中设置 obj-m 变量,它通过 -C 更改为源目录)。还是 $(MAKE) 的第二次调用继承变量?

注意传递给子品牌的选项:M=$(PWD)

这意味着子 make 知道您的 makefile 所在的工作目录(在其 $(M) 变量中),然后可以执行类似 include $(M)/Makefile 的操作来设置您的 obj-m 变量.