#!/usr/bin/make -f

# Verbose mode
#export DH_VERBOSE=1

export PYBUILD_NAME=masakari

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)

PYTHON3S:=$(shell py3versions -vr)

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

%:
	dh $@ --with apache2,python3 --buildsystem=pybuild

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

override_dh_install:
	pkgos-dh_auto_install --no-py2
	rm -rf $(CURDIR)/debian/python3-masakari/usr/etc
	PYTHONPATH=$(CURDIR) oslopolicy-sample-generator --config-file=etc/masakari/masakari-policy-generator.conf
	PYTHONPATH=$(CURDIR) oslo-config-generator --config-file=etc/masakari/masakari-config-generator.conf
	PYTHONPATH=$(CURDIR) oslo-config-generator --config-file=etc/masakari/masakari-customized-recovery-flow-config-generator.conf
	cp etc/masakari/masakari.conf.sample etc/masakari/masakari.conf
	cp etc/masakari/masakari-custom-recovery-methods.conf.sample etc/masakari/masakari-custom-recovery-methods.conf
	crudini --set $(CURDIR)/etc/masakari/masakari.conf database connection sqlite:////var/lib/masakari/masakari.sqlite
	dh_install
	dh_missing --fail-missing

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

override_dh_auto_clean:
	dh_auto_clean -O--buildsystem=pybuild
	rm -rf doc/build/* doc/source/api doc/.autogenerated debian/doctrees

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 -d debian/doctrees doc/source doc/build/man
	PYTHONPATH=$(CURDIR) sphinx-build -b html -d debian/doctrees doc/source doc/build/html
endif

override_dh_auto_install:
	echo "Do nothing..."
