-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathMakefile
201 lines (153 loc) · 6.14 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
#
# Makefile
#
# Execute 'make help' for a list of build targets.
#
target = thesis
paper_size ?= a4
#paper_size ?= letter
pdf_quality ?= printer
all: pdf
## Rule to generate plot output from the gnuplot input.
plot/%.eps: plot/%.plot
@echo "$< --> $@"
gnuplot plot/term-eps-nofont.plot $< > $@
plot/%-color.eps: plot/%.plot
@echo "$< --> $@"
gnuplot plot/term-eps-nofont-color.plot $< > $@
plot/%.pdf: plot/%.eps
@echo "$< --> $@"
epstopdf $< > $@
## Rules to generate other output
fig/%.eps: fig/%.fig
@echo "$< --> $@"
@fig2dev -L eps -p dummy $< $@
fig/%.eps: fig/%.gif
@echo "$< --> $@"
@giftopnm $< | pnmtops -noturn -rle > $@
fig/%.eps: fig/%.prn
@echo "$< --> $@"
@ps2eps -f $<
fig/%.eps: fig/%.ps
@echo $(EPS)
@echo "$< --> $@"
@ps2eps -f $<
fig/%.pdf: fig/%.eps
@echo "$< --> $@"
epstopdf --embed $< > $@ || epstopdf --embed fig/$*.prn > $@
plotclean::
rm -f plot/*.eps plot/*.pdf
texclean::
rm -f *.aux
clean::
rm -f $(eps_targets) $(pdf_targets) rev.tex
###########################################################################
pdf_target = $(addsuffix .pdf, $(target))
ps_target = $(addsuffix .ps, $(target))
dvi_target = $(addsuffix .dvi, $(target))
eps_targets = $(shell grep 'includegraphics' *.tex | grep -v "\%" | grep 'fig\|plot' |\
sed 's/file=//' | sed 's/,scale=.*}/}/' | \
sed 's/.*{\([^{]*\)}.*/\1.eps/;' )
$(dvi_target):: *.tex *.bib $(eps_targets)
pdf_targets = $(shell grep 'includegraphics' *.tex | grep -v "\%" | grep 'fig\|plot' |\
sed 's/file=//' | sed 's/,scale=.*}/}/' | \
sed 's/.*{\([^{]*\)}.*/\1.pdf/;' )
$(pdf_target):: *.tex *.bib $(pdf_targets)
pdf: $(pdf_target)
ps: $(ps_target)
dvi: $(dvi_target)
help:
@echo
@echo "Automatic build target:"
@echo " $(pdf_target)"
@echo "Other build target:"
@echo " $(ps_target)"
@echo
clean = $(target) $(optional)
##############################################################################
git.tex: Makefile
@changeset=`git rev-parse HEAD` && echo '\\renewcommand{\Revision}' "{$${changeset}}" > $@
-@tipdate=`git log -1 --format="%cd"` && echo '\\renewcommand{\RevisionDate}' "{$${tipdate}}" >> $@
rev.tex: git.tex
mv $< $@
timezone.tex: Makefile
-@timezone=`date +%z` && echo '\renewcommand{\TimeZone}' "{$${timezone}}" > $@
##############################################################################
RERUN = '(There were undefined references|Rerun to get (cross-references|the bars) right)'
RERUNBIB = 'No file.*\.bbl|Citation.*undefined'
UNDEFINED = '((Reference|Citation).*undefined)|(Label.*multiply defined)'
DVIPDFM_SPECIAL = 'pdf:.*docinfo'
latex = latex -interaction=batchmode $(1)
pdflatex = pdflatex -interaction=batchmode $(1)
bibtex = bibtex $(1)
gs_screen = -dPDFSETTINGS=/screen
gs_printer = -dPDFSETTINGS=/printer
gs_ebook = -dPDFSETTINGS=/ebook
gs_prepress = -dPDFSETTINGS=/prepress
gs2pdf_options = -dCompatibilityLevel=1.4 $(gs_$(pdf_quality))
gs2pdf = gs -q -dSAFER -dNOPAUSE -dBATCH -sOutputFile=$(1) $(gs2pdf_options) -sDEVICE=pdfwrite -c .setpdfwrite -f $(2)
dvipdfm = dvipdfm -p $(paper_size) -o $(1) $(2)
dvips = dvips -Pdownload35 -Pcmz -Pcmz -Pamz -t $(paper_size) -G0 -o $(1) $(2)
%.pdf:: %.tex
@echo "====> LaTeX first pass"
$(call pdflatex,$<) || cat $*.log
@if egrep -q $(RERUNBIB) $*.log ; then echo "====> BibTex" && $(call bibtex,$*) && echo "====> LaTeX BibTeX pass" && $(call pdflatex, $<) ; fi
@if egrep -q $(RERUN) $*.log ; then echo "====> LaTeX rerun" && $(call pdflatex,$<); fi;
@if egrep -q $(RERUN) $*.log ; then echo "====> LaTeX rerun" && $(call pdflatex,$<); fi;
@echo "====> Undefined references and citations:"
@egrep -i $(UNDEFINED) $*.log || echo "None."
@echo "====> Dimensions:"
@grep "dimension:" $*.log || echo "None."
## Automatically choose the method to convert a DVI into a PDF, favoring
## dvips since dvipdfm is fragile.
#%.pdf: %.dvi
# @if egrep -q $(DVIPDFM_SPECIAL) $< ; \
# then echo "====> Using dvipdfm" && $(call dvipdfm,$@,$<) ; \
# else echo "====> Using dvips" && $(call dvips,$(<:.dvi=.ps),$<) && $(call gs2pdf,$@,$(<:.dvi=.ps)) ; \
# fi
## Build a PDF from PS. To enable, put this rule before other PDF rules.
#%.pdf: %.ps
# @echo "====> Converting Postscript to PDF"
# $(call gs2pdf,$@,$<)
## Build a Postscript file from the DVI.
%.ps: %.dvi
@echo "====> Generating Postscript"
$(call dvips,$@,$<)
%.dvi: %.tex
@echo "====> LaTeX first pass"
$(call latex,$<) || cat $*.log
@if egrep -q $(RERUNBIB) $*.log ; then echo "====> BibTex" && $(call bibtex,$*) && echo "====> LaTeX BibTeX pass" && $(call latex, $<) ; fi
@if egrep -q $(RERUN) $*.log ; then echo "====> LaTeX rerun" && $(call latex,$<); fi;
@if egrep -q $(RERUN) $*.log ; then echo "====> LaTeX rerun" && $(call latex,$<); fi
@echo "====> Undefined references and citations:"
@egrep -i $(UNDEFINED) $*.log || echo "None."
@echo "====> Dimensions:"
@grep "dimension:" $*.log || echo "None."
clean::
rm -rf $(addsuffix .pdf, $(clean)) $(addsuffix .ps, $(clean))
rm -rf $(addsuffix .dvi, $(clean)) $(addsuffix .toc, $(clean))
rm -rf $(addsuffix .log, $(clean)) $(addsuffix .aux, $(clean))
rm -rf $(addsuffix .bbl, $(clean)) $(addsuffix .blg, $(clean))
rm -rf $(addsuffix .out, $(clean))
rm -rf rev.tex timezone.tex
rm -rf $(tmp_subdirs)
##############################################################################
# Additional dependencies
##############################################################################
rev_style = timezone.tex rev.tex
$(addsuffix .dvi, $(target) $(optional)):: $(rev_style)
$(addsuffix .pdf, $(target) $(optional)):: $(rev_style)
##############################################################################
#
# tex4ht - Renders html from a LaTeX file, using CSS style sheets.
#
# To build the html output for a given LaTeX file, such as paper.tex,
# substitute -html for .tex, such as paper-html
#
##############################################################################
tex4ht ?= ~joshua/tex4ht.dir
tex4ht_bin = $(tex4ht)/bin/unix
tex4ht_styles = $(tex4ht)/texmf/tex/generic/tex4ht
%-html: %.tex FORCE
mkdir -p $@
cd $@ && env PATH=$(PATH):$(tex4ht_bin) TEXINPUTS=:..:$(tex4ht_styles) htlatex $<