#!/usr/bin/make -f

# Verbose mode
#export DH_VERBOSE=1

export PYBUILD_NAME=masakari-monitors

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 --buildsystem=pybuild

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

override_dh_install:
	rm -rf $(CURDIR)/debian/python3-masakari-monitors/usr/etc
	PYTHONPATH=$(CURDIR) oslo-config-generator --config-file=etc/masakarimonitors/masakarimonitors-config-generator.conf
	cp etc/masakarimonitors/masakarimonitors.conf.sample etc/masakarimonitors/masakarimonitors.conf
	cp etc/masakarimonitors/process_list.yaml.sample etc/masakarimonitors/process_list.yaml
	crudini --set etc/masakarimonitors/masakarimonitors.conf api auth_url http://localhost:5000/v3
	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
	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
