#!/usr/bin/make -f

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

export PYBUILD_NAME=ajsonrpc

SPHINXOPTS := -E -N

%:
	dh $@ --buildsystem=pybuild

override_dh_clean:
	dh_clean
	rm -rf .mypy_cache .pybuild .pytest_cache debian/.doctrees

override_dh_sphinxdoc:
	# Building the documentation
	cd .pybuild && \
	    PYTHONPATH=$$PWD/`dirname $$(find . -type d -name "$(PYBUILD_NAME)" | sort | head -n1)` && \
	    PATH=$(shell realpath $$(find . -type d -name scripts | sort | head -n1)):$(PATH) && \
	    export PYTHONPATH && \
	    export PATH && \
	    python3 -m sphinx -b man $(SPHINXOPTS) ../docs $(CURDIR)/debian
ifeq (,$(findstring nodoc, $(DEB_BUILD_OPTIONS)))
	# Building the manpage
	cd .pybuild && \
	    PYTHONPATH=$$PWD/`dirname $$(find . -type d -name "$(PYBUILD_NAME)" | sort | head -n1)` && \
	    PATH=$(shell realpath $$(find . -type d -name scripts | sort | head -n1)):$(PATH) && \
	    export PYTHONPATH && \
	    export PATH && \
	    python3 -m sphinx -b html $(SPHINXOPTS) ../docs $(CURDIR)/debian/python-ajsonrpc-doc/usr/share/doc/python-ajsonrpc-doc/html
endif
	dh_sphinxdoc
