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