# 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
TUTORIALSDIR  = source/tutorials
GITTAG       = $(shell python getversion.py)
IPYNB_FILES  = $(shell ls ../tutorials/*.ipynb)
MODULE_NAME  = playmolecule

IPYNB_OUT     := $(addprefix $(TUTORIALSDIR)/,$(notdir $(IPYNB_FILES)))


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

.PHONY: help Makefile

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

# Copy .ipynb tutorials into source/tutorials/; myst-nb consumes them
# directly (see source_suffix in conf.py).
$(TUTORIALSDIR)/%.ipynb: ../tutorials/%.ipynb
	mkdir -p $(TUTORIALSDIR)
	cp $< $@

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

tutorials: writeversion $(IPYNB_OUT)

rst: clean writeversion tutorials
	$(SPHINXAPIDOC) --force --separate -o $(SOURCEDIR) ../$(MODULE_NAME)/ >/dev/null
	echo "$(GITTAG)" > source/version
	@echo
	@echo "Build finished. The RST files are on source/"

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