在scripts/Makefile.build有如下定义
# note:scripts/Makefile.build# Modified for U-Bootprefix := tplsrc := $(patsubst $(prefix)/%,%,$(obj))ifeq ($(obj),$(src))prefix := splsrc := $(patsubst $(prefix)/%,%,$(obj))ifeq ($(obj),$(src))prefix := .endifendif
在命令make -f ./scripts/Makefile.build obj=scripts/basic我们传入了obj=scripts/basic 所以src = https://www.huyubaike.com/biancheng/obj = scripts/basic, prefix := .
4.1.4.2 kbuild-dir的定义在scripts/Makefile.build有如下定义
kbuild-dir := $(if $(filter /%,$(src)),$(src),$(srctree)/$(src))
所以 kbuild-dir = ./scripts/basic
4.1.4.3 kbuild-file的定义在scripts/Makefile.build有如下定义
kbuild-file := $(if $(wildcard $(kbuild-dir)/Kbuild),$(kbuild-dir)/Kbuild,$(kbuild-dir)/Makefile)
所以kbuild-file = ./scripts/basic/Makefile
所以include $(kbuild-file)即为include ./scripts/basic/Makefile
在./scripts/basic/Makefile中:
# note:scripts/basic/Makefilehostprogs-y := fixdepalways:= $(hostprogs-y)# fixdep is needed to compile other host programs$(addprefix $(obj)/,$(filter-out fixdep,$(always))): $(obj)/fixdep
所以always = fixdep
4.1.4.4 又在Makefile.build中包含include scripts/Makefile.lib而在scripts/Makefile.lib中
# note:scripts/Makefile.libalways:= $(addprefix $(obj)/,$(always))
所以最终 always = scripts/basic/fixdep。
故__build 展开如下: __build: scripts/basic/fixdep@:1. 在Makefile.build中有如下定义:
# note:scripts/Makefile.buildifneq ($(hostprogs-y)$(hostprogs-m),)include scripts/Makefile.hostendif
在./scripts/basic/Makefile中hostprogs-y = fixdep, 所以scripts/Makefile.host被包含进Makefile.build;在scripts/Makefile.host中# note:scripts/Makefile.host__hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
hostprogs-m为空,所以__hostprogs = fixdep 。在scripts/Makefile.host中# note:scripts/Makefile.host# C code# Executables compiled from a single .c filehost-csingle := $(foreach m,$(__hostprogs), \$(if $($(m)-objs)$($(m)-cxxobjs)$($(m)-sharedobjs),,$(m)))......host-csingle := $(addprefix $(obj)/,$(host-csingle))
因为fixdep-objs与fixdep-cxxobjs都不存在,所以host-csingle = fixdep; 又 host-csingle := $ (addprefix $ (obj)/,$(host-csingle)) , 所以host-csingle = scripts/basic/fixdep 。host-csingle规则如下:# note:scripts/Makefile.host$(host-csingle): $(obj)/%: $(src)/%.c FORCE $(call if_changed_dep,host-csingle)
等价于:scripts/basic/fixdep:scripts/basic/fixdep.c FORCE$(call if_changed_dep,host-csingle)
2. if_changed_dep在scripts/Kbuild.include中定义# note:scripts/Kbuild.include# Execute the command and also postprocess generated .d dependencies file.if_changed_dep = $(if $(strip $(any-prereq) $(arg-check) ),\ @set -e;\ $(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.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)
推荐阅读
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Ubuntu安装Docker及镜像加速器
- HYTHIOL-C PLUS白兔牌美白丸 吃了一个月后的反馈
- 十一 前后端分离项目:实现"删"功能(前后端)
- 七 pod:静态pod
- 夯实Java基础,一篇文章全解析线程问题
- 天猫童装店铺销量排行榜前十,巴拉巴拉童装销量第一
- 红魔6SPro参数配置_参数详情
- 电脑玩游戏很卡,根本带不动怎么办(电脑玩游戏玩一会就卡怎么办)
- 玩游戏卡怎么办(一招恢复手机卡顿)
- 怎么画羊简笔画四年级(画一个最简单的羊)