vmliux的生成以及相关依赖

来源:互联网 发布:paper airplane软件 编辑:程序博客网 时间:2024/06/08 10:37
分析的版本:
linux3.10.84
分析方法:从顶层makefile进行分析,了解一下为了生成vmlinux,makefile都做了什么。
运行一个新的shell:# SHELL used by kbuildCONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \  else if [ -x /bin/bash ]; then echo /bin/bash; \  else echo sh; fi ; fi)

vmlinux依赖关系中,第一个依赖便是link-vmlinux.sh,这里相当于把第一个依赖加载到shell中,$<便是第一个依赖

# Final link of vmlinux      cmd_link-vmlinux = $(CONFIG_SHELL) $< $(LD) $(LDFLAGS) $(LDFLAGS_vmlinux)quiet_cmd_link-vmlinux = LINK    $@

当执行make命令后,默认生成的便是vmlinux
all: vmlinux
vmlinux的依赖关系vmlinux: scripts/link-vmlinux.sh $(vmlinux-deps) FORCE                    +$(call if_changed,link-vmlinux)     //根据if_changed的作用,就是有任何的文件更新等操作,就重新链接生成vmlinux文件 
vmlinux-deps的依赖
vmlinux-deps := $(KBUILD_LDS) $(KBUILD_VMLINUX_INIT) $(KBUILD_VMLINUX_MAIN)

接下来一次说一下vmlinux-deps的依赖
KBUILD_VMLINUX_INIT := $(head-y) $(init-y)KBUILD_VMLINUX_MAIN := $(core-y) $(libs-y) $(drivers-y) $(net-y) $(virt-y)KBUILD_LDS          := arch/$(SRCARCH)/kernel/vmlinux.ldshead-y := arch/mips/kernel/head.oinit-y:= init/init-y:= $(patsubst %/, %/built-in.o, $(init-y))最后生成:init-y:= init-y/built-in.ocore-y:= usr/core-y+= kernel/ mm/ fs/ ipc/ security/ crypto/ block/core-y:= $(patsubst %/, %/built-in.o, $(core-y))最后生成:core-y:= usr/built-in.o kernel/built-in.o mm/built-in.o fs/built-in.o ipc/built-in.o security/built-in.o crypto/built-in.o block/built-in.olibs-y:= lib/libs-y+= arch/mips/fw/lib/libs-y+= arch/mips/lib/libs-y    := lib/ arch/mips/fw/lib/ arch/mips/lib/libs-y1:= $(patsubst %/, %/lib.a, $(libs-y))libs-y1:= lib/lib.a   arch/mips/fw/lib/lib.a   arch/mips/lib/lib.alibs-y2:= $(patsubst %/, %/built-in.o, $(libs-y))libs-y2:= lib/built-in.o arch/mips/fw/lib/built-in.o arch/mips/lib/built-in.olibs-y:= $(libs-y1) $(libs-y2)最后生成:libs-y:= libs-y/lib.a  libs-y/built-in.odrivers-y:= drivers/ sound/ firmware/drivers-y:= $(patsubst %/, %/built-in.o, $(drivers-y))最后生成:drivers-y:=drivers/built-in.o   sound/built-in.o   firmware/built-in.o  net-y:= net/net-y:= $(patsubst %/, %/built-in.o, $(net-y))最后生成:net-y:=net-y/built-in.ovirt-y:= virt/virt-y:= $(patsubst %/, %/built-in.o, $(virt-y))最后生成:virt-y:=virt-y/built-in.o
这就把源码中所有的目录都包含了,最后链接成vmlinux。
这里看一下这个:if_changed:
位于文件script/Kbuild.include中,直接看注释,了解主要是做什么工作:

#### if_changed      - execute command if any prerequisite is newer than#                   target, or command line has changed# if_changed_dep  - as if_changed, but uses fixdep to reveal dependencies#                   including used config symbols# if_changed_rule - as if_changed but execute rule instead# See Documentation/kbuild/makefiles.txt for more info# Execute command if command has changed or prerequisite(s) are updated.#if_changed = $(if $(strip $(any-prereq) $(arg-check)),                       \@set -e;                                                             \$(echo-cmd) $(cmd_$(1));                                             \echo 'cmd_$@ := $(make-cmd)' > $(dot-target).cmd)# Execute the command and also postprocess generated .d dependencies file.if_changed_dep = $(if $(strip $(any-prereq) $(arg-check) ),                  \@set -e;                                                             \$(echo-cmd) $(cmd_$(1));                                             \scripts/basic/fixdep $(depfile) $@ '$(make-cmd)' > $(dot-target).tmp;\rm -f $(depfile);                                                    \mv -f $(dot-target).tmp $(dot-target).cmd)# Usage: $(call if_changed_rule,foo)# Will check if $(cmd_foo) or any of the prerequisites changed,# and if so will execute $(rule_foo).if_changed_rule = $(if $(strip $(any-prereq) $(arg-check) ),                 \@set -e;                                                             \$(rule_$(1)))


原创粉丝点击