#!/usr/bin/make -f

# pybuild matches the python3-pkgos binary package against this name.
export PYBUILD_NAME = pkgos

# PBR reads its version from the git tags, which are absent from the
# source used by sbuild: export the version from debian/changelog, the
# same way pkgos.make does for the packages built with it.
export PBR_VERSION?=$(shell dpkg-parsechangelog -SVersion | sed -e 's/^[[:digit:]]*://' -e 's/[-].*//' -e 's/~git.*//' -e 's/~bpo.*//' -e 's/~/.0/' -e 's/+dfsg1//' -e 's/+ds1//' -e 's/~/.0/' | head -n 1)

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

override_dh_auto_test:
ifeq (,$(findstring nocheck, $(DEB_BUILD_OPTIONS)))
	stestr run
endif

override_dh_install:
ifeq (,$(findstring nocheck, $(DEB_BUILD_OPTIONS)))
	echo "===> Running tests on pkgos_func"
	./run_tests
	echo "===> Checking scripts"
	set -e ; for i in `ls $(CURDIR)/salsa-scripts/pkgos-salsa-* $(CURDIR)/build-tools/pkgos-* $(CURDIR)/misc/pkgos-* | grep -v misc/pkgos-check-changelog` ; do \
		echo "-> Checking $$i" ; \
		sh -n $$i ; \
	done
endif
	dh_install
