在makefile中指定重建策略

在makefile中指定重建策略,makefile,pdf-generation,Makefile,Pdf Generation,我有一个包含许多latex文档的文件夹scructure。我假设所有.tex文件都可以生成,除非它们位于前缀为00-的文件夹下: ./presentation/slide.tex → BUILD ./presentation/section/1-introduction.tex → BUILD ./presentation/00-assets/packages.tex → DONT BUILD 我的makefile非常简单: CC := latexmk

我有一个包含许多latex文档的文件夹scructure。我假设所有
.tex
文件都可以生成,除非它们位于前缀为
00-
的文件夹下:

./presentation/slide.tex                  → BUILD
./presentation/section/1-introduction.tex → BUILD
./presentation/00-assets/packages.tex     → DONT BUILD
我的makefile非常简单:

CC := latexmk -pdf -pdflatex="pdflatex -interaction=nonstopmode" -use-make

all: makefile
    @find -L . -not -path "*/.*" -not -path "*/00-*" -name "*.tex" -execdir $(MAKE) -f $(PWD)/makefile {} \;
%.tex:
    $(CC) $@
不幸的是,它不起作用,因为我不知道如何指定产品是
%.pdf
,而
%.tex
是输入文件。如果
.pdf
文件不存在,或者源文件自上次生成以来已被修改,我不知道如何指定必须生成源文件

有人能帮我吗?

以后有一个
输出目录
选项

tex := latexmk -pdf -pdflatex="pdflatex -interaction=nonstopmode" -use-make

texfiles != find -L . -not -path "*/.*" -not -path "*/00-*" -name "*.tex"

.PHONY: all

all: $(texfiles:.tex=.pdf)

%.pdf: %.tex
    $(tex) -output-directory $(@D) $<
tex:=latexmk-pdf-pdflatex=“pdflatex-interaction=nonstopmode”-使用make
texfiles!=查找-L-not-路径“*/.*”-not-路径“*/00-*”-名称“*.tex”
冒牌货:全部
全部:$(tex文件:.tex=.pdf)
%.pdf:%.tex
$(tex)-输出目录$(@D)$<

使用
$(shell…
而不是
=如果您使用的是旧版本的SUP.

我不确定您想做什么,但请考虑:

每个非虚假规则都必须用其目标的确切名称更新文件

嗯,这不是强制性的,不遵守这些规则是一个非常糟糕的主意,如果你不知道自己在做什么,那就更糟了。如果我对Latex理解得足够透彻,那么您的.tex文件不是构建输出,而是输入,因此它不应该是目标,而应该是目标的先决条件

我建议通过删除%.tex规则并将其替换为以下内容来修改生成文件:

%.pdf: %.tex
    $(CC) $^
现在我不确定Latex的PDF生成是如何工作的,但是有了它,您将为所有给定的.tex文件生成一个PDF文件。您只需在
all
目标的先决条件中指定所有.tex文件

-输出目录$(@D)
在解析相对路径时会导致问题。我发现
-cd
选项更有用。谢谢你的回答!