#!/usr/bin/make -f

DEBVERS ?= $(shell dpkg-parsechangelog | sed -n -e 's/^Version: //p')
VERSION ?= $(shell echo '$(DEBVERS)' | sed -e 's/^[[:digit:]]*://' -e 's/[-].*//' -e 's/[+].*//' -e 's/~git.*//g' -e 's/~/./g')
export PBR_VERSION=$(VERSION)

include /usr/share/openstack-pkg-tools/pkgos.make

%:
	dh $@ --buildsystem=pybuild --with apache2,python3,sphinxdoc

override_dh_auto_build:
	dh_auto_build -O--buildsystem=pybuild

override_dh_auto_test:
ifeq (,$(findstring nocheck, $(DEB_BUILD_OPTIONS)))
	pkgos-dh_auto_test --no-py2
endif

override_dh_auto_install:
	pkgos-dh_auto_install --no-py2

override_dh_install:
	PYTHONPATH=$(CURDIR) oslo-config-generator \
		--config-file etc/oslo-config-generator/barbican.conf \
		--output-file etc/barbican/barbican.conf
	dh_install -Xusr/etc
	dh_missing --fail-missing -Xusr/etc
	rm -rf $(CURDIR)/debian/python*-barbican/usr/etc

override_dh_sphinxdoc:
ifeq (,$(findstring nodocs, $(DEB_BUILD_OPTIONS)))
	PYTHONPATH=. sphinx-build -b html doc/source $(CURDIR)/debian/barbican-doc/usr/share/doc/barbican-doc/html
	dh_sphinxdoc -O--buildsystem=pybuild
endif

override_dh_auto_clean:
	dh_auto_clean
	rm -f debian/*.init debian/*.service debian/*.upstart
	rm -rf build
	rm -rf barbican.sqlite
	rm -rf .eggs
	rm -f etc/barbican/barbican.conf

override_dh_python3:
	dh_python3 --shebang=/usr/bin/python3
