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 过程进行了介绍。

相关推荐
woho7788999 分钟前
不同网段IP的网络打印机,打印、扫描设置
运维·服务器·网络
耗子会飞16 分钟前
小白学习固定VM虚拟机的centos服务器的IP
运维·服务器·centos
dddddppppp12328 分钟前
qemu模拟的一个内核驱动 io口中断
linux
程序员老赵1 小时前
超全 Docker 镜像源配置指南|Windows/Mac/Linux一键搞定,拉镜像再也不卡顿
linux·后端·容器
门豪杰1 小时前
Ubuntu下安装Claude Code
linux·运维·ubuntu·claude·claude code
总要冲动一次1 小时前
离线安装 percona-xtrabackup-24
linux·数据库·mysql·centos
新新学长搞科研1 小时前
第五届电子、集成电路与通信技术国际学术会议(EICCT 2026)
运维·人工智能·自动化·集成测试·信号处理·集成学习·电气自动化
桌面运维家2 小时前
Windows/Linux双启动:BIOS/UEFI多配置桌面创建指南
linux·运维·windows
xlp666hub2 小时前
【Linux驱动实战】:字符设备驱动之内核态与用户态数据交互
linux·面试
無法複制2 小时前
debian安装Postgresql-14.x
运维·postgresql·debian