1. openwrt_widora/Makefile
world: 主目标
include $(TOPDIR)/include/host.mk
ifneq ($(OPENWRT_BUILD),1) //第一次运行
_SINGLE=export MAKEFLAGS=$(space);
override OPENWRT_BUILD=1
export OPENWRT_BUILD
GREP_OPTIONS=
export GREP_OPTIONS
include $(TOPDIR)/include/debug.mk
include $(TOPDIR)/include/depends.mk
include $(TOPDIR)/include/toplevel.mk
else // OPENWRT_BUILD = 1,第一次运行以后执行下面
include rules.mk
include $(INCLUDE_DIR)/depends.mk
include $(INCLUDE_DIR)/subdir.mk
include target/Makefile
include package/Makefile
include tools/Makefile
include toolchain/Makefile
在这里引入了
include target/Makefile include package/Makefile include tools/Makefile include toolchain/Makefile
这些子目录里的Makefile使用include/subdir.mk里定义的两个函数来动态生成规则,这两个函数是subdir和stampfile
拿target/Makefile举例:
(eval(call stampfile,$(curdir),target,prereq,.config))
会生成规则:
target/stamp-prereq:=$(STAGING_DIR)/stamp/.target_prereq
$$(target/stamp-prereq): $(TMP_DIR)/.build .config
@+$(SCRIPT_DIR)/timestamp.pl -n $$(target/stamp-prereq) target .config || \
make $$(target/flags-prereq) target/prereq
@mkdir -p $$$$(dirname $$(target/stamp-prereq))
@touch $$(target/stamp-prereq)
$$(if $(call debug,target,v),,.SILENT: $$(target/stamp-prereq))
.PRECIOUS: $$(target/stamp-prereq) # work around a make bug
target//clean:=target/stamp-prereq/clean
target/stamp-prereq/clean: FORCE
@rm -f $$(target/stamp-prereq)
拿target/Makefile举例:
(eval(call stampfile,$(curdir),target,prereq,.config))
会生成规则:
target/stamp-prereq:=$(STAGING_DIR)/stamp/.target_prereq
$$(target/stamp-prereq): $(TMP_DIR)/.build .config
@+$(SCRIPT_DIR)/timestamp.pl -n $$(target/stamp-prereq) target .config || \
make $$(target/flags-prereq) target/prereq
@mkdir -p $$$$(dirname $$(target/stamp-prereq))
@touch $$(target/stamp-prereq)
$$(if $(call debug,target,v),,.SILENT: $$(target/stamp-prereq))
.PRECIOUS: $$(target/stamp-prereq) # work around a make bug
target//clean:=target/stamp-prereq/clean
target/stamp-prereq/clean: FORCE
@rm -f $$(target/stamp-prereq)
所以可以简单的看作: (eval(call stampfile,(curdir),target,prereq,.config))生成了目标(target/stamp-prereq)
- 对于target分别生成了:(target/stamp-preq),(target/stamp-copile), $(target/stamp-install)
- toolchain : $(toolchain/stamp-install)
- package : (package/stamp?preq),(package/stamp-cleanup), (package/stamp?compile),(package/stamp-install)
- tools : $(tools/stamp-install)
subdir
subdir这个函数写了一大堆东西,看起来很复杂 。
$(call subdir, target) 会遍历下的子目录,执行 make -C 操作。这样就切入子目录中去了