#!/usr/bin/make -f

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

LAST_CHANGE = $(shell dpkg-parsechangelog -S Date)
BUILD_DATE  = $(shell LC_ALL=C date -u "+%B %d, %Y" -d "$(LAST_CHANGE)")
SPHINXOPTS := -D today="$(BUILD_DATE)"
SPHINXOPTS += -D html_last_updated_fmt="$(BUILD_DATE)"

export OSLO_PACKAGE_VERSION=$(VERSION)

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

ifeq (,$(findstring nocheck, $(DEB_BUILD_OPTIONS)))
override_dh_auto_test:
	./run_tests.sh -P -N || true
	#nosetests || true
endif

override_dh_auto_build:
	dh_auto_build

	/usr/share/openstack-pkg-tools/pkgos_insert_include pkgos_func glance-common.config
	/usr/share/openstack-pkg-tools/pkgos_insert_include pkgos_func glance-common.postinst
	/usr/share/openstack-pkg-tools/pkgos_insert_include pkgos_func glance-api.config
	/usr/share/openstack-pkg-tools/pkgos_insert_include pkgos_func glance-api.postinst

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

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

override_dh_auto_configure:
	echo $(VERSION) > glance/versioninfo
	dh_auto_configure


override_dh_auto_clean:
	echo $(VERSION) > glance/versioninfo
	# dh_auto_clean
	# debconf-updatepo
	find . -iname '*.pyc' -delete
	rm -rf glance.egg-info
	rm -rf doc/build
	rm -rf glance.sqlite
	rm -f glance/versioninfo
	rm -f debian/glance-common.config debian/glance-common.postinst
	rm -f debian/*.init debian/*.upstart debian/*.service
	rm -rf build

.PHONY: override_dh_auto_clean override_dh_installman override_dh_auto_build
