Boot 顶层Makefile解析(5)

#########################################################################
#########################################################################
# u-boot.srec u-boot.bin ...an so on

ALL = $(obj)u-boot.srec $(obj)u-boot.bin $(obj)System.map $(U_BOOT_NAND)


all:  $(ALL)


$(obj)u-boot.hex: $(obj)u-boot
  $(OBJCOPY) ${OBJCFLAGS} -O ihex $< $@


$(obj)u-boot.srec: $(obj)u-boot
  $(OBJCOPY) ${OBJCFLAGS} -O srec $< $@


$(obj)u-boot.bin: $(obj)u-boot
  $(OBJCOPY) ${OBJCFLAGS} -O binary $< $@


$(obj)u-boot.img: $(obj)u-boot.bin
  ./tools/mkimage -A $(ARCH) -T firmware -C none \
  -a $(TEXT_BASE) -e 0 \
  -n $(shell sed -n -e 's/.*U_BOOT_VERSION//p' $(VERSION_FILE) | \
   sed -e 's/"[  ]*$$/ for $(BOARD) board"/') \
  -d $< $@


$(obj)u-boot.dis: $(obj)u-boot
  $(OBJDUMP) -d $< > $@


$(obj)u-boot:  depend version $(SUBDIRS) $(OBJS) $(LIBS) $(LDSCRIPT)
  UNDEF_SYM=`$(OBJDUMP) -x $(LIBS) |sed  -n -e 's/.*\(__u_boot_cmd_.*\)/-u\1/p'|sort|uniq`;\
  cd $(LNDIR) && $(LD) $(LDFLAGS) $$UNDEF_SYM $(__OBJS) \
   --start-group $(__LIBS) --end-group $(PLATFORM_LIBS) \
   -Map u-boot.map -o u-boot

# $(OBJS) cpu/start.o
$(OBJS):
  $(MAKE) -C cpu/$(CPU) $(if $(REMOTE_BUILD),$@,$(notdir $@))

# $(LIBS)为每个子目录下的*.a 通过自动变量$@ 使得每个子目录下的Makefile得以执行 完成库文件的创建
$(LIBS):
  $(MAKE) -C $(dir $(subst $(obj),,$@))


$(SUBDIRS):
  $(MAKE) -C $@ all


$(NAND_SPL): version
  $(MAKE) -C nand_spl/board/$(BOARDDIR) all


$(U_BOOT_NAND): $(NAND_SPL) $(obj)u-boot.bin
  cat $(obj)nand_spl/u-boot-spl-16k.bin $(obj)u-boot.bin > $(obj)u-boot-nand.bin


version:
  @echo -n "#define U_BOOT_VERSION \"U-Boot " > $(VERSION_FILE); \
  echo -n "$(U_BOOT_VERSION)" >> $(VERSION_FILE); \
  echo -n $(shell $(CONFIG_SHELL) $(TOPDIR)/tools/setlocalversion \
    $(TOPDIR)) >> $(VERSION_FILE); \
  echo "\"" >> $(VERSION_FILE)
# >> $(VERSION_FILE) 追加版本信息到VERSION_FILE中


gdbtools:
  $(MAKE) -C tools/gdb all || exit 1


updater:
  $(MAKE) -C tools/updater all || exit 1


env:
  $(MAKE) -C tools/env all || exit 1


depend dep:
  for dir in $(SUBDIRS) ; do $(MAKE) -C $$dir _depend ; done
# 依赖目标depend:生成各个子目录.depend文件.  .depend列出每个目标文件的依赖文件。
# 生成方法:调用每个子目录的make_depend
# it's  .d??
# 以下:.d 文件
# GNU组织建议把编译器为每一个源文件的自动生成的依赖关系放到一个文件中,为每一个“name.c”的文件都生成一个“name.d”的Makefile文件,[.d]文件中就存放对应[.c]文件的依赖关系。
tags ctags:
  ctags -w -o $(OBJTREE)/ctags `find $(SUBDIRS) include \
    lib_generic board/$(BOARDDIR) cpu/$(CPU) lib_$(ARCH) \
    fs/cramfs fs/fat fs/fdos fs/jffs2 \
    net disk rtc dtt drivers drivers/sk98lin common \
   \( -name CVS -prune \) -o \( -name '*.[ch]' -print \)`


etags:
  etags -a -o $(OBJTREE)/etags `find $(SUBDIRS) include \
    lib_generic board/$(BOARDDIR) cpu/$(CPU) lib_$(ARCH) \
    fs/cramfs fs/fat fs/fdos fs/jffs2 \
    net disk rtc dtt drivers drivers/sk98lin common \
   \( -name CVS -prune \) -o \( -name '*.[ch]' -print \)`


$(obj)System.map: $(obj)u-boot
  @$(NM) $< | \
  grep -v '\(compiled\)\|\(\.o$$\)\|\( [aUw] \)\|\(\.\.ng$$\)\|\(LASH[RL]DI\)' | \
  sort > $(obj)System.map


#########################################################################
else
all $(obj)u-boot.hex $(obj)u-boot.srec $(obj)u-boot.bin \
$(obj)u-boot.img $(obj)u-boot.dis $(obj)u-boot \
$(SUBDIRS) version gdbtools updater env depend \
dep tags ctags etags $(obj)System.map:
 @echo "System not configured - see README" >&2
 @ exit 1
endif


.PHONY : CHANGELOG
CHANGELOG:
 git log --no-merges U-Boot-1_1_5.. | \
 unexpand -a | sed -e 's/\s\s*$$//' > $@


#########################################################################

# 清除上次生成的include/config.h和include/config.mk以及开发板目录下的一些临时配置文件
unconfig:
 @rm -f $(obj)include/config.h $(obj)include/config.mk \
  $(obj)board/*/config.tmp $(obj)board/*/*/config.tmp


#========================================================================
# PowerPC
#========================================================================

其实只要掌握Makefile的语法规则 这些Makefile文件都是一堆大同小异的small case了 

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/ad00de73f80fc7c227f48d502e9657da.html