#!/usr/bin/make -f

# Verbose mode
#export DH_VERBOSE=1

export PYBUILD_NAME=placement

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 apache2,python3 --buildsystem=pybuild

override_dh_auto_clean:
	dh_auto_clean
	rm -rf doc/build/* doc/source/api doc/.autogenerated

override_dh_auto_build:
	dh_auto_build
ifeq (,$(findstring nodocs, $(DEB_BUILD_OPTIONS)))
	mkdir -p doc/build/html
	mkdir -p doc/build/man
	PYTHONPATH=$(CURDIR) sphinx-build -b man doc/source doc/build/man
	PYTHONPATH=$(CURDIR) sphinx-build -b html doc/source doc/build/html
endif

override_dh_install:
	rm -rf $(CURDIR)/debian/python3-placement/usr/etc
	# Fix any api sample template files with broken permissions
	PYTHONPATH=$(CURDIR) oslopolicy-sample-generator --config-file=etc/placement/policy-generator.conf
	PYTHONPATH=$(CURDIR) oslo-config-generator --config-file=etc/placement/config-generator.conf
	cp etc/placement/placement.conf.sample etc/placement/placement.conf
	cp etc/placement/policy.yaml.sample etc/placement/policy.yaml
	crudini --set $(CURDIR)/etc/placement/placement.conf placement_database connection sqlite:////var/lib/placement/placement.sqlite
	dh_install
	dh_missing --fail-missing

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

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