]> gitweb.michael.orlitzky.com - mjotex.git/blob - makefile
cfe6f2016f92e8f6fd580bad4267521ab6f00df4
[mjotex.git] / makefile
1 #
2 # Example makefile using mjotex and a BibTeX references database.
3 #
4
5 # The latex compiler.
6 LATEX = pdflatex -file-line-error -halt-on-error
7
8 # The name of this document.
9 PN = paper
10
11 # A space-separated list of bib files. These must all belong to paths
12 # contained in your $BIBINPUTS environment variable.
13 BIBS = references.bib
14
15 # A space-separated list of the mjotex files that you use. The path to
16 # mjotex must be contain in your $TEXINPUTS environment variable.
17 MJOTEX = mjo-algorithm.tex mjo-arrow.tex mjo-common.tex mjo-cone.tex
18 MJOTEX += mjo-convex.tex mjo-font.tex mjo-linear_algebra.tex mjo-listing.tex
19 MJOTEX += mjo-misc.tex mjo-proof_by_cases.tex mjo-theorem.tex
20 MJOTEX += mjo-theorem-star.tex mjo-topology.tex
21
22 # Use kpsewhich (from the kpathsea suite) to find the absolute paths
23 # of the bibtex/mjotex files listed in in $(BIBS)/$(MJOTEX). The SRCS
24 # variable should contain all (Bib)TeX source files for the document.
25 SRCS = $(PN).tex $(shell kpsewhich $(BIBS)) $(shell kpsewhich $(MJOTEX))
26
27
28 # The first target is the default, so put the PDF document first.
29 #
30 # This voodoo is all designed to find a "fixed point" of calling
31 # $(LATEX). When you build a LaTeX document, it requires an unknown
32 # number of compilation passes. How do you know when to stop? Easy,
33 # stop when the output file stops changing! But how to encode that
34 # in a makefile?
35 #
36 # At the start of this target, we call $(LATEX) to compile $(PN).tex.
37 # If you ignore the "sed" for now, then the next step is to check for
38 # the existence of a "previous" file. If there isn't one, this is the
39 # first time that we've tried to build the PDF. In that case, take the
40 # PDF that we've just built and make *that* the previous file. Then
41 # start all over. If there is a previous file, then this is the second
42 # (or more) time that we've tried to build the PDF. We diff the PDF
43 # file that we've just built against the previous file; if they're the
44 # same, then we've succeeded and stop. Otherwise, we make the new PDF
45 # the previous file, and start all over. The end result is that we
46 # will loop until the newly-created PDF and the previous file are
47 # identical.
48 #
49 # But what about the "sed" call? By default, pdflatex will compile the
50 # creation date, modification date, and a unique ID into the output
51 # PDF. That means that two otherwise-identical documents, created
52 # seconds apart, will look different. We only need to know when the
53 # *contents* of the document are the same -- we don't care about the
54 # metadata -- so sed is used to remove those three nondeterministic
55 # pieces of information.
56 #
57 # The creation and modification dates should become optional in pdftex
58 # v1.40.17 thanks to Debian's SOURCE_DATE_EPOCH initiative. When that
59 # version of pdflatex makes it into TeX Live 2016, we can replace
60 # those two sed scripts with something smarter.
61 #
62 $(PN).pdf: $(SRCS) $(PN).bbl
63 $(LATEX) $(PN).tex
64
65 sed --in-place \
66 -e '/^\/ID \[<.*>\]/d' \
67 -e "s/^\/\(ModDate\) (.*)/\/\1 (D:19700101000000Z00'00')/" \
68 -e "s/^\/\(CreationDate\) (.*)/\/\\1 (D:19700101000000Z00'00')/" \
69 $@
70
71 if [ ! -f $@.previous ]; then \
72 mv $@ $@.previous; \
73 $(MAKE) $@; \
74 fi;
75
76 if cmp -s $@ $@.previous; then \
77 rm $@.previous; \
78 else \
79 mv $@ $@.previous; \
80 $(MAKE) $@; \
81 fi;
82
83
84 $(PN).aux: $(SRCS)
85 $(LATEX) $(PN).tex
86
87
88 # The pipe below indicates an "order-only dependency" on the aux file.
89 # Without it, every compilation of $(PN).tex would produce a new
90 # $(PN).aux, and thus $(PN).bbl would be rebuild. This in turn causes
91 # $(PN).pdf to appear out-of-date, which leads to a recompilation of
92 # $(PN).tex... and so on. The order-only dependency means we won't
93 # rebuild $(PN).bbl if $(PN).aux changes.
94 #
95 # As a side effect, we now need to depend on $(SRCS) here, since we
96 # won't pick it up transitively from $(PN).aux.
97 #
98 $(PN).bbl: $(SRCS) | $(PN).aux
99 bibtex $(PN).aux
100
101
102 # Run chktex to find silly mistakes. There is some exit code weirdness
103 # (Savannah bug 45979), so we just look for empty output.
104 .PHONY: check
105 check:
106 @[ -z "$(shell chktex --quiet mjotex.sty)" ]
107
108 # Clean up leftover junk.
109 .PHONY: clean
110 clean:
111 rm -f *.{aux,bbl,bcf,bib,blg,lof,log,nav,out,pdf,snm,toc,xml}
112 rm -rf dist/
113
114 # If this document will be published, the publisher isn't going to
115 # have your BibTeX database or your mjotex files. So, you need to
116 # package them up along with the code for your document. This target
117 # will create a "dist" directory and copy the necessary stuff there.
118 #
119 .PHONY: dist
120 dist: $(PN).bbl
121 mkdir -p dist
122 cp $(SRCS) $(PN).bbl dist/