#!/usr/bin/make -f

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

python3path = debian/sshoot/usr/lib/$(shell py3versions -d)/dist-packages

# generate manpage with help2man from --help option of python script
_mkman = PYTHONPATH=$(python3path) \
 help2man $(patsubst %,--name %,$3) --no-info --output $2 $1 \
 || { PYTHONPATH=$(python3path) $1 --help; false; }

# * generate bash-completion script
override_dh_auto_build:
	dh_auto_build
	register-python-argcomplete3 --shell bash sshoot \
		> debian/bash-completion

# check shell script
override_dh_auto_test:
	dh_auto_test
	shellcheck --shell bash -e SC2128,SC2181,SC2207 \
		debian/bash-completion

# * generate manpage
override_dh_auto_install:
	dh_auto_install
	$(call _mkman, debian/sshoot/usr/bin/sshoot, debian/sshoot.1, \
		manage multiple sshuttle VPN sessions)
	find debian/sshoot/usr/lib -name '*.pyc' -delete
	find debian/sshoot/usr/lib -type d -empty -delete
