#!/usr/bin/make -f

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

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 $@ --with python2,python3 --buildsystem=python_distutils

override_dh_auto_install:
	pkgos-dh_auto_install

override_dh_install:
	# NOTE: generate configuration files directly
	for file in `ls etc/oslo-config-generator/*`; do \
		 PYTHONPATH=$(CURDIR) oslo-config-generator --config-file=$$file \
			--output-file=etc/neutron/`basename $$file`; \
	done
	# NOTE: scrub usr/etc and usr/bin folder from install.
	rm -rf debian/python*-neutron-fwaas/usr/etc debian/python*-neutron-fwaas/usr/bin
	dh_install

override_dh_fixperms:
	find debian/python*-neutron-fwaas -name __init__.py -exec chmod a-x {} \;
	dh_fixperms

ifeq (,$(findstring nocheck, $(DEB_BUILD_OPTIONS)))
override_dh_auto_test:
	PYTHON=python python2-ostestr
	PYTHON=python3 python3-ostestr
endif

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