http://blog.chinaunix.net/uid-20564848-id-215793.html
其中
/gliethttp.ini是一个存在的空文件
/gliethttp/auto.conf不存在
我们可以看到,如果-include的文件不存在,首先不会报错,
其次如果在整个makefile中如果发现有创建该文件的规则,那么会在终极目标(第1个目标)
执行之前,首先尝试执行创建该-include文件的目标,
所以这时该文件目标就先于终极目标被make执行[luther.gliethttp]
luther@gliethttp:~$ make
222
111
来看看kernel的Makefile片段,
当我们执行make时,首先Makefile被make走一遍,提取规则和变量等,
如果是第1次执行,那么include/config/auto.conf并不存在,
所以我们看到
make -f /home/gliethttp/kernel/Makefile silentoldconfig
是第1条被执行的规则命令
luther@gliethttp:~/kernel$ make V=1
如下是kernel的Makefile片段内容
其中
/gliethttp.ini是一个存在的空文件
/gliethttp/auto.conf不存在
我们可以看到,如果-include的文件不存在,首先不会报错,
其次如果在整个makefile中如果发现有创建该文件的规则,那么会在终极目标(第1个目标)
执行之前,首先尝试执行创建该-include文件的目标,
所以这时该文件目标就先于终极目标被make执行[luther.gliethttp]
- {{{
- all:
- @echo 111
- -include /gliethttp/auto.conf
- /gliethttp/auto.conf:
- @echo 222
- -include /gliethttp.ini
- /gliethttp.ini:
- @echo 333
- }}}
luther@gliethttp:~$ make
222
111
来看看kernel的Makefile片段,
当我们执行make时,首先Makefile被make走一遍,提取规则和变量等,
如果是第1次执行,那么include/config/auto.conf并不存在,
所以我们看到
make -f /home/gliethttp/kernel/Makefile silentoldconfig
是第1条被执行的规则命令
luther@gliethttp:~/kernel$ make V=1
- {{{
- make -f /home/gliethttp/kernel/Makefile silentoldconfig
- make -f scripts/Makefile.build obj=scripts/basic
- gcc -Wp,-MD,scripts/basic/.fixdep.d -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer -o scripts/basic/fixdep scripts/basic/fixdep.c
- gcc -Wp,-MD,scripts/basic/.docproc.d -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer -o scripts/basic/docproc scripts/basic/docproc.c
- gcc -Wp,-MD,scripts/basic/.hash.d -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer -o scripts/basic/hash scripts/basic/hash.c
- mkdir -p include/linux include/config
- make -f scripts/Makefile.build obj=scripts/kconfig silentoldconfig
- }}}
如下是kernel的Makefile片段内容
- {{{
- # Read in config
- -include include/config/auto.conf
-
- ifeq ($(KBUILD_EXTMOD),)
- # Read in dependencies to all Kconfig* files, make sure to run
- # oldconfig if changes are detected.
- -include include/config/auto.conf.cmd
-
- # To avoid any implicit rule to kick in, define an empty command
- $(KCONFIG_CONFIG) include/config/auto.conf.cmd: ;
-
- # If .config is newer than include/config/auto.conf, someone tinkered
- # with it and forgot to run make oldconfig.
- # if auto.conf.cmd is missing then we are probably in a cleaned tree so
- # we execute the config step to be sure to catch updated Kconfig files
- include/config/auto.conf: $(KCONFIG_CONFIG) include/config/auto.conf.cmd
- $(Q)$(MAKE) -f $(srctree)/Makefile silentoldconfig
- }}}