2016-09-20 39 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文件。