#!/usr/bin/make -f
# You must remove unused comment lines for the released package.
#export DH_VERBOSE = 1
#export DEB_BUILD_MAINT_OPTIONS = hardening=+all
#export DEB_CFLAGS_MAINT_APPEND  = -Wall -pedantic
#export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed

# command 'install_with_pth' has no such option 'install_layout'
# https://github.com/pypa/setuptools/issues/2956
export SETUPTOOLS_USE_DISTUTILS=stdlib

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

override_dh_auto_install:
	dh_auto_install

	PYTHONPATH=$(CURDIR) $(MAKE) -C docs html

	mkdir -p debian/python3-setuptools-whl/usr/share/python-wheels
	python3 setup.py bdist_wheel \
	        -d debian/python3-setuptools-whl/usr/share/python-wheels

	# dh_pypy from dh-python < 1.20150705-1 falls over requires.txt
	# and our requires.txt aren't useful
	find debian/tmp -name requires.txt -delete

	find debian/tmp -name '*.exe' | xargs -r rm -f

override_dh_installchangelogs:
	dh_installchangelogs CHANGES.rst

override_dh_auto_clean:
#	# Keep entry_points, we need it to drive setup.py
#	-mv setuptools.egg-info/entry_points.txt .
	dh_auto_clean
#	mkdir -p setuptools.egg-info
#	mv entry_points.txt setuptools.egg-info

	rm -rf .eggs docs/build

override_dh_installdocs:
	dh_installdocs -p python3-pkg-resources \
	               docs/pkg_resources.rst
	dh_installdocs -p python3-setuptools \
	               -X pkg_resources docs/*.rst
	dh_installdocs -p python-setuptools-doc docs/build/html
	dh_installdocs --remaining-packages
	dh_link -p python-setuptools-doc \
	        /usr/share/doc/python-setuptools-doc/html \
	        /usr/share/doc/python3-setuptools/html \
