Except by explicit request, make exports a variable only if it is either defined in the environment initially, or if set on the command line and its name consists only of letters, numbers, and underscores.
Reproduce
```
root@a55311a49b3b:/home/xin/ics-pa/nemu# CC=gcc make menuconfig
/home/xin/ics-pa/nemu/scripts/config.mk:20: Warning: .config does not exists!
/home/xin/ics-pa/nemu/scripts/config.mk:21: To build the project, first run 'make menuconfig'.
+ CC confdata.c
+ CC expr.c
+ CC preprocess.c
+ CC symbol.c
+ CC util.c
+ YACC build/parser.tab.h
+ LEX build/lexer.lex.c
+ CC build/lexer.lex.c
+ CC build/parser.tab.c
+ CC mconf.c
+ CC lxdialog/util.c
+ CC lxdialog/checklist.c
+ CC lxdialog/yesno.c
+ CC lxdialog/inputbox.c
+ CC lxdialog/textbox.c
+ CC lxdialog/menubox.c
+ LD /home/xin/ics-pa/nemu/tools/kconfig/build/mconf
+ CC confdata.c
+ CC expr.c
+ CC preprocess.c
+ CC symbol.c
+ CC util.c
+ CC build/lexer.lex.c
+ CC build/parser.tab.c
+ CC conf.c
+ LD /home/xin/ics-pa/nemu/tools/kconfig/build/conf
+ CC fixdep.c
make[1]: O2: No such file or directory
+ LD /home/xin/ics-pa/nemu/tools/fixdep/build/fixdep
/usr/bin/ld: cannot find /home/xin/ics-pa/nemu/tools/fixdep/build/obj-fixdep/fixdep.o: No such file or directory
collect2: error: ld returned 1 exit status
make[1]: *** [/home/xin/ics-pa/nemu/scripts/build.mk:54: /home/xin/ics-pa/nemu/tools/fixdep/build/fixdep] Error 1
make: *** [/home/xin/ics-pa/nemu/scripts/config.mk:42: /home/xin/ics-pa/nemu/tools/fixdep/build/fixdep] Error 2
```
现在编译menuconfig时,会从CONFIG_CC的值中提取CC。但是在初始执行
make menuconfig
时,CONFIG_CC为空,导致CC的值也为空。根据GNU make的文档:如果在调用
make
时,环境变量中有CC,就会导致这个空的CC被export。而fixdep目录下的Makefile没有指定CC,就会导致因为找不到CC而failed。Reproduce
``` root@a55311a49b3b:/home/xin/ics-pa/nemu# CC=gcc make menuconfig /home/xin/ics-pa/nemu/scripts/config.mk:20: Warning: .config does not exists! /home/xin/ics-pa/nemu/scripts/config.mk:21: To build the project, first run 'make menuconfig'. + CC confdata.c + CC expr.c + CC preprocess.c + CC symbol.c + CC util.c + YACC build/parser.tab.h + LEX build/lexer.lex.c + CC build/lexer.lex.c + CC build/parser.tab.c + CC mconf.c + CC lxdialog/util.c + CC lxdialog/checklist.c + CC lxdialog/yesno.c + CC lxdialog/inputbox.c + CC lxdialog/textbox.c + CC lxdialog/menubox.c + LD /home/xin/ics-pa/nemu/tools/kconfig/build/mconf + CC confdata.c + CC expr.c + CC preprocess.c + CC symbol.c + CC util.c + CC build/lexer.lex.c + CC build/parser.tab.c + CC conf.c + LD /home/xin/ics-pa/nemu/tools/kconfig/build/conf + CC fixdep.c make[1]: O2: No such file or directory + LD /home/xin/ics-pa/nemu/tools/fixdep/build/fixdep /usr/bin/ld: cannot find /home/xin/ics-pa/nemu/tools/fixdep/build/obj-fixdep/fixdep.o: No such file or directory collect2: error: ld returned 1 exit status make[1]: *** [/home/xin/ics-pa/nemu/scripts/build.mk:54: /home/xin/ics-pa/nemu/tools/fixdep/build/fixdep] Error 1 make: *** [/home/xin/ics-pa/nemu/scripts/config.mk:42: /home/xin/ics-pa/nemu/tools/fixdep/build/fixdep] Error 2 ```如果在顶层Makefile判断CONFIG_CC非空后再赋值,即可解决这个问题。