什么鱼招财旺运多少条:kbuild与KMakefile

来源:百度文库 编辑:中财网 时间:2024/07/07 11:17:19
kbuild与KMakefile Software ? kernel ? kbuild与KMakefile FoldUnfoldTable of Contents顶层Makefile关于.version用yes命令回答make oldconfigbuild and install modules$(call if_changed, xxx)FORCE

顶层Makefile

默认的Makefile的入口点是第一条规则。而Linux内核的Makefile的第一条规则是这样的:

除去上面一长串赋值语句,来到:
PHONY := _all
_all:

是一条空规则。奇怪的是,下面不远处有如下规则:

ifeq ($(KBUILD_EXTMOD),)
_all: all
else
_all: modules
endif

也就是说目标_all被写了两遍。

原因如下:一般Makefile是不允许一个目标被重复写两遍的,如:

a:
echo a1
a:
echo a2

这种情况会生成一条警告,说一条规则将被忽略。但如果第一条规则是一条空规则则是可以的,如:

a:
a:
echo a2

而且还有如下用法:

b:
echo b
a:
echo a

此Makefile如果直接make将会执行echo b,因为这是第一条规则,会被当成默认规则。但如果写成下面的样子:

a:
b:
echo b
a:
echo a

由于第一条空规则的存在,echo a会被当成默认规则执行。
因此Linux内核中的Makefile的_all可以做如下解释:

真正的入口点是

ifeq ($(KBUILD_EXTMOD),)
_all: all
else
_all: modules
endif

这不必保证这几行代码是第一条规则,之前还可以插入任何内容,只需要保证空规则

_all:

是整个文件的第一条规则,正真入口点处的规则便会被当成默认规则被执行。

关于.version

make distclean后第一次make会在顶层目录生成.version文件.
内核在启动时打印出的如下第一句话

Linux version 2.6.23.17-alp_nl-kzm-arm11-g55714743 (kinhi@kinhi0) (gcc version 4.1.2 20081209 (Sony CE Linux 5.0.2.0)) #2 PREEMPT Thu Mar 19 09:29:53 JST 2009

其中的

 #2 PREEMPT

中的#2就是.version文件中的版本号, 表示kernel是由在make distclean之后的第几次make生成的.

参考顶层Makefile中的"#Generate new vmlinux version"段.

用yes命令回答make oldconfig

yes '' | make oldconfig

build and install modules

make modules
make modules_install INSTALL_MOD_PATH=/target/root/fs/

(if INSTALL_MOD_PATH is not specified, modules will be installed to host machine.)

$(call if_changed, xxx)

参考 scripts/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

和 Documentation/kbuild/makefiles.txt

FORCE

Page tags: makefile