#!/usr/bin/make -f

# Verbose mode
#export DH_VERBOSE=1

DEBVERS ?= $(shell dpkg-parsechangelog | sed -n -e 's/^Version: //p')
VERSION ?= $(shell echo '$(DEBVERS)' | sed -e 's/^[[:digit:]]*://' -e 's/[-].*//' -e 's/~/./g')
export OSLO_PACKAGE_VERSION=$(VERSION)

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

# Send HTTP traffic to “discard” service
export http_proxy = http://127.0.1.1:9/
export https_proxy = ${http_proxy}

%:
	dh $@ --with python2,systemd

override_dh_auto_clean:
	dh_auto_clean
	rm -rf doc/build/* doc/source/api doc/.autogenerated
	rm -rf tests.sqlite clean.sqlite run_tests.log
	rm -rf CA
	rm -f po/nova.pot
	rm -rf .autogenerated
	rm -f debian/*.init debian/*.service debian/*.upstart
	rm -rf .testrepository

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

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

override_dh_install:
	# Fix any api sample template files with broken permissions
	find $(CURDIR)/debian/tmp -name *.tpl -exec chmod a-x {} \;
	dh_install --fail-missing -Xbin/nova-all
	chmod 440 $(CURDIR)/debian/nova-common/etc/sudoers.d/nova_sudoers
	install -D -m 0644 $(CURDIR)/etc/nova/logging_sample.conf $(CURDIR)/debian/nova-common/etc/nova/logging.conf
	for hypervisor in qemu kvm xen lxc vmware; do \
		install -D -m 0600 $(CURDIR)/debian/nova-compute-$${hypervisor}.conf $(CURDIR)/debian/nova-compute-$${hypervisor}/etc/nova/nova-compute.conf; \
	done
	find $(CURDIR)/debian -name ".gitignore" -delete

override_dh_fixperms:
	dh_fixperms -Xnova_sudoers -Xnova_tgt.conf

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

endif
