phasm/Makefile
2023-11-14 15:04:20 +01:00

59 lines
2.0 KiB
Makefile

WABT_DIR := /home/johan/sources/github.com/WebAssembly/wabt
WAT2WASM := $(WABT_DIR)/bin/wat2wasm
WASM2C := $(WABT_DIR)/bin/wasm2c
%.wat: %.py $(shell find phasm -name '*.py') venv/.done
venv/bin/python -m phasm $< $@
%.wat.html: %.wat
venv/bin/pygmentize -l wat -O full -f html $^ -o $@
%.py.html: %.py
venv/bin/pygmentize -l py -O full -f html $^ -o $@
%.wasm: %.wat
$(WAT2WASM) $^ -o $@
%.c: %.wasm
$(WASM2C) $^ -o $@
# %.exe: %.c
# cc $^ -o $@ -I $(WABT_DIR)/wasm2c
examples: venv/.done $(subst .py,.wasm,$(wildcard examples/*.py)) $(subst .py,.wat.html,$(wildcard examples/*.py)) $(subst .py,.py.html,$(wildcard examples/*.py))
venv/bin/python3 -m http.server --directory examples
test: venv/.done $(subst .json,.py,$(subst /generator_,/test_generated_,$(wildcard tests/integration/test_lang/generator_*.json)))
venv/bin/pytest tests $(TEST_FLAGS)
lint: venv/.done
venv/bin/pylint phasm
typecheck: venv/.done
venv/bin/mypy --strict phasm tests/integration/helpers.py tests/integration/runners.py
venv/.done: requirements.txt
python3.10 -m venv venv
venv/bin/python3 -m pip install wheel pip --upgrade
venv/bin/python3 -m pip install -r $^
touch $@
tests/integration/test_lang/test_generated_%.py: venv/.done tests/integration/test_lang/generator.py tests/integration/test_lang/generator.md tests/integration/test_lang/generator_%.json
venv/bin/python3 tests/integration/test_lang/generator.py tests/integration/test_lang/generator.md tests/integration/test_lang/generator_$*.json > $@
clean-examples:
rm -f examples/*.wat examples/*.wasm examples/*.wat.html examples/*.py.html
clean-generated-tests:
rm -f tests/integration/test_lang/test_generated_*.py
.SECONDARY: # Keep intermediate files
.PHONY: examples
# So generally the right thing to do is to delete the target file if the recipe fails after beginning to change the file.
# make will do this if .DELETE_ON_ERROR appears as a target.
# This is almost always what you want make to do, but it is not historical practice; so for compatibility, you must explicitly request it.
.DELETE_ON_ERROR: