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