#!/usr/bin/make -f

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

cmd = ontospy
_ENV = $(strip \
 PATH="$(CURDIR)/debian/tmp/usr/bin:$(PATH)" \
 PYTHONPATH="$(CURDIR)/debian/tmp/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 --version-string $(DEB_VERSION_UPSTREAM) --output $2 $1 \
 || { $(_ENV) $1 --help; false; }

override_dh_auto_test:
	python3 -m ontospy.tests.test_load_local
	python3 -m ontospy.tests.test_methods
#	python3 -m ontospy.tests.test_load_remote
#	python3 -m ontospy.tests.test_sparql
	python3 -m ontospy.tests.test_shapes

# * generate manpage based on --help option of script itself
# * generate shell completion scripts
# TODO: run package testsuite during build
# TODO: generate files during build
execute_after_dh_auto_install:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	$(_ENV) prove debian/tests/*.t
endif
	$(_ENV) _ONTOSPY_COMPLETE=bash_source $(cmd) \
		> debian/bash-completion || true
	test -s debian/bash-completion
	$(_ENV) _ONTOSPY_COMPLETE=zsh_source $(cmd) \
		> debian/_$(cmd) || true
	test -s debian/_$(cmd)
	$(call _mkman, $(cmd), debian/$(cmd).1, \
		command-line tool to inspect and visualize RDF models)
	find debian/tmp/usr/lib -name '*.pyc' -delete
	find debian/tmp/usr/lib -type d -empty -delete

# unset bogus executable bits
execute_after_dh_fixperms:
	chmod --recursive a-x,a+X -- debian/*/usr/lib

%:
	dh $@ --buildsystem=pybuild