# Thin wrapper over the commands used to build, test and update the project. CMake does the building,
# scripts/ and docs/charts/ do the rest. `make help` lists the targets.
.DEFAULT_GOAL := help
BUILD ?= build
DOOS  := $(BUILD)/doos

.PHONY: help build test audit valgrind check-docs bench charts docs release clean

help: ## list the targets
	@grep -hE '^[a-z-]+:.*##' $(MAKEFILE_LIST) | sed -E 's/:.*## /\t/' | column -t -s "$$(printf '\t')"

build: ## configure and compile into build/
	cmake -S . -B $(BUILD) >/dev/null
	cmake --build $(BUILD)

test: build ## end-to-end suite (real downloads, needs network, pasta, gpg, cgroup v2)
	tests/run.sh $(DOOS)

audit: build ## run the CVE regression checks under audit/ against build/doos (concurrent, -j)
	$(MAKE) -C audit -j8 test DOOS=$(abspath $(DOOS))

valgrind: build ## memcheck against a fixed set of doos invocations (needs valgrind, see valgrind/README.md)
	scripts/valgrind.sh $(abspath $(DOOS))

check-docs: ## every document links to every other, every relative link resolves
	scripts/check-docs.sh

bench: build ## re-measure startup, binary sizes and cpu limit into docs/charts/bench.json
	scripts/bench.sh

charts: ## rebuild docs/charts/*.svg and the generated numbers in COMPARISON.md from bench.json
	python3 docs/charts/make_charts.py

docs: charts check-docs ## charts plus the docs check

release: ## KIND=patch|minor|major MSG="subject": bump, build, test, commit, tag
	@test -n "$(KIND)" -a -n "$(MSG)" || { echo 'usage: make release KIND=patch MSG="subject"'; exit 2; }
	scripts/release.sh $(KIND) "$(MSG)"

clean: ## remove build/
	rm -rf $(BUILD)
