#!/usr/bin/make -f

include /usr/share/dpkg/pkg-info.mk

# detect if build targets experimental suite (or is a draft)
DEB_SUITE_EXP = $(filter experimental% UNRELEASED,$(DEB_DISTRIBUTION))

export DH_OPTIONS = -O--buildsystem=pybuild

destdir = debian/ldh-client
cmd = liberty
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)") \
 $(if $4,--version-string "$(strip $4)") \
 --no-info --output $2 $1 \
 || { PYTHONPATH=$(python3path) $1 --help; false; }

override_dh_auto_test:
	dh_auto_test $(if $(DEB_SUITE_EXP),|| true)

# * avoid installing duplicate executable
# * generate manpage
#   TODO: enable when configfile is properly handled
execute_after_dh_auto_install:
	rm --force $(destdir)/usr/bin/$(cmd).py
#	$(call _mkman, $(destdir)/usr/bin/$(cmd), debian/$(cmd).1, \
#		interact with a Liberty Deckplan Host, \
#		$(DEB_VERSION_UPSTREAM_REVISION))
#	find $(destdir)/usr/lib -name '*.pyc' -delete
#	find $(destdir)/usr/lib -type d -empty -delete

%:
	dh $@
