DOCNAME = report
TARGET = report.pdf

RM         ?= rm -f
MPP         = perl -I../mpp ../mpp/mpp
MPPFLAGS    =
PANDOC      = pandoc
PANDOCFLAGS = --latex-engine=xelatex --listings --toc --no-tex-ligatures --normalize --chapters
BUTLER      = perl -I../butler/src ../butler.pl
BUTLERFLAGS = --docname=${DOCNAME} --xml=../internship.xml
LATEX       = xelatex
LATEXFLAGS  = -halt-on-error -no-shell-escape

DEPS   := ../internship.xml $(shell ${MPP} --list-includes ${TARGET:.pdf=.md})

all: ${TARGET}

assistant: MPPFLAGS += --assistant

assistant: all

clean:
	${RM} ${TARGET}

${TARGET}: ${DEPS}

.md.mppmd:
	${MPP} ${MPPFLAGS} $< > $@

.mppmd.maintex:
	${PANDOC} ${PANDOCFLAGS} -t latex -o $@ $<

.maintex.tex:
	${BUTLER} ${BUTLERFLAGS} --main=$< > $@

.tex.pdf:
	${LATEX} ${LATEXFLAGS} -jobname=${@:%.pdf=%} $<
	${LATEX} ${LATEXFLAGS} -jobname=${@:%.pdf=%} $< >/dev/null
	${RM} ${@:.pdf=.aux} ${@:.pdf=.log} ${@:.pdf=.out} ${@:.pdf=.toc}

.SUFFIXES: .md .mppmd .maintex .tex .pdf
