Makefile,Regex和多个依赖项

编程入门 行业动态 更新时间:2024-10-28 03:29:35
本文介绍了Makefile,Regex和多个依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

假定以下文件与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和多个依赖项

本文发布于:2023-11-13 11:49:56,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1584283.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   Makefile   Regex

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!