#!/usr/bin/make -f

cmd = silkaj
_ENV = $(strip \
 PATH="$(CURDIR)/debian/silkaj/usr/bin:$(PATH)" \
 PYTHONPATH="$(CURDIR)/debian/silkaj/usr/lib/$(shell py3versions -d)/dist-packages")

# generate manpage with help2man from --help option of python script
_mkman = $(_ENV) \
 help2man $(if $3,--name "$(strip $3)") --no-info --output $2 $1 \
 || { $(_ENV) $1 --help; false; }

%:
	dh $@ --buildsystem=pybuild

# generate manpage based on --help option of script itself
# * Fix encode special Duniter signature "Ğ"
# generate shell completion scripts
# check shell script
execute_after_dh_auto_install:
	$(call _mkman, $(cmd), debian/$(cmd).1, \
		command-line client for Duniter)
	perl -i -pe 's/\?\?(?=1|Test)/ \\\[u011E\]/g' \
		debian/$(cmd).1
	$(_ENV) \
	  _SILKAJ_COMPLETE=bash_source $(cmd) \
		> debian/bash-completion || true
	test -s debian/bash-completion
	$(_ENV) \
	  _SILKAJ_COMPLETE=zsh_source $(cmd) \
		> debian/_$(cmd) || true
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	test -s debian/_$(cmd)
endif
	$(_ENV) prove debian/tests/*.t
	find debian/silkaj/usr/lib -name '*.pyc' -delete
	find debian/silkaj/usr/lib -type d -empty -delete
