Files
dew/Makefile

48 lines
2.2 KiB
Makefile

ZIRAN ?= ziran
LOCK_FLAGS := $(if $(wildcard ziran.local.toml),,--locked)
TOOLCHAIN = $(shell $(ZIRAN) pkg path ziran $(LOCK_FLAGS))
ENTITY = $(shell $(ZIRAN) pkg path entity $(LOCK_FLAGS))
PORT ?= 8095
.PHONY: all test web web-test serve
# Where the site is built; the browser test builds its own copy elsewhere.
WEB ?= build/web
all: web
test: build/model-test/test
env -u DISPLAY -u WAYLAND_DISPLAY build/model-test/test
$(ZIRAN) fmt --check src/*.zi src/web/*.zi tests/*.zi
python3 tests/web_site_test.py --landing-only
build/model-test/test: src/topup_model.zi tests/topup_model_test.zi ziran.lock
rm -rf build/model-test
$(ZIRAN) build --project $(LOCK_FLAGS) --target=c --entry topup_model_test:main -o build/model-test tests/topup_model_test.zi
$(CC) -std=c99 -O2 -I'$(TOOLCHAIN)/include' -Ibuild/model-test $$(find build/model-test -type d -printf ' -iquote %p') \
$$(find build/model-test -name '*.c') -o $@
# The page and the shared Profile, linked with Entity's account provider.
# build/web is the whole site; version.json names the source it came from.
web:
$(MAKE) -C '$(ENTITY)' build/entity.zx ZIRAN='$(TOOLCHAIN)/build/bin/ziran'
rm -rf $(WEB)
ZIRAN='$(TOOLCHAIN)/build/bin/ziran' python3 '$(ENTITY)/scripts/build-web.py' \
--profile '$(ENTITY)/build/entity.zx' --source src/web/dew_web.tsx \
--entry dew_web:main --emit-main --output $(WEB)/runtime.html
rm -f $(WEB)/runtime.html
cp site/index.html site/_headers site/_redirects site/icon.svg site/manifest.webmanifest site/og.jpg site/icon-512.png site/apple-touch-icon.png $(WEB)/
cp src/web/referral.js $(WEB)/
printf '{"version":"%s","revision":"%s"}\n' \
"$$(python3 -c 'import json; print(json.load(open("version.json"))["version"])')" \
"$$(git rev-parse HEAD)" > $(WEB)/version.json
# Opens the site in a private headless browser. The test drives the page
# through Kryon's test driver, which only a build made with KRYON_TEST_DRIVER
# set includes, so it builds its own copy and leaves build/web as published.
web-test:
KRYON_TEST_DRIVER=1 $(MAKE) web WEB=build/web-test
python3 tests/web_site_test.py build/web-test
serve:
python3 -m http.server $(PORT) --bind 127.0.0.1 --directory build/web