2009-10-21 149 views
5

有没有办法检测是否已从环境中设置变量与命令行上的变量?命令行与环境的Makefile变量

我想区分有人在调用make与make LIB=mylibmake和$ LIB被定义。

+0

请用[make]标签标记与制作相关的问题。有关基本原理,请参阅http://meta.stackexchange.com/questions/24030/why-do-they-specify-makefile-tag-instead-of-make/26567#26567 – 2009-10-23 20:40:59

回答

5

是的。您可以使用origin函数来确定变量的定义位置。

 
ifneq (,$(findstring environment,$(origin LIB))) 
    # LIB was defined by the environment 
else 
    # LIB was defined some other way 
endif 
0

随着非GNU做,你可能有问题的变量运行export命令和grep。这只适用于规则,只要变量没有设置为一次性(如LIB=foo make)。