#!/usr/bin/make -f

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

export HOME="$(CURDIR)/debian/test"

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

%:
	dh $@  --with python2,systemd,sphinxdoc

override_dh_clean:
	dh_clean
	rm -rf .testrepository

override_dh_install:
	PYTHONPATH=$(CURDIR) oslo-config-generator --config-file=aodh-config-generator.conf
	dh_install --fail-missing

override_dh_auto_clean:
	dh_auto_clean
	rm -rf .testrepository
	find . -iname '*.pyc' -delete
	rm -f debian/*.init debian/*.service debian/*.upstart

override_dh_auto_test:
ifeq (,$(findstring nocheck, $(DEB_BUILD_OPTIONS)))
	rm -rf .testrepository
	testr init
	set -e ; \
		TEMP_REZ=`mktemp -t` ; \
		OS_TEST_PATH=./aodh/tests/unit testr run --subunit 'tests\.(?!.*test_bin.*)' | tee $$TEMP_REZ | subunit2pyunit ; \
		cat $$TEMP_REZ | subunit-filter -s --no-passthrough | subunit-stats ; \
		rm -f $$TEMP_REZ ;
	testr slowest
endif

override_dh_sphinxdoc:
ifeq (,$(findstring nodocs, $(DEB_BUILD_OPTIONS)))
	PYTHONPATH=. sphinx-build -b html doc/source $(CURDIR)/debian/aodh-doc/usr/share/doc/aodh-doc/html
	mkdir -p $(CURDIR)/debian/aodh-doc/usr/share/doc/aodh-doc/html/_static
	touch $(CURDIR)/debian/aodh-doc/usr/share/doc/aodh-doc/html/_static/toggle.js
	dh_sphinxdoc -O--buildsystem=python_distutils
endif
