6

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

我有一个可以正确构建所有内容的 Makefile,但由于某种原因,每次运行 make 时,make 都会坚持重新制作 report.pdf。阅读make -dMake 的输出后发现:“必须重新制作目标mp-int-2.4-ni'." and "Must remake targetmp-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 -d在 make 已经运行之后

$ 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
    # ..
4

1 回答 1

8

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

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

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

于 2013-07-30T14:21:20.230 回答