#!/usr/bin/make -f

#export DH_VERBOSE=1
#export PYBUILD_VERBOSE=1

ifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
    NUMJOBS = $(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
else
    NUMJOBS = True
endif
PICKLE_PROTOCOL=4
export PYBIK_NO_SETUPTOOLS=1

%:
	dh $@ --with python3 --buildsystem=pybuild

override_dh_auto_clean:
	dh_auto_clean
	rm -f debian/README

override_dh_auto_build-arch:
	dh_auto_build -- --build-args="--arch-only"

override_dh_auto_build-indep:
	python3 buildlib/create_docs.py --skip=Installation README=debian/README
	dh_auto_build -- --build-args=" \
	                        --indep-only \
	                        --parallel=$(NUMJOBS) \
	                        --pickle-protocol=$(PICKLE_PROTOCOL) \
	                        --reproducible"

override_dh_auto_install-arch:
	dh_auto_install -- --install-args=" \
	                        --arch-only \
	                        --install-lib=/usr/lib/pybik"

override_dh_auto_install-indep:
	dh_auto_install -- --install-args=" \
	                        --indep-only \
	                        --install-lib=/usr/lib/pybik \
	                        --install-scripts=/usr/lib/pybik \
	                        --data-dir=/usr/share"

override_dh_auto_test:
	# test whether pickled data can be loaded with all supported Python versions
	PYBUILD_SYSTEM=custom \
	PYBUILD_TEST_ARGS="{interpreter} -c 'import glob,pickle; \
	           [(print(\"test with {version}:\", f), pickle.load(open(f, \"rb\"))) \
	           for f in glob.glob(\"build/models/*\")]'" \
	dh_auto_test

override_dh_python3:
	# Python files in usr/share/pybik/tests/ are not modules
	# no other Python files in usr/share/pybik/
	dh_python3 -p pybik usr/lib/pybik/
	dh_python3 -p pybik-bin usr/lib/pybik/pybiklib/

override_dh_builddeb:
	dh_builddeb -- -Zxz

