Linux内核---6.make menuconfig 流程分析

分析一下在命令行输入了make menuconfig 之后,到底发生了哪些事情:

点击(此处)折叠或打开

  1. linux_2.6.30.4/Makefile
  2. #scripts/Kbuild.include 文件L144包含build
  3.         #L144 build := -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Makefile.build obj
  4.    184    $(srctree)/scripts/Kbuild.include: ;
  5.    185    include $(srctree)/scripts/Kbuild.include
  6.            
  7.    245    
  8.    246    PHONY += scripts_basic
  9.    247    scripts_basic:
  10.    248        $(Q)$(MAKE) $(build)=scripts/basic
  11.            #make -f scripts/Makefile.build obj=scripts/basic
  12.    249    
  13.    250    scripts/basic/%: scripts_basic ;
  14.    251    
  15.    252    PHONY += outputmakefile
  16.    253    outputmakefile:
  17.            #此处KBUILD_SRC为空,ifneq条件不成立,所以outputmakefile不作任何操作
  18.    254    ifneq ($(KBUILD_SRC),)
  19.    255        $(Q)ln -fsn $(srctree) source
  20.    256        $(Q)$(CONFIG_SHELL) $(srctree)/scripts/mkmakefile \
  21.    257         $(srctree) $(objtree) $(VERSION) $(PATCHLEVEL)
  22.    258    endif
  23.    259    
  24.    260    
  25.    261    no-dot-config-targets := clean mrproper distclean \
  26.    262                 cscope TAGS tags help %docs check% \
  27.    263                 include/linux/version.h headers_% \
  28.    264                 kernelrelease kernelversion
  29.    265    
  30.    266    config-targets := 0
  31.    267    mixed-targets := 0
  32.    268    dot-config := 1
  33.    269 #因为MAKECMDGOALS=menuconfig,此处filter结果为空,ifneq条件不成立,所以dot-config:=1
  34.    270    ifneq ($(filter $(no-dot-config-targets), $(MAKECMDGOALS)),)
  35.    271        ifeq ($(filter-out $(no-dot-config-targets), $(MAKECMDGOALS)),)
  36.    272            dot-config := 0
  37.    273        endif
  38.    274    endif
  39.    275 #KBUILD_EXTMOD为空,ifeq条件成立进入,filter执行结果为menuconfig不为空,ifneq条件不成立config-targets=1,mixed-targets=0    
  40.    276    ifeq ($(KBUILD_EXTMOD),)
  41.    277     ifneq ($(filter config %config,$(MAKECMDGOALS)),)
  42.    278     config-targets := 1
  43.    279     ifneq ($(filter-out config %config,$(MAKECMDGOALS)),)
  44.    280     mixed-targets := 1
  45.    281     endif
  46.    282     endif
  47.    283    endif
  48.    284 #config-targets=1 mixed-targets=0 dot-config=1    #所以执行L291
  49.    285    ifeq ($(mixed-targets),1)
  50.    286    
  51.    287    %:: FORCE
  52.    288        $(Q)$(MAKE) -C $(srctree) KBUILD_SRC= $@
  53.    289    
  54.    290    else
  55.    291    ifeq ($(config-targets),1)
  56.    292    # 将 ./arch/arm/Makefile 包含进来
  57.    293    include $(srctree)/arch/$(SRCARCH)/Makefile
  58.    294    export KBUILD_DEFCONFIG KBUILD_KCONFIG
  59.    295    
  60.    296    config: scripts_basic outputmakefile FORCE
  61.    297        $(Q)mkdir -p include/linux include/config
  62.    298        $(Q)$(MAKE) $(build)=scripts/kconfig $@
  63.    299    #%config匹配了menuconfig,不仔细看还真看不出来
  64.    300    %config: scripts_basic outputmakefile FORCE
  65.    301        $(Q)mkdir -p include/linux include/config
  66.    302        $(Q)$(MAKE) $(build)=scripts/kconfig $@
  67. #由scripts/Kbuild.include的build知,L302:make -f scripts/Makefile.build obj=scripts/kconfig menuconfig

所以执行了 make menuconfig 之后,会执行以下五步:
1. 执行 scripts_basic 依赖:( make -f scripts/Makefile.build obj=scripts/basic )
2. 执行 outputmakefile 依赖:( KBUILD_SRC为空,所以不做任何操作 )
3. FORCE
4. mkdir -p include/linux include/config :(创建文件夹)
5. $(MAKE) $(build)=scripts/kconfig $@ (make -f scripts/Makefile.build obj=scripts/kconfig menuconfig)
所以最重要的是第1步和第5步,下面详细分析一下这两步
1.执行 scripts_basic 依赖:( make -f scripts/Makefile.build obj=scripts/basic )

点击(此处)折叠或打开

  1. scripts/Makefile.build
  2.      1    #传参数obj=scripts/basic
  3.      2    src := $(obj)
  4.      4    PHONY := __build
  5.      5    __build:
  6.     27    -include include/config/auto.conf
  7.     28    
  8.     29    include scripts/Kbuild.include
  9.     32    #src=scripts/basic, filter判断$(src)是不是以/开头,绝对路径,不是绝对路径则加$(srctree)/$(src)    
  10.     33    kbuild-dir := $(if $(filter /%,$(src)),$(src),$(srctree)/$(src))
  11.         #wildcard判断绝对路径$(srctree)/script/basic目录下是否有Kbuild文件,如果没有则为$(srctree)/script/basic/Makefile
  12.     34    kbuild-file := $(if $(wildcard $(kbuild-dir)/Kbuild),$(kbuild-dir)/Kbuild,$(kbuild-dir)/Makefile)
  13.         #将$(srctree)/script/basic/Makefile加入,这个Makefile中有menuconfig的依赖关系
  14.     35    include $(kbuild-file)
  15.     36
  16.         #在$(srctree)/script/basic/Makefile中定义了,hostprogs-y
  17.     51    ifneq ($(hostprogs-y)$(hostprogs-m),)
  18.     52    include scripts/Makefile.host
  19.     53    endif

  20.         # 有两个__build,用下面这个最新的__build
  21.         # KBUILD_BUILTIN=1, KBUILT_MODULES=null, 所以__build=(builtin-target lib-target extra-y modorder-target subdir-ym always)
  22.         # __build=(modorder-target always)
  23.         # always=scripts/basic/fixdep scripts/basic/docproc scripts/basic/hash
  24.         # modorder-target=scripts/basic/modules.order
  25.     77    __build: $(if $(KBUILD_BUILTIN),$(builtin-target) $(lib-target) $(extra-y)) \
  26.     78         $(if $(KBUILD_MODULES),$(obj-m) $(modorder-target)) \
  27.     79         $(subdir-ym) $(always)
  28.     80        @:
  29.         # $(modorder-target)在Makefile.build中
  30.         # $(modorder-target): $(subdir-ym) FORCE
  31.         #     $(Q)(cat /dev/null; $(modorder-cmds)) > $@
  32.         # 没干什么实事
  33.         # 所以 scripts/basic 就是在scripts/basic/Makefile作用下编译生成docproc fixdep hash 这三个elf文件
  34.     81
5.执行$(MAKE) $(build)=scripts/kconfig $@ (make -f scripts/Makefile.build obj=scripts/kconfig menuconfig) ,与scripts_basic传的obj路径不一样,这将导致执行Makefile的路径也不一样。


点击(此处)折叠或打开

  1. scripts/kconfig/Makefile
  2. #没有定义KBUILD_KCONFIG,所以Kconfig=arch/arm/Kconfig    
  3.      4    ifdef KBUILD_KCONFIG
  4.      5    Kconfig := $(KBUILD_KCONFIG)
  5.      6    else
  6.      7    Kconfig := arch/$(SRCARCH)/Kconfig
  7.      8    endif        
  8.         # 先去生成mconf这个elf文件(看到的图形界面就是这个东东),然后调用scripts/kconfig/mconf arch/arm/Kconfig
  9.         # 这样就可以看到配置选项
  10.     16    menuconfig: $(obj)/mconf
  11.     17        $< $(Kconfig)
  12.         
  13.     86    check-lxdialog := $(srctree)/$(src)/lxdialog/check-lxdialog.sh
  14.     87    
  15.     88    HOST_EXTRACFLAGS = $(shell $(CONFIG_SHELL) $(check-lxdialog) -ccflags)
  16.     89    HOST_LOADLIBES = $(shell $(CONFIG_SHELL) $(check-lxdialog) -ldflags $(HOSTCC))
  17.     90    
  18.     91    HOST_EXTRACFLAGS += -DLOCALE
  19.     92    
  20.     93    
  21.     94    
  22.     95    lxdialog := lxdialog/checklist.o lxdialog/util.o lxdialog/inputbox.o
  23.     96    lxdialog += lxdialog/textbox.o lxdialog/yesno.o lxdialog/menubox.o
  24.     97    #没有看出mconf和mconf-objs是通过什么关系对应起来的,通过打印mconf的生成过程,可以看出mconf就是mconf-objs
  25.         #gcc -o scripts/kconfig/mconf scripts/kconfig/mconf.o scripts/kconfig/zconf.tab.o scripts/kconfig/lxdialog/checklist.o scripts/kconfig/lxdialog/util.o scripts/kconfig/lxdialog/inputbox.o scripts/kconfig/lxdialog/textbox.o scripts/kconfig/lxdialog/yesno.o scripts/kconfig/lxdialog/menubox.o -lncurses 
  26.     99    mconf-objs    := mconf.o zconf.tab.o $(lxdialog)
  27.    101    
  28.    102    hostprogs-:= conf qconf gconf kxgettext
  29.    103    
  30.    104    ifeq ($(MAKECMDGOALS),menuconfig)
  31.    105        hostprogs-+= mconf
  32.    106    endif
  33.    130    PHONY += $(obj)/dochecklxdialog
  34.    131    $(addprefix $(obj)/,$(lxdialog)): $(obj)/dochecklxdialog
  35.    132    $(obj)/dochecklxdialog:
  36.    133        $(Q)$(CONFIG_SHELL) $(check-lxdialog) -check $(HOSTCC) $(HOST_EXTRACFLAGS) $(HOST_LOADLIBES)
  37.    134    
  38.    135    always := dochecklxdialog


写到快吐了!!!!

你可能感兴趣的:(linux内核)