-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
252 lines (203 loc) · 7.26 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
# OS specific sed
UNAME := $(shell uname)
ifeq ($(UNAME), Linux)
SED=sed -i
endif
ifeq ($(UNAME), Darwin)
SED=sed -i ""
endif
# Required executables
PYTHON=python3
PANDOC=pandoc
LATEXRUN := $(abspath tools/latexrun)
LATEX=pdflatex
BIB=biber
SINGLEPAGE=singlepage
PDF2SVG=pdf2svg
# Project Settings
build = _build
name = diss-haarhoff
version := $(shell ./tools/pretty_git_sha.sh)
date := $(shell git log -1 --date=short --format=%cd)
bibfile := $(abspath text/bibliography.yaml)
stylefolder := $(abspath style)
pandoc-html-flags = --verbose \
-F pandoc-crossref \
-F pandoc-include-code \
-F pandoc-include \
--bibliography="$(bibfile)" \
--include-in-header="$(stylefolder)/style.css" \
--include-after-body=$(stylefolder)/anchors.js \
--template="$(stylefolder)/template.html" \
--mathml \
--standalone \
--csl="$(stylefolder)/ref_format.csl" \
--toc \
--number-sections
pandoc-tex-flags = --verbose \
-F pandoc-crossref \
-F pandoc-include-code \
-F pandoc-include \
--lua-filter=tools/short-captions.lua \
-H "$(stylefolder)/preamble.tex" \
--template="$(stylefolder)/template.tex" \
--bibliography="$(bibfile)" \
--number-sections \
--csl="$(stylefolder)/ref_format.csl"
pandoc-epub-flags = --verbose \
-F pandoc-crossref \
-F pandoc-include-code \
-F pandoc-include \
--template="$(stylefolder)/template.epub.html" \
--bibliography="$(bibfile)" \
--number-sections \
--mathjax \
--epub-cover-image cover.jpeg \
--csl="$(stylefolder)/ref_format.csl"
ghostscript-flags = -sDEVICE=pdfwrite \
-dCompatibilityLevel=1.4 \
-dPDFSETTINGS=/printer \
-dPrinted=false \
-dNOPAUSE \
-dQUIET \
-dBATCH
# Where make looks for source files
VPATH := $(wildcard data/*):figures:text
# Source collections
text := $(wildcard text/*.md)
images := $(wildcard figures/*.png) $(wildcard figures/*.jpg) $(wildcard figures/*.svg)
mov := $(wildcard figures/*.mp4)
plots_py := $(wildcard data/*/*.py)
sketches := $(wildcard figures/*.sk)
tikz := $(wildcard figures/*.tex)
html-style := $(wildcard $(stylefolder)/*.html) $(wildcard $(stylefolder)/*.js) $(wildcard $(stylefolder)/*.css)
tex-style := $(wildcard $(stylefolder)/*.tex)
ref-style = $(stylefolder)/ref_format.csl
# Target collections
text4tex := $(addprefix $(build)/text4tex/, $(notdir $(text)))
text4epub := $(addprefix $(build)/text4epub/, $(notdir $(text)))
static := $(images:%=$(build)/%) $(mov:%=$(build)/%)
svgaspdf := $(static:.svg=.pdf)
plots_name := $(basename $(notdir $(plots_py)))
plots_pdf := $(plots_name:%=$(build)/figures/%.pdf)
plots_svg := $(plots_name:%=$(build)/figures/%.svg)
sketches_name := $(basename $(notdir $(sketches)))
sketches_pdf := $(sketches_name:%=$(build)/figures/%.pdf)
sketches_png := $(sketches_name:%=$(build)/figures/%.png)
tikz_name := $(basename $(notdir $(tikz)))
tikz_pdf := $(tikz_name:%=$(build)/figures/%.pdf)
tikz_png := $(tikz_name:%=$(build)/figures/%.png)
mov_names := $(basename $(notdir $(mov)))
gif := $(mov_names:%=$(build)/figures/%.gif)
gifaspng := $(mov_names:%=$(build)/figures/%.png)
# High-Level Targets
main: html pdf standalone
all: html pdf standalone epub bigzip
html: html-figures $(build)/$(name).html | $(build)
pdf: pdf-figures $(build)/$(name).pdf | $(build)
ebook: epub
epub: pdf-figures html-figures code4epub $(build)/$(name).epub | $(build)
standalone: $(build)/$(name).standalone.html | html
zip: $(build)/$(name).zip
bigzip: $(build)/$(name).zip
html-figures: $(plots_pdf) $(plots_svg) $(sketches_png) $(tikz_png) $(gif) $(static) | $(build)/figures
pdf-figures: $(plots_pdf) $(sketches_png) $(tikz_png) $(gifaspng) $(static) $(svgaspdf) | $(build)/figures
# HTML Targets
$(build)/$(name).html: $(text) $(html-style) $(ref-style) | $(build)
$(PANDOC) text/*.md -o $@ $(pandoc-html-flags)
%.html: %.md $(html-style) $(ref-style) html-figures | $(build)
$(PANDOC) $< -o "$@" -M title="$(basename $@)" $(pandoc-html-flags)
$(build)/$(name).standalone.html: $(build)/$(name).html
cd $(build) && \
$(SINGLEPAGE) $(name).html > $(name).standalone.html
$(SED) 's/<math disp/ <math disp/g' $@
# TeX Target
$(build)/$(name).tex: pdf-figures $(text4tex) $(tex-style) $(ref-style)
$(PANDOC) $(build)/text4tex/*.md -o "$(build)/$(name).tex" $(pandoc-tex-flags)
$(build)/text4tex/%.md: %.md | $(build)/text
cp $< $@
$(SED) 's/\.svg/\.pdf/g' $@
$(SED) 's/\.gif/\.png/g' $@
$(SED) 's/^```{.*/CODE LISTING REMOVED FROM PDF -- /g' $@
$(SED) 's/^```/AVAILABLE IN HTML FILE/g' $@
# ZIP of all
$(build)/$(name).zip: html pdf standalone epub
cd $(build) && \
cp $(name).pdf $(name).orig.pdf && \
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/printer -dNOPAUSE -dQUIET -dBATCH -sOutputFile=$(name).pdf $(name).orig.pdf && \
zip -r $(name).zip $(name).pdf $(name).standalone.html $(name).epub $(name).html figures
# eBook Targets
$(build)/$(name).epub: $(text4epub) $(ref-style) | $(build)
cp cover.jpeg $(build)/cover.jpeg && \
cd $(build) && \
$(PANDOC) text4epub/*.md -o $(notdir $@) $(pandoc-epub-flags)
$(build)/text4epub/%.md: %.md | $(build)/text
cp $< $@
$(SED) 's/\.gif/\.png/g' $@
# Required folders
$(build):
mkdir -p $(build)
$(build)/figures:
mkdir -p $(build)/figures
$(build)/text:
mkdir -p $(build)/text
mkdir -p $(build)/text4tex
mkdir -p $(build)/text4epub
# Convert pdf plots to svg as matplotlib borks tex symbols in svg
$(build)/figures/%.svg: $(build)/figures/%.pdf | $(build)/figures
$(PDF2SVG) $< $@
$(SED) 's/width.*pt\"//g' $@
$(SED) 's/height.*pt\"//g' $@
# Plots from python scripts
$(build)/figures/%.pdf: %.py | $(build)/figures
$(PYTHON) $< $@
# Static files that need to be copied
$(build)/figures/%.png: %.png | $(build)/figures
cp $< $@
$(build)/figures/%.jpg: %.jpg | $(build)/figures
cp $< $@
$(build)/figures/%.mp4: %.mp4 | $(build)/figures
cp $< $@
$(build)/figures/%.svg: %.svg | $(build)/figures
cp $< $@
$(build)/figures/%.pdf: %.svg | $(build)/figures
rsvg-convert --zoom=3.0 -f pdf -o $@ $<
code4epub:
cp -r code $(build)/code
# sketch >>> TeX
%.tex: %.sk
@echo $@ $<
sketch -Te $< -o $@
# TeX >>> PDF
%.pdf: %.tex
@echo "$< >>> $@"
cd $(dir $(abspath $<)) && \
$(LATEXRUN) -O $(abspath $(build))/latexrun/$(basename $@).latexrun \
-o $(abspath $@) --latex-cmd $(LATEX) --bibtex-cmd $(BIB) $(notdir $<)
# TeX >>> PDF with crop for figures
$(build)/figures/%.pdf: %.tex | $(build)/figures
@echo "$< >>> $@"
cd $(dir $(abspath $<)) && \
$(LATEXRUN) -O $(abspath $(build))/latexrun/$(basename $@).latexrun \
-o $(abspath $@) --latex-cmd $(LATEX) --bibtex-cmd $(BIB) $(notdir $<)
pdfcrop $@ $@ -margins "5 5 5 5"
# Other files conversions
$(build)/figures/%.png: %.pdf | $(build)/figures
pdfcrop $< $< -margins "5 5 5 5"
convert -flatten -density 300 -define profile:skip=ICC $< -quality 90 $@
$(build)/figures/%.png: %.mp4 | $(build)/figures
ffmpeg -y -sseof -1 -i $< -vframes 1 -q:v 2 -vf scale=1024:-2 $@
convert $@ -gravity south -undercolor black -fill yellow -font Lato-Regular -pointsize 18 -annotate +0+0 "This should be a video. Please see HTML-version of this document." $@
$(build)/figures/%.gif: %.mp4 | $(build)/figures
gifify $< --resize '800:-1' -o $@
$(build)/figures/robot_comp.gif: robot_comp.mp4 | $(build)/figures
gifify $< --resize '800:-1' --fps 30 --colors 160 -o $@
clean-all:
rm -r $(build)
clean-pdf:
rm -r $(build)/text
rm $(build)/*.tex
rm $(build)/*.pdf
clean:
rm -r $(build)/text*
rm $(build)/diss-haarhoff*