# # Example makefile using mjotex 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-algorithm.tex mjo-arrow.tex mjo-common.tex mjo-cone.tex MJOTEX += mjo-convex.tex mjo-font.tex mjo-linear_algebra.tex mjo-listing.tex MJOTEX += mjo-misc.tex mjo-proof_by_cases.tex mjo-theorem.tex MJOTEX += mjo-theorem-star.tex mjo-topology.tex # Use kpsewhich (from the kpathsea suite) to find the absolute paths # of the bibtex/mjotex files listed in in $(BIBS)/$(MJOTEX). The SRCS # variable should contain all (Bib)TeX source files for the document. SRCS = $(PN).tex $(shell kpsewhich $(BIBS)) $(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. # # Why use the aux file and not the PDF, which is what we really care # about? The pdflatex tool currently embeds the creation/modification # time into the PDF, so every new version will differ from the last, # making comparisons meaningless. This is fixed in pdftex v1.40.17 # thanks to Debian's SOURCE_DATE_EPOCH initiative. When that version # of pdflatex makes it into TeX Live 2016, we can replace this junk # with something smarter # $(PN).pdf: $(SRCS) $(PN).aux $(PN).bbl 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: $(SRCS) $(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 $(SRCS) $(PN).bbl dist/