永远重拍PHONY静态规则目标

时间:2013-07-30 14:09:24

标签: makefile latex

我现在已经摸不着头脑了一个小时,谷歌已被证明使用有限。 我有一个包含图形的报告的Makefile。图形由目录图形/中的.plot文件表示,gnuplot用于从它们生成.tex和.eps文件。然后使用ps2pdf从.eps生成pdf,最后在report.tex中的\include命令将图形.tex包含到文档中,该文档再次包含图形.pdf以将图形放入最终报告中.PDF。

我有一个正确构建所有内容的Makefile,但出于某种原因,每次运行make时都坚持重新生成report.pdf。通读make -d的输出显示,Make说:“必须重新制作目标mp-int-2.4-ni'." and "Must remake target mp-int-2.4-i'。”每次运行,但这些都被声明为PHONY,因此除非他们所依赖的东西发生变化,否则不应重新制作。或者至少我这么认为?

有关可能导致此问题的原因,以及我如何避免每次都重新制作最终的PDF文件?

生成文件

GRAPHS := mp-int-2.4-ni mp-int-2.4-i

.PHONY : $(GRAPHS)
.PRECIOUS : graphs/%.pdf

report.pdf: report.tex $(GRAPHS)
    # ...

$(GRAPHS): %: graphs/%.pdf graphs/%.tex

graphs/%.pdf: graphs/%.eps
    # ...

graphs/%.tex graphs/%.eps: graphs/%.plot
    # ...
make之后

make -d已经运行

$ make -d | grep -Ev "Trying|Reject|Avoid|intermediate"
Considering target file `report.pdf'.
  Considering target file `report.tex'.
   Looking for an implicit rule for `report.tex'.
   No implicit rule found for `report.tex'.
   Finished prerequisites of target file `report.tex'.
  No need to remake target `report.tex'.
  Considering target file `mp-int-2.4-i'.
   File `mp-int-2.4-i' does not exist.
    Considering target file `graphs/mp-int-2.4-i.pdf'.
     Looking for an implicit rule for `graphs/mp-int-2.4-i.pdf'.
     Found an implicit rule for `graphs/mp-int-2.4-i.pdf'.
       Considering target file `graphs/mp-int-2.4-i.plot'.
        Looking for an implicit rule for `graphs/mp-int-2.4-i.plot'.
        No implicit rule found for `graphs/mp-int-2.4-i.plot'.
        Finished prerequisites of target file `graphs/mp-int-2.4-i.plot'.
       No need to remake target `graphs/mp-int-2.4-i.plot'.
     Finished prerequisites of target file `graphs/mp-int-2.4-i.pdf'.
     Prerequisite `graphs/mp-int-2.4-i.eps' of target `graphs/mp-int-2.4-i.pdf' does not exist.
    No need to remake target `graphs/mp-int-2.4-i.pdf'.
    Considering target file `graphs/mp-int-2.4-i.tex'.
     Looking for an implicit rule for `graphs/mp-int-2.4-i.tex'.
     Found an implicit rule for `graphs/mp-int-2.4-i.tex'.
      Pruning file `graphs/mp-int-2.4-i.plot'.
      Pruning file `graphs/mp-int-2.4-i.plot'.
     Finished prerequisites of target file `graphs/mp-int-2.4-i.tex'.
     Prerequisite `graphs/mp-int-2.4-i.plot' is older than target `graphs/mp-int-2.4-i.tex'.
    No need to remake target `graphs/mp-int-2.4-i.tex'.
   Finished prerequisites of target file `mp-int-2.4-i'.
  Must remake target `mp-int-2.4-i'.
  Successfully remade target file `mp-int-2.4-i'.
  Considering target file `mp-int-2.4-ni'.
   File `mp-int-2.4-ni' does not exist.
    Considering target file `graphs/mp-int-2.4-ni.pdf'.
     Looking for an implicit rule for `graphs/mp-int-2.4-ni.pdf'.
     Found an implicit rule for `graphs/mp-int-2.4-ni.pdf'.
       Considering target file `graphs/mp-int-2.4-ni.plot'.
        Looking for an implicit rule for `graphs/mp-int-2.4-ni.plot'.
        No implicit rule found for `graphs/mp-int-2.4-ni.plot'.
        Finished prerequisites of target file `graphs/mp-int-2.4-ni.plot'.
       No need to remake target `graphs/mp-int-2.4-ni.plot'.
     Finished prerequisites of target file `graphs/mp-int-2.4-ni.pdf'.
     Prerequisite `graphs/mp-int-2.4-ni.eps' of target `graphs/mp-int-2.4-ni.pdf' does not exist.
    No need to remake target `graphs/mp-int-2.4-ni.pdf'.
    Considering target file `graphs/mp-int-2.4-ni.tex'.
     Looking for an implicit rule for `graphs/mp-int-2.4-ni.tex'.
     Found an implicit rule for `graphs/mp-int-2.4-ni.tex'.
      Pruning file `graphs/mp-int-2.4-ni.plot'.
      Pruning file `graphs/mp-int-2.4-ni.plot'.
     Finished prerequisites of target file `graphs/mp-int-2.4-ni.tex'.
     Prerequisite `graphs/mp-int-2.4-ni.plot' is older than target `graphs/mp-int-2.4-ni.tex'.
    No need to remake target `graphs/mp-int-2.4-ni.tex'.
   Finished prerequisites of target file `mp-int-2.4-ni'.
  Must remake target `mp-int-2.4-ni'.
  Successfully remade target file `mp-int-2.4-ni'.
 Finished prerequisites of target file `report.pdf'.
 Prerequisite `report.tex' is older than target `report.pdf'.
 Prerequisite `mp-int-2.4-i' of target `report.pdf' does not exist.
 Prerequisite `mp-int-2.4-ni' of target `report.pdf' does not exist.
Must remake target `report.pdf'.

在下面的Etan Reisner回答之后使用Makefile:

GRAPHS := mp-int-2.4-i mp-int-2.4-ni
GRAPHS_WD := $(addprefix graphs/,$(GRAPHS))
REAL_GRAPHS := $(addsuffix .pdf,$(GRAPHS_WD)) $(addsuffix .tex,$(GRAPH_SWD))

.PHONY : clean

report.pdf: report.tex $(REAL_GRAPHS)
    # ...

graphs/%.pdf: graphs/%.eps
    # ..

graphs/%.tex graphs/%.eps: graphs/%.plot
    # ..

1 个答案:

答案 0 :(得分:7)

PHONY规则是您告诉make的规则与实际文件不对应的规则,因此它不检查文件是否存在,因此它始终假定规则需要运行,因此report.pdf具有以下先决条件:更新(这是输出告诉你的)。

make文档说“伪目标不应该是真实目标文件的先决条件;如果是,则每次make更新该文件时都会运行其配方。” [ref]

您将这些文件标记为PHONY的目的是什么?