-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMakefile
309 lines (258 loc) · 9.64 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
# Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)
#
# SPDX-License-Identifier: BSD-2-Clause
#
# Generic paper Makefile
#
# For usage hints, "make help"
#
# To create a LaTeX diff against the git HEAD revision, use the target
# "diff" (or "viewdiff").
# To use a revision other than HEAD, speciff DIFF=x on the
# make command line to choose the revision x.
#
# Verbosity
ifeq (${V},1)
Q:=
else
Q:=@
endif
.PHONY: all
BIBDIR ?= /home/disy/lib/BibTeX:../../../bibtex:../bibtex
LaTeXEnv = TEXINPUTS=".:/home/disy/lib/TeX:/home/disy/lib/ps:${TEXINPUTS}:"
BibTexEnv = BIBINPUTS=".:${BIBDIR}:${BIBINPUTS}:"
BibFiles = defs,extra,combined,systems,fm,other
LaTeX = ${LaTeXEnv} pdflatex -interaction=nonstopmode
# Uncomment the following for "unsw" when using TrueType fonts (which they require)
#LaTeX = ${LaTeXEnv} lualatex -interaction=nonstopmode
LaTeXdiff = ./tools/latexdiff
BibTeX = ${BibTexEnv} bibtex
BibExport = ./tools/bibexport.sh
Fig2Eps = fig2dev -L eps
Dia2Eps = dia -t eps -e
AS = $(shell which as)
CC = $(shell which gcc)
GnuPlot = gnuplot
Inkscape = $(shell which inkscape)
Svg2Eps = ${Inkscape}
Svg2Pdf = ${Inkscape}
Eps2Pdf = epstopdf --outfile
PdfView = xpdf
Pdf2Ps = pdf2ps
Md2Pdf = pandoc
RmCR = tr -d '\r'
sed = $(shell which sed)
Lpr = lpr
mv = mv
awk = awk
R = R
# Use either "report" or "paper", depending on the template.
# To add a further target, simply append the basename of the .tex file here
# NOTE: for the "simple", "report" and "unsw" templates, uncomment the lualatex line above!
TexFiles = $(basename $(wildcard *.tex))
Targets = whitepaper
# CONFIGURATION OPTIONS
# =====================
# Extra figures that aren't supplied as dia, gnuplot or fig sources
# (eg figures already supplied in PDF, or supplied in EPS).
# List with pdf extensions.
# Note that PDF files should be added to the repo with an additional -shipped extension,
# but should appear here with just the .pdf extension.
ExtraFigs= $(wildcard imgs/*.pdf)
# Any other stuff that may be needed
# END CONFIGURATION OPTIONS
# =========================
Optional = $(addsuffix -diff, $(Targets))
All = $(Targets) $(Optional)
Diffopts= #--type=BWUNDERLINE #-c .latexdiffconfig --append-safecmd="Comment"
Perf_Sources = $(wildcard imgs/*.perf)
Dia_Sources = $(wildcard imgs/*.dia)
Fig_Sources = $(wildcard imgs/*.fig)
Gnuplot_Sources = $(wildcard imgs/*.gnuplot)
SVG_Sources = $(wildcard imgs/*.svg)
R_Sources = $(wildcard imgs/*.r)
Styles = $(wildcard *.sty) $(wildcard *.cls)
Figures = $(Perf_Sources:.perf=.pdf) $(Dia_Sources:.dia=.pdf) $(Fig_Sources:.fig=.pdf) $(SVG_Sources:.svg=.pdf) $(Gnuplot_Sources:.gnuplot=.pdf) $(R_Sources:.r=.pdf) $(ExtraFigs)
Pdf = $(addsuffix .pdf, $(Targets))
Bib = references.bib
Tex = $(addsuffix .tex, $(Targets))
Diff_Pdf = $(addsuffix .pdf, $(Optional))
.PHONY: FORCE
all: pdf
diff: diff_pdf
FORCE: pdf
ps: $(Ps)
pdf: $(Figures) Makefile $(Pdf)
diff_pdf: $(Figures) Makefile $(Diff_Pdf)
%.pdf: %.perf ./tools/bargraph.pl
@echo $< '->' $@
${Q} ${BarGraph} -pdf $< > $@
%.pdf: %.eps
@echo $< '->' $@
${Q} ${Eps2Pdf} $@ $<
%.pdf: %.ps
@echo $< '->' $@
${Q} ${Eps2Pdf} $@ $<
%.eps: %.svg
@echo $< '->' $@
${Q} $(if ${Svg2Eps},,echo "You need inkscape installed to build $@" >&2; exit 1)
${Q} ${Svg2Eps} $< -D -E -o $@ > /dev/null 2>&1
%.pdf: %.svg
@echo $< '->' $@
${Q} $(if ${Svg2Pdf},,echo "You need inkscape installed to build $@" >&2; exit 1)
${Q} ${Svg2Pdf} $< -D -o $@ > /dev/null 2>&1
# This target allows you to add figures which have the extension .c_pp that
# correspond to .c sources. Your .c sources can use the lines '/*<*/' and
# '/*>*/' to surround parts of the source you don't want shown in your PDF.
# This allows you to write a .c file that can be compile-checked here and then
# remove extraneous lines for display.
%.c_pp: %.c
@echo $< '->' $@
${Q}$(if ${CC},${CC} -c "$<" -o /dev/null,)
${Q}${sed} -e '/\/\*<\*\//,/\/\*>\*\//d' "$<" >"$@"
%.s_pp: %.s
@echo $< '->' $@
${Q}$(if ${AS},${AS} -c "$<" -o /dev/null,)
${Q}${sed} -e '/\/\*<\*\//,/\/\*>\*\//d' "$<" >"$@"
%.eps: %.dia
@echo $< '->' $@
${Q} ${Dia2Eps} $@ $<
%.eps: %.fig
@echo $< '->' $@
${Q} ${Fig2Eps} $< $@
%.eps: %.gnuplot
@echo $< '->' $@
${Q} ${GnuPlot} $<
%.eps: %.r
@echo $< '->' $@
${Q} ${R} --vanilla < $<
%.pdf: %.pdf-shipped
cp $< $@
%.pdf: %.md
$(Md2Pdf) $< -o $@
%.view: %.pdf
$(PdfView) $<
view: pdf
${Q}for i in $(Pdf); do \
$(PdfView) $$i & \
done
viewdiff: diff
${Q}for i in $(Diff_Pdf); do \
$(PdfView) $$i & \
done
print: pdf
${Q}for i in $(Pdf); do \
$(Lpr) $$i \
done
clean:
rm -f *.aux *.toc *.bbl *.blg *.dvi *.log *.pstex* *.eps *.cb *.brf \
*.rel *.idx *.out *.ps *-diff.* *.mps .log *.diff *.cut tmp.* $(GreyFigs)
realclean: clean
rm -f *~ *.pdf *.tgz $(Bib)
git checkout $(Bib)
tar: realclean
( p=`pwd` && d=`basename "$$p"` && cd .. && \
tar cfz $$d.tgz $$d && \
mv $$d.tgz $$d )
help:
@echo "Main targets: all diff camera view viewdiff print clean realclean tar"
@echo "'make diff' will show changes to head revision"
@echo "'make grey' will generate greyscale figures (for B&W readibility check)"
@echo "'make DIFF=<rev> diff' will show changes to revision <rev>"
@echo 'Avoid TeX \def with arguments, this breaks latexdiff (use \newcommand)'
##############################################################################
DIFF ?= HEAD
%-diff.dvi: %-diff.tex
%-diff.tex: %.tex FORCE
@echo "====> Retrieving revision $(DIFF) of $<"
git show $(DIFF):$< > $(@:-diff.tex=-$(DIFF)-diff.tex)
@echo "====> Creating diff of revision $(DIFF) of $<"
$(LaTeXdiff) $(Diffopts) $(@:-diff.tex=-$(DIFF)-diff.tex) $< | \
${RmCR} > $@
.PHONY: FORCE
FORCE:
# don't delete %.aux intermediates
.SECONDARY:
##############################################################################
Rerun = '(There were undefined (references|citations)|Rerun to get (cross-references|the bars) right)'
Rerun_Bib = 'No file.*\.bbl|Citation.*undefined'
Undefined = '((Reference|Citation).*undefined)|(Label.*multiply defined)'
Error = '^! '
BibWarn = '^Warning--'
LaTeXWarn = ' [Ww]arning: '
# combine citation commands from all targets into tmp.aux, generate references.bib from this
# WARNING: This will only re-generate references.bib if citations have been
# added or removed, not if an BibTeX entry has been edited.
# It's a good idea to force rebuilding references.bib before submitting!
$(Bib): $(addsuffix .tex, $(Targets))
@echo "====> Parsing targets for references"
@cat </dev/null > .log
@cat </dev/null > all_refs.aux
${Q}for i in $(Targets); do \
$(LaTeX) $$i.tex >>.log; \
cat $$i.aux | grep -e "\(citation\|bibdata\|bibstyle\)" | sed 's/bibdata{references}/bibdata{$(BibFiles)}/g' >> all_refs.aux; \
done
@echo "====> Removing duplicate bib entries"
${Q}cat all_refs.aux | sort -u | sed '/\\bibstyle/d' > tmp.aux
${Q}grep '\\bibstyle' all_refs.aux | head -1 >> tmp.aux
${Q}touch references.aux
${Q}if [ -r references.aux ]; then \
diff references.aux tmp.aux > references.diff 2> /dev/null; \
else rm -f references.diff; \
fi; true
${Q}if [ -s references.diff ] && [ -e $(Bib) ]; then \
echo "====> Changed references:"; \
cat references.diff | grep "citation"; \
echo -n "These will cause changes to $(Bib), do you want to rebuild this file? (yes/NO): "; \
read rebuild_refs; \
fi; \
if [ "$$rebuild_refs" = "yes" ] || [ -s all_refs.aux -a \! -e $(Bib) ]; then \
echo "====> Building $(Bib)"; \
$(BibTexEnv) $(BibExport) -t -o tmp.bib tmp.aux > .log 2>&1; \
if grep -q 'error message' .log; then \
cat .log; \
exit 1; \
fi; \
: Clean out junk. Remove following command if you really want it in; \
: Note: awkward expression because sed is different on Mac and Linux; \
${sed} <tmp.bib > $(Bib) \
-e 's/^ *isbn *= *{/ NOisbn = {/' \
-e 's/^ *issn *= *{/ NOissn = {/' \
-e 's/^ *editor *= *{/ NOeditor = {/' \
-e 's/^ *paper[uU]rl *=/ url =/'; \
cp tmp.aux references.aux; \
fi;
${Q}rm -f all_refs.aux tmp.aux references.diff
%.pdf: %.tex $(Bib) $(Figures) $(Styles) Makefile
${Q}if test $*.bbl -ot $(Bib); then rm -f $*.bbl; fi
@echo "====> LaTeX first pass: $(<)"
${Q}$(LaTeX) $< >.log || if egrep -q $(Error) $*.log ; then cat .log; rm $@; false ; fi
${Q}if egrep -q $(Rerun_Bib) $*.log ; then echo "====> BibTex" && ( $(BibTeX) $* > .log || ( cat .log ; false ) ) && echo "====> LaTeX BibTeX pass" && $(LaTeX) >.log $< || if egrep -q $(Error) $*.log ; then cat .log; rm $@; false ; fi ; fi
${Q}if egrep -q $(Rerun) $*.log ; then echo "====> LaTeX rerun" && $(LaTeX) >.log $<; fi
${Q}if egrep -q $(Rerun) $*.log ; then echo "====> LaTeX rerun" && $(LaTeX) >.log $<; fi
${Q}if egrep -q $(Rerun) $*.log ; then echo "====> LaTeX rerun" && $(LaTeX) >.log $<; fi
@echo "====> Undefined references and citations in $(<):"
@egrep -i $(Undefined) $*.log || echo "None."
@echo "====> Dimensions:"
@grep "dimension:" $*.log || echo "None."
@echo "====> Warnings:"
${Q}bibw=`if test -e $*.blg; then grep -c $(BibWarn) $*.blg; else echo 0; fi`; \
texw=`grep -c $(LaTeXWarn) $*.log`; \
if [ "$$bibw" -gt 0 ]; then echo " $$bibw BibTeX\c"; fi; \
if [ "$$texw" -gt 0 ]; then echo " $$texw LaTeX\c"; fi; \
if [ "$$bibw$$texw" = 00 ]; then echo "None."; \
else echo ". 'make warn' will show them."; fi
warn:
@echo "====> BibTeX warnings from" *.blg
@grep $(BibWarn) *.blg || echo "None."
@echo "====> LaTeX warnings from" *.log
@grep $(LaTeXWarn) *.log || echo "None."
##############################################################################
# Generate a list of FIXMEs
fixmes:
${Q}for i in $(Tex); do \
echo "FIXMEs in $$i:"; \
nl -b a $$i | grep "FIXME{" | nl -b a; \
echo -n "Total FIXMES: " && grep "FIXME{" $$i | wc -l; \
echo; \
done