没有配方的 makefile 模式规则
我正在观察 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
即具有配方(尽管是空的)的模式规则有效,而没有配方的模式规则则无效。我是否错过了它应该工作的方式?
I'm observing an interesting behavior of make and I wonder if there is a reasonable explanation to it besides a bug in gmake.
Let's say we have the following in makefile:
%-animal:
echo "$* is an animal"
%-fox: %-fox-animal
%-wolf: %-wolf-animal
The difference between the last two targets is that "%-wolf" does not have any recipe, and "%-fox" has an empty recipe (i.e. just a line with a tab at the beginning).
When we try to execute the rules, here's what happens:
[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
i.e.the pattern rule that has a recipe (although an empty one) works, the one that doesn't does not. Am I missing something in the way it's supposed to work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根本没有配方的模式规则被记录为与提供配方(甚至是空配方)的含义完全不同的东西。相反,他们取消任何预先存在的隐式规则:
因此,您的“%-wolf”模式实际上用于取消 %-wolf-animal 的任何现有隐式规则 -> %-狼。反正也没有。
Pattern rules with no recipes at all are documented as meaning something quite different from those providing a recipe, even an empty one. Instead they cancel any pre-existing implicit rule:
Thus your "%-wolf" pattern actually serves to cancel any existing implicit rule for %-wolf-animal -> %-wolf. And there wasn't one anyway.