2016-09-20 37 views
3

我有一个包含许多乳胶文档的文件夹scructure。我认为所有.tex文件可以被建立,除非它们与00-前缀的文件夹下:在makefile中指定重建策略

./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) [email protected] 

不幸的是,我没有它不工作知道如何指定产品是%.pdf,并且%.tex是输入文件。如果.pdf文件不存在,或者源文件自上次构建以来已被修改,我不知道如何指定必须构建源文件。

任何人都可以帮助我吗?

回答

2

latexmk 4.27a此后有output-directory选项。

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) $< 

使用$(shell ...),而不是!=如果您使用化妆的旧版本。

+0

'-output-directory $(@ D)'在解析相对路径时会导致问题。我发现'-cd'选项更有用。 无论如何您的答案! – Amxx

0

我不知道理解你正在试图做什么,而是考虑the second rule of Makefiles

每个非.PHONY规则必须更新文件与目标的确切名称。

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

我建议通过删除%.tex规则并以此代替它来修改你的Makefile:

%.pdf: %.tex 
    $(CC) $^ 

现在,我不知道从乳胶生成PDF文件是如何工作的,但这个你为给出的所有.tex文件生成一个pdf文件。您只需在all目标的先决条件中指定所有的.tex文件。