强制使用更具体的规则 [英] Force make to use a more specific rule
问题描述
我似乎无法强迫make
使用更具体的规则.我正在使用版本3.81,该版本应该使用它涉及的第一个规则,但这似乎没有当更具体的规则具有依赖项必须与另一个规则一起构建时,该规则便可以正常工作.这是基本图片:
I can't seem to force make
to use a more specific rule. I'm working with version 3.81, which is supposed to use the first rule it comes to, but this doesn't seem to work when the more specific rule has a dependency that must be constructed with another rule. Here's the basic picture:
#rule for the dependency of the more specific rule
%.bbl: %.tex *.bib
<build the .bbl file>
#more specific rule
some_prefix%.pdf: some_prefix%.tex some_prefix%.bbl
<build the .pdf>
#general rule
%.pdf: %.tex
<build the .pdf>
因此,基本上,我希望make
与some_prefix
匹配时使用.bbl
文件构建pdf,否则请使用更通用的规则.不幸的是,除非我删除对.bbl
文件的依赖性,否则永远不会调用第二条规则.
So basically I want make
to build the pdf with the .bbl
file if it matches some_prefix
, otherwise use the more general rule. Unfortunately, unless I remove the dependency on the .bbl
file, the second rule never gets called.
我似乎可以通过向一般规则中添加hack来使其正常工作:
I seem to be able to get it working by adding a hack to the general rule:
%.pdf: %.tex %.hack
<make the pdf with a more general rule>
%.hack: %.tex
touch $@
这似乎可行,并且.hack
文件会自动删除,但是顾名思义,这是一个可怕的骇客.似乎必须有一些更好的方法来强制使用特定规则.
This seems to work, and the .hack
files are deleted automatically, but as the name implies, this is a terrible hack. It seems like there must be some better way to force the use of the specific rule.
如何强制使使用更具体的规则?放在第一位似乎没有帮助.
How can I force make to use the more specific rule? Putting it first doesn't seem to help.
推荐答案
You are forgetting a very important aspect of the implicit rule search algorithm: make
always prefers implicit rules which have prerequisites which are explicit targets, over an implicit rule where one of the prerequisite patterns does not match a known target and must be built by rule chaining. See step #5 in the algorithm, vs. step #6. This is apart from the normal "first in the makefile" ordering of pattern rules.
如果要执行此操作,则必须将bbl
规则写为静态模式规则,而不是实际模式规则,以便bbl
文件是显式目标,而不是隐式目标.
If you want to do this you'll have to write the bbl
rule as a static pattern rule, not a real pattern rule, so that the bbl
files are explicit targets not implicit targets.
这篇关于强制使用更具体的规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!