2014-10-09 58 views
1

我有一个简单的Makefile(只是用于测试)奇怪行为做出

define my_macro 
var_$(1) := $(1) 
$(warning $(var_$(1)))  
$(warning $(var_some_value)) 
endef 

$(eval $(call my_macro,some_value)) 
$(warning $(var_some_value)) 

使用GNU make(V 3.80)产生:

Makefile:8: 
Makefile:8: 
Makefile:10: some_value 

为什么第一和第二甚至警告不要打印什么?

回答

1

作为手册说,The argument to the eval function is expanded, then the results of that expansion are parsed as makefile syntax.

这意味着eval得到由在宏$(1)some_value扩大到这样的:

var_some_value := some_value 
$(warning $(var_some_value)) 
$(warning $(var_some_value)) 

那么变量$(var_some_value)被扩大,但在这一点上宏扩展的结果尚未被评估为makefile语法,因此该变量尚未设置。这意味着它扩展为:

var_some_value := some_value 
$(warning) 
$(warning) 

然后最后是扩展后的文字处理为makefile文件的语法,所以变量被定义,那么空的警告得到打印。