[194] ifeq need-sub-make = 0
该篇主要分析这部分主makefile内容
[1906] end need-sub-make
[211] C: 源代码check, KBUILD_CHECKSRC
[220] M: 指定外部模块目录,KBUILD_EXTMOD
extmod-prefix: 外部模块路径
ifeq ($(abs_srctree),$(abs_objtree))
srctree := .
building_out_of_srctree :=
else
ifeq($(abs_srctree)/, $(dir $(abs_objtree)))
srctree :=
else
srctree := $(abs_srctree)
endif
building_out_of_srctree := 1
endif
objtree := .
VPATH := $(srctree) 为什么不直接用绝对路径
version_h
clearn-target :=
no-dot-config-targets
no-sync-config-targets
single-targets:
config-build:
默认空,如果KBUILD_EXTMOD为空,且MAKECMDGOALS包含%config,置1;
mixed-build:
默认空,
如果KBUILD_EXTMOD为空,且MAKECMDGOALS包含%config,且多于1个 goals,置1;
如果MAKECMDGOALS 包含有single-targets,且还包含有其他,置1;
如果MAKECMDGOALS包含有clean-targets,且还包含有其他,置1;
如果MAKECMDGOALS包含有install,和modules-install,置1;
need-config:
默认是1,如果MAKECMDGOALS 只包含 no-dot-config-targets,清空;
may-sync-config:
默认是1,如果MAKECMDGOALS 只包含no-sync-config-targets,清空;
如果KBUILD_EXTMOD被定义,清空;
single-build:
默认空,如果MAKECMDGOALS包含single-targets,置1;
[327]ifdef mixed-build
递归构建每一个goals
__build_one_by_one:
for $(MAKECMDGOALS):
make -f $(srctree)/Makefile each
[343]else mixend-build
单个构建的处理放在下面分析
[1905]end mixend-build
include scripts/kbuild.include: 各种makefile函数的定义
KERNELRELEASE KERNELVERSION
include scripts/subarch.include: 获取宿主机架构SUBARCH
ARCH ?= $SUBARCH: 交叉编译的话,需要提前指定ARCH
UTS_MACHINE := $ARCH
SRCATCH := $ARCH
KCONIFG_CONFIG ?= .config
KBUILD_DEFCONFIG := defconfig
HOST配置:编译选项,shell等
[430]交叉编译器配置:
CC = $(CROSS_COMPILE)gcc
LD = $(CROSS_COMPILE)gcc
.......
[472]各种FLAG:
CHECKFLAGS:
NOSTDINC_FLAGS:
CFLAGS_MODULE:
.........
[483]USERINCLUDE
LINUXINCLUDE
KBUILD_XXXX
[539]config 目标和 build 目标共享的规则
scripts_basic: 基础的辅助构建, make $(build)=scripts/basic
outputmakefile: 如果obj和src不是同一个目录,在obj目录生成makefile,根据前面定义的宏building_out_of_srctree来判断是否需要
CC_VERSION_TEXT
[592] end config 目标和 build 目标共享的规则
[594] ifdef config-build
include arch/$(SRCARCH)/Makefile: 获取KBUILD_DEFCONFIG定义
%config or config: outputmakefile scriptps 构建kconfig
make $build=scripts/kconfig $@
[611]else config-build
build目标构建分析
[1904]end config-build
[612]config-build = 0
__all: 如果定义KBUILD_EXTMOD,则依赖modules,否则依赖all
KBUILD_MODULES:
默认空;
如果MAKECMDGOALS包含 all modules nsdeps,则置1;
如果MAKECMDGOALS为空,则置1;
KBUILD_BUILTIN:
默认1;
如果MAKECMDGOALS 是 modules, 则清空;
include include/config/auto.conf: 如果定义 need-config,则包含。里面包含了kconfig生成的所有配置
[654]KBUILD_EXTMOD为空: 构建vmlinux
core-y := init/ usr/
drivers-y := drivers/ sound/
drivers-$(CONFIG_SAMPLES) += samples/
drivers-y += net/ virt/
libs-y := lib/
[661]end KBUILD_EXTMOD为空
all: vmlinux all 默认目标
[669] 一些编译选项的宏
include arch/$(SRCARCH)/Makefile: 可以在这个目录增加架构相关的配置
[690] ifdef need-config
[691]ifdef may-sync-config
include include/config/auto.conf.cmd: 定义了 kconfig文件的依赖关系,以及auto.conf,确保这些可以是最新的
%/config/auto.conf %/config/auto.conf.cmd %/generated/autoconf.h: $(KCONFIG_CONFIG)
make -f $(srctree)/Makefiel syncconfig
[715]else may-sync-config
include/config/auto.conf: ????
[730] end may-sync-config
[731] end ifdef need-config
kBUILD_xx: 编译选项控制
[961] include-y: scripts/Makefile.xxxx
KBUILD_IMAGR ?= vmlinux
INSTALL_PATH ?= /boot
INSTALL_DTBS_PATH = $(INSTALL_PATH)/dtbs/$(KERNELRELEASE)
MODLIB = $(INSTALL_MOD_PATH)/lib/modules/$(KERNELRELEASE)
module strip compressed sign: 相关操作
[1096] MODORDER: $(extmod-prefix)modules.order
MODULES_NSDEPS: $(extmod-prefix)modules.nsdeps
[1099] if 没有定义KBUILD_EXTMOD
core-y += kernel/ certs/ mm/ fs/ ipc/ security/ crypto/ block/
vmlinux-dir = core-y core-m drivers-y drivers-m libs-y libs-m
vmlinux-alldir = vmlinux-dir Documentation core- drivers- libs-
subdir-modorder = core-y/modules.order core-m/modules.order libxxx driversxxx
build-dirs = vmlinux-dir
clean-dirs = vmlinux-alldirs
KBUILD_VMLINUX_OBJS = head-y core-y/built-in.a libs-y/built-in.a drivers-y/built-in.a
ifdef CONFIG_MODULES(来自kconfig), += libs-y/lib.a
KBUILD_VMLINUX_LIBS =
ifdef CONFIG_MODULES, +=libs-y(非/结尾),否则libs-y/lib.a
KBUILD_LDS = arch/$(SRCARCH)/kernel/vmlinux.lds
KBUILD_ALLDIRS: 供 scripts/Makefile.package使用
vmlinux-deps = KBUILD_LDS KBUILD_VMLINUX_OBJS KBUILD_VMLINUX_LINBS
autoksyms_recursive:
ifdef CONFIG_TRIM_UNUSED_KSYMS
KBUILD_MODULES = 1
autoksyms_recursive: descend modules.order
shell $(srctree)/scripts/adjust_autoksyms.sh :
make -f $(srctree)/Makefile vmlinux
endif
autoksyms_h quiet_cmd_autoksyms_h cmd_autoksyms_h
autoksyms_h: xxxx
ARCH_POSTLINK: arm没有
cmd_link-vmlinux: ld
vmlinux: scripts/link-vmlinux.sh autoksyms_recursive $(vmlinux-deps)
targets := vmlinux
vmlinux-deps subdir-modorder : descend
archprepare: outputmakefile archheaders archscripts scripts include/cnfig/kernel.release ... include/generates/autoconf.h
prepare: prepare0 prepare-objtool preprare-resolve_btfids
asm-generic
[1270] kernel header:生成和安装
[1307] kernel selftest: 运行自检脚本
[1324] devicetree file:
[1370] modules ifdef CONFIG_MODULES
modules: vmlinux modules_check
make -f scriptes/Makefile.modpost
cmd_modules_order =
[1440] else CONFIG_MODULES
[1675] else KBUILD_EXTMOD
[1729] end KBUILD_EXTMOD