# Makefile for Sphinx documentation generated by sphinx-quickstart
# ----------------------------------------------------------------------------

# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS    ?=
SPHINXBUILD   ?= sphinx-build
SOURCEDIR     = source
BUILDDIR      = _build
# We generate this directory based on the template in `authenticator.rst.tpl`
# so we should clean it up too
APIDIR        = source/reference/api
GENDIR        = source/reference/api/gen

# Put it first so that "make" without argument is like "make help".
help:
	@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS)

.PHONY: help Makefile

clean:
	@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS)
	@echo "Removing the generated docs from $(API)..."
	rm -rf -v "$(GENDIR)"
	rm -v "$(APIDIR)/index.rst"

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option.
%: Makefile
	@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS)


# Manually added commands
# ----------------------------------------------------------------------------

# For local development:
# - builds and rebuilds html on changes to source
# - starts a livereload enabled webserver and opens up a browser
devenv:
	sphinx-autobuild -b html --open-browser "$(SOURCEDIR)" --ignore "*/reference/api/*" "$(BUILDDIR)/html" $(SPHINXOPTS)

# For local development and CI:
# - verifies that links are valid
linkcheck:
	$(SPHINXBUILD) -b linkcheck "$(SOURCEDIR)" "$(BUILDDIR)/linkcheck" $(SPHINXOPTS)
	@echo
	@echo "Link check complete; look for any errors in the above output " \
	      "or in $(BUILDDIR)/linkcheck/output.txt."
