# Which tests to run? This applies both for `cargo test` and the Subplot tests.
TESTS =

# Build binaries for this target. Unset to use default for toolchain.
BUILD_FOR = 

# Construct cargo option for build target, if needed.
ifdef BUILD_FOR
TARGET_OPTION = --target $(BUILD_FOR)
else
TARGET_OPTION =
endif

all: clippy test subplot doc

clippy:
	cargo clippy --all-targets -- -Dwarnings

build: clippy
	cargo build --all-targets $(TARGET_OPTION)

test: build
	cargo test $(TARGET_OPTION) -- ${TESTS}

.PHONY: doc
doc: subplot_build
	env 'RUSTDOCFLAGS=-D warnings' cargo doc --no-deps
	make -C doc

subplot_build:
	subplot docgen obnam/obnam.subplot --output obnam.html
	subplot codegen obnam/obnam.subplot --output test.py

	subplot docgen obnam-server/obnam-server.subplot --output obnam-server.html
	subplot codegen obnam-server/obnam-server.subplot --output test-server.py

subplot: subplot_build
	rm -f test.log
	python3 test.py --log test.log ${TESTS}
	python3 test-server.py --log test-server.log ${TESTS}

mutants:
	cargo mutants -e 'src/bin/**/*.rs'

roadmap.svg: roadmap.yaml
	roadmap "$<" > "$@"
