]> gitweb.michael.orlitzky.com - mjotex.git/blob - GNUmakefile
Add mjo-calculus.tex for the gradient.
[mjotex.git] / GNUmakefile
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 database.
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-calculus.tex mjo-common.tex
21 MJOTEX += mjo-complex.tex mjo-cone.tex mjo-convex.tex mjo-font.tex
22 MJOTEX += mjo-linear_algebra.tex mjo-listing.tex mjo-misc.tex
23 MJOTEX += mjo-proof_by_cases.tex mjo-theorem.tex mjo-theorem-star.tex
24 MJOTEX += mjo-topology.tex mjo.bst
25
26 # Use kpsewhich (from the kpathsea suite) to find the absolute paths
27 # of the bibtex/mjotex files listed in in $(BIBS)/$(MJOTEX). The SRCS
28 # variable should contain all (Bib)TeX source files for the document.
29 SRCS = $(PN).tex
30 ifdef BIBS
31 BIBPATHS = $(shell kpsewhich $(BIBS))
32 SRCS += $(BIBPATHS)
33 endif
34 ifdef MJOTEX
35 MJOTEXPATHS = $(shell kpsewhich $(MJOTEX))
36 SRCS += $(MJOTEXPATHS)
37 endif
38
39
40 # The first target is the default, so put the PDF document first.
41 #
42 # This voodoo is all designed to find a "fixed point" of calling
43 # $(LATEX). When you build a LaTeX document, it requires an unknown
44 # number of compilation passes. How do you know when to stop? Easy,
45 # stop when the output file stops changing! But how to encode that
46 # in a makefile?
47 #
48 # At the start of this target, we call $(LATEX) to compile $(PN).tex.
49 # If you ignore the "sed" for now, then the next step is to check for
50 # the existence of a "previous" file. If there isn't one, this is the
51 # first time that we've tried to build the PDF. In that case, take the
52 # PDF that we've just built and make *that* the previous file. Then
53 # start all over. If there is a previous file, then this is the second
54 # (or more) time that we've tried to build the PDF. We diff the PDF
55 # file that we've just built against the previous file; if they're the
56 # same, then we've succeeded and stop. Otherwise, we make the new PDF
57 # the previous file, and start all over. The end result is that we
58 # will loop until the newly-created PDF and the previous file are
59 # identical.
60 #
61 # But what about the "sed" call? By default, pdflatex will compile the
62 # creation date, modification date, and a unique ID into the output
63 # PDF. That means that two otherwise-identical documents, created
64 # seconds apart, will look different. We only need to know when the
65 # *contents* of the document are the same -- we don't care about the
66 # metadata -- so sed is used to remove those three nondeterministic
67 # pieces of information.
68 #
69 # The creation and modification dates should become optional in pdftex
70 # v1.40.17 thanks to Debian's SOURCE_DATE_EPOCH initiative. When that
71 # version of pdflatex makes it into TeX Live 2016, we can replace
72 # those two sed scripts with something smarter.
73 #
74 $(PN).pdf: $(SRCS) $(PN).bbl
75 $(LATEX) $(PN).tex
76
77 sed --in-place \
78 -e '/^\/ID \[<.*>\]/d' \
79 -e "s/^\/\(ModDate\) (.*)/\/\1 (D:19700101000000Z00'00')/" \
80 -e "s/^\/\(CreationDate\) (.*)/\/\\1 (D:19700101000000Z00'00')/" \
81 $@
82
83 if [ ! -f $@.previous ]; then \
84 mv $@ $@.previous; \
85 $(MAKE) $@; \
86 fi;
87
88 if cmp -s $@ $@.previous; then \
89 rm $@.previous; \
90 else \
91 mv $@ $@.previous; \
92 $(MAKE) $@; \
93 fi;
94
95
96 $(PN).aux: $(SRCS)
97 $(LATEX) $(PN).tex
98
99
100 # The pipe below indicates an "order-only dependency" on the aux file.
101 # Without it, every compilation of $(PN).tex would produce a new
102 # $(PN).aux, and thus $(PN).bbl would be rebuilt. This in turn causes
103 # $(PN).pdf to appear out-of-date, which leads to a recompilation of
104 # $(PN).tex... and so on. The order-only dependency means we won't
105 # rebuild $(PN).bbl if $(PN).aux changes.
106 #
107 # As a side effect, we now need to depend on $(SRCS) here, since we
108 # won't pick it up transitively from $(PN).aux.
109 #
110 # If the $BIBS variable is undefined, we presume that there are no
111 # references and create an empty bbl file. Otherwise, we risk trying
112 # to run biblatex on an aux file containing no citations. If you do
113 # define $BIBS but don't cite anything, you'll run into a similar
114 # problem. Don't do that.
115 #
116 $(PN).bbl: $(SRCS) | $(PN).aux
117 ifdef BIBS
118 bibtex $(PN).aux
119 else
120 echo -n '' > $@
121 endif
122
123 # If the output PDF exists but the log file does not, then an attempt
124 # to "build the log file" (i.e. build the PDF) would do nothing. Thus
125 # whenever the log file does not exist, we do a fresh build.
126 $(PN).log: $(SRCS)
127 $(MAKE) clean
128 $(MAKE)
129
130 # Ensure that there are no overfull or underfull boxes in the output
131 # document by parsing the log for said warnings.
132 .PHONY: check-boxes
133 check-boxes: $(PN).log
134 @! grep -i 'overfull\|underfull' $<
135
136 # Run chktex to find silly mistakes. There is some exit code weirdness
137 # (Savannah bug 45979), so we just look for empty output.
138 .PHONY: check-chktex
139 CHKTEX = chktex --localrc .chktexrc --quiet --inputfiles=0
140 check-chktex:
141 @[ -z "$(shell $(CHKTEX) mjotex.sty)" ]
142
143 # Ensure that there are no undefined references in the document by
144 # parsing the log file for said warnings.
145 .PHONY: check-undefined
146 check-undefined: $(PN).log
147 @! grep -i 'undefined' $<
148
149 # Run a suite of checks.
150 .PHONY: check
151 check: check-boxes check-chktex check-undefined
152
153 # Clean up leftover junk. This only looks overcomplicated because
154 # the *.{foo,bar} syntax supported by Bash is not POSIX, and Make
155 # will execute these commands using /bin/sh (which should be POSIX).
156 JUNK_EXTENSIONS = aux bbl bcf bib blg listing lof log nav out pdf
157 JUNK_EXTENSIONS += snm spl toc xml
158 .PHONY: clean
159 clean:
160 for ext in $(JUNK_EXTENSIONS); do rm -f *.$$ext; done;
161 rm -rf dist/
162
163 # If this document will be published, the publisher isn't going to
164 # have your BibTeX database or your mjotex files. So, you need to
165 # package them up along with the code for your document. This target
166 # will create a "dist" directory and copy the necessary stuff there.
167 #
168 .PHONY: dist
169 dist: $(PN).bbl
170 mkdir -p dist
171 cp $(SRCS) $(PN).bbl $(BIBPATHS) $(MJOTEXPATHS) dist/