#!/usr/bin/make -f

export PYBUILD_NAME=barbican
SHELL := /bin/sh -e

UPSTREAM_GIT := https://opendev.org/openstack/barbican.git

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_clean:
	dh_auto_clean
	rm -rf build .pybuild .testrepository .eggs
	rm -rf barbican.sqlite
	rm -f etc/barbican/barbican.conf

override_dh_auto_build:
	dh_auto_build -O--buildsystem=pybuild

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

override_dh_auto_install:
	pkgos-dh_auto_install --no-py2
	rm -rf $(CURDIR)/debian/python3-barbican/usr/etc

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

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

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

override_dh_clean:
	dh_clean
	rm -f debian/*.init debian/*.service debian/*.upstart
