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