linux kernel makefile 分析 - 6

上一篇: https://www.cnblogs.com/zhangzhiwei122/p/16029174.html

背景说明

版本:

5.10.0 - 下面分析中 使用的行号,都是 参考 这个 版本的 Makefile 。

在线浏览: https://lxr.missinglinkelectronics.com/linux/Makefile

 

使用场景:

在源码文件夹下面建立一个build 文件夹,然后使用 O=build 

mkdir build

make O=build

 

683 ~ 727 单个编译目标 need-config  may-sync-config 相关

643 ~ 645  if need-config                                       需要auto.conf 等文件,就  include auto.conf

683 ~ 727 if need config                                        需要 auto.conf 等配置文件

          684 ~ 710  if may-sync-config                               可以使用 .config 文件更新  auto.conf 等配置文件

         711 ~ 727 else                                                     不可以更新  auto.conf 等配置文件

 

1、643 ~ 645 if need-config  include auto.conf

   need-config 变量的设置,见 https://www.cnblogs.com/zhangzhiwei122/p/16026987.html 编译类型的设定

 643ifdef need-config
 644include include/config/auto.conf
 645endif
 646

644  include  include/config/auto.conf  会触发make 去查找和更新   include/config/auto.conf 文件。这个 include/config/auto.conf 目标在 683 ~ 727 之间定义。

 

2、684 ~ 710 可以使用 .config 更新 include/config/auto.conf 目标

688 又 include auto.conf.cmd ,这个 auto.conf.cmd 的更新规则和 auto.conf 相同,都在  709 ~ 710 之间定义。

690 ~ 698 定义  $(KCONFIG_CONFIG) (即 .config ) 文件的生产规则。 这个 .config 文件 应该通过 make defconfig  或 make menuconfig 命令得到。

       606 ~ 1945 之间是处理 单个编译目标( 587 ~ 603 才是处理 config 目标) 。

       690 这儿需要更新.config 文件,场景 通常是   在make all 或 make <不指定目标> 执行前,没有执行过 make xxconfig 。

      所以这儿报错提示  Please run some configurator (e.g. "make oldconfig" or make menuconfig or make xconfig).

 

706 ~ 707 定义了 cmd_syncconfig 命令,启动 sub make,指定makefile 和目标 syncconfig

709 ~ 710 定义 auto.conf auto.conf.cmd  autoconf.h 目标的更新规则,依赖 .config 文件,调用 cmd_syncconfig 命令。

 688include include/config/auto.conf.cmd
 689
 690$(KCONFIG_CONFIG):
 691        @echo >&2 '***'
 692        @echo >&2 '*** Configuration file "$@" not found!'
 693        @echo >&2 '***'
 694        @echo >&2 '*** Please run some configurator (e.g. "make oldconfig" or'
 695        @echo >&2 '*** "make menuconfig" or "make xconfig").'
 696        @echo >&2 '***'
 697        @/bin/false
 698
 699# The actual configuration files used during the build are stored in
 700# include/generated/ and include/config/. Update them if .config is newer than
 701# include/config/auto.conf (which mirrors .config).
 702#
 703# This exploits the 'multi-target pattern rule' trick.
 704# The syncconfig should be executed only once to make all the targets.
 705# (Note: use the grouped target '&:' when we bump to GNU Make 4.3)
 706quiet_cmd_syncconfig = SYNC    $@
 707      cmd_syncconfig = $(MAKE) -f $(srctree)/Makefile syncconfig
 708
 709%/config/auto.conf %/config/auto.conf.cmd %/generated/autoconf.h: $(KCONFIG_CONFIG)
 710        +$(call cmd,syncconfig)

 

3、711 ~ 727 不可以使用 .config 更新  include/config/auto.conf 目标

            需要这个目标,这个目标又不能被更新,发生在 编译外部模块,但是kernel 文件夹下面没有 auto.conf  autoconf.h 等文件的场景。只能报错处理了。

 715PHONY += include/config/auto.conf
 716
 717include/config/auto.conf:
 718        $(Q)test -e include/generated/autoconf.h -a -e $@ || (          \
 719        echo >&2;                                                       \
 720        echo >&2 "  ERROR: Kernel configuration is invalid.";           \
 721        echo >&2 "         include/generated/autoconf.h or $@ are missing.";\
 722        echo >&2 "         Run 'make oldconfig && make prepare' on kernel src to fix it.";      \
 723        echo >&2 ;                                                      \
 724        /bin/false)
 725

 

下一篇:

__all -> all-> vmlinux -> ?

 

https://www.cnblogs.com/zhangzhiwei122/p/16029589.html

 

posted @ 2022-03-20 11:12  张志伟122  阅读(420)  评论(0编辑  收藏  举报