#!/usr/bin/make -f
# -*- makefile -*-

#export DH_VERBOSE=1
PYTHONS:=$(shell pyversions -vr)

include /usr/share/openstack-pkg-tools/pkgos.make
export OSLO_PACKAGE_VERSION=$(VERSION)

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

override_dh_installman:
ifeq (,$(findstring nodocs, $(DEB_BUILD_OPTIONS)))
        PYTHONPATH=. sphinx-build -b man doc/source doc/build/man
        dh_installman -O--buildsystem=python_distutils
endif

ifeq (,$(findstring nocheck, $(DEB_BUILD_OPTIONS)))
override_dh_auto_test:
	rm -rf .testrepository
	testr init && \
        set -e && \
        TEMP_REZ=`mktemp -t` && \
        testr run --subunit sahara.tests.unit | tee $$TEMP_REZ | subunit2pyunit; \
        rm -f $$TEMP_REZ
endif

override_dh_clean:
	rm -f	debian/sahara-common.postinst \
		debian/sahara-common.preinst
	rm -rf doc/build
	rm -f debian/*.init debian/*.service debian/*.upstart
	dh_clean -O--buildsystem=python_distutils

override_dh_auto_install:
	dh_auto_install
	mkdir -p debian/sahara/etc
	cp -r etc/sahara debian/sahara/etc/

override_dh_auto_build:
	dh_auto_build
	/usr/share/openstack-pkg-tools/pkgos_insert_include pkgos_func sahara-common.postinst
	/usr/share/openstack-pkg-tools/pkgos_insert_include pkgos_func sahara-common.preinst

override_dh_sphinxdoc:
ifeq (,$(findstring nodocs, $(DEB_BUILD_OPTIONS)))
	PYTHONPATH=. sphinx-build $(SPHINXOPTS) -b html doc/source $(CURDIR)/debian/sahara-doc/usr/share/doc/sahara-doc/html
	dh_sphinxdoc -O--buildsystem=python_distutils
endif
