强制 make 使用更具体的规则

Force make to use a more specific rule

我似乎无法强制 make 使用更具体的规则。我正在使用版本 3.81,它是 supposed to use the first rule it comes to,但是当更具体的规则具有必须使用另一个规则 构建的依赖项 时,这似乎不起作用。这是基本图片:

#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 使用 .bbl 文件构建 pdf,如果它匹配 some_prefix,否则使用更通用的规则。不幸的是,除非我删除对 .bbl 文件的依赖,否则永远不会调用第二条规则。

我似乎可以通过在一般规则中添加 hack 来让它工作:

%.pdf: %.tex %.hack
    <make the pdf with a more general rule>

%.hack: %.tex
    touch $@

这似乎有效,并且 .hack 文件会自动删除,但顾名思义,这是一个可怕的 hack。似乎必须有一些更好的方法来强制使用特定规则。

如何强制 make 使用更具体的规则?放在第一位似乎没有帮助。

您忘记了 implicit rule search algorithm 的一个非常重要的方面:make 总是 更喜欢具有显式目标先决条件的隐式规则,而不是隐式其中一个先决条件模式与已知目标不匹配且必须通过规则链构建的规则。请参阅算法中的步骤 #5 与步骤 #6。这与模式规则的正常 "first in the makefile" 排序不同。

如果你想这样做,你必须将 bbl 规则写成静态模式规则,而不是真正的模式规则,这样 bbl 文件是显式目标而不是隐式目标目标。