#!/usr/bin/make -f

DH_OPTIONS = -O--buildsystem=pybuild

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

# generate manpage with help2man from --help option of python script
_mkman = PYTHONPATH=$(python3path) \
 help2man $(if $3,--name "$(strip $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 $(cmd) \
		> debian/bash-completion

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

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

%:
	dh $@ --with python3,bash-completion $(DH_OPTIONS:-O%=%)
