-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile
150 lines (112 loc) · 4.12 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
SHELL = zsh
.SHELLFLAGS += -e
MAKEFLAGS += --jobs=$(shell nproc)
.ONESHELL:
.SECONDARY:
.SECONDEXPANSION:
.DELETE_ON_ERROR:
.PRECIOUS: .fonts/%
CURL ?= curl
GIT ?= git
GROFF ?= groff
MAGICK ?= magick
NPM ?= npm
NPX ?= npx
PAGEDJS ?= $(NPX) pagedjs-cli
SATYSFI ?= satysfi
SED ?= sed
SILE ?= sile
TERA ?= tera
TOMLQ ?= tomlq
TYPST ?= typst
WEASYPRINT ?= weasyprint
XELATEX ?= xelatex
XQ ?= xq
ZOLA ?= zola
BASE_URL = /
GROFF_ARGS = -T pdf $< > $@
PAGEDJS_ARGS = -i $< -o $@
SATYSFI_ARGS = $< -o $@
SILE_ARGS = -o $@ $<
TYPST_ARGS = compile $< $@
WEASYPRINT_ARGS = $< $@
XELATEX_ARGS = -interaction=batchmode -halt-on-error
XELATEX_ARGS += -jobname $*-xelatex $<
.PHONY: default
default: public
get_typesetters = $(shell $(SED) '0,/^\+\+\+$$/d;/^\+\+\+$$/,$$d' $1 | $(TOMLQ) -r '.extra.typesetters[]' | xargs)
get_typesetter_args = $(shell $(SED) '0,/^\+\+\+$$/d;/^\+\+\+$$/,$$d' $1 | $(TOMLQ) -r '.extra.typesetter_args.$2 // empty')
SAMPLES := $(notdir $(shell echo data/*(/)))
MANIFESTS := $(foreach S,$(SAMPLES),$(foreach T,$(call get_typesetters,content/$(S).md),data/$(S)-$(T).toml))
PDFS := $(addsuffix .pdf,$(basename $(MANIFESTS)))
PREVIEWS := $(addsuffix .avif,$(basename $(PDFS)))
define make_manifest ?=
cat <<- EOF > $(basename $@).toml
src = "$<"
demosrc = "$(notdir $(basename $@)$(suffix $<))"
demoout = "$(notdir $@)"
preview = "$(notdir $(basename $@)).avif"
cmd = "$(subst $(NPX) ,,$(subst $<,$(notdir $(basename $@)$(suffix $<)),$(subst $@,$(notdir $@),$1)))"
EOF
exec $1
endef
.PHONY: all
all: $(PDFS)
node_modules:
$(NPM) ci
.PHONY: fonts
fonts: .fonts/EgyptianOpenType.ttf
.fonts:
mkdir -p $@
.fonts/EgyptianOpenType.ttf: | .fonts
$(CURL) -fsSL https://github.com/microsoft/font-tools/raw/main/EgyptianOpenType/font/eot.ttf -o $@
touch $@
%-groff.pdf %-groff.toml: TYPESETTER_ARGS = $(call get_typesetter_args,content/$(notdir $(basename $*)).md,$(notdir $(basename $<)))
%-groff.pdf %-groff.toml: %/groff.groff
$(call make_manifest,$(GROFF) $(TYPESETTER_ARGS) $(GROFF_ARGS))
%-groff.pdf %-groff.toml: %/groff.ms
$(call make_manifest,$(GROFF) -ms $(TYPESETTER_ARGS) $(GROFF_ARGS))
%-groff.pdf %-groff.toml: %/groff.mom
$(call make_manifest,$(GROFF) -mom $(TYPESETTER_ARGS) $(GROFF_ARGS))
%-pagedjs.pdf %-pagedjs.toml: %/pagedjs.html
local args="$(call get_typesetter_args,content/$(notdir $(basename $@)).md,$(notdir $(basename $<)))"
$(call make_manifest,$(PAGEDJS) $(TYPESETTER_ARGS) $(PAGEDJS_ARGS))
%-satysfi.pdf %-saty.toml: %/satysfi.saty
$(call make_manifest,$(SATYSFI) $(SATYSFI_ARGS))
%-sile.pdf %-sile.toml: %/sile.sil
local args="$(call get_typesetter_args,content/$(notdir $(basename $@)).md,$(notdir $(basename $<)))"
$(call make_manifest,$(SILE) $(TYPESETTER_ARGS) $(SILE_ARGS))
%-sile.pdf %-sile.toml: %/sile.xml
local args="$(call get_typesetter_args,content/$(notdir $(basename $@)).md,$(notdir $(basename $<)))"
$(call make_manifest,$(SILE) $(TYPESETTER_ARGS) $(SILE_ARGS))
%-typst.pdf %-typst.toml: %/typst.typ
local args="$(call get_typesetter_args,content/$(notdir $(basename $@)).md,$(notdir $(basename $<)))"
$(call make_manifest,$(TYPST) $(TYPESETTER_ARGS) $(TYPST_ARGS))
%-weasyprint.pdf %-weasyprint.html: %/weasyprint.html
local args="$(call get_typesetter_args,content/$(notdir $(basename $@)).md,$(notdir $(basename $<)))"
$(call make_manifest,$(WEASYPRINT) $(TYPESETTER_ARGS) $(WEASYPRINT_ARGS))
%-xelatex.pdf %-xelatex.toml: %/xelatex.tex
local args="$(call get_typesetter_args,content/$(notdir $(basename $@)).md,$(notdir $(basename $<)))"
$(call make_manifest,$(XELATEX) $(TYPESETTER_ARGS) $(XELATEX_ARGS))
static/%.css: sass/%.scss | node_modules
$(NPX) sass --no-source-map $<:$@
$(NPX) postcss -u autoprefixer --no-map $@ -o $@
%.avif: %.pdf
$(MAGICK) convert -density 150 $< $@
.PHONY: static
static: $(PDFS) $(PREVIEWS) static/main.css
install -Dm0644 -t static $(filter-out static/%,$^)
for m in $(MANIFESTS); do
tomlq -r '[.src, .demosrc] | @tsv' $$m | read src demosrc
install -Dm0644 $$src static/$$demosrc
done
.PHONY: public
public: zola
.PHONY: serve
serve: public
zola serve
.PHONY: zola
zola: static
$(ZOLA) build -u $(BASE_URL)
public/CNAME:
echo polytype.dev > $@