MAKEFLAGS+="-j -l $(shell grep -c ^processor /proc/cpuinfo)"
MD=pandoc
#MD=multimarkdown
#MD=markdown
ifeq ("pandoc","$(MD)")
 MD_FLAGS=-f markdown_mmd+task_lists+emoji+autolink_bare_uris -t html --filter pandoc-plantuml
# MD_FLAGS=-f gfm -t html
# MD_FLAGS=-f markdown-grid_tables-multiline_tables-simple_tables-table_captions -t html
else
 MD_FLAGS=
endif
HDIR=html
SRC = $(wildcard *.txt)
STYLE = $(wildcard *.css)
OUT = $(patsubst %.txt,$(HDIR)/%.html,$(SRC)) $(patsubst %,$(HDIR)/%,$(STYLE))

all: $(OUT)
	# Done.

.PHONY: clean all

$(HDIR):
	mkdir -p $(HDIR)
	ln -s ../plantuml-images $(HDIR)

$(HDIR)/%.html: %.txt header.html footer.html Makefile |$(HDIR)
	sed "s/MY_TITLE/$(shell head -n 1 $<)/" header.html > $@
	$(MD) $(MD_FLAGS) $< >> $@
	cat footer.html >> $@

$(HDIR)/%: % |$(HDIR)
	cp $< $@

clean:
	rm -f $(OUT)
	rm -f $(HDIR)/plantuml-images
	rm -rf plantuml-images
	rmdir $(HDIR)

