# Makefile for Sphinx documentation
#

# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS    ?= -T -E -d _build/doctrees -D language=en
EXCLUDENB     ?= -D exclude_patterns="notebooks/*","_build","**.ipynb_checkpoints"
SPHINXBUILD   ?= sphinx-build
SOURCEDIR     = .
BUILDDIR      = ../_readthedocs/

.PHONY: help clean stubs Makefile no-nb no-notebooks

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

# Regenerate the .pyi stub for the compiled C++ extension (lephare._lephare),
# so that sphinx-autoapi (a static parser, it cannot see into the compiled
# .so nor into the pybind11 docstrings directly) picks up the C++ bindings'
# docstrings. Requires the package to already be installed (`pip install -e .`
# or `pip install .`) and pybind11-stubgen (see docs/requirements.txt). The
# stub is a derived build artifact, not committed to the repository.
stubs:
	pybind11-stubgen lephare._lephare -o ../src

# Build all Sphinx docs locally, except the notebooks
no-nb no-notebooks: stubs
	@$(SPHINXBUILD) -M html "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(EXCLUDENB) $(O)

# Cleans up files generated by the build process
clean:
	rm -r "_build/doctrees"
	rm -r "$(BUILDDIR)"
	rm -f ../src/lephare/_lephare.pyi

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option.  $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile stubs
	@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

