在顶层 Makefile 里看到:
[code=Makefile]
# The actual objects are generated when descending,
# make sure no implicit rule kicks in
$(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): $(vmlinux-dirs) ;[/mw_shl_code]
可见 vmlinux-init, vmlinux-main, vmlinux-lds 这 3 个目标都依赖于 vmlinux-dirs 。
对于 vmlinux-dirs 的处理在顶层 Makefile 中可看到:
[code=Makefile]
# Handle descending into subdirectories listed in $(vmlinux-dirs)
# Preset locale variables to speed up the build process. Limit locale
# tweaks to this spot to avoid wrong language settings when running
# make menuconfig etc.
# Error messages still appears in the original language
prepare2 的定义见顶层 Makefile :
[code=Makefile]
# prepare2 creates a makefile if using a separate output directory
prepare2: prepare3 outputmakefile[/mw_shl_code]
outputmakefile 的讨论可参考:http://www.groad.net/bbs/read.php?tid-3895.html
prepare3 的依赖也在定义顶层 Makefile 中:
[code=Makefile]# prepare3 is used to check if we are building in a separate output directory,
# and if so do:
# 1) Check that make has not been executed in the kernel src $(srctree)
prepare3: include/config/kernel.release
[/mw_shl_code]
假设上面的依赖都已经更新完毕,现在回头来看 prepare1 底下的 $(cmd_crmodverdir) 命令,该命令定义在顶层 Makefile 中:
[code=Makefile]
# Create temporary dir for module support files
# clean it up only when building all modules
cmd_crmodverdir = $(Q)mkdir -p $(MODVERDIR) \
$(if $(KBUILD_MODULES),; rm -f $(MODVERDIR)/*)[/mw_shl_code]
上面 $(MODVERDIR) 变量的定义在顶层 Makefile 中:
[code=Makefile]# When compiling out-of-tree modules, put MODVERDIR in the module
# tree rather than in the kernel tree. The kernel tree might
# even be read-only.
export MODVERDIR := $(if $(KBUILD_EXTMOD),$(firstword $(KBUILD_EXTMOD))/).tmp_versions[/mw_shl_code]
如果不是编译外部模块(在命令行中使用 M 选项),那么 $(KBUILD_EXTMOD) 变量为空。也就是说,make vmlinux 时,该变量为空;而如果你编译自己的模块时,才会指定该变量。
另外,当直接执行 make ,make all, make modules 时,$(KBUILD_MODULES) 变量值为 1,而 make vmlinux 时,该变量为 0 。
底下的 if 判断函数里的 “分号” 是因为 $(Q)mkdir -p $(MODVERDIR) 是条 shell 语句,如果一行执行两条命令时,两个命令之间要用分号隔开。