#!/usr/bin/make -f

# Verbose mode
#export DH_VERBOSE=1

# auth_token middleware now requires access to HOME, otherwise
# test suite cause FTBFS.  See (LP: #1031022)
export HOME="$(CURDIR)/debian/tests/"
include /usr/share/openstack-pkg-tools/pkgos.make

%:
	dh $@ --with python2,sphinxdoc

override_dh_auto_test:
ifeq (,$(findstring nocheck, $(DEB_BUILD_OPTIONS)))
	mkdir -p $(CURDIR)/keystone/tests/tmp
	./run_tests.sh -N -P
endif

override_dh_auto_build:
	dh_auto_build

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

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

override_dh_install:
	dh_install --fail-missing
	rm -rf debian/python-keystone/usr/lib/python*/*/doc
	rm -rf debian/python-keystone/usr/lib/python*/*/tools
	rm -rf debian/python-keystone/usr/lib/python*/*/examples
	install -D -m 0600 $(CURDIR)/debian/logging.conf $(CURDIR)/debian/keystone/etc/keystone/logging.conf
	install -D -m 0600 $(CURDIR)/etc/keystone.conf.sample  $(CURDIR)/debian/keystone/etc/keystone/keystone.conf
	install -D -m 0644 $(CURDIR)/httpd/keystone.py $(CURDIR)/debian/keystone/usr/share/keystone/wsgi.py

override_dh_clean:
	rm -rf $(CURDIR)/build $(CURDIR)/keystone.egg-info $(CURDIR)/.cache
	rm -rf $(CURDIR)/keystone/tests/tmp
	rm -rf $(CURDIR)/.testrepository
	rm -rf $(CURDIR)/debian/tmp
	rm -rf $(CURDIR)/doc/build
	# NOTE(adam_g) The following stuff is built in /doc/source.  Safe for now, but
	# should be fixed upstream or updated here post-essex
	rm -rf $(CURDIR)/doc/source/keystone*.rst
	rm -rf $(CURDIR)/doc/source/modules.rst
	dh_clean

#Commands not to run:
override_dh_installdocs:
override_dh_testdir:
override_dh_testroot:
override_dh_prep:
