TESTS =
TARGET = --target x86_64-unknown-linux-musl

all: test

check:
	cargo clippy --all-targets -- --deny warnings
	cargo fmt --check

build:
	cargo build --all-targets $(TARGET)
	subplot docgen clab.subplot -o clab.html
	subplot codegen clab.subplot -o test.py

test: build
	cargo test -- $(TESTS)

	target="$(cargo metadata --format-version=1 | jq -r .target_directory)"; \
	rm -f test.log; \
	if [ "$$(id -un)" = root ]; then \
		echo Not running tests as root.; \
	else \
		python3 test.py --log test.log --env "CARGO_TARGET_DIR=$$cargo metadata" $(TESTS); \
	fi
