# Nécessaire pour avoir les dépendances dans le répertoire lié à l'article.
.SECONDEXPANSION:

# Un article par fichier .md.
ARTICLES=$(wildcard *.md)

# Tâche par défaut.
all: $(patsubst %.md,%.odt,$(ARTICLES)) docs/all
.DEFAULT_GOAL:=all

# Tâches virtuelles.
.PHONY: all docs/all src/all clean docs/clean filters/clean src/clean filters/diamond

# Tâches liées à la doc.
docs/clean:
	$(MAKE) -C docs clean

docs/all:
	$(MAKE) -C docs all

# Tâche de nettoyage des sources.
src/clean:
	$(MAKE) -C src clean

# Tâche de génération du filtre.
filters/diamond:
	$(MAKE) -C filters diamond

# Tâche générique pour un article.
ARTICLE_DEPS=$(wildcard $*/*)

%.odt: %.md filters/diamond reference.odt templates/diamond.opendocument $$(ARTICLE_DEPS)
	echo $^
	pandoc \
		$< \
		--data-dir=. \
		--filter=diamond \
		--template=diamond.opendocument \
		--output=$@

%.unfiltered.json: %.md $$(ARTICLE_DEPS)
	pandoc \
		$< \
		-t json \
		--outpur=$@

# Nettoyage.
clean: docs/clean filters/clean src/clean
	rm -f $(patsubst %.md,%.odt,$(ARTICLES))

# vim: set tw=80 ts=4 sw=4 sts=4 spelllang=fr:
