使隐式规则在没有命令的情况下不起作用 [英] make implicit rules don't work without command
问题描述
我有一个像这样的简单Makefile:
I have a simple Makefile like this:
%.t1: %.t2
%.t2:
echo "t2"
当我键入
make x.t2
它工作正常.但是当我打字
make x.t1
我得到
When I type
make x.t2
it works fine. But when I type
make x.t1
I get
make: *** No rule to make target 'x.t1'. Stop.
如果我将%.t1目标修改为说
If I modify the %.t1 target to say
%.t1: %.t2
echo
然后它起作用.如果没有命令,为什么它不起作用?我在Fedora 23上使用GNU make 4.0.
Then it works. Why doesn't it work without a command? I'm using GNU make 4.0 on Fedora 23.
推荐答案
没有配方的模式规则不会添加规则,它会取消隐式规则.参见 http://www.gnu.org/software/make/manual/make.html#Canceling-Rules :
A pattern rule with no recipe does not add a rule, it cancels implicit rules. See http://www.gnu.org/software/make/manual/make.html#Canceling-Rules:
您可以通过定义具有相同目标和先决条件但没有配方的模式规则来取消内置的隐式规则.例如,以下将取消运行汇编程序的规则:
You can cancel a built-in implicit rule by defining a pattern rule with the same target and prerequisites, but no recipe. For example, the following would cancel the rule that runs the assembler:
%.o : %.s
可以添加一个分号来告知它有一个空配方:
A semi-colon can be added to tell make that it has an empty recipe:
%.t1: %.t2 ;
%.t2:
echo t2
哪种产量:
$ make x.t1
t2
这篇关于使隐式规则在没有命令的情况下不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!