#!/usr/bin/make -f

export PYBUILD_NAME=ppft

export PYBUILD_TEST_CUSTOM=1
export PYBUILD_TEST_ARGS={interpreter} -m ppft.tests

%:
	dh $@ --with sphinxdoc --buildsystem=pybuild

execute_after_dh_auto_install:
	rm -rf debian/python3-ppft/usr/lib/python3/dist-packages/ppft/tests

execute_before_dh_installman:
	pybuilddir=.pybuild/$$(/bin/ls -1 .pybuild | head -n 1); PYTHONPATH=$$pybuilddir/build help2man -N -n 'PPFT (Parallel Python) Network Server' $$pybuilddir/scripts/ppserver > debian/ppserver.1.tmp
	perl -i -pe 's/^\.TH PARALLEL/.TH PPSERVER/; s/^Parallel \\-/ppserver \\-/' debian/ppserver.1.tmp
	perl -i -pe 's/^\\fB\\-/\n\\fB\\-/;' debian/ppserver.1.tmp
	# for some reason, the content is duplicated
	sed -ne '1,/support forums/p' debian/ppserver.1.tmp > debian/ppserver.1
	rm -f debian/ppserver.1.tmp

ifeq (,$(findstring nodoc,$(DEB_BUILD_OPTIONS)))
execute_after_dh_auto_build:
	PYTHONPATH=$(CURDIR) $(MAKE) -C docs SPHINXBUILD=sphinx-build html

execute_after_dh_auto_clean:
	$(MAKE) -C docs SPHINXBUILD=sphinx-build clean

override_dh_installdocs:
	dh_installdocs -ppython-ppft-doc --doc-main-package=python3-ppft
	dh_installdocs --remaining-packages
	mv debian/python-ppft-doc/usr/share/doc/python3-ppft/build debian/python-ppft-doc/usr/share/doc/python3-ppft/html
endif
