-
Notifications
You must be signed in to change notification settings - Fork 183
/
Makefile
354 lines (296 loc) · 11.8 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
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
# See the README file for usage instructions
INKSCAPE = inkscape
PDFLATEX = xelatex
DIA = dia
EPSTOPDF = epstopdf
INKSCAPE_IS_NEW = $(shell inkscape --version | grep -q "^Inkscape 1" && echo YES)
ifeq ($(INKSCAPE_IS_NEW),YES)
INKSCAPE_PDF_OPT = -o
else
INKSCAPE_PDF_OPT = -A
endif
# Needed macros
UPPERCASE = $(shell echo $1 | tr "[:lower:]-" "[:upper:]_")
define sep
endef
include $(wildcard mk/*.mk)
# Output directory
OUTDIR = $(shell pwd)/out
# Latex variable definitions
VARS = $(OUTDIR)/vars
# Environment for pdflatex, which allows it to find the stylesheet in the
# common/ directory.
PDFLATEX_ENV = TEXINPUTS=.:$(shell pwd):$(shell pwd)/common: texfot --tee /tmp/fot.`id -u`
# Arguments passed to pdflatex
PDFLATEX_OPT = -shell-escape -file-line-error -halt-on-error
# The common slide stylesheet
STYLESHEET = common/beamerthemeBootlin.sty
#
# === Picture lookup ===
#
# Function that computes the list of pictures of the extension given
# in $(2) from the directories in $(1), and transforms the filenames
# in .pdf in the output directory. This is used to compute the list of
# .pdf files that need to be generated from .dia or .svg files.
PICTURES_WITH_TRANSFORMATION = \
$(patsubst %.$(2),$(OUTDIR)/%.pdf,$(foreach s,$(1),$(wildcard $(s)/*.$(2))))
# Function that computes the list of pictures of the extension given
# in $(2) from the directories in $(1). This is used for pictures that
# to not need any transformation, such as bitmap files in the .png or
# .jpg formats.
PICTURES_NO_TRANSFORMATION = \
$(patsubst %,$(OUTDIR)/%,$(foreach s,$(1),$(wildcard $(s)/*.$(2))))
# Function that computes the list of pictures from the directories in
# $(1) and returns output filenames in the output directory.
PICTURES = \
$(call PICTURES_WITH_TRANSFORMATION,$(1),svg) \
$(call PICTURES_WITH_TRANSFORMATION,$(1),dia) \
$(call PICTURES_NO_TRANSFORMATION,$(1),png) \
$(call PICTURES_NO_TRANSFORMATION,$(1),jpg) \
$(call PICTURES_NO_TRANSFORMATION,$(1),pdf)
# List of common pictures
COMMON_PICTURES = $(call PICTURES,common)
default: help
#
# === Compilation of slides ===
#
# This rule allows to build slides of the training. It is done in two
# parts with make calling itself because it is not possible to compute
# a list of prerequisites depending on the target name. See
# https://stackoverflow.com/questions/3381497/dynamic-targets-in-makefiles
# for details.
#
# The value of slide can be "full-kernel", "full-sysdev" (for the
# complete trainings) or the name of an individual chapter.
ifdef SLIDES
# Compute the set of chapters to build depending on the name of the
# PDF file that was requested.
ifeq ($(firstword $(subst -, , $(SLIDES))),full)
SLIDES_TRAINING = $(strip $(subst -slides, , $(subst full-, , $(SLIDES))))
SLIDES_COMMON_BEFORE = common/slide-header.tex \
common/$(SLIDES_TRAINING)-title.tex
SLIDES_CHAPTERS = $($(call UPPERCASE, $(subst -,_, $(SLIDES_TRAINING)))_SLIDES)
SLIDES_COMMON_AFTER = common/slide-footer.tex
else
SLIDES_TRAINING = $(firstword $(subst -, , $(SLIDES)))
ifeq ($(SLIDES_TRAINING),sysdev)
SLIDES_TRAINING = embedded-linux
else ifeq ($(SLIDES_TRAINING),kernel)
SLIDES_TRAINING = linux-kernel
endif
# We might be building multiple chapters that share a common
# prefix. In this case, we want to build them in the order they are
# listed in the <training>_SLIDES variable that corresponds to the
# current training, as identified by the first component of the
# chapter name.
SLIDES_CHAPTERS = $(filter $(SLIDES)%, $($(call UPPERCASE, $(SLIDES_TRAINING))_SLIDES))
ifeq ($(words $(SLIDES_CHAPTERS)),1)
SLIDES_COMMON_BEFORE = common/slide-header.tex common/single-subsection-slide-title.tex
else
SLIDES_COMMON_BEFORE = common/slide-header.tex common/single-slide-title.tex
endif
SLIDES_COMMON_AFTER = common/slide-footer.tex
endif
TRAINING = $(SLIDES_TRAINING)
ifeq ($(SLIDES_CHAPTERS),)
$(error "No chapter to build, maybe you're building a single chapter whose name doesn't start with a training session name")
endif
# Compute the set of corresponding .tex files and pictures
SLIDES_TEX = \
$(SLIDES_COMMON_BEFORE) \
$(foreach s,$(SLIDES_CHAPTERS),$(wildcard slides/$(s)/$(s).tex)) \
$(SLIDES_COMMON_AFTER)
SLIDES_PICTURES = $(call PICTURES,$(foreach s,$(SLIDES_CHAPTERS),slides/$(s))) $(COMMON_PICTURES)
# Check for all slides .tex file to exist
$(foreach file,$(SLIDES_TEX),$(if $(wildcard $(file)),,$(error Missing file $(file) !)))
%-slides.pdf: $(VARS) $(SLIDES_TEX) $(SLIDES_PICTURES) $(STYLESHEET) $(OUTDIR)/last-update.tex
@mkdir -p $(OUTDIR)
# We generate a .tex file with \input{} directives (instead of just
# concatenating all files) so that when there is an error, we are
# pointed at the right original file and the right line in that file.
rm -f $(OUTDIR)/$(basename $@).tex
echo "\input{last-update}" >> $(OUTDIR)/$(basename $@).tex
echo "\input{$(VARS)}" >> $(OUTDIR)/$(basename $@).tex
for f in $(filter %.tex,$^) ; do \
cp $$f $(OUTDIR)/`basename $$f` ; \
sed -i 's%__SESSION_NAME__%$(SLIDES_TRAINING)%' $(OUTDIR)/`basename $$f` ; \
printf "\input{%s}\n" `basename $$f .tex` >> $(OUTDIR)/$(basename $@).tex ; \
done
(cd $(OUTDIR); $(PDFLATEX_ENV) $(PDFLATEX) $(PDFLATEX_OPT) $(basename $@).tex)
# The second call to pdflatex is to be sure that we have a correct table of
# content and index
(cd $(OUTDIR); $(PDFLATEX_ENV) $(PDFLATEX) $(PDFLATEX_OPT) $(basename $@).tex > /dev/null 2>&1)
# We use cat to overwrite the final destination file instead of mv, so
# that evince notices that the file has changed and automatically
# reloads it (which doesn't happen if we use mv here). This is called
# 'Maxime's feature'.
cat out/$@ > $@
else
FORCE:
%-slides.pdf: FORCE
@$(MAKE) $@ SLIDES=$*
endif
#
# === Compilation of labs ===
#
ifdef LABS
ifeq ($(firstword $(subst -, , $(LABS))),full)
LABS_TRAINING = $(strip $(subst -labs, , $(subst full-, , $(LABS))))
LABS_HEADER = common/labs-header.tex
LABS_VARSFILE = common/$(LABS_TRAINING)-labs-vars.tex
LABS_CHAPTERS = $($(call UPPERCASE, $(subst -,_, $(LABS_TRAINING)))_LABS)
LABS_FOOTER = common/labs-footer.tex
else
LABS_TRAINING = $(firstword $(subst -, , $(LABS)))
LABS_VARSFILE = common/single-lab-vars.tex
LABS_CHAPTERS = $(LABS)
LABS_HEADER = common/single-lab-header.tex
LABS_FOOTER = common/labs-footer.tex
endif
TRAINING = $(LABS_TRAINING)
# Compute the set of corresponding .tex files and pictures
LABS_TEX = \
$(LABS_VARSFILE) \
$(LABS_HEADER) \
$(foreach s,$(LABS_CHAPTERS),$(wildcard labs/$(s)/$(s).tex)) \
$(LABS_FOOTER)
LABS_PICTURES = $(call PICTURES,$(foreach s,$(LABS_CHAPTERS),labs/$(s))) $(COMMON_PICTURES)
# Check for all labs .tex file to exist
$(foreach file,$(LABS_TEX),$(if $(wildcard $(file)),,$(error Missing file $(file) !)))
%-labs.pdf: common/labs.sty $(VARS) $(LABS_TEX) $(LABS_PICTURES) $(OUTDIR)/last-update.tex
@mkdir -p $(OUTDIR)
# We generate a .tex file with \input{} directives (instead of just
# concatenating all files) so that when there is an error, we are
# pointed at the right original file and the right line in that file.
rm -f $(OUTDIR)/$(basename $@).tex
echo "\input{last-update}" >> $(OUTDIR)/$(basename $@).tex
echo "\input{$(VARS)}" >> $(OUTDIR)/$(basename $@).tex
for f in $(filter %.tex,$^) ; do \
cp $$f $(OUTDIR)/`basename $$f` ; \
sed -i 's%__SESSION_NAME__%$(LABS_TRAINING)%' $(OUTDIR)/`basename $$f` ; \
printf "\input{%s}\n" `basename $$f .tex` >> $(OUTDIR)/$(basename $@).tex ; \
done
(cd $(OUTDIR); $(PDFLATEX_ENV) $(PDFLATEX) $(basename $@).tex)
# The second call to pdflatex is to be sure that we have a correct table of
# content and index
(cd $(OUTDIR); $(PDFLATEX_ENV) $(PDFLATEX) $(basename $@).tex > /dev/null 2>&1)
# We use cat to overwrite the final destination file instead of mv, so
# that evince notices that the file has changed and automatically
# reloads it (which doesn't happen if we use mv here). This is called
# 'Maxime's feature'.
cat out/$@ > $@
else
FORCE:
%-labs.pdf: FORCE
@$(MAKE) $@ LABS=$*
endif
#
# Lab data archive generation
#
%-labs.tar.xz: LAB_DATA=$(patsubst %-labs.tar.xz,%,$@)
%-labs.tar.xz: OUT_LAB_DATA=$(OUTDIR)/$(LAB_DATA)-labs
%-labs.tar.xz:
rm -rf $(OUT_LAB_DATA)
mkdir -p $(OUT_LAB_DATA)
rsync --exclude=.git -a -k --delete --copy-links lab-data/$(LAB_DATA)/ $(OUT_LAB_DATA)
fakeroot common/process-lab-data.sh $(OUT_LAB_DATA)
find $(OUT_LAB_DATA) -name '*.xz' -exec unxz {} \;
(cd $(OUTDIR); tar Jcf $@ $(LAB_DATA)-labs)
mv $(OUTDIR)/$@ $@
#
# === Compilation of agendas ===
#
ifdef AGENDA
AGENDA_TEX = agenda/$(AGENDA)-agenda.tex
AGENDA_PICTURES = $(COMMON_PICTURES) $(call PICTURES,agenda)
%-agenda.pdf: common/agenda.sty $(AGENDA_TEX) $(AGENDA_PICTURES) $(OUTDIR)/last-update.tex
rm -f $(OUTDIR)/$(basename $@).tex
cp $(filter %-agenda.tex,$^) $(OUTDIR)/$(basename $@).tex
(cd $(OUTDIR); $(PDFLATEX_ENV) $(PDFLATEX) $(basename $@).tex)
cat $(OUTDIR)/$@ > $@
else
FORCE:
%-agenda.pdf: FORCE
@$(MAKE) $@ AGENDA=$*
endif
#
# === Last update file generation ===
#
$(OUTDIR)/last-update.tex: FORCE
mkdir -p $(@D)
t=`git log -1 --format=%ct` && printf "\def \lastupdateen{%s}\n" "`(LANG=en_EN.UTF-8 date -d @$${t} +'%B %d, %Y')`" > $@
t=`git log -1 --format=%ct` && printf "\def \lastupdatefr{%s}\n" "`(LANG=fr_FR.UTF-8 date -d @$${t} +'%d %B %Y')`" >> $@
#
# === Picture generation ===
#
.PRECIOUS: $(OUTDIR)/%.pdf
$(OUTDIR)/%.pdf: %.svg
@printf "%-15s%-20s->%20s\n" INKSCAPE $(notdir $^) $(notdir $@)
@mkdir -p $(dir $@)
ifeq ($(V),)
$(INKSCAPE) -D $(INKSCAPE_PDF_OPT) $@ $< > /dev/null 2>&1
else
$(INKSCAPE) -D $(INKSCAPE_PDF_OPT) $@ $<
endif
$(OUTDIR)/%.pdf: $(OUTDIR)/%.eps
@printf "%-15s%-20s->%20s\n" EPSTOPDF $(notdir $^) $(notdir $@)
@mkdir -p $(dir $@)
$(EPSTOPDF) --outfile=$@ $^
.PRECIOUS: $(OUTDIR)/%.eps
$(OUTDIR)/%.eps: %.dia
@printf "%-15s%-20s->%20s\n" DIA $(notdir $^) $(notdir $@)
@mkdir -p $(dir $@)
$(DIA) -e $@ -t eps $^
.PRECIOUS: $(OUTDIR)/%.png
$(OUTDIR)/%.png: %.png
@mkdir -p $(dir $@)
@cp $^ $@
.PRECIOUS: $(OUTDIR)/%.jpg
$(OUTDIR)/%.jpg: %.jpg
mkdir -p $(dir $@)
@cp $^ $@
$(OUTDIR)/%.pdf: %.pdf
mkdir -p $(dir $@)
@cp $^ $@
#
# === Misc targets ===
#
$(VARS): FORCE
@mkdir -p $(dir $@)
/bin/echo "\def \sessionurl {$(patsubst %/,%,$(SESSION_URL))}" > $@
/bin/echo "\def \training {$(TRAINING)}" >> $@
/bin/echo "\def \trainer {$(TRAINER)}" >> $@
clean:
$(RM) -rf $(OUTDIR) *.pdf *-labs *.xz
ALL_TRAININGS = $(sort $(patsubst %.mk,%,$(notdir $(wildcard mk/*.mk))))
ALL_SLIDES = $(foreach p,$(ALL_TRAININGS),$(if $($(call UPPERCASE,$(p)_SLIDES)),full-$(p)-slides.pdf))
ALL_LABS = $(foreach p,$(ALL_TRAININGS),$(if $($(call UPPERCASE,$(p)_LABS)),full-$(p)-labs.pdf))
ALL_AGENDAS = $(patsubst %.tex,%.pdf,$(notdir $(wildcard agenda/*.tex)))
ALL_LABS_TARBALLS = $(patsubst %,%-labs.tar.xz,$(filter-out common,$(notdir $(wildcard lab-data/*))))
all: $(ALL_SLIDES) $(ALL_LABS) $(ALL_AGENDAS) $(ALL_LABS_TARBALLS)
list-courses:
@echo $(ALL_TRAININGS)
HELP_FIELD_FORMAT = " %-36s %s\n"
help:
@echo "Available targets:"
@echo
@echo "Slides:"
$(foreach p,$(ALL_SLIDES),\
@printf $(sort $(HELP_FIELD_FORMAT)) "$(p)" "Complete slides for the '$(patsubst full-%-slides.pdf,%,$(p))' course"$(sep))
@echo
@echo "Labs:"
$(foreach p,$(ALL_LABS),\
@printf $(sort $(HELP_FIELD_FORMAT)) "$(p)" "Complete labs for the '$(patsubst full-%-labs.pdf,%,$(p))' course"$(sep))
@echo
@echo "Agendas:"
$(foreach p,$(ALL_AGENDAS),\
@printf $(sort $(HELP_FIELD_FORMAT)) "$(p)" "Agenda for the '$(patsubst %-agenda.pdf,%,$(p))' course"$(sep))
@echo
@echo "Tarballs:"
$(foreach p,$(ALL_LABS_TARBALLS),\
@printf $(sort $(HELP_FIELD_FORMAT)) "$(p)" "Lab data for the '$(patsubst %-labs.tar.xz,%,$(p))' course"$(sep))
@echo
@printf $(HELP_FIELD_FORMAT) "<some-chapter>-slides.pdf" "Slides for a particular chapter in slides/"
@printf $(HELP_FIELD_FORMAT) "<some-chapter>-labs.pdf" "Labs for a particular chapter in labs/"
@echo
@printf $(HELP_FIELD_FORMAT) "list-courses" "List all courses"