#!/usr/bin/make -f
# Sample debian/rules that uses debhelper.
# This file is public domain software, originally written by Joey Hess.
#

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

%:
	dh $@ --with python2

override_dh_auto_configure:
	./configure \
	  --prefix=/usr \
	  --localstatedir=/var \
	  --sysconfdir=/etc \
	  --with-export-dir=/var/lib/ganeti/export \
	  --with-iallocator-search-path=/usr/local/lib/ganeti/iallocators,/usr/lib/ganeti/iallocators \
	  --with-os-search-path=/srv/ganeti/os,/usr/local/lib/ganeti/os,/usr/lib/ganeti/os,/usr/share/ganeti/os \
	  --docdir=/usr/share/doc/ganeti \
	  --enable-htools --enable-htools-rapi --enable-restricted-commands

override_dh_auto_clean:
	[ ! -f Makefile ] || $(MAKE) distclean
	# this is not removed by make distclean :(
	rm -f ganeti

	rm -f debian/ganeti.init
	rm -f debian/ganeti.cron.d
	rm -f debian/ganeti.default

	dh_auto_clean

override_dh_auto_install:
	dh_auto_install
	cp $(CURDIR)/doc/examples/ganeti.initd $(CURDIR)/debian/ganeti.init
	cp $(CURDIR)/doc/examples/ganeti.cron $(CURDIR)/debian/ganeti.cron.d
	cp $(CURDIR)/doc/examples/ganeti.default $(CURDIR)/debian/ganeti.default
	install -m 0644 $(CURDIR)/doc/examples/bash_completion \
	   $(CURDIR)/debian/ganeti/etc/bash_completion.d/ganeti
	
	# Hack to make our life a bit easier and be able to use wildcards in .install files
	mv $(CURDIR)/debian/tmp/usr/lib/ganeti/mon-collector $(CURDIR)/debian/ganeti-haskell/usr/lib/ganeti
	mv $(CURDIR)/debian/tmp/usr/sbin/ganeti-confd $(CURDIR)/debian/ganeti-haskell/usr/sbin
	mv $(CURDIR)/debian/tmp/usr/share/man/man8/ganeti-confd.8 \
	   $(CURDIR)/debian/ganeti-haskell/usr/share/man/man8/

	mv $(CURDIR)/debian/tmp/usr/lib/ganeti/iallocators/hail \
	   $(CURDIR)/debian/ganeti-htools/usr/lib/ganeti/iallocators

	# Dummy Python module for the RAPI client
	touch $(CURDIR)/debian/python-ganeti-rapi/usr/share/pyshared/ganeti/__init__.py
	touch $(CURDIR)/debian/python-ganeti-rapi/usr/share/pyshared/ganeti/rapi/__init__.py

override_dh_installinit:
	dh_installinit --error-handler=true -i -- defaults 20 80

override_dh_install:
	dh_install --fail-missing

.PHONY: override_dh_auto_configure override_dh_auto_clean override_dh_auto_install \
	override_dh_installinit override_dh_install
