#!/usr/bin/make -f

# Verbose mode
#export DH_VERBOSE=1

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

# auth_token middleware now requires access to HOME, otherwise
# test suite cause FTBFS.  See (LP: #1031022)
export HOME="$(CURDIR)/debian/tests/"

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

ifeq (,$(findstring nocheck, $(DEB_BUILD_OPTIONS)))
override_dh_auto_test:
	patch -p1 -R < debian/patches/sql_connection.patch
	mkdir -p $(CURDIR)/keystone/tests/tmp
	ostestr
	patch -p1 < debian/patches/sql_connection.patch
endif

override_dh_auto_build:
	dh_auto_build
ifeq (,$(findstring nodocs, $(DEB_BUILD_OPTIONS)))
	mkdir -p $(CURDIR)/doc/build/html
	mkdir -p $(CURDIR)/doc/build/man
	sphinx-build -b man doc/source doc/build/man
	sphinx-build -b html doc/source doc/build/html
endif

override_dh_install:
	dh_install --fail-missing -Xusr/etc
	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/python-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
	rm -f debian/*.init debian/*.service debian/*.upstart
	dh_clean

override_dh_auto_clean:
	dh_auto_clean
	rm -rf .eggs .testrepository

get-orig-source:
	uscan --verbose --force-download --rename --destdir=../build-area
