Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
709 views
in Technique[技术] by (71.8m points)

makefile - Force make to use a more specific rule

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>

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.

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 $@

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...