Reputation: 842
I'm trying to make a make file for a static page generator, and I'm using jinja
and pandoc
so far, and the idea is to have a file structure as such
.
|-content
|-public
|-templates
|-Makefile
VPATH=public
TARGETS=$(find content -regex ".*(htm|md)" | sed -e "s/md$/htm/g;s/^content/public/g")
all: $(TARGETS)
@echo fullbuild
public/%: content/%
content/%.md:
# Pandoc script
pandoc -i $@ -o ${${@:.md=.htm}:content=public}
content/%.htm:
# Jinja Script
The problem I'm having (At least I think that's it) is that according to me the syntax is
# For a final result
target: dependency
commands
# A rule for dependency
dependency:
commands
My dependencies are in the content
dir and my targets are in the public
dir that may or may not exist yet, and almost all the files I generate will be htm
files, and in that case if the target is public/some/route/to/file.htm
the dependency will be any of this two content/some/route/to/file.(htm|md)
.
I can easily generate by walking the content dir, and changing extensions.
How should I write the rules properly, so
- Make knows where to "watch" for changes every time I do a make
, because right now it points that every file is up to date
- How do I indicate properly the dependency of a file to it's content file.
Upvotes: 0
Views: 99
Reputation: 100836
This rule:
public/%: content/%
does nothing because pattern rules without recipes delete existing pattern rules, they don't define new pattern rules.
It's very simple, you should write two rules like this:
public/%.htm: content/%.md:
# Pandoc script
pandoc -i $< -o $@
public/%.htm: content/%.htm
# Jinja Script
Here's a hint: whenever you're writing a makefile recipe and you discover that you need to create a target which is different than exactly $@
, unmodified, immediately stop what you're doing and back up: you've taken a wrong turn.
Upvotes: 1