没有配方的makefile模式规则

没有配方的makefile模式规则

本文介绍了没有配方的makefile模式规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在观察一个有趣的作品行为,我想知道除了gmake中的错误,是否有合理的解释。



假设我们有以下在makefile中:

 % - 动物:
echo$ *是动物

%-fox:%-fox-animal

%-wolf:%-wolf-animal

最后两个目标之间的区别是%-wolf没有任何配方,%-fox有一个空的配方(即只是开头有一个标签的行) / p>

当我们尝试执行规则时,会发生什么:

  [root @ cv19 tmp]#make freddy-animal 
echofreddy是一个动物
freddy是一个动物
[root @ cv19 tmp]#make freddy-wolf
make :***没有规定使目标freddy-wolf。停止。
[root @ cv19 tmp]#make freddy-fox
echofreddy-fox是一个动物
freddy-fox是一个动物

有一个配方的模式规则(虽然是空的)可以工作,但不是没有。我想要以某种方式工作吗?

解决方案

根本没有食谱的图案规则被记录在一起与提供食谱的人不同,甚至是空的。而是:

因此,您的%-wolf模式实际上用于取消任何现有的% - wolf-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?

解决方案

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.

这篇关于没有配方的makefile模式规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 12:54