问题
Imagine a directory tree (which might be more than one level deep) containing several Markdown files. A PDF version of each file exist in the same directory and must be updated each time the corresponding Markdown file is updated. What rule must be written in a single Makefile in the root directory of this tree to achieve this?
I am looking a for a solution where files can be added or removed from the directory tree without a need for updating the Makefile.
Assumptions:
- all markdown files follow a certain pattern in their name; for example they end with a .md postfix.
- GNU Make is being used.
回答1:
You can use $(shell find) to find files recursively. For example:
markdown := $(shell find . -name '*.md')
all: $(patsubst %.md, %.pdf, $(markdown))
%.pdf: %.md
pandoc -o $@ $<
来源:https://stackoverflow.com/questions/36246713/how-to-write-a-make-rule-for-files-of-certain-type-in-a-directory-tree