作为从 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
Run Code Online (Sandbox Code Playgroud)
我的人物是 .dot 文件,我将其转换为 PNG 文件。我可以使用一些基本的 shell 命令来制作 PNG,但是使用 shell 脚本没有意义,因为你会失去make.
这是我在阅读一些文档后一直在尝试的内容。
%.png: %.dot
dot -Tpng $(.SOURCE) -o $(.TARGET)
Run Code Online (Sandbox Code Playgroud)
和
.dot.png:
dot -Tpng $(.SOURCE) -o $(.TARGET)
Run Code Online (Sandbox Code Playgroud)
但是,每当我尝试直接运行目标时,终端打印的是:
dot -Tpng -o
Run Code Online (Sandbox Code Playgroud)
它之所以成立,是因为它等待来自 STDIN 的输入,因为没有输入文件。
如果我尝试通过运行来调用规则,make *.dot我会得到输出:
make: Nothing to be done for `figure-1a.dot'.
make: Nothing to be done for `figure-1b.dot'.
Run Code Online (Sandbox Code Playgroud)
我显然不明白我需要做什么。每次创建 PDF 时,如何让 makefile 获取所有 .dot 文件并创建 .png 文件?
更新:这是我尝试过的另一次尝试
graphs := $(wildcard *.dot)
.dot.png: $(graphs)
dot -Tpng $(.SOURCE) -o $(.TARGET).png
Run Code Online (Sandbox Code Playgroud)
GNU make 使用$<and $@,而不是.SOURCEand .TARGET,配方应该是
.PHONY: all
all: $(patsubst %.dot,%.png,$(wildcard *.dot))
%.png: %.dot
dot -Tpng $< -o $@
Run Code Online (Sandbox Code Playgroud)