override SHELL := /bin/sh
override MAKEFLAGS += --no-print-directory

.DEFAULT_GOAL := help
.DELETE_ON_ERROR:

override MDBOOK := mdbook

override PRIMARY_GOAL := $(firstword $(MAKECMDGOALS))

ifeq ($(PRIMARY_GOAL),run)

.PHONY: run

# Application arguments may also look like Make goals. The run recipe recovers
# their exact boundaries from the original invocation.
.DEFAULT:
	@:

else

.PHONY: help run check

help:
	@printf '%s\n' 'Usage: make docs -- <mdbook arguments...>' '' \
		'With no arguments, mdbook test and mdbook build are run.' \
		'Example: make docs -- build' '' \
		'Project target:' \
		'  check  Run mdbook test and mdbook build'

endif

check:
	$(MDBOOK) test
	$(MDBOOK) build

run:
	@exec python3 ../scripts/make-argv.py exec run $(MDBOOK)
