#!/usr/bin/make -f

# Verbose mode
#export DH_VERBOSE=1

VERSION := $(shell dpkg-parsechangelog | sed -rne 's,^Version: ([0-9]:)*([^-]+).*,\2,p')
export OSLO_PACKAGE_VERSION=$(VERSION)

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

%:
	dh $@ --with python2

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

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:
	dh_install --fail-missing -Xbin/nova-all
	chmod 440 $(CURDIR)/debian/nova-common/etc/sudoers.d/nova_sudoers
	install -D -m 644 debian/source_nova.py debian/php5-common/usr/share/apport/package-hooks/source_nova.py
	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

override_dh_fixperms:
	dh_fixperms -Xnova_sudoers
	dh_fixperms -Xnova_tgt.conf
	rm -f $(CURDIR)/debian/python-nova/usr/share/pyshared/nova/CA/.gitignore
	rm -f $(CURDIR)/debian/python-nova/usr/share/pyshared/nova/CA/projects/.gitignore
	rm -f $(CURDIR)/debian/python-nova/usr/share/pyshared/nova/CA/reqs/.gitignore

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

override_dh_python2:
	dh_python2

override_dh_installlogrotate:
	dh_installlogrotate
	dh_installlogrotate --name=nova-manage
	dh_installlogrotate --name=nova-dhcpbridge

override_dh_installchangelogs:
	dh_installchangelogs ChangeLog
