慢慢欣赏linux make menuconfig流程

先看一下打印(使用前需要make clean)

[root@cliffr linux-2.6.32]# ls
arch   COPYING  crypto         drivers   fs       init  Kbuild  lib          Makefile  Module.symvers  README          samples  security  tools  virt
block  CREDITS  Documentation  firmware  include  ipc   kernel  MAINTAINERS  mm        net             REPORTING-BUGS  scripts  sound     usr
[root@cliffr linux-2.6.32]# make menuconfig V=1
make -f scripts/Makefile.build obj=scripts/basic
  gcc -Wp,-MD,scripts/basic/.fixdep.d -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer     -o scripts/basic/fixdep scripts/basic/fixdep.c  
  gcc -Wp,-MD,scripts/basic/.docproc.d -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer     -o scripts/basic/docproc scripts/basic/docproc.c  
  gcc -Wp,-MD,scripts/basic/.hash.d -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer     -o scripts/basic/hash scripts/basic/hash.c  
mkdir -p include/linux include/config
make -f scripts/Makefile.build obj=scripts/kconfig menuconfig
  gcc -Wp,-MD,scripts/kconfig/.conf.o.d -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer   -I/usr/include/ncurses -DCURSES_LOC="<ncurses.h>" -DLOCALE   -c -o scripts/kconfig/conf.o scripts/kconfig/conf.c
  gcc -Wp,-MD,scripts/kconfig/.kxgettext.o.d -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer   -I/usr/include/ncurses -DCURSES_LOC="<ncurses.h>" -DLOCALE   -c -o scripts/kconfig/kxgettext.o scripts/kconfig/kxgettext.c
/bin/sh /usr/local/src/linux-2.6.32/scripts/kconfig/lxdialog/check-lxdialog.sh -check gcc -I/usr/include/ncurses -DCURSES_LOC="<ncurses.h>" -DLOCALE  -lncursesw
  gcc -Wp,-MD,scripts/kconfig/lxdialog/.checklist.o.d -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer   -I/usr/include/ncurses -DCURSES_LOC="<ncurses.h>" -DLOCALE   -c -o scripts/kconfig/lxdialog/checklist.o scripts/kconfig/lxdialog/checklist.c
  gcc -Wp,-MD,scripts/kconfig/lxdialog/.inputbox.o.d -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer   -I/usr/include/ncurses -DCURSES_LOC="<ncurses.h>" -DLOCALE   -c -o scripts/kconfig/lxdialog/inputbox.o scripts/kconfig/lxdialog/inputbox.c
  gcc -Wp,-MD,scripts/kconfig/lxdialog/.menubox.o.d -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer   -I/usr/include/ncurses -DCURSES_LOC="<ncurses.h>" -DLOCALE   -c -o scripts/kconfig/lxdialog/menubox.o scripts/kconfig/lxdialog/menubox.c
  gcc -Wp,-MD,scripts/kconfig/lxdialog/.textbox.o.d -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer   -I/usr/include/ncurses -DCURSES_LOC="<ncurses.h>" -DLOCALE   -c -o scripts/kconfig/lxdialog/textbox.o scripts/kconfig/lxdialog/textbox.c
  gcc -Wp,-MD,scripts/kconfig/lxdialog/.util.o.d -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer   -I/usr/include/ncurses -DCURSES_LOC="<ncurses.h>" -DLOCALE   -c -o scripts/kconfig/lxdialog/util.o scripts/kconfig/lxdialog/util.c
  gcc -Wp,-MD,scripts/kconfig/lxdialog/.yesno.o.d -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer   -I/usr/include/ncurses -DCURSES_LOC="<ncurses.h>" -DLOCALE   -c -o scripts/kconfig/lxdialog/yesno.o scripts/kconfig/lxdialog/yesno.c
  gcc -Wp,-MD,scripts/kconfig/.mconf.o.d -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer   -I/usr/include/ncurses -DCURSES_LOC="<ncurses.h>" -DLOCALE   -c -o scripts/kconfig/mconf.o scripts/kconfig/mconf.c
  gcc -Wp,-MD,scripts/kconfig/.zconf.tab.o.d -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer   -I/usr/include/ncurses -DCURSES_LOC="<ncurses.h>" -DLOCALE  -Iscripts/kconfig -c -o scripts/kconfig/zconf.tab.o scripts/kconfig/zconf.tab.c
  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 -lncursesw 
scripts/kconfig/mconf arch/x86/Kconfig

先分析如下语句

feq ($(KBUILD_EXTMOD),)	# $(KBUILD_EXTMOD为空
        ifneq ($(filter config %config,$(MAKECMDGOALS)),)	# $(MAKECMDGOALS)表示 menuconfig 所以满足if条件
                config-targets := 1
                ifneq ($(filter-out config %config,$(MAKECMDGOALS)),) # $(MAKECMDGOALS)只有一个 menuconfig 所以不满足if条件
                        mixed-targets := 1
                endif
        endif
endif

由于 config-targets 为1, 而 mixed-targets 为0, 所以进入如下分支

代码流程如下

%config: scripts_basic outputmakefile FORCE
	$(Q)mkdir -p include/linux include/config
	$(Q)$(MAKE) $(build)=scripts/kconfig $@
	
	依赖1
	scripts_basic:
		$(Q)$(MAKE) $(build)=scripts/basic
		=>make -f scripts/Makefile.build obj=scripts/basic
		
		其中
		scripts/Kbuild.include:150:build := -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Makefile.build obj
		=>build := -f scripts/Makefile.build obj
		
		Makefile.build 里面找第一个目标编译, 也就是
		__build: $(if $(KBUILD_BUILTIN),$(builtin-target) $(lib-target) $(extra-y)) \
		 $(if $(KBUILD_MODULES),$(obj-m) $(modorder-target)) \
		 $(subdir-ym) $(always)
		 
		其中
		scripts/basic/Makefile:13:always                := $(hostprogs-y)
		scripts/basic/Makefile:12:hostprogs-y   := fixdep docproc hash
		也就是说, __build 需要将 fixdep docproc hash 编译为目标文件。
        
		Makefile.build 是怎么将 scripts/basic/Makefile 包含进来的呢
		# The filename Kbuild has precedence over Makefile
		kbuild-dir := $(if $(filter /%,$(src)),$(src),$(srctree)/$(src))
		=>kbuild-dir := $(if $(filter /%,$(obj)),$(obj),$(srctree)/$(obj))
		=>kbuild-dir := $(if $(filter /%,scripts/basic),scripts/basic,$(srctree)/scripts/basic)
		=>kbuild-dir := scripts/basic
		
		kbuild-file := $(if $(wildcard $(kbuild-dir)/Kbuild),$(kbuild-dir)/Kbuild,$(kbuild-dir)/Makefile)
		include $(kbuild-file)
		=>kbuild-file := $(if $(wildcard scripts/basic/Kbuild),scripts/basic/Kbuild,scripts/basic/Makefile)
		include $(kbuild-file)
		=>kbuild-file := scripts/basic/Makefile #scripts/basic/Kbuild不存在, 所以走else分支
		include scripts/basic/Makefile

		# 由于 $(hostprogs-y) 存在, 所以在 Makefile.build 同时满足如下条件:
		# Do not include host rules unless needed
		ifneq ($(hostprogs-y)$(hostprogs-m),)
		include scripts/Makefile.host
		endif
		
		#所以如下条件成立
		# C code
		# Executables compiled from a single .c file
		host-csingle	:= $(foreach m,$(__hostprogs),$(if $($(m)-objs),,$(m)))
		
		#进入如下流程, 告诉我们如何编译.c和生成.cmd
		$(host-csingle): $(obj)/%: $(src)/%.c FORCE
			$(call if_changed_dep,host-csingle)
	
	行为2
	$(MAKE) $(build)=scripts/kconfig $@
	=>make -f scripts/Makefile.build obj=scripts/kconfig menuconfig
		其中 scripts/kconfig/Makefile:20:menuconfig: $(obj)/mconf
		进入文件里面查看
		menuconfig: $(obj)/mconf
			$< $(Kconfig)
		=>menuconfig: scripts/kconfig/mconf
			scripts/kconfig arch/x86/Kconfig
			
		其中
		./scripts/kconfig/Makefile:11:Kconfig := arch/$(SRCARCH)/Kconfig

mconf 的作用是根据 kconfig 生成 .config

main
{
    conf_parse(av[1]); //解析Kconfig
	conf_read(NULL);
	set_config_filename(conf_get_configname());	//生成.config
		
}

Linux之Makefile(filter)
https://blog.csdn.net/zhoudengqing/article/details/41777957

makefile的wildcard函数
https://blog.csdn.net/qq_32693119/article/details/84701554

Makefile中wildcard的介绍
https://www.cnblogs.com/haoxing990/p/4629454.html

linux内核Makefile中的build构建机制
https://blog.csdn.net/metersun/article/details/52212842

配置Linux Kernel时make menuconfig执行流程分析
https://www.cnblogs.com/LoTGu/p/5968042.html

Linux 内核 Makefile 体系简单分析
https://blog.csdn.net/chenliujiang1989/article/details/7539211

linux驱动基础开发3——linux 内核配置机制(make menuconfig、Kconfig、makefile)讲解
https://blog.csdn.net/xdw1985829/article/details/6833319

make menuconfig过程讲解        OS总结的文档不错
https://blog.csdn.net/a746742897/article/details/52247292
https://blog.csdn.net/qingkongyeyue/article/details/52503313

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值