2.1 $(strip $(any-prereq) $(arg-check) ) (1) any-prereq在scripts/Kbuild.include中定义
# note:scripts/Kbuild.include any-prereq = $(filter-out $(PHONY),$?) $(filter-out $(PHONY) $(wildcard $^),$^)
$ ? 表示所有比目标还要新的依赖文件;$ ^ 表示所有的依赖文件,$(filter-out $ (PHONY), $?)就是过滤到比目标还要新的依赖文件中的伪目标,即为 scripts/basic/fixdep.c, $ (filter-out $ (PHONY) $ (wildcard $ ^ ), $^)表示过滤掉所有的依赖文件中的伪目标与存在的依赖文件,这里为空,所以any-prereq = scripts/basic/fixdep.c 。(2) arg-check在scripts/Kbuild.include中定义:
# note:scripts/Kbuild.includeifneq ($(KBUILD_NOCMDDEP),1)arg-check = $(strip $(filter-out $(cmd_$(1)), $(cmd_$@)) \$(filter-out $(cmd_$@),$(cmd_$(1))) )elsearg-check = $(if $(strip $(cmd_$@)),,1)endif
KBUILD_NOCMDDEP是在make命令行中定义,我们并没有定义,所以:
arg-check = $(strip $(filter-out $(cmd_$(1)), $(cmd_$@)) $(filter-out $(cmd_$@), $(cmd_$(1))) )
<1> $ (filter-out $ (cmd_ $ (1)), $ (cmd_ $@)) 表示过滤掉 $(cmd_ $@)中符合 $(cmd_ $(1))的项 。$(1)表示if_changed_dep函数的第一个参数host-csingle, $@表示目标文件scripts/basic/fixdep 。<2> cmd_scripts/basic/fixdep并没有定义,所以 $(filter-out $(cmd_ $(1)), $(cmd_ $@))为空; <3> cmd_host-csingle 在Makefile.host中定义:
cmd_host-csingle= $(HOSTCC) $(hostc_flags) -o $@ $<$(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
所以arg-check = $ (filter-out $ (cmd_$ @), $ (cmd_$ (1))) = $ (HOSTCC) $ (hostc_flags) -o $@ $< $(HOST_LOADLIBES) $(HOSTLOADLIBES_ $(@F))
$(any-prereq) $(arg-check)都为非空,所以:
if_changed_dep = @set -e;\ /如果任何语句的执行结果不是true则应该退出 $(echo-cmd) $(cmd_$(1));\ scripts/basic/fixdep $(depfile) $@ '$(make-cmd)' > $(dot-target).tmp;\ rm -f $(depfile);\ mv -f $(dot-target).tmp $(dot-target).cmd)
2.2 $(echo-cmd) $(cmd_ $ (1))等价于$(echo-cmd) $(cmd_host-csingle)
echo-cmd = $(if $( $(quiet)cmd_$(1)),echo '$(call escsq, $( $(quiet)cmd_ $(1))) $(echo-why)';)
quiet=quiet_,在顶层Makefile分析过(当然如果你想看到更详细的打印,您可以通过传入V值,来改变), $(cmd_host-csingle)上面分析过,存在,所以:
echo-cmd = echo '$(call escsq,$(cmd_host-csingle))$(echo-why)';
在scripts/Kbuild.include中:
# Escape single quote for use in echo statementsescsq = $(subst $(squote),'\$(squote)',$1)ifeq ($(KBUILD_VERBOSE),2)why =\$(if $(filter $@, $(PHONY)),- due to target is PHONY,\$(if $(wildcard $@),\$(if $(strip $(any-prereq)),- due to: $(any-prereq),\$(if $(arg-check),\$(if $(cmd_$@),- due to command line change,\$(if $(filter $@, $(targets)),\- due to missing .cmd file,\- due to $(notdir $@) not in $$(targets)\)\)\)\),\- due to target missing\)\)echo-why = $(call escsq, $(strip $(why)))endif
KBUILD_VERBOSE一般我们会采用默认值0(需要调试编译除外),所以 echo-why 为空 。
quiet_cmd_host-csingle= HOSTCC$@ //用来打印cmd_host-csingle ='$(HOSTCC) $(hostc_flags) -o $@ $<$(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))'
$(HOSTCC)为cc,此处不再深入解释,hostc_flags在Makefile.host中定义:
###### Handle options to gcc. Support building with separate output directory_hostc_flags= $(HOSTCFLAGS)$(HOST_EXTRACFLAGS)\$(HOSTCFLAGS_$(basetarget).o) //-Wall -Wstrict-prototypes -O2 -fomit-frame-pointer_hostcxx_flags = $(HOSTCXXFLAGS) $(HOST_EXTRACXXFLAGS) \$(HOSTCXXFLAGS_$(basetarget).o)ifeq ($(KBUILD_SRC),) //KBUILD_SRC在make命令行定义,此处未定义__hostc_flags = $(_hostc_flags)__hostcxx_flags = $(_hostcxx_flags)else__hostc_flags = -I$(obj) $(call flags,_hostc_flags)__hostcxx_flags = -I$(obj) $(call flags,_hostcxx_flags)endifhostc_flags= -Wp,-MD,$(depfile) $(__hostc_flags)
在scripts/Kbuild.include中:
经验总结扩展阅读
- Ubuntu安装Docker及镜像加速器
- 2023年1月29日拆房好不好 2023年1月29日拆房吉日一览表
- 2023年1月29日搬新家吉日一览表 2023年1月29日是搬新家吉日吗
- 2023年1月29日拆迁吉日一览表 2023年农历正月初八宜拆迁吗
- 2023年农历正月初八宜乔迁吗 2023年1月29日乔迁吉日一览表
- 精选600个 唐姓女孩名字2023年属兔
- 取一个寓意好的名字 2023年女宝宝名字库300个
- 水果店名字独一无二 大气的水果店名字
- 丁火男喜欢一个人的表现 疼爱有加情投意合
- 适合文科内向男孩的专业有什么 学什么专业有前途