从命令行到环境的Makefile变量

时间:2009-10-21 19:13:53

标签: makefile

有没有办法检测是否已从环境设置变量而不是命令行?

我想区分使用make LIB=mylibmake调用make并定义$ LIB的人。

2 个答案:

答案 0 :(得分:5)

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

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

答案 1 :(得分:0)

使用非Gnu make,您可以为相关变量运行export命令和grep。这仅适用于规则,只要变量未设置为一次性(如LIB=foo make)。

相关问题