#!/usr/bin/make -f
#export DH_VERBOSE = 1

SHELL := /bin/sh -e

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 $@  --with python3,sphinxdoc --buildsystem=pybuild

override_dh_auto_install:
	pkgos-dh_auto_install --no-py2
	rm -rf $(CURDIR)/debian/python*-networking-bagpipe/usr/etc $(CURDIR)/debian/python*-networking-bagpipe/etc

override_dh_install:
	# NOTE: generate configuration files directly
	mkdir -p etc/neutron
	for file in `ls etc/oslo-config-generator/*`; do \
	     PYTHONPATH=$(CURDIR) oslo-config-generator --config-file=$$file \
	        --output-file=etc/neutron/`basename $$file`; \
	done
	dh_install

override_dh_auto_clean:
	rm -rf .stestr build etc/neutron
	for file in `ls etc/oslo-config-generator/*`; do rm -f etc/neutron/`basename $$file`; done
	dh_auto_clean

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

override_dh_sphinxdoc:
	sphinx-build -b html doc/source debian/python-networking-bagpipe-doc/usr/share/doc/python-networking-bagpipe-doc/html
	dh_sphinxdoc -O--buildsystem=pybuild

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