+#
+# Example makefile using some of mjotex (fonts, theorems) and a BibTeX
+# references database.
+#
+
+# The latex compiler.
+LATEX = pdflatex -file-line-error -halt-on-error
+
+# The name of this document.
+PN := paper
+
+# A space-separated list of bib files. These must all belong to paths
+# contained in your $BIBINPUTS environment variable.
+BIBS = references.bib
+
+# A space-separated list of the mjotex files that you use. The path to
+# mjotex must be contain in your $TEXINPUTS environment variable.
+MJOTEX = mjo-fonts.tex mjo-theorems.tex
+
+# Use kpsewhich (from the kpathsea suite) to find the absolute paths
+# of the bibtex/mjotex files listed in in $(BIBS)/$(MJOTEX).
+BIBPATHS = $(shell kpsewhich $(BIBS))
+MJOTEXPATHS = $(shell kpsewhich $(MJOTEX))
+
+
+# The first target is the default, so put the PDF document first.
+#
+# The voodoo here is to avoid rebuilding the project when nothing has
+# changed. Each compilation pass with pdflatex will produce a new aux
+# file, even if nothing has changed. That cases Make to think that we
+# need to regenerate the bbl file, which in turn means we need to
+# rebuild the whole project...
+#
+# To avoid that, we save a copy of the current aux file and compare it
+# to the new one afterwards. If the files are the same, great, put the
+# old one (with the old timestamp) back. If not, we need to compile
+# again, so we just invoke $(MAKE) again on this target.
+#
+# The process is kind of like finding a fixpoint of `make` with
+# respect to the contents of the aux file.
+#
+$(PN).pdf: $(PN).tex $(PN).aux $(PN).bbl $(MJOTEXPATHS)
+ mv $(PN).aux $(PN).aux.bak
+ $(LATEX) $< && $(LATEX) $<
+ if cmp -s $(PN).aux $(PN).aux.bak; then \
+ mv $(PN).aux.bak $(PN).aux; \
+ else \
+ $(MAKE) $@; \
+ fi;
+
+$(PN).aux: $(PN).tex $(BIBPATHS)
+ $(LATEX) $<
+
+$(PN).bbl: $(PN).aux
+ bibtex $<
+
+
+# Clean up leftover junk.
+.PHONY: clean
+clean:
+ rm -f *.{out,nav,snm,toc,aux,log,pdf,bcf,xml,bbl,blg,bib}
+ rm -rf dist/
+
+
+
+# If this document will be published, the publisher isn't going to
+# have your BibTeX database or your mjotex files. So, you need to
+# package them up along with the code for your document. This target
+# will create a "dist" directory and copy the necessary stuff there.
+#
+.PHONY: dist
+dist: $(PN).bbl
+ mkdir -p dist
+ cp $(PN).tex $(PN).bbl $(BIBPATHS) $(MJOTEXPATHS) dist/