]> gitweb.michael.orlitzky.com - mjotex.git/blob - makefile
Initial commit of a big mess that will eventually be a library of LaTeX code.
[mjotex.git] / makefile
1 #
2 # Example makefile using some of mjotex (fonts, theorems) and a BibTeX
3 # references database.
4 #
5
6 # The latex compiler.
7 LATEX = pdflatex -file-line-error -halt-on-error
8
9 # The name of this document.
10 PN := paper
11
12 # A space-separated list of bib files. These must all belong to paths
13 # contained in your $BIBINPUTS environment variable.
14 BIBS = references.bib
15
16 # A space-separated list of the mjotex files that you use. The path to
17 # mjotex must be contain in your $TEXINPUTS environment variable.
18 MJOTEX = mjo-fonts.tex mjo-theorems.tex
19
20 # Use kpsewhich (from the kpathsea suite) to find the absolute paths
21 # of the bibtex/mjotex files listed in in $(BIBS)/$(MJOTEX).
22 BIBPATHS = $(shell kpsewhich $(BIBS))
23 MJOTEXPATHS = $(shell kpsewhich $(MJOTEX))
24
25
26 # The first target is the default, so put the PDF document first.
27 #
28 # The voodoo here is to avoid rebuilding the project when nothing has
29 # changed. Each compilation pass with pdflatex will produce a new aux
30 # file, even if nothing has changed. That cases Make to think that we
31 # need to regenerate the bbl file, which in turn means we need to
32 # rebuild the whole project...
33 #
34 # To avoid that, we save a copy of the current aux file and compare it
35 # to the new one afterwards. If the files are the same, great, put the
36 # old one (with the old timestamp) back. If not, we need to compile
37 # again, so we just invoke $(MAKE) again on this target.
38 #
39 # The process is kind of like finding a fixpoint of `make` with
40 # respect to the contents of the aux file.
41 #
42 $(PN).pdf: $(PN).tex $(PN).aux $(PN).bbl $(MJOTEXPATHS)
43 mv $(PN).aux $(PN).aux.bak
44 $(LATEX) $< && $(LATEX) $<
45 if cmp -s $(PN).aux $(PN).aux.bak; then \
46 mv $(PN).aux.bak $(PN).aux; \
47 else \
48 $(MAKE) $@; \
49 fi;
50
51 $(PN).aux: $(PN).tex $(BIBPATHS)
52 $(LATEX) $<
53
54 $(PN).bbl: $(PN).aux
55 bibtex $<
56
57
58 # Clean up leftover junk.
59 .PHONY: clean
60 clean:
61 rm -f *.{out,nav,snm,toc,aux,log,pdf,bcf,xml,bbl,blg,bib}
62 rm -rf dist/
63
64
65
66 # If this document will be published, the publisher isn't going to
67 # have your BibTeX database or your mjotex files. So, you need to
68 # package them up along with the code for your document. This target
69 # will create a "dist" directory and copy the necessary stuff there.
70 #
71 .PHONY: dist
72 dist: $(PN).bbl
73 mkdir -p dist
74 cp $(PN).tex $(PN).bbl $(BIBPATHS) $(MJOTEXPATHS) dist/