]> gitweb.michael.orlitzky.com - beamer-mjo.git/blob - GNUmakefile
COPYING,LICENSE: add 'em (AGPL-3.0+)
[beamer-mjo.git] / GNUmakefile
1 #
2 # Example makefile using mjotex and a BibTeX references database.
3 #
4
5 # The latex compiler. The SOURCE_DATE_EPOCH=0 prevents the creation
6 # and modification dates from being embedded as metadata into the
7 # output file; that in turn is important because it allows us to tell
8 # when the output stops changing (that is, when we are done). The
9 # variable is supported in pdftex v1.40.17 and later.
10 LATEX = SOURCE_DATE_EPOCH=0 pdflatex -file-line-error -halt-on-error
11
12 # The name of this document.
13 #
14 # For example, to use the name of our parent directory:
15 #
16 # PN = $(notdir $(realpath .))
17 #
18 PN = example
19
20 # A space-separated list of bib files. These must all belong to paths
21 # contained in your $BIBINPUTS environment variable.
22 #
23 # Leave commented if you don't use a bibliography database.
24 #
25 #BIBS = local-references.bib
26
27 # A space-separated list of the mjotex files that you use. The path to
28 # mjotex must be contain in your $TEXINPUTS environment variable.
29 #
30 MJOTEX = mjotex.sty mjo.bst
31
32 # Beamer template
33 BEAMERMJO = beamercolorthememjo.sty beamerfontthememjo.sty
34 BEAMERMJO += beamerinnerthememjo.sty beamerouterthememjo.sty
35 BEAMERMJO += beamerthememjo.sty
36 BEAMERMJOPATHS = $(shell kpsewhich $(BEAMERMJO))
37
38 # Use kpsewhich (from the kpathsea suite) to find the absolute paths
39 # of the bibtex/mjotex files listed in in $(BIBS)/$(MJOTEX). The SRCS
40 # variable should contain all (Bib)TeX source files for the document.
41 SRCS = $(PN).tex
42 ifdef BIBS
43 BIBPATHS = $(shell kpsewhich $(BIBS))
44 SRCS += $(BIBPATHS)
45 endif
46 ifdef MJOTEX
47 MJOTEXPATHS = $(shell kpsewhich $(MJOTEX))
48 SRCS += $(MJOTEXPATHS)
49 endif
50
51 SRCS += $(BEAMERMJOPATHS)
52
53
54 # The first target is the default, so put the PDF document first.
55 #
56 # This voodoo is all designed to find a "fixed point" of calling
57 # $(LATEX). When you build a LaTeX document, it requires an unknown
58 # number of compilation passes. How do you know when to stop? Easy,
59 # stop when the output file stops changing! But how to encode that
60 # in a makefile?
61 #
62 # At the start of this target, we call $(LATEX) to compile $(PN).tex.
63 # Afterwards, we check for the existence of a "previous" file. If
64 # there isn't one, then this is the first time that we've built the
65 # PDF. In that case, we take the PDF that we've just built and make it
66 # the "previous" file before starting all over. If, on the other hand,
67 # there already *was* a "previous" file, then this is the second (or
68 # third...) time that we've built the PDF. We diff the newly-built PDF
69 # against the "previous" file; if they're the same, then we've
70 # succeeded and stop. Otherwise, we make the new PDF the "previous"
71 # one, and start all over. The end result is that we will loop until
72 # the newly-created PDF and the "previous" one are identical.
73 #
74 $(PN).pdf: $(SRCS) $(PN).bbl
75 $(LATEX) $(PN).tex
76
77 if [ -f $@.previous ] && cmp -s $@ $@.previous; then \
78 rm $@.previous; \
79 else \
80 mv $@ $@.previous; \
81 $(MAKE) $@; \
82 fi;
83
84
85 $(PN).aux: $(SRCS)
86 $(LATEX) $(PN).tex
87
88
89 ifdef INDICES
90 # We need to be able to build the index source files without involving
91 # the main $(PN).pdf rule, in order to avoid a chicken-and-egg problem.
92 # This is similar to the $(PN).aux rule above, except that an index is
93 # optional and there might be more than one of them.
94 $(INDEX_SRCS): $(PN).tex
95 $(LATEX) $(PN).tex
96 endif
97
98 # The pipe below indicates an "order-only dependency" on the aux file.
99 # Without it, every compilation of $(PN).tex would produce a new
100 # $(PN).aux, and thus $(PN).bbl would be rebuilt. This in turn causes
101 # $(PN).pdf to appear out-of-date, which leads to a recompilation of
102 # $(PN).tex... and so on. The order-only dependency means we won't
103 # rebuild $(PN).bbl if $(PN).aux changes.
104 #
105 # As a side effect, we now need to depend on $(SRCS) here, since we
106 # won't pick it up transitively from $(PN).aux.
107 #
108 # If the $BIBS variable is undefined, we presume that there are no
109 # references and create an empty bbl file. Otherwise, we risk trying
110 # to run biblatex on an aux file containing no citations. If you do
111 # define $BIBS but don't cite anything, you'll run into a similar
112 # problem. Don't do that.
113 #
114 $(PN).bbl: $(SRCS) | $(PN).aux
115 ifdef BIBS
116 bibtex $(PN).aux
117 else
118 printf '' > $@
119 endif
120
121 # If the output PDF exists but the log file does not, then an attempt
122 # to "build the log file" (i.e. build the PDF) would do nothing. Thus
123 # whenever the log file does not exist, we do a fresh build.
124 $(PN).log: $(SRCS)
125 $(MAKE) clean
126 $(MAKE)
127
128 # Ensure that there are no overfull or underfull boxes in the output
129 # document by parsing the log for said warnings.
130 .PHONY: check-boxes
131 check-boxes: $(PN).log
132 @! grep -i 'overfull\|underfull' $<
133
134 # Run chktex to find silly mistakes. There is some exit code weirdness
135 # (Savannah bug 53129), so we just look for empty output.
136 .PHONY: check-chktex
137 CHKTEX = chktex --localrc .chktexrc --quiet --inputfiles=0
138 check-chktex:
139 @chktexout=$$($(CHKTEX) $(PN).tex); \
140 test -z "$${chktexout}" || { echo "$${chktexout}" 1>&2; exit 1; }
141
142 # Ensure that there are no undefined references in the document by
143 # parsing the log file for said warnings.
144 .PHONY: check-undefined
145 check-undefined: $(PN).log
146 @! grep -i 'undefined' $<
147
148 # Run a suite of checks.
149 .PHONY: check
150 check: check-boxes check-chktex check-undefined
151
152 # Clean up leftover junk. This only looks overcomplicated because
153 # the *.{foo,bar} syntax supported by Bash is not POSIX, and Make
154 # will execute these commands using /bin/sh (which should be POSIX).
155 JUNK_EXTENSIONS = aux bbl bcf blg glo ilg ist listing lof log nav out pdf
156 JUNK_EXTENSIONS += snm spl toc xml
157 .PHONY: clean
158 clean:
159 for ext in $(JUNK_EXTENSIONS); do rm -f *.$$ext; done;