--- /dev/null
+DOCS:=thesis
+LATEX:=pdflatex
+BIBTEX:=bibtex
+BIBTEXFLAGS:=
+LATEXFLAGS:=-file-line-error -halt-on-error -no-shell-escape
+
+.PHONY: all clean
+.SECONDARY: $(addsuffix .fmt,$(DOCS))
+
+all: $(addsuffix .pdf,$(DOCS))
+
+%.fmt: %.pre
+ $(LATEX) $(LATEXFLAGS) -ini -jobname="$(basename $@)" "&$(LATEX) $<\dump"
+
+%.fmt: preamble.tex
+ $(LATEX) $(LATEXFLAGS) -ini -jobname="$(basename $@)" "&$(LATEX) $<\dump"
+
+%.pdf: %.mlog
+ grep -iFq 'Rerun to get' $< &&\
+ $(LATEX) $(LATEXFLAGS) $(basename $<) || true
+
+%.mlog: %.tex %.fmt $(wildcard *.bib)
+ $(LATEX) $(LATEXFLAGS) $<
+ grep -q '^\\bibdata{' $(basename $<).aux &&\
+ $(BIBTEX) $(BIBTEXFLAGS) $(basename $<) || true
+ $(LATEX) $(LATEXFLAGS) $< | tee $@
+
+clean:
+ $(RM) $(foreach DOC,$(DOCS),\
+ $(addprefix $(DOC).,aux log fmt toc bbl blg run.xml out pdf snm nav snm vrb))