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

相关推荐
cui_ruicheng44 分钟前
Linux进程间通信(三):System V IPC与共享内存
linux·运维·服务器
蚰蜒螟1 小时前
深入 Linux 内核同步机制:从 futex 到 spinlock 的完整旅程
linux·windows·microsoft
运维全栈笔记1 小时前
Linux安装配置Tomcat保姆级教程:从部署到性能调优
linux·服务器·中间件·tomcat·apache·web
dllmayday2 小时前
Linux 上用终端连接 WiFi
linux·服务器·windows
ACP广源盛139246256732 小时前
IX8024与科学大模型的碰撞@ACP#筑牢科研 AI 算力高速枢纽分享
运维·服务器·网络·数据库·人工智能·嵌入式硬件·电脑
峥无3 小时前
Linux系统编程基石:静态库·动态库·ELF文件·进程地址空间全景图
linux·运维·服务器
用户2367829801684 小时前
从 chmod 755 说起:Unix 文件权限到底是怎么算的?
linux
码云数智-大飞4 小时前
本地部署大模型:隐私安全与多元优势一站式解读
运维·网络·人工智能
Strugglingler4 小时前
【systemctl 学习总结】
linux·systemd·systemctl·journalctl·unit file
Harvy_没救了5 小时前
【网络部署】 Win11 + VMware CentOS8 + Nginx 文件共享服务 Wiki
运维·网络·nginx