如何在makefile中的文件名中捕获数字后缀?更确切地说,我有一本用乳胶编写的书,并由多章文件拆分,我想编写一个支持以下语法的makefile,用于编译整本书:
make book
个别章节:
make chapter_1
例如,。我的文件为book.tex
,其中包含多行\include{chapter_i}
和多个chapter_i.tex
个文件,其中i
是章节编号。
感谢所有人!
答案 0 :(得分:0)
Pattern rules和/或static pattern rules:
CHAPTERS := $(wildcard chapter_*.tex)
CHAPTER_PDFS := $(patsubst %.tex,%.pdf,$(CHAPTERS))
SHORT_TARGETS := book $(patsubst %.pdf,%,$(CHAPTER_PDFS))
.PHONY: all $(SHORT_TARGETS)
all: book
$(SHORT_TARGETS): %: %.pdf
book.pdf: book.tex $(CHAPTERS)
pdflatex $<
$(CHAPTER_PDFS): chapter_%.pdf: chapter_%.tex book.tex
pdflatex -jobname=chapter_$* "\includeonly{chapter_$*}\input{book}"
注意:在配方中(仅在配方中),$*
自动变量会扩展为规则的匹配模式。因此,对于chapter_42
,例如,最后一条规则意味着:
chapter_42.pdf: chapter_42.tex book.tex
pdflatex -jobname=chapter_42 "\includeonly{chapter_42}\input{book}"