#!/usr/bin/make -f
# -*- makefile -*-

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

# Avoid failures in unit tests
# See https://github.com/kislyuk/argcomplete/issues/199
unexport LC_ALL

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

override_dh_auto_install:
	dh_auto_install -O--buildsystem=pybuild
	mkdir -p debian/python3-argcomplete/usr/share/man/man1
	for i in \
		activate-global-python-argcomplete \
		python-argcomplete-check-easy-install-script \
		python-argcomplete-tcsh \
		register-python-argcomplete; \
	do \
		mv debian/python3-argcomplete/usr/bin/$$i debian/python3-argcomplete/usr/bin/$${i}3; \
		sed -i -e 's/python-argcomplete-tcsh/python-argcomplete-tcsh3/' debian/python3-argcomplete/usr/bin/$${i}3; \
		cp debian/$$i.1 debian/python3-argcomplete/usr/share/man/man1/$${i}3.1; \
	done

generate_manpages:
	VERSION=$$(./setup.py -V) ; \
	for file in \
		activate-global-python-argcomplete \
		python-argcomplete-check-easy-install-script \
		register-python-argcomplete; \
	do \
		cp -f scripts/$$file debian/$$file ; \
		chmod a+x debian/$$file ; \
		PYTHONPATH=. help2man --version-string="$$VERSION" \
			--no-info --include=debian/help2man.include \
			--name "$$file - argcomplete utility script" \
			-o debian/$$file.1 --no-discard-stderr \
			debian/$$file ; \
		rm -f debian/$$file; \
	done ; \
	rm -f argcomplete/*.py[co]
