Makefile Gnu make:ifeq和$*
我试图测试配方中Makefile Gnu make:ifeq和$*,makefile,gnu-make,Makefile,Gnu Make,我试图测试配方中$*的值 main.txt: main.dat # ... other.txt: other.dat # ... %.dat: # ... ifeq "$*" "other" # .., do something special for 'other' endif 但是,我似乎无法正确理解语法。无论我如何编写ifeq“$*”other”语句都不会执行。自动变量如$*在make解析makefile后会展开
$*
的值
main.txt: main.dat
# ...
other.txt: other.dat
# ...
%.dat:
# ...
ifeq "$*" "other"
# .., do something special for 'other'
endif
但是,我似乎无法正确理解语法。无论我如何编写
ifeq“$*”other”
语句都不会执行。自动变量如$*
在make解析makefile后会展开,因此不能在条件中使用它们。但您可以使用shell条件:
%.dat:
if [ "$*" = "other" ]; then \
do something special for other; \
else \
do something else for others than other; \
fi
但由于模式规则的优先级低于非模式规则,您不妨尝试:
other.dat:
do something for other
%.dat:
do something else for others than other
换一种说法,自动变量在配方中只有一个值(用制表符缩进)。它们不是在食谱之外设定的。另一方面,配方是shell脚本,而不是make语法,因此不能在配方中使用make语法,如
ifeq
(不能用制表符缩进),因为它将传递给shell,而不是由make解析,并且shell对ifeq
一无所知。因此,不能将自动变量与make构造一起使用,例如ifeq
:它们存在于完全独立的域中,不会重叠。