#!/usr/bin/make -f

export DH_VERBOSE=1

# Lucid does not have dh_python2, but we would like to be able to use this
# rules file to build on lucid as well. Thus the branching logic.
WITH_PYTHON2 = $(shell test -f /usr/bin/dh_python2 && echo "--with python2")

WITH_SPHINXDOC = $(shell test -f /usr/bin/dh_sphinxdoc && echo "--with sphinxdoc")

%:
	dh $@ \
		--with quilt \
	   	${WITH_SPHINXDOC} ${WITH_PYTHON2} --buildsystem=python_distutils

override_dh_auto_clean:
	rm -rf docs/html/
	find -type d \( -name '*.egg-info' -or -name 'build' \) | xargs rm -fr
	dh_auto_clean

override_dh_auto_build:
	dh_auto_build
	dh_auto_build -Dplugins/holland.lib.common
	dh_auto_build -Dplugins/holland.lib.mysql
	dh_auto_build -Dplugins/holland.lib.lvm
	dh_auto_build -Dplugins/holland.backup.mysqldump
	dh_auto_build -Dplugins/holland.backup.mysql_lvm
	dh_auto_build -Dplugins/holland.backup.pgdump
	dh_auto_build -Dplugins/holland.backup.example
	dh_auto_build -Dplugins/holland.backup.xtrabackup
        
	# Build the HTML documentation.
	PYTHONPATH=. sphinx-build -N -q -E -b html docs/source/ docs/html/

override_dh_auto_install:
	dh_auto_install -O--buildsystem=python_distutils
	dh_auto_install -O--buildsystem=python_distutils -Dplugins/holland.lib.common 
	dh_auto_install -O--buildsystem=python_distutils -Dplugins/holland.lib.mysql
	dh_auto_install -O--buildsystem=python_distutils -Dplugins/holland.lib.lvm
	dh_auto_install -O--buildsystem=python_distutils -Dplugins/holland.backup.mysqldump
	dh_auto_install -O--buildsystem=python_distutils -Dplugins/holland.backup.mysql_lvm
	dh_auto_install -O--buildsystem=python_distutils -Dplugins/holland.backup.pgdump
	dh_auto_install -O--buildsystem=python_distutils -Dplugins/holland.backup.example
	dh_auto_install -O--buildsystem=python_distutils -Dplugins/holland.backup.xtrabackup
	find debian/tmp/ \( -name '*.pth' -or -name 'namespace_packages.txt' \) -delete

override_dh_installdocs:
	dh_installdocs
	# Remove embedded copy of libjs-jquery, if sphinxdocs will not
	if [ ! ${WITH_SPHINXDOC} ]; then \
	cd debian/holland/usr/share/doc/holland/html/_static \
		&& rm jquery.js \
                && ln -s ../../../../javascript/jquery/jquery.js .; \
	fi

override_dh_compress:
	dh_compress -X.txt

override_dh_python2:
	# only build for current python version
	dh_python2 -V $(shell pyversions -vd)
