#!/usr/bin/make -f

non_default_python_versions = $(shell python -c "print \"`pyversions -v -s`\".replace(\"`pyversions -v -d`\", '').strip()")

# one ring to rule them all ...
%:
	dh $@ --buildsystem=makefile --with python2

override_dh_auto_configure:
	# disable warning about unused results (necessary because warning is error
	# is ON)
	CFLAGS="$(CFLAGS) -Wno-unused-result" ./configure --with-globus-path /usr \
		--with-mysql-path /usr --with-krb5-path /usr --with-readline-path /usr \
		--with-mpi-path /usr --with-fuse-path /usr --with-zlib-path /usr \
		--with-python-path /usr

override_dh_auto_install:
	dh_auto_install -- CCTOOLS_INSTALL_DIR=$(CURDIR)/debian/tmp
	# make extensions for other supported python versions
	if [ -n "$(non_default_python_versions)" ]; then \
		for pyver in $(non_default_python_versions); do \
			PYTHON=/usr/bin/python$${pyver} ./configure.rerun ; \
			make -B -C work_queue/src/python install CCTOOLS_INSTALL_DIR=$(CURDIR)/debian/tmp ; \
		done ; \
	fi
	# fix permissions
	find debian/tmp/lib -name '*.py' -exec chmod 644 {} \;
	# remove undesired pieces
	-rm debian/tmp/doc/COPYING
	# upstream says it should not go into the page
	-rm debian/tmp/bin/watchdog
	# HDFS helpers are useless without HDFS in Debian
	-rm debian/tmp/bin/*_hdfs
	# newer doxygen puts jquery copy
	-rm debian/tmp/doc/api/html/jquery.js

override_dh_auto_clean:
	[ -e Makefile.config ] && dh_auto_clean || true
	-rm Makefile.config configure.rerun
	-rm -rf api hdfs-setup.template python/python-workqueue/setup.cfg
	# remove testrun left-overs
	-rm dttools/src/microbench dttools/src/work_queue_example
	-find $(CURDIR) -name '*.test.log' -delete
	-find $(CURDIR) -name '*_test' -delete
	-rm -rf sand/test/filter_verification/random.cand.filter.tmp/
	-rm -rf sand/test/test_20.cand.filter.tmp/
	-rm -f sand/test/test_20.cand sand/test/test_20.cfa sand/test/*.log
	-rm -rf makeflow/test/input/ makeflow/test/worker.pid
	-rm -rf makeflow/test/dirs/testcase.subdir.01.makeflow.makeflowlog
	-rm -rf makeflow/test/dirs/testcase.subdir.01.makeflow.wqlog
	-rm -rf makeflow/test/src/
	-rm dttools/src/multirun sand/test/banded.log
