gpt4 book ai didi

makefile - make 总是重制 PHONY 静态规则目标

转载 作者:行者123 更新时间:2023-12-02 19:29:19 37 4
gpt4 key购买 nike

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

我有一个 Makefile,它可以正确构建所有内容,但由于某种原因,每次运行 make 时,make 都会坚持重新制作 report.pdf。仔细阅读 make -d 的输出发现 Make 说:“必须重新制作目标 mp-int-2.4-ni'。”和“必须重新制作目标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 -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
# ..

最佳答案

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

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

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

关于makefile - make 总是重制 PHONY 静态规则目标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17949376/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com