#!/usr/bin/make -f

export DH_VERBOSE=1

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

%:
	dh $@ --buildsystem=python_distutils --with apache2,python2,sphinxdoc,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 -rf nova.egg-info
	rm -rf .autogenerated
	rm -f debian/*.init debian/*.service debian/*.upstart
	rm -f etc/nova/nova.conf.sample

override_dh_auto_build:
	dh_auto_build
	PYTHONPATH=$(CURDIR)/debian/tmp/usr/lib/python2.7/dist-packages oslo-config-generator --config-file=etc/nova/nova-config-generator.conf
	PYTHONPATH=$(CURDIR)/debian/tmp/usr/lib/python2.7/dist-packages oslopolicy-sample-generator --config-file=etc/nova/nova-policy-generator.conf
	/usr/share/openstack-pkg-tools/pkgos_insert_include pkgos_func nova-common.postinst

override_dh_sphinxdoc:
ifeq (,$(findstring nodocs, $(DEB_BUILD_OPTIONS)))
	PYTHONPATH=$(CURDIR)/debian/tmp/usr/lib/python2.7/dist-packages sphinx-build -b html doc/source $(CURDIR)/debian/nova-doc/usr/share/doc/nova-doc/html
	PYTHONPATH=$(CURDIR)/debian/tmp/usr/lib/python2.7/dist-packages sphinx-build -b man doc/source doc/build/man
#	Uncomment once searchindex will be included in search.html file.
#	dh_sphinxdoc -O--buildsystem=python_distutils
endif

override_dh_installman:
ifeq (,$(findstring nodocs, $(DEB_BUILD_OPTIONS)))
	dh_installman -O--buildsystem=python_distutils
endif

override_dh_auto_install:
	echo "Please do nothing"

override_dh_install:
	rm -rf $(CURDIR)/debian/tmp
	python setup.py install -f --install-layout=deb --root=$(CURDIR)/debian/tmp

	dh_install --fail-missing -Xbin/nova-all
	mkdir -p $(CURDIR)/debian/nova-common/usr/share/nova-common
	cp etc/nova/nova.conf.sample $(CURDIR)/debian/nova-common/usr/share/nova-common/nova.conf
	cp etc/nova/policy.yaml.sample $(CURDIR)/debian/nova-common/usr/share/nova-common/policy.yaml
	pkgos-fix-config-default $(CURDIR)/debian/nova-common/etc/nova/nova.conf DEFAULE state_path /var/lib/nova

	install -D -m 0440 $(CURDIR)/debian/nova-common.sudoers $(CURDIR)/debian/nova-common/etc/sudoers.d/nova-common
	install -D -m 0644 $(CURDIR)/etc/nova/logging_sample.conf $(CURDIR)/debian/nova-common/usr/share/nova-common/logging.conf
	set -e ; for hypervisor in qemu kvm lxc ironic 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

override_dh_apache2:
	dh_apache2 --noenable

override_dh_auto_test:
ifeq (,$(findstring nocheck, $(DEB_BUILD_OPTIONS)))
	pkgos-dh_auto_test
endif

# We use override_dh_installmenu because it's done in the sequence with dh,
# and we already override dh_installinit in pkgos.make.
# Obviously, we will never use a Desktop menu in such a package, so that's
# not a problem.
override_dh_installmenu:
	#dh_installinit -pnova-console --name=nova-consoleauth
	dh_installinit --name=nova-novncproxy
	dh_installinit --name=nova-spicehtml5proxy
	dh_installinit --name=nova-xenvncproxy
	dh_installinit --name=nova-serialproxy
	install -D -m 0644 $(CURDIR)/debian/nova-consoleproxy.mydefault $(CURDIR)/debian/nova-consoleproxy/usr/share/nova-consoleproxy/default
	rm -f $(CURDIR)/debian/nova-compute/etc/init/nova-compute.conf
