#!/usr/bin/make -f

PYTHONS:=$(shell pyversions -vr)

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

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

%:
	dh $@ --buildsystem=python_distutils --with apache2,python2,systemd,sphinxdoc

override_dh_auto_build:
	dh_auto_build -O--buildsystem=python_distutils

override_dh_auto_test:
ifeq (,$(findstring nocheck, $(DEB_BUILD_OPTIONS)))
	ostestr --regex "^barbican.tests.*"
endif

override_dh_auto_install:
	python setup.py install --root=debian/tmp --install-layout=deb

override_dh_install:
	PYTHONPATH=$(CURDIR) oslo-config-generator \
		--config-file etc/oslo-config-generator/barbican.conf \
		--output-file etc/barbican/barbican.conf
	dh_install --fail-missing

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=python_distutils
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
