第一次编译 Linux 之前,都要使用 “make xxx_defconfig”命令先配置 Linux 内核。
下面来分析一下,当执行 "make xxx_defcofig"命令时,Linux内核源码的顶层Makefile做了什么?
第一次编译 Linux 之前都要使用 “make xxx_defconfig”命令先配置 Linux 内核,在顶层 Makefile
490 config-targets := 0
491 mixed-targets := 0
492 dot-config := 1
493
494 ifneq ($(filter $(no-dot-config-targets), $(MAKECMDGOALS)),)
495 ifeq ($(filter-out $(no-dot-config-targets), $(MAKECMDGOALS)),)
496 dot-config := 0
497 endif
498 endif
499
500 ifeq ($(KBUILD_EXTMOD),)
501 ifneq ($(filter config %config,$(MAKECMDGOALS)),)
502 config-targets := 1
503 ifneq ($(words $(MAKECMDGOALS)),1)
504 mixed-targets := 1
505 endif
506 endif
507 endif
508
509 ifeq ($(mixed-targets),1)
510 # =================================================================
511 # We're called with mixed targets (*config and build targets).
512 # Handle them one by one.
513
514 PHONY += $(MAKECMDGOALS) __build_one_by_one
515
516 $(filter-out __build_one_by_one, $(MAKECMDGOALS)):
__build_one_by_one
517 @:
518
519 __build_one_by_one:
520 $(Q)set -e; \
521 for i in $(MAKECMDGOALS); do \
522 $(MAKE) -f $(srctree)/Makefile $$i; \
523 done
524
525 else
526 ifeq ($(config-targets),1)
527 # ================================================================
528 # *config targets only - make sure prerequisites are updated, and
529 # descend in scripts/kconfig to make the *config target
530
531 # Read arch specific Makefile to set KBUILD_DEFCONFIG as needed.
532 # KBUILD_DEFCONFIG may point out an alternative default
533 # configuration used for 'make defconfig'
534 include arch/$(SRCARCH)/Makefile
535 export KBUILD_DEFCONFIG KBUILD_KCONFIG
536
537 config: scripts_basic outputmakefile FORCE
538 $(Q)$(MAKE) $(build)=scripts/kconfig $@
539
540 %config: scripts_basic outputmakefile FORCE
541 $(Q)$(MAKE) $(build)=scripts/kconfig $@
...
563 endif # KBUILD_EXTMOD
config-targets= 1
mixed-targets= 0
dot-config= 1
目标“%config” 依赖 scripts_basic、outputmakefile 和 FORCE,“%config” 真正有意义的依赖就只有 scripts_basic。
scripts_basic 的规则如下:
448 scripts_basic:
449 $(Q)$(MAKE) $(build)=scripts/basic
450 $(Q)rm -f .tmp_quiet_recordmcount
scripts_basic:
@make -f $(srctree)/scripts/Makefile.build obj=scripts/basic //也可以没有@,视配置而定
@rm -f . tmp_quiet_recordmcount //也可以没有@
%config 目标对应的配置命令:
540 %config: scripts_basic outputmakefile FORCE
541 $(Q)$(MAKE) $(build)=scripts/kconfig $@
展开如下:
$(Q)$(MAKE) $(build)=scripts/basic
$(Q)$(MAKE) $(build)=scripts/kconfig $@
上面第二行命令中 $@ 指的是目标的意思,即 %config ,也就是 xxx_defconfig。
而 $(srctree) 参数是 . 。
最终,%config 目标对应的配置命令展开就是:
make -f ./scripts/Makefile.build obj= scripts/basic
make -f ./scripts/Makefile.build obj= scripts/kconfig xxx_defconfig
下一篇文章具体分析这两条配置命令实际做的事。