Reputation: 1544
For each .md
file underneath a directory called src
, I want to generate an HTML file underneath a new directory pub
with the same internal directory structure, e.g.
src/foo/hello.md -> pub/foo/hello.html
src/bar/world.md -> pub/bar/world.html
I'm stuck on writing the prerequisites for each html file. Here's what I have so far:
SRCS = $(shell find src -name "*.md")
HTML = $(subst src/,pub/,$(SRCS:.md=.html))
%.html: %.md
@echo "placeholder to generate $@ from $<"
publish: $(HTML)
As written, I get
$ make publish
make: *** No rule to make target `pub/foo/hello.html', needed by `publish'. Stop.
If I remove the prerequisites like this:
%.html: %.md
@echo "placeholder to generate $@ from $<"
then I get:
$ make publish
placeholder to generate pub/foo/hello.html from
placeholder to generate pub/bar/world.html from
which is closer, but does not handle the prerequisite Markdown file.
How do I write a pattern for the prerequisite with both differing root directory and extension?
Upvotes: 0
Views: 42
Reputation: 100856
Just write the prefix and the suffix in the pattern:
pub/%.html : src/%.md
...
Upvotes: 1