aboutsummaryrefslogtreecommitdiff
path: root/book/GNUmakefile
blob: 1bfeac518d922523c31489c3b8734f8a80c6b230 (plain)
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
noop =
space = $(noop) $(noop)
comma = ,
langs = $(patsubst locale/%.ini,%,$(wildcard locale/*.ini))

s_pages = 01,02,03,04,05,06,07,08,09,10,11
s_langs = $(subst $(space),$(comma),$(langs))
png_pages = $(shell echo out/book_{$(s_pages)}.{$(s_langs)}.png)
svg_pages = $(shell echo out/book_{$(s_pages)}.{$(s_langs)}.svg)
webp_pages = $(shell echo out/book_{$(s_pages)}.{$(s_langs)}.webp)
pdfs = $(shell echo out/book.{$(s_langs)}.pdf)

MINIMAL = book.json
MOST = book.json $(pdfs)
ALL = book.json out/book.webp.tar.zst out/book.svg.tar.zst \
	$(pdfs) $(png_pages) $(webp_pages) $(svg_pages)

JSR = deno run

.PHONY: all
minimal: $(MINIMAL)
most: $(MOST)
all: $(ALL)

out:
	@mkdir -p out

book.json: book.js
	{ pushd .. >/dev/null; cargo $(CARGOFLAGS) run --release --bin hurrycurry-tools -- book; popd >/dev/null; } > $@~ && cp $@~ $@

$(wordlist 2,99,$(png_pages)): $(word 1,$(png_pages))
out/book_01.%.png: book.typ book.json locale/%.ini out
	typst compile --font-path assets/fonts --input lang=$(subst out/,,$(*)) $< out/book_\{n\}.$(subst out/,,$(*)).png
$(wordlist 2,99,$(svg_pages)): $(word 1,$(svg_pages))
out/book_01.%.svg: book.typ book.json locale/%.ini out
	typst compile --font-path assets/fonts --input lang=$(subst out/,,$(*)) $< out/book_\{n\}.$(subst out/,,$(*)).svg
out/book.%.pdf: book.typ book.json locale/%.ini out
	typst compile --font-path assets/fonts --input lang=$(subst out/,,$(*)) $< $@

out/%.webp: out/%.png
	ffmpeg -i $< -y $@

out/book.svg.tar.zst: $(svg_pages)
	tar -cf $@ $^
out/book.webp.tar.zst: $(webp_pages)
	tar -cf $@ $^

.PHONY: clean
clean:
	rm -rf out
	rm -f book.json