#!/usr/bin/make -f

UPSTREAM_GIT ?= https://opendev.org/openstack/supply.git
include /usr/share/openstack-pkg-tools/pkgos.make

export OSLO_PACKAGE_VERSION=$(shell dpkg-parsechangelog -SVersion | sed -e 's/^[[:digit:]]*://' -e 's/[-].*//' -e 's/~git.*//' -e 's/~/.0/' -e 's/+dfsg1//' -e 's/+ds1//' -e 's/.[0]*bpo[0-9]*//' | head -n 1)

%:
	dh $@ --buildsystem=python_distutils --with python3

override_dh_clean:
	dh_clean
	rm -rf debian/*.service debian/*.templates
	rm -rf build
	find . -name '*.pyc' -delete
	rm -rf .stestr
	rm -rf supply.egg-info
	rm -f AUTHORS ChangeLog

override_dh_auto_clean:
	echo "Do nothing..."

override_dh_auto_install:
	echo "Do nothing..."

override_dh_auto_test:
	echo "Do nothing..."

override_dh_auto_build:
	/usr/share/openstack-pkg-tools/pkgos_insert_include pkgos_func supply-common.config
	/usr/share/openstack-pkg-tools/pkgos_insert_include pkgos_func supply-common.postinst
	/usr/share/openstack-pkg-tools/pkgos_insert_include pkgos_postrm supply-common.postrm
	pkgos-merge-templates supply-common supply db ksat

override_dh_install:
	pkgos-dh_auto_install --no-py2 --in-tmp

#ifeq (,$(findstring nocheck, $(DEB_BUILD_OPTIONS)))
#	pkgos-dh_auto_test --no-py2 'supply\.tests.*'
#endif

	mkdir -p $(CURDIR)/debian/supply-common/usr/share/supply-common
	PYTHONPATH=$(CURDIR)/debian/tmp/usr/lib/python3/dist-packages oslo-config-generator \
		--output-file $(CURDIR)/debian/supply-common/usr/share/supply-common/supply.conf \
		--wrap-width 140 \
		--namespace supplyopts \
		--namespace oslo.log \
		--namespace keystonemiddleware.auth_token

	pkgos-readd-keystone-authtoken-missing-options $(CURDIR)/debian/supply-common/usr/share/supply-common/supply.conf keystone_authtoken supply

	dh_install
	mkdir -p $(CURDIR)/debian/supply-baremetal
	cp -axuf baremetal/* $(CURDIR)/debian/supply-baremetal
	dh_missing --fail-missing

#override_dh_fixperms:
#	dh_fixperms
#	chmod 640 /etc/supply-baremetal/supply-baremetal.conf

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