Makefile,Regex和多个依赖项 [英] Makefile, Regex and multiple dependencies
问题描述
假定以下文件与makefile位于同一目录中:
Assume the following files are in the same directory as the makefile:
01.1.dot
01.2.dot
02.1.dot
03.1.dot
03.2.dot
03.3.dot
这意味着我们拥有格式为[0-9] [0-9].[0-9] .dot
That means we have files of the form [0-9][0-9].[0-9].dot
此外,makefile包含以下目标:
Furthermore, the makefile contains the following target:
%.dot.tex: %.dot
dot2tex <...>
现在,我想创建一个目标,该目标依赖于格式为[0-9] [0-9] .tex的文件,并且它们还应该依赖于格式为[0-9] [0-9]的所有文件].*.dot.tex,以便前两位数字匹配.例如,make 03.pdf
应该依赖于03.tex
,03.1.dot.tex
,03.2.dot.tex
和03.3.dot.tex
.我提出了以下建议:
Now I would like to create a target which depend on files of the form [0-9][0-9].tex and they should also depend on all files of the form [0-9][0-9].*.dot.tex, such that the first two digits match. For example, make 03.pdf
should depend on 03.tex
, 03.1.dot.tex
, 03.2.dot.tex
and 03.3.dot.tex
. I came up with the following:
%.pdf: %.tex $(addsuffix .tex,$(wildcard %.*.dot))
@echo $?
pdflatex <...>
但是,未在通配符函数中评估百分比.有人知道如何解决这个问题吗?
However, the percentage is not evaluated in the wildcard-function. Does someone have an idea how to solve this?
推荐答案
函数是在模式匹配规则之前应用的,因此您不能在glob中使用%.
Functions are applied before pattern matching rules, so you cannot use % in a glob.
可能有更好的解决方案,但我想出了:
There is probably a better solution, but I came up with:
.dep-%.pdf: %.tex
@bash -c 'shopt -s nullglob; for x in $*.*.dot; do \
echo "$*.pdf: $$x.tex"; \
done' > $@
PDFS := $(patsubst %.tex,%.pdf,$(wildcard [0-9][0-9].tex))
include $(patsubst %,.dep-%,$(PDFS))
%.pdf: %.tex | .dep-%.pdf
只要您不添加或创建X.*.dot文件而不修改X.tex文件,这应该可以工作.
As long as you don't add or create X.*.dot files without also modifying X.tex files, this should work.
这篇关于Makefile,Regex和多个依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!