raz / Makefile

237 lines · 10.0 KiB · raw · history · last change b6a29ae3

1# Builds the compiler, raz, from src/ into the repository's root; the
2# library it needs is lib/, beside it. The previous release builds it:
3# BOOT names that release and its tarball's SHA-256, and src/boot.sh
4# puts its raz in build/boot/, with this lib/ beside it (as every raz
5# has its library), so that src/ is built against today's library. The
6# one module the build makes, Version, holds what git says the version is.
7
8raz: build/boot/raz src/*.raz build/src/Version.raz
9 build/boot/raz -Werror -I src -I build/src -o raz src/Raz.raz
10
11build/boot/raz: BOOT src/boot.sh | build
12 src/boot.sh
13
14build/src/Version.raz: build/version.inc | build
15 mkdir -p build/src
16 printf 'module Version;\nconst Text* = "%s";\nend Version.\n' "$$(tr -d "'" < build/version.inc)" >$@
17
18# The version is git's name for the commit (a tag's, or with no tag, as in a
19# shallow fetch, the commit's hash), or VERSION where it is given
20# (make dist REV=... VERSION=0.20.0 packs a release before its tag is
21# pushed, as the tag will); the file changes only when that does, so
22# raz isn't rebuilt for nothing.
23build/version.inc: FORCE | build
24 @v=$(if $(VERSION),$(VERSION),$$(git describe --tags --always --dirty 2>/dev/null || echo unknown)); \
25 v="'$${v#v}'"; echo "$$v" | cmp -s - $@ || echo "$$v" >$@
26
27FORCE:
28
29build:
30 mkdir -p build
31
32clean:
33 rm -rf build raz
34
35# every example and test, against what it should print
36check: raz build/raz-lib.3
37 test/check.sh
38
39# the compiler's speed against the previous release's, BOOT's, on the
40# same program: fails if this one is more than a tenth slower
41prev-bench: raz | build
42 src/bench.sh
43
44# the previous release builds src/, that builds src/, that builds it
45# again: the last two must be the same file; check and bench then run on it
46fixpoint: raz | build
47 src/fixpoint.sh
48
49# line numbers: gdb stops at a line and names it
50gdb: raz
51 test/gdb.sh
52
53# the same for lldb, on a Mac: a program made for darwin-arm64 by the
54# container's cross compiler (mac-build), stopped at a line
55lldb: mac-build
56 test/lldb.sh
57
58# the compiler's speed, on a generated program of about 350,000 lines,
59# the best of three runs; fails below 400,000 lines a second
60bench: raz | build
61 sh test/genbench.sh 12000 > build/Bench.raz
62 @lines=$$(($$(wc -l < build/Bench.raz))); best=0; \
63 for i in 1 2 3; do \
64 start=$$(sh test/nanos.sh); ./raz build/Bench.raz || exit 1; end=$$(sh test/nanos.sh); \
65 t=$$((end - start)); if [ $$best = 0 ] || [ $$t -lt $$best ]; then best=$$t; fi; \
66 done; \
67 rate=$$((lines * 1000000000 / best)); \
68 echo "$$lines lines in $$((best / 1000000)) ms: $$rate lines a second"; \
69 test $$rate -ge 400000
70
71# the code's speed: the kernels of test/bench, which say check off,
72# against their twins in Pascal built by FPC -O2
73kernels: raz
74 test/bench/run.sh
75
76# native threads under load: 40,000 spawned and joined, 200 alive at a
77# time, all waiting on one Mutex; then, with little memory, spawn must
78# fail with Thread.Failed. make check runs a small version.
79# test/libc on Alpine, over musl, in docker
80alpine: raz
81 test/alpine.sh
82
83stress: raz | build
84 ./raz -o build/Stress lib/Thread.linux-x86_64.raz
85 build/Stress 40000 200
86 (ulimit -v 60000; build/Stress fail)
87
88# the formatter, tools/Pretty.raz: the library, examples, tools and site programs are
89# formatted already
90fmt: raz | build
91 ./raz -o build/Pretty tools/Pretty.raz
92 @fail=0; for f in lib/*.raz examples/*.raz tools/*.raz site/*.raz src/*.raz src/test/*.raz; do \
93 build/Pretty $$f | cmp -s - $$f || { echo "not formatted: $$f"; fail=1; }; \
94 done; test $$fail = 0
95
96# lines of the compiler, by rloc: each file's blank, comment and code,
97# then the lines of code in all
98loc:
99 @rloc -f src/*.raz
100 @rloc -c src/*.raz
101
102# raz-lib(3), the library's manual page, made by tools/Doc.raz from
103# its sources, in the order of doc/raz-lib.md, between the page's own
104# head (with its date) and tail
105LIBDOC = Rt Mem Heap Arena Lock Thread.linux-x86_64 Out Sys.linux-x86_64 \
106 Str Bytes.x86_64 Buf Fmt List Map Vec Task Guarded Sort Math Files Opt Width Rand Check Prop C
107
108man: build/raz-lib.3
109
110build/raz-lib.3: raz tools/Doc.raz tools/Scan.raz lib/*.raz doc/raz-lib.head doc/raz-lib.tail | build
111 ./raz -Werror -o build/Doc tools/Doc.raz
112 build/Doc man $(LIBDOC:%=lib/%.raz) > build/raz-lib.modules
113 cat doc/raz-lib.head build/raz-lib.modules doc/raz-lib.tail > $@
114
115# the two volumes of the report as PDFs, by pandoc and Chromium; not
116# part of check, as CI has neither
117pdf: build/raz.pdf build/raz-lib.pdf
118
119build/%.pdf: doc/%.md doc/report.css | build
120 pandoc doc/$*.md -s --toc --toc-depth=1 --shift-heading-level-by=-1 \
121 --syntax-highlighting=none -c ../doc/report.css \
122 -o build/$*.html
123 chromium --headless --no-pdf-header-footer --print-to-pdf=$@ build/$*.html 2>/dev/null
124
125# raz, its library and its tools go together under $(PREFIX)/lib/raz,
126# laid out as in the tarball; the link on PATH works since raz finds
127# lib/ beside its real path, and a program's make finds tools/ so.
128# raztest, tools/Test.raz, is built onto PATH by this raz. The manual
129# pages go where man looks, beside bin.
130PREFIX = $(HOME)/.local
131MAN = $(PREFIX)/share/man
132TOOLS = Pretty Doc Scan Test
133
134install: raz build/raz-lib.3
135 rm -rf $(PREFIX)/lib/raz
136 mkdir -p $(PREFIX)/lib/raz/tools $(PREFIX)/bin $(MAN)/man1 $(MAN)/man3 $(MAN)/man7
137 cp -r raz lib $(PREFIX)/lib/raz
138 cp $(TOOLS:%=tools/%.raz) $(PREFIX)/lib/raz/tools
139 ln -sf $(PREFIX)/lib/raz/raz $(PREFIX)/bin/raz
140 ./raz -Werror -o $(PREFIX)/bin/raztest tools/Test.raz
141 cp doc/raz.1 doc/raztest.1 $(MAN)/man1
142 cp build/raz-lib.3 $(MAN)/man3/raz-lib.3
143 cp doc/raz.7 doc/raz-tutorial.7 $(MAN)/man7
144
145uninstall:
146 rm -rf $(PREFIX)/lib/raz $(PREFIX)/bin/raz $(PREFIX)/bin/raztest \
147 $(MAN)/man1/raz.1 $(MAN)/man1/raztest.1 $(MAN)/man3/raz-lib.3 \
148 $(MAN)/man7/raz.7 $(MAN)/man7/raz-tutorial.7
149
150# A release's tarball, build/raz-V-linux-x86_64.tar.gz: raz, the lib/
151# it reads beside itself, the tools a program's make may build (the
152# formatter, Doc and the Scan they share, and raztest) and the manual
153# pages, V being what raz --version says. It is made of the commit
154# REV, HEAD unless given: CI packs the tag it checked out, and
155# site/Build.raz each tag it lacks. A release whose tag isn't pushed yet
156# is made with VERSION, its version without the v: the same tarball as
157# the tag's, once the tag is at REV.
158#
159# The tarball is the same, byte for byte, wherever it is made, so that
160# its SHA-256 can be checked against GitHub's or the website's. raz is
161# built in a checkout at a fixed place, DIST, since the debugging
162# information names the directory it was built in; the archive gives
163# every file the commit's time, owner 0 and plain modes, in order of
164# name, and gzip leaves out its own date.
165REV = HEAD
166DIST = /tmp/raz-dist
167
168dist:
169 rm -rf $(DIST) && git worktree prune && git worktree add -q --detach $(DIST) $(REV)
170 # the tarball BOOT names, if fetched, lent to the checkout (src/boot.sh checks its sum)
171 if [ -d build/boot ]; then mkdir -p $(DIST)/build/boot && cp build/boot/*.tar.gz $(DIST)/build/boot/; fi
172 $(MAKE) -C $(DIST) raz man
173 v=$$($(DIST)/raz --version | sed 's/^raz \([^,]*\),.*/\1/'); \
174 d=raz-$$v-linux-x86_64; \
175 rm -rf build/$$d && mkdir -p build/$$d/man && \
176 cp -r $(DIST)/raz $(DIST)/lib $(DIST)/LICENSE $(DIST)/README.md build/$$d && \
177 mkdir build/$$d/tools && cp $(TOOLS:%=$(DIST)/tools/%.raz) build/$$d/tools && \
178 cp $(DIST)/doc/raz.1 $(DIST)/doc/raztest.1 $(DIST)/doc/raz.7 $(DIST)/doc/raz-tutorial.7 \
179 $(DIST)/build/raz-lib.3 build/$$d/man && \
180 tar -cf - --format=gnu --sort=name --mtime=@$$(git log -1 --format=%ct $(REV)) \
181 --owner=0 --group=0 --numeric-owner --mode=a+rX,u+w,go-w \
182 -C build $$d | gzip -9n > build/$$d.tar.gz && \
183 rm -rf build/$$d && echo build/$$d.tar.gz
184 git worktree remove --force $(DIST)
185
186# The website, plain files in site/public/: its home page, the tour
187# "Raz, Set, Go" (whose programs are run here, so the output shown is
188# real), the report and the latest release's tarball. site/Build.raz
189# says how; it needs ./raz, pandoc and pdfinfo. RELEASES, "vX.Y.Z=COMMIT ...",
190# adds release records to those kept in site/releases. site-source runs
191# ladle after the pages: its Git store and releases live under /source/,
192# with their headers merged at the upload's root. The pinned ladle is
193# bundled for Cloudflare; LADLE may name a locally built one instead.
194# The site's programs are raz programs, site/Build.raz, Source.raz and
195# Verify.raz, built by this raz into build/site/.
196LADLE ?=
197build/site/%: site/%.raz site/*.raz raz
198 mkdir -p build/site
199 ./raz -Werror -o $@ site/$*.raz
200
201site: raz pdf build/site/Build
202 build/site/Build $(RELEASES)
203 $(MAKE) site-source
204
205# Wrangler runs this before deploying the committed pages. The generated
206# Git store must never be committed: otherwise later stores contain copies
207# of earlier ones. See site/README.md for the release and upload procedure.
208site-source: build/site/Source
209 build/site/Source $(if $(LADLE),--ladle $(LADLE)) $(RELEASES)
210
211# Checks the site's release selection against small real Git repositories.
212site-check: build/site/Verify
213 build/site/Verify
214
215.PHONY: docker-image docker-check mac-build mac-check lldb docker-shell prev-bench fixpoint check gdb bench kernels stress alpine fmt loc man pdf dist site site-source site-check clean install uninstall
216
217# `make check` in a linux/amd64 container, for a machine that isn't one
218# (the repository is mounted at its own path, so git and the tests see
219# the same names). DOCKERFLAGS is for what a host's runtime needs.
220DOCKER = docker run --rm --platform linux/amd64 $(DOCKERFLAGS) -v $(CURDIR):$(CURDIR) -w $(CURDIR)
221DOCKERIMAGE = raz-check
222docker-image:
223 docker build --platform linux/amd64 -t $(DOCKERIMAGE) containers/check
224
225docker-check: docker-image
226 $(DOCKER) $(DOCKERIMAGE) sh -c "git config --global --add safe.directory '*' && make check"
227
228# test/mac's programs (test/mac.sh), on an Apple Silicon Mac: compiled
229# for darwin-arm64 by the cross compiler in the container, then run here
230mac-build: docker-image
231 $(DOCKER) $(DOCKERIMAGE) sh -c "git config --global --add safe.directory '*' && timeout 1200 test/mac.sh build"
232
233mac-check: mac-build
234 test/mac.sh run
235
236docker-shell: docker-image
237 $(DOCKER) -it $(DOCKERIMAGE) sh -c "git config --global --add safe.directory '*' && exec bash"