-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
258 lines (202 loc) · 6.49 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
#------------------------------------------------------------------------------
# This is a makefile tailored to work with the latex documents for the
# Licentiate and PhD thesis (MechThesis).
#------------------------------------------------------------------------------
# Variables:
#
kappa := overview
main := thesis
chapter := chapter_01_0_intro
paper := paper_0*
TEMPLATE_DIR := ./templates/mechthesis/
TEX := pdflatex
DRAFT_FLAGS := -draftmode -interaction=nonstopmode -shell-escape
FINAL_FLAGS := -interaction=nonstopmode -shell-escape
ifdef CI
TEX := texliveonfly --terminal_only -f
DRAFT_FLAGS := -a "$(DRAFT_FLAGS)"
FINAL_FLAGS := -a "$(FINAL_FLAGS)"
endif
VIM := nvim
VIM_FLAGS := +'set backupcopy=yes'
BIB := biber
BIB_FLAGS :=
BIB_FILE := $(main).bib
red:="\033[0;31m"
end:="\033[0m"
define cprint =
@echo -e $(red)[$(shell date +'%H.%M.%S')] $(1)$(end)
endef
define watchdog =
@echo -e "Execute watchdog: on pattern $(1): run $(2)"
nohup watchmedo shell-command --patterns=$(1) --command=$(2) --drop 2>watch.log&
endef
define pandoc_standalone =
@pandoc \
$(PANDOC_FILTERS) \
-F pandoc-crossref \
-F pandoc-citeproc \
--bibliography $(BIB_FILE) \
--csl templates/journal-of-fluid-mechanics.csl \
--standalone \
--from markdown+table_captions \
--metadata-file=pandoc-meta.yml \
--number-sections \
$(1) -o $(2)
endef
define fix_toc =
@sed -i 's/\\000t\\000o\\000P\\000a\\000p\\000e\\000r/\\000P\\000a\\000p\\000e\\000r/g' thesis.out
endef
# ifndef CI
REDIRECT := | tail -n 2
# else
# REDIRECT := # no redirect
# endif
RUBBER_INFO := $(shell command -v rubber-info 2> /dev/null)
# Dependencies:
#
TEMPLATE_PAPER = templates/template_mechthesis_paper.tex
META_PAPER = $(wildcard $(paper)/paper.yml)
SRCS_PAPER = $(subst /,/paper.tex,$(wildcard $(paper)/))
SRCS = packages.tex \
commands.tex \
frontmatter.tex \
acknowledgements.md \
$(kappa).tex \
$(main).tex \
$(SRCS_PAPER)
# Template and BibTeX dependencies
#
DEPS = $(TEMPLATE_DIR)/MechThesis.cls \
$(TEMPLATE_DIR)/jfm.bst \
$(BIB_FILE)
AUXS = $(kappa).aux \
$(subst /,/paper.aux,$(wildcard $(paper)/)) \
$(main).toc \
$(main).glo \
$(main).ist
# $(main).aux \
BBLS = $(main).bbl \
$(main).bcf
IMGS = imgs/cascade.pdf \
imgs/dependency.pdf \
imgs/spectral_flux.pdf
MKDWN = $(sort $(wildcard chapter*.md))
MKDWN2TEX = $(subst .md,.latex,$(MKDWN))
MKDWN2PANDOCTEX = $(subst .md,.pandoc.tex,$(MKDWN))
PANDOC_FILTERS = $(subst ./,-F ./,$(wildcard ./scripts/pandoc_*.py))
# Rules:
#
.PHONY: default all clean clean_papers clean_thesis clean_minted cleanall vimtex doit red end
.NOPARALLEL: $(main).pdf $(main).bbl $(main).gls log watch
all: glossary.tex log
#
$(main).pdf: $(SRCS) $(DEPS) $(AUXS) $(BBLS) $(main).gls
$(call cprint,"building $@ with $(TEX)")
$(TEX) $(FINAL_FLAGS) $(main) $(REDIRECT)
$(call fix_toc)
$(AUXS): $(main).aux
$(main).aux: $(SRCS) $(DEPS) $(MKDWN2TEX) $(IMGS)
$(call cprint,"building $@ with $(TEX)")
$(TEX) $(DRAFT_FLAGS) $(main) $(REDIRECT)
$(call fix_toc)
$(main).gls: $(AUXS) $(BBLS) glossary.tex
$(call cprint,"building $@ with makeglossaries")
@makeglossaries -t $(main).log $(main)
%.bcf: %.aux
$(call cprint,"building $@ with $<")
%.bbl: %.bcf %.aux $(BIB_FILE)
$(call cprint,"building $@ with $(BIB) on $(BIB_FILE)")
@$(BIB) $(BIB_FLAGS) $(main) $(REDIRECT)
%.tex: %.yml $(TEMPLATE_PAPER) scripts/render_paper_yml.py
$(call cprint,"building $@ with python $(TEMPLATE_PAPER)")
@python scripts/render_paper_yml.py $< $(TEMPLATE_PAPER)
glossary.tex: glossary.yml scripts/render_glossary_yml.py
$(call cprint,"building $@ with python scripts/render_glossary_yml.py")
@python scripts/render_glossary_yml.py $< templates/template_glossary.tex
imgs/%.pdf: imgs/%/plot.py
$(call cprint,"building $@ with $<")
PYTHONSTARTUP=scripts/pythonrc.py python $<
chapter_%.md: $(IMGS)
$(call cprint,"ensuring $^ required for $@")
# MKDWN2TEX
chapter_%.latex: chapter_%.md
$(call cprint,"building $@ with pandoc $<")
@pandoc \
$(PANDOC_FILTERS) \
-F pandoc-crossref \
--natbib \
$< -o $@
chapter_%.pandoc.tex: chapter_%.md
$(call cprint,"building $@ with pandoc $<")
$(call pandoc_standalone,$<,$@)
chapters.pandoc.tex: $(MKDWN)
$(call cprint,"building $@ with pandoc $^")
$(call pandoc_standalone,$^,$@)
chapter_%.pandoc.pdf: chapter_%.pandoc.tex
$(call cprint,"building $@ with latexmk")
@latexmk -silent -use-make -pdf $<
chapters.pandoc.pdf: chapters.pandoc.tex
$(call cprint,"building $@ with latexmk")
@latexmk -silent -use-make -pdf $<
$(BIB_FILE):
$(call cprint,"building $@ with python scripts/get_bib.py")
@python scripts/get_bib.py
log: $(main).pdf
$(call cprint,"printing $@")
ifndef RUBBER_INFO
cat $(main).log
else
rubber-info $(main).tex
endif
clean: clean_papers clean_thesis
$(call cprint,"basic cleaning done")
cleanall: clean
$(call cprint,"cleaning generated documents")
@rm -f *.{ps,dvi,pdf,pandoc.pdf}
@rm -f chapter*.latex
@rm -f paper*/paper.tex
clean_minted:
$(call cprint,"cleaning minted")
@rm -rf _minted-$(main) $(paper)/_minted-*
clean_thesis:
$(call cprint,"cleaning thesis")
@rm -f *.{aux,toc,log,out,bbl,bcf,blg,pls,psm,synctex.gz,fls,fdb_latexmk,run.xml,gl?,ist,pandoc.tex,acn,acr}
clean_papers:
$(call cprint,"cleaning papers")
@rm -f paper*/*.{aux,bbl,blg,fls,fdb_latexmk,log,out,synctex.gz}
todo:
@# grep -r --color=tty '%.*[Tt][Oo][Dd][Oo]:'
@# ack --nomake '[Tt][Oo][Dd][Oo]:'
@rg -Tmake '[Tt][Oo][Dd][Oo]:'
opentex:
$(VIM) $(chapter).tex $(VIM_FLAGS) 2> /dev/null &
openmkdwn:
$(VIM) $(chapter).md $(VIM_FLAGS)
openchapter: $(chapter).pandoc.pdf
zathura $< 2> /dev/null &
openchapters: chapters.pandoc.pdf
zathura $< 2> /dev/null &
openthesis: $(main).pdf
zathura $< 2> /dev/null &
watchchapter:
$(call cprint,"watching for changes")
$(call watchdog,"*.md",'make $(chapter).pandoc.pdf $(chapter).latex')
watchchapters:
$(call cprint,"watching for changes")
$(call watchdog,"*.md",'make chapters.pandoc.pdf')
watchthesis:
$(call cprint,"watching for changes")
$(call watchdog,"*.tex",'make -j')
watchstop:
@pgrep -f watchmedo | xargs kill
# doit: openthesis watchthesis opentex
# doit: $(chapter).pandoc.pdf openchapter watchchapter openmkdwn
doit: openchapters watchchapters openmkdwn
%.txt: %.in
pip-compile $<
pyenv:
python -m venv $@
pyrequirements: requirements.txt dev-requirements.txt pandoc-requirements.txt
bash -c 'source pyenv/bin/activate; pip install pip-tools; pip-sync $^'
python: pyenv pyrequirements