答:分析以下makefile即可获取整个过程
以nxp layerscape系统的编译过程为例
1.分析target/linux/layerscape/image/Makefile的最后一句,这是一个好的开端
$(eval $(call BuildImage))
2.宏BuildImage定义在哪里呢?定义在include/image.mk中,简化后如下
define BuildImage ... $(foreach device,$(TARGET_DEVICES),$(call Device,$(device)) install-images: kernel_prepare $(foreach fs,$(filter-out $(if $(UBIFS_OPTS),,ubifs),$(TARGET_FILESYSTEMS) $(fs-subtypes-y)),$(KDIR)/root.$(fs)) $(foreach fs,$(TARGET_FILESYSTEMS), $(call Image/Build,$(fs)) ) ... endef
3.在宏定义BuildImage中会由上到下根据依赖依次执行,我们首先关注
$(foreach device,$(TARGET_DEVICES),$(call Device,$(device))
4.宏Device又定义在哪里呢?同样定义在include/image.mk文件中,定义简化后如下
define Device ... $(call Device/$(if $(DUMP),Dump,Build),$(1)) endef
5.此时会执行宏Device/Dump或宏Device/Build,那么以执行宏Device/Build为例,宏Device/Build简化后如下
define Device/Build ... $$(eval $$(foreach compile,$$(COMPILE), \ $$(call Device/Build/compile,$$(compile),$(1)))) $$(eval $$(foreach image,$$(IMAGES), \ $$(foreach fs,$$(filter $(TARGET_FILESYSTEMS),$$(FILESYSTEMS)), \ $$(call Device/Build/image,$$(fs),$$(image),$(1))))) endef
6.接着执行宏Device/Build/compile和Device/Build/image,这两个宏都定义在include/image.mk中,在Device/Build/image会做根文件系统制作方面的工作