# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS    ?=
SPHINXBUILD   ?= sphinx-build
SPHINXAPIDOC  = sphinx-apidoc
SOURCEDIR     = source
BUILDDIR      = build
REFDIR        = source/reference
TUTORIALSDIR  = source/tutorials
GITTAG       = $(shell python getversion.py)
MODULE_NAME  = playmolecule

# sphinx-apidoc auto-skips underscore-prefixed packages (_backends, _config, ...)
# so the auto-generated reference only covers the public subpackages.

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

.PHONY: help Makefile rst clean writeversion

html: Makefile rst
	@$(SPHINXBUILD) -M html "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

writeversion:
	echo "$(GITTAG)" > source/version

rst: clean writeversion
	mkdir -p $(REFDIR)
	$(SPHINXAPIDOC) --force --separate -o $(REFDIR) ../$(MODULE_NAME)/ >/dev/null
	# Drop the apidoc-generated modules.rst (we have our own index.md) and
	# playmolecule.rst (we hand-author playmolecule.md so imported public
	# symbols like describe_apps and ExecutableDirectory appear).
	rm -f $(REFDIR)/modules.rst $(REFDIR)/$(MODULE_NAME).rst
	@echo
	@echo "Auto-generated reference RST files are in $(REFDIR)/"

clean:
	rm -f $(REFDIR)/$(MODULE_NAME).*.rst $(REFDIR)/$(MODULE_NAME).rst $(REFDIR)/modules.rst
	rm -rf $(BUILDDIR)
	rm -f source/version
