#!/usr/bin/make -f

#export DH_VERBOSE=1

export PYBUILD_NAME=fdb
DOC_PACKAGE=python-$(PYBUILD_NAME)-doc
DOC_DIR=usr/share/doc/$(DOC_PACKAGE)/html

%:
	#dh $@ -v --with python2,python3,sphinxdoc --buildsystem=pybuild
	dh "$@" -v --with python3 --buildsystem=pybuild

get-orig-source:
	uscan --force-download

override_dh_auto_build: $(PYBUILD_NAME).egg-info.orig
	dh_auto_build
	rm -rf docs
	$(MAKE) --directory sphinx html SPHINXBUILD=/usr/share/sphinx/scripts/python3/sphinx-build
	rm -rf html
	mv docs html

override_dh_auto_test:
	# Test doesn't work without root.

override_dh_installdocs:
	dh_installdocs --no-package=$(DOC_PACKAGE) README.rst
	dh_installdocs --package=$(DOC_PACKAGE) html
	dh_sphinxdoc --package=$(DOC_PACKAGE) $(DOC_DIR)
	debian/ras-sphinxdoc.sh $(DOC_PACKAGE)/$(DOC_DIR)

#
# A bit of a kludge to work around upstream shipping a prebuilt docs
# directory.  We want to build our own so we can be 100% certain
# the shipped .js files come from Debian's python-sphinx's package.
#
override_dh_auto_clean: $(PYBUILD_NAME).egg-info.orig
	dh_auto_clean
	$(MAKE) --directory sphinx clean
	[ ! -d $(PYBUILD_NAME).egg-info.orig ] || { rm -rf $(PYBUILD_NAME).egg-info; mv $(PYBUILD_NAME).egg-info.orig $(PYBUILD_NAME).egg-info; }
	rm -rf html debian/missing-sources .eggs

override_dh_auto_install: $(PYBUILD_NAME).egg-info.orig
	dh_auto_install


$(PYBUILD_NAME).egg-info.orig:
	[ ! -d $(PYBUILD_NAME).egg-info -o -d $(PYBUILD_NAME).egg-info.orig ] || mv $(PYBUILD_NAME).egg-info $(PYBUILD_NAME).egg-info.orig
