-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile
103 lines (86 loc) · 2.13 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
docs = cryptoparty-intro
tex_ext = pdf aux log toc nav snm out
TEX_FLAGS = -interaction=nonstopmode
TEX2PDF = pdflatex $(TEX_FLAGS)
DOT2PNG = dot -Tpng
SVG2PDF = inkscape
MKIDX = makeindex
SED = sed
pdf_docs = $(patsubst %,%.pdf,$(docs))
dot_figs = $(wildcard graphs/*.dot)
svg_figs = $(wildcard images/*.svg)
svgpdf_figs = $(patsubst %.svg,%.pdf,$(svg_figs))
png_figs = $(patsubst %.dot,%.png,$(dot_figs))
tex_docs = $(wildcard *.tex include/*.tex)
targets = $(pdf_docs)
### helpers
ifeq (1,$(V))
verbose := true
else
verbose := false
endif
# print output on failure only
define try
tmp=`mktemp`; \
($(1)) >$$tmp; \
ret=$$?; \
if $(verbose) || test $$ret -ne 0; then \
cat $$tmp; \
fi; \
exit $$ret
endef
### generic rules
.PHONY: all
all: $(targets)
$(png_figs): %.png: %.dot
@echo "DOT $*"; \
$(DOT2PNG) $^ > $@
$(svgpdf_figs): %.pdf: %.svg
@echo "SVG $*"; \
$(SVG2PDF) --export-pdf=$@ $<
.DELETE_ON_ERROR: $(pdf_docs)
%.pdf: %.tex
@echo "AUX $*"; \
$(call try,cd `dirname $*` && $(TEX2PDF) `basename $*` && cd -)
@if test -f $*.glo; then \
echo "GLS $*"; \
$(call try,$(MKIDX) $*.glo -s nomencl.ist -o $*.gls 2>&1); \
$(call try,cd `dirnrame $*` && $(TEX2PDF) `basename $*` && cd -); \
fi
@echo "PDF $*"; \
$(call try,cd `dirname $*` && $(TEX2PDF) `basename $*` && cd -)
.PHONY: clean
clean:
@for i in $(docs); do \
echo "CLEAN $$i"; \
for e in $(tex_ext); do \
rm -f $$i.$$e; \
done; \
done; \
for i in $(dot_figs); do \
f=`basename $$i .dot`; \
echo "CLEAN $$f"; \
rm -f $$f.png; \
done; \
for i in $(svg_figs); do \
f=`basename $$i .svg`; \
echo "CLEAN $$f"; \
rm -f $$f.pdf; \
done; \
rm -f .tex_dep
### automatic dependencies
.tex_dep: $(tex_docs)
@$(MAKE) --no-print-directory dep
.PHONY: dep
dep:
@echo "DEP $@"; \
for i in $(tex_docs); do \
echo "$$i:" `$(SED) -n 's#^[^%]*\\includegraphics\(\[[^]]*\]\)\?{\([^}]*\)}.*$$#\2#p' $$i; \
$(SED) -n 's/^[^%]*\\input{\([^}]*\)}.*$$/\1/p' $$i; \
$(SED) -n 's/^[^%]*\\include{\([^}]*\)}.*$$/\1.tex/p' $$i`; \
echo " @touch \$$@"; \
echo; \
done > .tex_dep
ifneq ($(MAKECMDGOALS),dep)
-include .tex_dep
endif