linux 系统移植(第九期)----Linux 内核顶层 Makefile- make xxx_defconfig 过程-- Ubuntu20.04

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档

文章目录

前言

[make xxx_defconfig 过程](#make xxx_defconfig 过程)

总结


前言

上一期主要介绍了Linux 内核的获取,编译以及顶层 Makefile 的简单介绍,这一期开始会对顶层 Makefile进行更加细致的研究。


make xxx_defconfig 过程

第一次编译 Linux 之前都要使用"make xxx_defconfig"先配置 Linux 内核,在顶层 Makefile 中有"%config"这个目标,如下所示:

复制代码
490 config-targets := 0
491 mixed-targets := 0
492 dot-config := 0
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 ifneq ($(KBUILD_EXTMOD),)
501   ifneq ($(filter config %config,$(MAKECMDGOALS)),)
502     config-targets := 1
503   endif
504 endif
---
# 第二部分:混合目标处理
505 ifneq ($(words $(MAKECMDGOALS)),1)
506   mixed-targets := 1
507 endif
508 endif
509 endif
510
511 ifeq ($(mixed-targets),1)
512   # We're called with mixed targets (*config and build targets).
513   # Handle them one by one.
514   PHONY += $(MAKECMDGOALS) __build_one_by_one
515   $(filter-out __build_one_by_one, $(MAKECMDGOALS)): __build_one_by_one
516   __build_one_by_one:
517 	@:
518
519 _build_one_by_one:
520   for i in $(MAKECMDGOALS); do \
521     $(MAKE) -f $(srctree)/Makefile $$i; \
522   done
523
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 $@
542
543 else

......
563 endif # KBUILD_EXTMOD

第 490~507 行和 uboot 一样,都是设置定义变量 config-targets、mixed-targets 和 dot-config

的值,最终这三个变量的值为:

复制代码
config-targets=1
mixed-targets=0
dot-config=1

因为 config-targets=1,因此第 534 行~541 行成立。第 534 行引用 arch/arm/Makefile 这个文

件,这个文件很重要,因为 zImage、uImage 等这些文件就是由 arch/arm/Makefile 来生成的。

第 535 行导出变量 KBUILD_DEFCONFIG KBUILD_KCONFIG。

第 537 行,没有目标与之匹配,因此不执行。

第 540 行,"make xxx_defconfig"与目标"%config"匹配,因此执行。"%config"依赖scripts_basic、outputmakefile 和 FORCE,"%config"真正有意义的依赖就只有 scripts_basic, scripts_basic 的规则如下:

复制代码
scripts_basic:
	$(Q)$(MAKE) $(build)=scripts/basic
	$(Q)rm -f .tmp_quiet_recordmcount

build 定义在文件 scripts/Kbuild.include 中,值为 build := -f $(srctree)/scripts/Makefile.build obj,因此将上述代码展开就是:

复制代码
scripts_basic:
	@make -f ./scripts/Makefile.build obj=scripts/basic    // 也可以没有@,视配置而定
	@rm -f .tmp_quiet_recordmcount                       // 也可以没有@

其实

复制代码
%config: scripts_basic outputmakefile FORCE
	$(Q)$(MAKE) $(build)=scripts/kconfig $@

展开就是:

复制代码
@make -f ./scripts/Makefile.build obj=scripts/kconfig xxx_defconfig

总结

本期主要对make xxx_defconfig 过程进行了介绍。

相关推荐
RisunJan几秒前
Linux命令-lpq(查看打印队列状态)
linux·运维·服务器
山君爱摸鱼2 分钟前
Linux-服务进程
linux·运维·服务器
阿乐艾官3 分钟前
【linux文件系统重要目录及命令解释】
linux·运维·服务器
blueSatchel5 分钟前
U-Boot启动后做的事情
linux·u-boot
senijusene8 分钟前
Linux软件编程: Linux 操作系统基础与shell脚本
linux·运维·chrome
郝学胜-神的一滴24 分钟前
超越Spring的Summer(一): PackageScanner 类实现原理详解
java·服务器·开发语言·后端·spring·软件构建
乾元25 分钟前
身份与访问:行为生物识别(按键习惯、移动轨迹)的 AI 建模
运维·网络·人工智能·深度学习·安全·自动化·安全架构
ghostwritten28 分钟前
春节前夕,运维的「年关」:用 Kubeowler 给集群做一次「年终体检」
运维·云原生·kubernetes
予枫的编程笔记28 分钟前
【Linux进阶篇】Linux后台运行避坑指南:nohup、& 用法及Systemd守护进程实操
linux·进程管理·linux运维·nohup·systemctl·ps命令·kill命令
code monkey.31 分钟前
【Linux之旅】Linux 进程间通信(IPC)全解析:从管道到共享内存,吃透进程协作核心
linux·c++·ipc