Makefile, Regex and multiple dependencies

做~自己de王妃 提交于 2020-02-02 05:18:09

问题


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

That means we have files of the form [0-9][0-9].[0-9].dot

Furthermore, the makefile contains the following target:

%.dot.tex: %.dot
    dot2tex <...>

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?


回答1:


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

As long as you don't add or create X.*.dot files without also modifying X.tex files, this should work.



来源:https://stackoverflow.com/questions/19822593/makefile-regex-and-multiple-dependencies

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!