# Run `make html` here or through the repository documentation targets.
# An explicit SPHINXBUILD still selects a custom documentation environment.
ifneq ($(wildcard ../work/docs-venv),)
DOCS_PYTHON := $(abspath ../work/docs-venv/bin/python)
SPHINXBUILD ?= "$(DOCS_PYTHON)" -I -m sphinx
else
SPHINXBUILD ?= sphinx-build
endif

ifeq ($(strip $(SPHINXBUILD)),)
$(error SPHINXBUILD is empty; select Sphinx or install docs/requirements.txt)
endif

SPHINXOPTS ?= -n -W --keep-going
SOURCEDIR = .
BUILDDIR = _build

.DEFAULT_GOAL := help
.PHONY: help Makefile

$(info Documentation builder: $(SPHINXBUILD))

define sphinx_install_hint
printf '%s\n' 'For missing or incompatible documentation dependencies, run from the project root:' '  python3.14 -m venv work/docs-venv' '  work/docs-venv/bin/python -m pip install -r docs/requirements.txt' >&2
endef

define run_sphinx
	@$(SPHINXBUILD) --version || { $(sphinx_install_hint); exit 2; }
	@$(SPHINXBUILD) -M $(1) "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) || { status=$$?; $(sphinx_install_hint); exit $$status; }
endef

help:
	$(call run_sphinx,help)

%: Makefile
	$(call run_sphinx,$@)
