-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
167 lines (130 loc) · 4.73 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
INKSCAPE := inkscape
CONVERT := convert
PDFPOSTER := pdfposter
PDFLATEX := pdflatex
TMP := intermediates
OUT := outputs
DPIS := 75 150 300
DPI ?= 300
THUMB_DPI := 25
THUMB := docs/thumbnail.jpg
OUTDIRS += $(TMP)
OUTDIRS += $(OUT)
BOARD_SVG := Cornwall.svg
PNG_OUTPUTS += $(foreach dpi,$(DPIS) $(THUMB_DPI),$(OUT)/Cornwall-$(dpi)dpi.png)
JPG_OUTPUTS += $(foreach dpi,$(THUMB_DPI),$(OUT)/Cornwall-$(dpi)dpi.jpg)
PDF_OUTPUTS += $(foreach dpi,$(DPIS),$(OUT)/Cornwall-$(dpi)dpi.pdf)
TILED_NOMARG += $(foreach dpi,$(DPIS),$(TMP)/Cornwall-$(dpi)dpi-a4-tight.pdf)
TILED_TEX += $(foreach dpi,$(DPIS),$(TMP)/Cornwall-$(dpi)dpi-a4.tex)
TILED_TMPOUT += $(foreach dpi,$(DPIS),$(TMP)/Cornwall-$(dpi)dpi-a4.pdf)
TILED_OUTPUTS += $(foreach dpi,$(DPIS),$(OUT)/Cornwall-$(dpi)dpi-a4.pdf)
BOARD_OUTPUTS := $(TILED_OUTPUTS)
BOARD_DEFAULT := $(OUT)/Cornwall-$(DPI)dpi-a4.pdf
INTERMEDIATES += $(TMP)/ticket_background.png
PAGES := $(shell grep 'inkscape:label="Page [0-9]\+"' cornwall_tickets.svg | \
sed 's/^.*Page \([0-9]\+\).*$$/\1/')
SVG_TICKETS += $(foreach page,$(PAGES),$(TMP)/cornwall_tickets.page$(page).svg)
PNG_TICKETS += $(foreach page,$(PAGES),$(TMP)/cornwall_tickets.page$(page)-$(DPI)dpi.png)
TICKET_OUTPUTS := $(OUT)/cornwall_tickets-$(DPI)dpi.pdf
OUTPUTS += $(BOARD_OUTPUTS)
OUTPUTS += $(TICKET_OUTPUTS)
# Perform some arithmetic using bc to calculate tile sizes
bc = $(shell echo "$(1)" | bc)
bc_fp = $(call bc,scale=10; $(1))
# Poster size can be taken straight from SVG
POSTER_WIDTH := $(shell grep -m1 width= "$(BOARD_SVG)" | sed 's/^.*"\(.*\)mm".*$$/\1/')
POSTER_HEIGHT := $(shell grep -m1 height= "$(BOARD_SVG)" | sed 's/^.*"\(.*\)mm".*$$/\1/')
# Tile based on size of A4 (landscape) subtracting margins
MAX_TILE_WIDTH = (297-10-15)
MAX_TILE_HEIGHT = (210-10-10)
TILES_X := $(call bc,($(POSTER_WIDTH)+$(MAX_TILE_WIDTH)-1) / $(MAX_TILE_WIDTH))
TILES_Y := $(call bc,($(POSTER_HEIGHT)+$(MAX_TILE_HEIGHT)-1) / $(MAX_TILE_HEIGHT))
# Find actual tile size
TILE_WIDTH := $(call bc_fp,$(POSTER_WIDTH) / $(TILES_X))
TILE_HEIGHT := $(call bc_fp,$(POSTER_HEIGHT) / $(TILES_Y))
.PHONY: default
default: board tickets
.PHONY: all
all: prepare $(OUTPUTS) $(JPG_OUTPUTS)
.PHONY: board
board: $(BOARD_DEFAULT)
.PHONY: tickets
tickets: $(TICKET_OUTPUTS)
.PHONY: png
png: $(PNG_OUTPUTS)
.PHONY: pdf
pdf: $(PDF_OUTPUTS) $(TILED_OUTPUTS)
.PHONY: prepare
prepare: $(INTERMEDIATES)
.PHONY: thumb
thumb: $(THUMB)
$(THUMB): $(OUT)/Cornwall-$(THUMB_DPI)dpi.jpg
cp $< $@
$(OUTDIRS):
mkdir $@
$(INTERMEDIATES): $(TMP)/%.png: %.svg | $(TMP)
rm -f $@
$(INKSCAPE) $< -o [email protected] --export-dpi=300
mv [email protected] $@
$(PNG_OUTPUTS): $(OUT)/Cornwall-%dpi.png: $(BOARD_SVG) | $(OUT)
rm -f $@
$(INKSCAPE) $< -o [email protected] --export-dpi=$(@:$(OUT)/Cornwall-%dpi.png=%)
mv [email protected] $@
$(JPG_OUTPUTS): %.jpg: %.png
rm -f $@
$(CONVERT) -quality 80 $< [email protected]
mv [email protected] $@
$(PDF_OUTPUTS): %.pdf: %.png
rm -f $@
$(CONVERT) $< [email protected]
mv [email protected] $@
$(TILED_TEX): %-a4.tex: margins-a4.tex
rm -f $@
sed -e 's/_TILE_WIDTH_/$(TILE_WIDTH)/' \
-e 's/_TILE_HEIGHT_/$(TILE_HEIGHT)/' \
-e 's/_SRC_/$(subst /,\/,$(@:%.tex=%-tight.pdf))/' $< > [email protected]
mv [email protected] $@
$(TILED_NOMARG): $(TMP)/%-a4-tight.pdf: $(OUT)/%.pdf
rm -f $@
$(PDFPOSTER) -m$(TILE_WIDTH)x$(TILE_HEIGHT)mm -p$(POSTER_WIDTH)x$(POSTER_HEIGHT)mm $< [email protected]
mv [email protected] $@
$(TILED_TMPOUT): %-a4.pdf: %-a4.tex %-a4-tight.pdf
$(PDFLATEX) -output-directory=$(TMP) $<
$(TILED_OUTPUTS): $(OUT)/%: $(TMP)/%
cp $< $@
$(SVG_TICKETS): cornwall_tickets.svg | $(TMP)
rm -f $@
cp cornwall_tickets.svg [email protected]
sed -i '/\(inkscape:label="Page [0-9]\+"\|style="display:inline"\)/{N;N;N;/inkscape:label="Page [0-9]\+"/{/style=/{s/style="display:inline"/style="display:none"/}}}' [email protected]
sed -i '/\(inkscape:label="Page $(patsubst $(TMP)/cornwall_tickets.page%.svg,%,$@)"\|style="display:none"\)/{N;N;N;/inkscape:label="Page $(patsubst $(TMP)/cornwall_tickets.page%.svg,%,$@)"/{/style=/{s/style="display:none"/style="display:inline"/}}}' [email protected]
mv [email protected] $@
# This symlink is required due to links in the ticket SVG which we have
# intermediate versions of in the temp directory.
$(TMP)/$(TMP):
ln -s . $(TMP)/$(TMP)
$(PNG_TICKETS): %-$(DPI)dpi.png: %.svg $(TMP)/ticket_background.png $(TMP)/$(TMP)
rm -f $@
$(INKSCAPE) $< -o [email protected] --export-dpi=$(DPI)
mv [email protected] $@
$(TICKET_OUTPUTS): $(PNG_TICKETS) | $(OUT)
rm -f $@
$(CONVERT) $^ [email protected]
mv [email protected] $@
clean:
rm -f $(INTERMEDIATES)
rm -f $(PNG_OUTPUTS)
rm -f $(JPG_OUTPUTS)
rm -f $(PDF_OUTPUTS)
rm -f $(TILED_NOMARG)
rm -f $(TILED_TEX)
rm -f $(TILED_TMPOUT)
rm -f $(TILED_OUTPUTS)
rm -f $(SVG_TICKETS)
rm -f $(PNG_TICKETS)
rm -f $(OUTPUTS)
rm -f $(TMP)/$(TMP)
rm -f $(TMP)/*.tmp
rm -f $(TMP)/*.aux
rm -f $(TMP)/*.log
rm -f $(OUT)/*.tmp
rmdir $(OUTDIRS) || true