zoukankan      html  css  js  c++  java
  • (转)autoconfig.mk文件的自动生成

    autoconf.mk

    uboot的顶层Makefile中有如下的一段代码
    [plain] view plaincopy在CODE上查看代码片派生到我的代码片
     
    1. #  
    2. # Auto-generate the autoconf.mk file (which is included by all makefiles)  
    3. #  
    4. # This target actually generates 2 files; autoconf.mk and autoconf.mk.dep.  
    5. # the dep file is only include in this top level makefile to determine when  
    6. # to regenerate the autoconf.mk file.  
    7. $(obj)include/autoconf.mk.dep: $(obj)include/config.h include/common.h  
    8.     @$(XECHO) Generating $@ ;   
    9.     set -e ;   
    10.     : Generate the dependancies ;   
    11.     $(CC) -x c -DDO_DEPS_ONLY -M $(CFLAGS) $(CPPFLAGS)   
    12.         -MQ $(obj)include/autoconf.mk include/common.h > $@  
    13.   
    14. $(obj)include/autoconf.mk: $(obj)include/config.h  
    15.     @$(XECHO) Generating $@ ;   
    16.     set -e ;   
    17.     : Extract the config macros ;   
    18.     $(CPP) $(CFLAGS) -DDO_DEPS_ONLY -dM include/common.h |   
    19.         sed -n -f tools/scripts/define2mk.sed > $@.tmp &&   
    20.     mv $@.tmp $@  
    [plain] view plain copy
     
     在CODE上查看代码片派生到我的代码片
    1. #  
    2. # Auto-generate the autoconf.mk file (which is included by all makefiles)  
    3. #  
    4. # This target actually generates 2 files; autoconf.mk and autoconf.mk.dep.  
    5. # the dep file is only include in this top level makefile to determine when  
    6. # to regenerate the autoconf.mk file.  
    7. $(obj)include/autoconf.mk.dep: $(obj)include/config.h include/common.h  
    8.     @$(XECHO) Generating $@ ;   
    9.     set -e ;   
    10.     : Generate the dependancies ;   
    11.     $(CC) -x c -DDO_DEPS_ONLY -M $(CFLAGS) $(CPPFLAGS)   
    12.         -MQ $(obj)include/autoconf.mk include/common.h > $@  
    13.   
    14. $(obj)include/autoconf.mk: $(obj)include/config.h  
    15.     @$(XECHO) Generating $@ ;   
    16.     set -e ;   
    17.     : Extract the config macros ;   
    18.     $(CPP) $(CFLAGS) -DDO_DEPS_ONLY -dM include/common.h |   
    19.         sed -n -f tools/scripts/define2mk.sed > $@.tmp &&   
    20.     mv $@.tmp $@  

    先看第一个: $(obj)include/autoconf.mk.dep: $(obj)include/config.h include/common.h, 它表示autoconf.mk.dep依赖于config.h和common.h这两个文件.
    • @$(XECHO) Generating $@ ;  这句话会在编译阶段输出编译信息 Generating include/autoconf.mk.dep
    • set -e ; 这句话表示, 当下面命令返回值不会0时, 整个脚本立即停止退出
    • : Generate the dependancies ;  没有明白是啥意思~~
    • $(CC) -x c -DDO_DEPS_ONLY -M $(CFLAGS) $(CPPFLAGS) -MQ $(obj)include/autoconf.mk include/common.h > $@
      • -DDO_DEPS_ONLY: 设置flag, 具体来说, 我们可以在common.h里面看见#ifdef DO_DEPS_ONLY这样的语句, 这个-D就表示DO_DEPS_ONLY被定义了
      • -M : 表示生成依赖关系. 我还专门做了个实验, 如下
        • gcc -M main.c 输出结果为 main.o: main.c
      • -MQ: 表示指定依赖关系中target的名称, 看下面的实验
        • gcc -M -MQ newname.mk main.c 输出结果为 newname.mk: main.c
      • 这句话表示: 生成依赖关系 include/autoconf.mk: include/common.h, 结果最终输出到include/autoconf.mk.dep
    • 打开编译后生成的include/autoconf.mk.dep, 可以查阅里面的内容. 至于为什么需要生成这个文件, 我现在还不清楚.
     
    再看第二个: $(obj)include/autoconf.mk: $(obj)include/config.h, 它表示autoconf.mk依赖于include/config.h这个文件
    • @$(XECHO) Generating $@ ;  这句话会在编译阶段输出编译信息Generating include/autoconf.mk
    • set -e; 同上
    • $(CPP) $(CFLAGS) -DDO_DEPS_ONLY -dM include/common.h | sed -n -f tools/scripts/define2mk.sed > $@.tmp && mv $@.tmp $@
      • -DDO_DEPS_ONLY: 同上
      • -dM : 作用是输出include/common.h中定义的所有宏
      • |      : shell中的管道, 表示将前面的结果传递给后面的命令
      • define2mk.sed : 查找和处理以“CONFIG_”开头的宏定义的功能, 将处理的结果输出到include/autoconf.mk.tmp
      • mv $@.tmp $@ : 重命名为include/autoconf.mk. 
      • 最终就会生成include/autoconf.mk
    •  include/common.h文件包含了include/config.h文件,而include/config.h文件又包含了config_defaults.h等uboot下的通用头文件, 还会包含<configs/${CONFIG_NAME}.h>, 这个.h是我们自己创建的, 可以在里面添加自己的"CONFIG_"宏定义. 已决定开启哪些功能.
    至此, 我们知道, 系统中所有的"CONFIG_"开头的宏开关, 都被放到了include/autoconf.mk中. 
     

    depend

    在uboot的顶层Makefile中, 我们经常会看到类似的代码片段
    [plain] view plaincopy在CODE上查看代码片派生到我的代码片
     
    1. $(obj)spl/u-boot-spl.bin:   $(SUBDIR_TOOLS) <span style="color: rgb(255, 0, 0);">depend</span>  
    2.         $(MAKE) -C spl all  
    [plain] view plain copy
     
     在CODE上查看代码片派生到我的代码片
    1. $(obj)spl/u-boot-spl.bin:   $(SUBDIR_TOOLS) <span style="color:#ff00;">depend</span>  
    2.         $(MAKE) -C spl all  

    这个depend是什么意思呢, Makefile中有如下一段代码
    [plain] view plaincopy在CODE上查看代码片派生到我的代码片
     
    1. # Explicitly make _depend in subdirs containing multiple targets to prevent  
    2. # parallel sub-makes creating .depend files simultaneously.  
    3. depend dep: $(TIMESTAMP_FILE) $(VERSION_FILE)   
    4.         $(obj)include/spl-autoconf.mk   
    5.         $(obj)include/tpl-autoconf.mk   
    6.         $(obj)include/autoconf.mk   
    7.         $(obj)include/generated/generic-asm-offsets.h   
    8.         $(obj)include/generated/asm-offsets.h  
    9.         for dir in $(SUBDIRS) $(CPUDIR) $(LDSCRIPT_MAKEFILE_DIR) ; do   
    10.             $(MAKE) -C $$dir _depend ; done  
    [plain] view plain copy
     
     在CODE上查看代码片派生到我的代码片
    1. # Explicitly make _depend in subdirs containing multiple targets to prevent  
    2. # parallel sub-makes creating .depend files simultaneously.  
    3. depend dep: $(TIMESTAMP_FILE) $(VERSION_FILE)   
    4.         $(obj)include/spl-autoconf.mk   
    5.         $(obj)include/tpl-autoconf.mk   
    6.         $(obj)include/autoconf.mk   
    7.         $(obj)include/generated/generic-asm-offsets.h   
    8.         $(obj)include/generated/asm-offsets.h  
    9.         for dir in $(SUBDIRS) $(CPUDIR) $(LDSCRIPT_MAKEFILE_DIR) ; do   
    10.             $(MAKE) -C $$dir _depend ; done  

    • depend dep : 它表示这个规则有两个目标. 也就是你自己的目标依赖depend或者dep都会跑到这里来继续.
    • $(obj)include/spl-autoconf.mk : 表示depend依赖spl-autoconf.mk. 这个mk的生成规则也在Makefile中有定义. 细节方面参考上面的autoconf.mk
    • $(obj)include/tpl-autoconf.mk : 同上
    • $(obj)include/autoconf.mk     : 同上
    • $(obj)include/generated/generic-asm-offsets.h : 暂不分析
    • $(obj)include/generated/asm-offsets.h : 暂不分析
    • for dir in $(SUBDIRS) $(CPUDIR) $(LDSCRIPT_MAKEFILE_DIR) ; do $(MAKE) -C $$dir _depend ; done
      • 这句话表示去上面各个目录下执行 make _depend命令.
    那我们看看对应子目录下的Makefile, 例如$(CPUDIR) , 会看到如下的代码片段
    [plain] view plaincopy在CODE上查看代码片派生到我的代码片
     
    1. # defines $(obj).depend target  
    2. include $(SRCTREE)/rules.mk  
    3.   
    4. sinclude $(obj).depend  
    [plain] view plain copy
     
     在CODE上查看代码片派生到我的代码片
    1. # defines $(obj).depend target  
    2. include $(SRCTREE)/rules.mk  
    3.   
    4. sinclude $(obj).depend  

    并没有看到_depend这个目标, 那make _depend在这个目录下如何执行呢? 来看看它include的rules.mk
    [plain] view plaincopy在CODE上查看代码片派生到我的代码片
     
    1. _depend:    $(obj).depend  
    2.   
    3. # Split the source files into two camps: those in the current directory, and  
    4. # those somewhere else. For the first camp we want to support CPPFLAGS_<fname>  
    5. # and for the second we don't / can't.  
    6. PWD_SRCS := $(filter $(notdir $(SRCS)),$(SRCS))  
    7. OTHER_SRCS := $(filter-out $(notdir $(SRCS)),$(SRCS))  
    8.   
    9. # This is a list of dependency files to generate  
    10. DEPS := $(basename $(patsubst %,$(obj).depend.%,$(PWD_SRCS)))  
    11.   
    12. # Join all the dependencies into a single file, in three parts  
    13. #   1 .Concatenate all the generated depend files together  
    14. #   2. Add in the deps from OTHER_SRCS which we couldn't process  
    15. #   3. Add in the HOSTSRCS  
    16. $(obj).depend:  $(src)Makefile $(TOPDIR)/config.mk $(DEPS) $(OTHER_SRCS)   
    17.         $(HOSTSRCS)  
    18.     cat /dev/null $(DEPS) >$@  
    19.     @for f in $(OTHER_SRCS); do   
    20.         g=`basename $$f | sed -e 's/(.*).[[:alnum:]_]/1.o/'`;   
    21.         $(CC) -M $(CPPFLAGS) -MQ $(obj) f >> $@ ;   
    22.     done  
    23.     @for f in $(HOSTSRCS); do   
    24.         g=`basename $$f | sed -e 's/(.*).[[:alnum:]_]/1.o/'`;   
    25.         $(HOSTCC) -M $(HOSTCPPFLAGS) -MQ $(obj) f >> $@ ;   
    26.     done  
    27.   
    28. MAKE_DEPEND = $(CC) -M $(CPPFLAGS) $(EXTRA_CPPFLAGS_DEP)   
    29.         -MQ $(addsuffix .o,$(obj)$(basename $<)) $< >$@  
    30.   
    31.   
    32. $(obj).depend.%:    %.c  
    33.     $(MAKE_DEPEND)  
    34.   
    35. $(obj).depend.%:    %.S  
    36.     $(MAKE_DEPEND)  
    37.   
    38. $(HOSTOBJS): $(obj)%.o: %.c  
    39.     $(HOSTCC) $(HOSTCFLAGS) $(HOSTCFLAGS_$(@F)) $(HOSTCFLAGS_$(BCURDIR)) -o $@ $< -c  
    40. $(NOPEDOBJS): $(obj)%.o: %.c  
    41.     $(HOSTCC) $(HOSTCFLAGS_NOPED) $(HOSTCFLAGS_$(@F)) $(HOSTCFLAGS_$(BCURDIR)) -o $@ $< -c  
    42.   
    43. #########################################################################  
    [plain] view plain copy
     
     在CODE上查看代码片派生到我的代码片
    1. _depend:    $(obj).depend  
    2.   
    3. # Split the source files into two camps: those in the current directory, and  
    4. # those somewhere else. For the first camp we want to support CPPFLAGS_<fname>  
    5. # and for the second we don't / can't.  
    6. PWD_SRCS := $(filter $(notdir $(SRCS)),$(SRCS))  
    7. OTHER_SRCS := $(filter-out $(notdir $(SRCS)),$(SRCS))  
    8.   
    9. # This is a list of dependency files to generate  
    10. DEPS := $(basename $(patsubst %,$(obj).depend.%,$(PWD_SRCS)))  
    11.   
    12. # Join all the dependencies into a single file, in three parts  
    13. #   1 .Concatenate all the generated depend files together  
    14. #   2. Add in the deps from OTHER_SRCS which we couldn't process  
    15. #   3. Add in the HOSTSRCS  
    16. $(obj).depend:  $(src)Makefile $(TOPDIR)/config.mk $(DEPS) $(OTHER_SRCS)   
    17.         $(HOSTSRCS)  
    18.     cat /dev/null $(DEPS) >$@  
    19.     @for f in $(OTHER_SRCS); do   
    20.         g=`basename $$f | sed -e 's/(.*).[[:alnum:]_]/1.o/'`;   
    21.         $(CC) -M $(CPPFLAGS) -MQ $(obj)
       
      f >> $@ ;   
    22.     done  
    23.     @for f in $(HOSTSRCS); do   
    24.         g=`basename $$f | sed -e 's/(.*).[[:alnum:]_]/1.o/'`;   
    25.         $(HOSTCC) -M $(HOSTCPPFLAGS) -MQ $(obj)
       
      f >> $@ ;   
    26.     done  
    27.   
    28. MAKE_DEPEND = $(CC) -M $(CPPFLAGS) $(EXTRA_CPPFLAGS_DEP)   
    29.         -MQ $(addsuffix .o,$(obj)$(basename $<)) $< >$@  
    30.   
    31.   
    32. $(obj).depend.%:    %.c  
    33.     $(MAKE_DEPEND)  
    34.   
    35. $(obj).depend.%:    %.S  
    36.     $(MAKE_DEPEND)  
    37.   
    38. $(HOSTOBJS): $(obj)%.o: %.c  
    39.     $(HOSTCC) $(HOSTCFLAGS) $(HOSTCFLAGS_$(@F)) $(HOSTCFLAGS_$(BCURDIR)) -o $@ $< -c  
    40. $(NOPEDOBJS): $(obj)%.o: %.c  
    41.     $(HOSTCC) $(HOSTCFLAGS_NOPED) $(HOSTCFLAGS_$(@F)) $(HOSTCFLAGS_$(BCURDIR)) -o $@ $< -c  
    42.   
    43. #########################################################################  

    这里有_depend目标, make _depend的时候, 执行的其实就是这里的_depend. 这个里面的细节不分析了, 大体来说有几点
    • $(obj).depend: obj一般为空, 所以这里会在当前目录下生成一个.depend文件
    • .depend里面的内容就是类似于 : main.o : main.c main.h . 
      • 想深究的话可以参考这里 : http://blog.csdn.net/panfengsoftware/article/details/7877864
    最后在Makefile里面引用了当前目录下的这个.depend
  • 相关阅读:
    Java 7的javax.net.ssl.SSLHandshakeException
    Oracle数据泵导出数据库
    ORA-00054: 资源正忙 --锁表的解决方法
    Linux学习私人笔记-Shell基础
    Linux学习私人笔记-目录和文件的基本命令
    Linux学习私人笔记-文件基本命令
    Linux学习私人笔记-账号管理
    Linux学习私人笔记-Vim
    form提交表单时本地下载
    SQL Servel 中分页解决
  • 原文地址:https://www.cnblogs.com/biaohc/p/6366588.html
Copyright © 2011-2022 走看看