如何讓include/config/auto.conf超越終極目標的

http://blog.chinaunix.net/uid-20564848-id-215793.html

其中
/gliethttp.ini是一個存在的空文件
/gliethttp/auto.conf不存在
我們可以看到,如果-include的文件不存在,首先不會報錯,
其次如果在整個makefile中如果發現有創建該文件的規則,那麼會在終極目標(第1個目標)
執行之前,首先嚐試執行創建該-include文件的目標,
所以這時該文件目標就先於終極目標被make執行[luther.gliethttp]
  1. {{{
  2. all:
  3.     @echo 111
  4. -include /gliethttp/auto.conf
  5. /gliethttp/auto.conf:
  6.     @echo 222
  7. -include /gliethttp.ini
  8. /gliethttp.ini:
  9.     @echo 333
  10. }}}

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
  1. {{{
  2. make -/home/gliethttp/kernel/Makefile silentoldconfig
  3. make -f scripts/Makefile.build obj=scripts/basic
  4.   gcc -Wp,-MD,scripts/basic/.fixdep.-Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer -o scripts/basic/fixdep scripts/basic/fixdep.
  5.   gcc -Wp,-MD,scripts/basic/.docproc.-Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer -o scripts/basic/docproc scripts/basic/docproc.
  6.   gcc -Wp,-MD,scripts/basic/.hash.-Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer -o scripts/basic/hash scripts/basic/hash.
  7. mkdir -include/linux include/config
  8. make -f scripts/Makefile.build obj=scripts/kconfig silentoldconfig
  9. }}}

如下是kernel的Makefile片段內容
  1. {{{
  2. # Read in config
  3. -include include/config/auto.conf

  4. ifeq ($(KBUILD_EXTMOD),)
  5. # Read in dependencies to all Kconfig* files, make sure to run
  6. # oldconfig if changes are detected.
  7. -include include/config/auto.conf.cmd

  8. # To avoid any implicit rule to kick in, define an empty command
  9. $(KCONFIG_CONFIG) include/config/auto.conf.cmd: ;

  10. # If .config is newer than include/config/auto.conf, someone tinkered
  11. # with it and forgot to run make oldconfig.
  12. # if auto.conf.cmd is missing then we are probably in a cleaned tree so
  13. # we execute the config step to be sure to catch updated Kconfig files
  14. include/config/auto.conf: $(KCONFIG_CONFIG) include/config/auto.conf.cmd
  15.     $(Q)$(MAKE) -f $(srctree)/Makefile silentoldconfig
  16. }}}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章