我正在观察 make 的一个有趣行为,我想知道除了 gmake 中的错误之外是否还有合理的解释。
假设我们在makefile中有以下内容:
%-animal:
echo "$* is an animal"
%-fox: %-fox-animal
%-wolf: %-wolf-animal
最后两个目标的区别在于“%-wolf”没有任何配方,而“%-fox”有一个空配方(即只有一行开头有一个制表符)。
当我们尝试执行规则时,会发生以下情况:
[root@cv19 tmp]# make freddy-animal
echo "freddy is an animal"
freddy is an animal
[root@cv19 tmp]# make freddy-wolf
make: *** No rule to make target `freddy-wolf'. Stop.
[root@cv19 tmp]# make freddy-fox
echo "freddy-fox is an animal"
freddy-fox is an animal
即具有配方的模式规则(尽管是空的)有效,没有配方的则无效。我是否错过了它应该工作的方式?