This repository has been archived by the owner on Oct 31, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
60 lines (46 loc) · 2.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
# Note: this whole makefile is a huge hack, is highly unportable, and probably
# won’t even do what it’s supposed to do. So, use with care, have fun :)
PRESENTATIONS=$(patsubst %.tex, %.pdf, $(wildcard presentations/*.tex))
BUILD_DIR=build
BUILD_DECKS=$(subst presentations/,$(BUILD_DIR)/,$(wildcard presentations/content/*))
LATEX=pdflatex -output-directory $(BUILD_DIR)
all: $(PRESENTATIONS)
clean:
rm -fr presentations/$(BUILD_DIR)
distclean: clean
rm -f presentations/*.pdf
# Extract dependencies for presentations by looking at the source code and
# extracting all calls to \includedeck from them; it returns a list of elements
# like ’presentations/content/ccc/ccc_lokal.tex’
# Yes, we are using perl: a system that has make probably also has perl; if not,
# blame me.
define presentation_dependencies
$(shell perl -ne '/includedeck\{(.*)\}/ && print "presentations/content/", $$1, ".tex "' $(1))
endef
# This template is called with arguments like ‘presentations/xxx.pdf’; it
# generates a rule that dependes on the corresponding tex file as well as on all
# decks used in that tex file; dependencies are of the form
# ‘presentations/content/ccc/ccc_lokal.tex’
define PRESENTATION_template
.ONESHELL: $(1)
$(1): $(subst .pdf,.tex,$(1)) $(call presentation_dependencies,$(subst .pdf,.tex,$(1)))
echo $$^
cd presentations
mkdir -p $(BUILD_DECKS)
$(LATEX) $$(notdir $$<)
$(LATEX) $$(notdir $$<)
mv $(subst presentations/,$(BUILD_DIR)/,$(1)) .
endef
$(foreach presentation, $(PRESENTATIONS), \
$(eval $(call PRESENTATION_template, $(presentation))))
# This template is called with a single argument like
# ‘presentations/content/ccc/ccc_bundesweit.tex’; it generates a rule that
# dependes on all images used by the tex file. The actual recipe just checks
# whether the tex file is existent and updates the timestamp.
define DECK_template
$(1): $(shell perl -ne '/includegraphics[^\{]*\{([^\}]*)\}/ && print "presentations/", $$1, " "' $(1))
test -f $(1) && touch $(1)
endef
# Files contained in decks are only considered at top-level.
$(foreach deck, $(wildcard presentations/content/*/*.tex), \
$(eval $(call DECK_template, $(deck))))