-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
430 lines (331 loc) · 11.5 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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
default: full
PINAFOREVERSION := 0.6
# must be three numbers, add .0 as necessary
PINAFOREVERSIONABC := $(PINAFOREVERSION).0
### Flags for stack
ifeq ($(nodocker),1)
DOCKERFLAGS := --no-docker
else
DOCKERFLAGS :=
endif
ifeq ($(single),1)
JOBFLAGS := --no-keep-going --jobs 1
else
JOBFLAGS := --keep-going
endif
ifeq ($(stackroot),1)
STACKROOTFLAGS := --stack-root $$PWD/.stack-root
else
STACKROOTFLAGS :=
endif
STACKFLAGS := $(STACKROOTFLAGS) $(DOCKERFLAGS) $(JOBFLAGS) --ta --hide-successes
STACKEXEC := stack $(STACKFLAGS) exec
ifeq ($(test),1)
TESTFLAGS :=
else
TESTFLAGS := --no-run-tests
endif
ifeq ($(bench),1)
BENCHFLAGS := --ba "--json benchmarks.json"
else
BENCHFLAGS := --no-run-benchmarks
endif
ifeq ($(haddock),1)
HADDOCKFLAGS := --haddock
else
HADDOCKFLAGS :=
endif
ifeq ($(nix-docker),1)
BINPATH := /binpath
else
BINPATH := $(shell stack $(STACKFLAGS) path --local-bin)
endif
### Docker image
.PHONY: docker-image
docker-image:
ifeq ($(nodocker),1)
else
docker build -t local-build docker
endif
### Formatting
${BINPATH}/hindent: docker-image
stack $(STACKFLAGS) install hindent
.PHONY: hindent
hindent: ${BINPATH}/hindent
.PHONY: format
format: ${BINPATH}/hindent
env BINPATH=${BINPATH} stack --docker-env BINPATH $(STACKFLAGS) exec -- bin/hindent-all
### Licensing info
out:
mkdir -p $@
out/licensing: out
stack ls dependencies --license | awk '{t=$$1;$$1=$$2;$$2=t;print}' | sort > $@
.PHONY: licensing
licensing: out/licensing
### Executables
${BINPATH}/pinafore ${BINPATH}/pinadata ${BINPATH}/pinadoc &: out docker-image
ifeq ($(nodocker),1)
else
rm -rf out/logs
ifeq ($(haddock),1)
rm -rf out/haddock
endif
endif
xhost +si:localuser:$${USER}
stack --docker-env DISPLAY $(STACKFLAGS) install --test --bench $(TESTFLAGS) $(BENCHFLAGS) $(HADDOCKFLAGS)
strip --remove-section=.comment ${BINPATH}/pinafore
strip --remove-section=.comment ${BINPATH}/pinadoc
ifeq ($(nodocker),1)
else
ifeq ($(haddock),1)
cp -r `stack $(STACKFLAGS) path --local-doc-root` out/haddock
endif
endif
ifeq ($(bench),1)
test -n "$$(git status -s)" || ($(STACKEXEC) -- benchgraph/adapters/criterion/export_benchs.sh Pinafore/pinafore-app/benchmarks.json > benchmarks/pinafore-`git rev-parse HEAD`.ndjson)
endif
.PHONY: exe
exe: ${BINPATH}/pinafore
### Debian package
PACKAGENAME := pinafore
PACKAGEVERSION := $(PINAFOREVERSION)
PACKAGEREVISION := 1
PACKAGEFULLNAME := $(PACKAGENAME)_$(PACKAGEVERSION)-$(PACKAGEREVISION)
PACKAGEDIR := .build/deb/$(PACKAGEFULLNAME)
DEBIANREL := bookworm
LIBMODULEFILES := \
UILib/Context \
UILib/Command \
UILib/Pane \
UILib/Set \
UILib/Named \
UILib
.build/deb/$(PACKAGEFULLNAME).deb: \
${BINPATH}/pinafore \
${BINPATH}/pinadoc \
$(foreach I,$(LIBMODULEFILES),Pinafore/pinafore-lib-script/data/$(I).pinafore) \
deb/copyright \
deb/control.m4 \
deb/changelog.m4
rm -rf $(PACKAGEDIR)
mkdir -p $(PACKAGEDIR)/usr/bin
cp ${BINPATH}/pinafore $(PACKAGEDIR)/usr/bin/
cp ${BINPATH}/pinadoc $(PACKAGEDIR)/usr/bin/
mkdir -p $(PACKAGEDIR)/usr/share/pinafore/lib/UILib
for i in $(LIBMODULEFILES); do cp Pinafore/pinafore-lib-script/data/$$i.pinafore $(PACKAGEDIR)/usr/share/pinafore/lib/$$i.pinafore; done
mkdir -p $(PACKAGEDIR)/usr/share/doc/pinafore
cp deb/copyright $(PACKAGEDIR)/usr/share/doc/pinafore/
$(STACKEXEC) -- \
m4 \
-D PACKAGENAME="$(PACKAGENAME)" \
-D PACKAGEVERSION="$(PACKAGEVERSION)" \
-D PACKAGEREVISION="$(PACKAGEREVISION)" \
-D DEBIANREL="$(DEBIANREL)" \
-D RELEASEDATE="$$(date -R)" \
deb/changelog.m4 | gzip -9 > $(PACKAGEDIR)/usr/share/doc/pinafore/changelog.Debian.gz
mkdir -p $(PACKAGEDIR)/usr/share/bash-completion/completions/
$(STACKEXEC) -- $< --bash-completion-script /usr/bin/pinafore > $(PACKAGEDIR)/usr/share/bash-completion/completions/pinafore
mkdir -p $(PACKAGEDIR)/DEBIAN
$(STACKEXEC) -- \
m4 \
-D PACKAGENAME="$(PACKAGENAME)" \
-D PACKAGEVERSION="$(PACKAGEVERSION)" \
-D PACKAGEREVISION="$(PACKAGEREVISION)" \
deb/control.m4 > $(PACKAGEDIR)/DEBIAN/control
$(STACKEXEC) --cwd $(PACKAGEDIR) -- md5sum $$(cd $(PACKAGEDIR) && find * -type f -not -path 'DEBIAN/*') > $(PACKAGEDIR)/DEBIAN/md5sums
chmod -R g-w $(PACKAGEDIR)
$(STACKEXEC) --cwd .build/deb -- dpkg-deb --root-owner-group --build -Zxz $(PACKAGEFULLNAME)
$(STACKEXEC) -- \
lintian \
--tag-display-limit 0 \
--display-info \
--fail-on info \
--suppress-tags-from-file deb/lintian-ignore \
.build/deb/$(PACKAGEFULLNAME).deb
TESTDISTROS := ubuntu:22.04 bitnami/minideb:$(DEBIANREL)
out/pinafore.deps: ${BINPATH}/pinafore out
ldd $< > $@
.PHONY: deps
deps: out/pinafore.deps
out/$(PACKAGEFULLNAME).deb: .build/deb/$(PACKAGEFULLNAME).deb deb/installtest out
install -m 755 deb/installtest .build/deb/
install -m 755 deb/checkscript .build/deb/
for distro in $(TESTDISTROS); do echo DISTRO: $$distro; docker run --rm -v `pwd`/.build/deb:/home -e DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix:rw -it $$distro /home/installtest $(PACKAGEFULLNAME).deb `id -u` || exit $$?; done
cp $< $@
.PHONY: deb
deb: out/$(PACKAGEFULLNAME).deb
### Nix
# Use this on a Nix system
# broken, see https://github.com/NixOS/nix/issues/9347
nix-fmt:
nix fmt
# Use this on a Nix system
nix-flake: out
nix flake check .?submodules=1
nix build .?submodules=1#vscode-extension
nix/docker/flake.nix: flake.nix
cp $< $@
nix/docker/flake.lock: flake.lock
cp $< $@
nix/docker/stack.yaml: stack.yaml
$(STACKEXEC) -- yq '.packages=[]' $< > $@
nix/docker/stack.yaml.lock: stack.yaml.lock
cp $< $@
nix-docker-image: nix/docker/flake.nix nix/docker/flake.lock nix/docker/stack.yaml nix/docker/stack.yaml.lock
docker build -t nix-build nix/docker
nix-docker-flake: nix-docker-image
mkdir -p nix/home
docker run --rm -v `pwd`:/workspace -ti nix-build make nix-docker=1 nix-flake
nix-docker-shell: nix-docker-image
mkdir -p nix/home
docker run --rm -v `pwd`:/workspace -ti nix-build bash
### Support data
out/support:
mkdir -p $@
out/support/syntax-data.json: ${BINPATH}/pinadata out/support
$(STACKEXEC) -- $< --syntax-data > $@
### Pygments lexer
PYGLEXERVERSION := $(PINAFOREVERSIONABC)
support/pygments-lexer/pinafore_lexer/syntax-data.json: out/support/syntax-data.json
cp $< $@
out/support/pinafore_lexer-$(PYGLEXERVERSION).tar.gz: \
out/support \
support/pygments-lexer/pyproject.toml \
support/pygments-lexer/pinafore_lexer/__init__.py \
support/pygments-lexer/pinafore_lexer/syntax-data.json
$(STACKEXEC) -- env PYGLEXERVERSION="$(PYGLEXERVERSION)" python3 -m build -o out/support/ support/pygments-lexer/
.PHONY: pyg-lexer
pyg-lexer: out/support/pinafore_lexer-$(PYGLEXERVERSION).tar.gz
### Website
LIBMODULEDOCS := \
pinafore \
media \
gnome \
UILib
support/website/library/%.md: ${BINPATH}/pinadoc
mkdir -p support/website/library
$(STACKEXEC) -- $< $(subst .,/,$*) --include Pinafore/pinafore-lib-script/data > $@
support/website/generated/infix.md: ${BINPATH}/pinadata
mkdir -p support/website/generated
$(STACKEXEC) -- $< --infix > $@
support/website/generated/type-infix.md: ${BINPATH}/pinadata
mkdir -p support/website/generated
$(STACKEXEC) -- $< --infix-type > $@
.PHONY: scour
scour: support/website/img/information.svg docker-image
$(STACKEXEC) -- scour $< | $(STACKEXEC) -- sponge $<
support/website/generated/img/information.png: support/website/img/information.png
mkdir -p support/website/generated/img
cp $< $@
support/website/generated/img/logo.png: support/branding/logo.svg
mkdir -p support/website/generated/img
$(STACKEXEC) -- rsvg-convert -w 200 -h 200 $< -o $@
support/website/generated/img/favicon.png: support/branding/logo.svg
mkdir -p support/website/generated/img
$(STACKEXEC) -- rsvg-convert -w 32 -h 32 $< -o $@
%.ico: %.png
$(STACKEXEC) -- convert $< -background transparent $@
.PHONY: docs
docs: \
support/website/generated/img/logo.png \
support/website/generated/img/favicon.ico \
$(foreach f,$(LIBMODULEDOCS),support/website/library/$f.md) \
support/website/generated/infix.md \
support/website/generated/type-infix.md \
support/website/generated/img/information.png \
out/support/pinafore_lexer-$(PYGLEXERVERSION).tar.gz \
docker-image
mkdir -p support/website/generated/examples
cp Pinafore/pinafore-app/examples/* support/website/generated/examples/
$(STACKEXEC) -- pip3 install --user out/support/pinafore_lexer-$(PYGLEXERVERSION).tar.gz
rm -rf out/support/website
mkdir -p out/support/website
$(STACKEXEC) -- sphinx-build -D release="$(PINAFOREVERSION)" -D myst_substitutions.PINAFOREVERSION="$(PINAFOREVERSION)" -W --keep-going -b dirhtml support/website out/support/website/dirhtml
.PHONY: check-snippets
check-snippets: ${BINPATH}/pinafore
mkdir -p out/support/website/snippets
rm -f out/support/website/snippets/*
$(STACKEXEC) --docker-env BINPATH=${BINPATH} -- support/website/check-snippets
### VSCode extension
VSCXVERSION := $(PINAFOREVERSIONABC)
VSCXDIR := support/vsc-extension/vsce
$(VSCXDIR)/%.json: $(VSCXDIR)/%.yaml out/support/syntax-data.json
$(STACKEXEC) -- env VSCXVERSION="$(VSCXVERSION)" yq --from-file support/vsc-extension/transform.yq -o json $< > $@
$(VSCXDIR)/images/logo.png: support/branding/logo.svg
mkdir -p $(VSCXDIR)/images
$(STACKEXEC) -- rsvg-convert -w 256 -h 256 $< -o $@
out/support/pinafore-$(VSCXVERSION).vsix: docker-image out/support \
$(VSCXDIR)/package.json \
$(VSCXDIR)/LICENSE \
$(VSCXDIR)/README.md \
$(VSCXDIR)/CHANGELOG.md \
$(VSCXDIR)/language-configuration.json \
$(VSCXDIR)/images/logo.png \
$(VSCXDIR)/syntaxes/pinafore.tmLanguage.json
cd $(VSCXDIR) && $(STACKEXEC) -- vsce package -o ../../../$@
.PHONY: vsc-extension
vsc-extension: out/support/pinafore-$(VSCXVERSION).vsix
### Test images
Changes/changes-gnome/examples/showImages/images/%.RGB.jpeg: Changes/changes-gnome/examples/showImages/%.jpeg
mkdir -p Changes/changes-gnome/examples/showImages/images
$(STACKEXEC) -- convert $< -colorspace RGB $@
Changes/changes-gnome/examples/showImages/images/%.YCbCr.jpeg: Changes/changes-gnome/examples/showImages/%.jpeg
mkdir -p Changes/changes-gnome/examples/showImages/images
$(STACKEXEC) -- convert $< -colorspace YCbCr $@
.PHONY: testimages
testimages: docker-image \
Changes/changes-gnome/examples/showImages/images/cat.RGB.jpeg \
Changes/changes-gnome/examples/showImages/images/cat.YCbCr.jpeg \
Changes/changes-gnome/examples/showImages/images/stairs.RGB.jpeg \
Changes/changes-gnome/examples/showImages/images/stairs.YCbCr.jpeg
### Full build, clean
.PHONY: full
full: testimages format deb nix-docker-flake deps licensing check-snippets docs pyg-lexer vsc-extension
.PHONY: clean
clean:
rm -rf .build
rm -rf out
rm -rf Changes/*/*.cabal
rm -rf Pinafore/*/*.cabal
rm -rf Changes/changes-gnome/examples/showImages/images
rm -rf nix/docker/flake.nix
rm -rf nix/docker/flake.lock
rm -rf nix/docker/stack.yaml
rm -rf nix/docker/stack.yaml.lock
rm -rf support/website/generated
rm -rf support/website/library
rm -rf support/vsc-extension/*.json
rm -rf support/vsc-extension/*/*.json
rm -rf support/vsc-extension/*/*/*.json
rm -rf support/pygments-lexer/*/*.json
rm -rf support/pygments-lexer/*.egg-info
rm -rf .stack-work
rm -rf */*/.stack-work
rm -rf */*/test/*/*.out
rm -rf */*/test/*/*/*.out
rm -rf result
ifeq ($(stackroot),1)
rm -rf .stack-root
endif
.PHONY: update-locks
update-locks: docker-image
rm -f stack.yaml.lock
stack exec -- echo -n
nix flake update
### Top
top-format:
make format
top-build:
make exe
top-single-build:
make single=1 exe
top-nix-flake:
make nix-flake
top-format-test:
make test=1 format exe
top-full-resume:
make haddock=1 test=1 bench=1 full
top-full:
make haddock=1 test=1 bench=1 clean full
top-release:
make stackroot=1 haddock=1 test=1 bench=1 clean full