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