gpt4 book ai didi

点文件的 Makefile (graphviz)

转载 作者:行者123 更新时间:2023-12-02 04:05:52 25 4
gpt4 key购买 nike

作为从 latex 文件生成 PDF 的一部分,我从 tex.stackexchange.com 获得了一个 makefile。 .

# You want latexmk to *always* run, because make does not have all the info.
# Also, include non-file targets in .PHONY so they are run regardless of any
# file of the given name existing.
.PHONY: paper-1.pdf all clean

# The first rule in a Makefile is the one executed by default ("make"). It
# should always be the "all" rule, so that "make" and "make all" are identical.
all: paper-1.pdf

# CUSTOM BUILD RULES

# In case you didn't know, '$@' is a variable holding the name of the target,
# and '$<' is a variable holding the (first) dependency of a rule.
# "raw2tex" and "dat2tex" are just placeholders for whatever custom steps
# you might have.

%.tex: %.raw
./raw2tex $< > $@

%.tex: %.dat
./dat2tex $< > $@

# MAIN LATEXMK RULE

# -pdf tells latexmk to generate PDF directly (instead of DVI).
# -pdflatex="" tells latexmk to call a specific backend with specific options.
# -use-make tells latexmk to call make for generating missing files.

# -interaction=nonstopmode keeps the pdflatex backend from stopping at a
# missing file reference and interactively asking you for an alternative.

paper-1.pdf: paper-1.tex
latexmk -bibtex -pdf -pdflatex="pdflatex -interaction=nonstopmode" -use-make paper-1.tex

clean:
latexmk -bibtex -CA

我的图形是 .dot 文件,我将其转换为 PNG 文件。我可以使用一些基本的 shell 命令来制作 PNG,但使用 shell 脚本没有意义,因为你失去了 make 的优势。

这是我在阅读一些文档后一直在尝试的内容。

%.png: %.dot
dot -Tpng $(.SOURCE) -o $(.TARGET)

.dot.png:
dot -Tpng $(.SOURCE) -o $(.TARGET)

但是,每当我尝试直接运行目标时,终端打印的是:

dot -Tpng  -o

它之所以成立,是因为它等待来自 STDIN 的输入,因为没有输入文件。

如果我尝试通过运行 make *.dot 来调用规则,我会得到输出:

make: Nothing to be done for `figure-1a.dot'.
make: Nothing to be done for `figure-1b.dot'.

我显然不明白我需要做什么。如何让 makefile 在每次创建 PDF 时获取所有 .dot 文件并创建 .png 文件?

更新:这是我尝试过的另一次尝试

graphs := $(wildcard *.dot)
.dot.png: $(graphs)
dot -Tpng $(.SOURCE) -o $(.TARGET).png

最佳答案

GNU make 使用$<$@ ,不是.SOURCE.TARGET ,食谱应该是

.PHONY: all

all: $(patsubst %.dot,%.png,$(wildcard *.dot))

%.png: %.dot
dot -Tpng $< -o $@

关于点文件的 Makefile (graphviz),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39603422/

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