#!/usr/bin/make -f
# -*- makefile -*-

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

include /usr/share/cdbs/1/rules/debhelper.mk
include /usr/share/cdbs/1/class/python-distutils.mk

# Prepare support for python 3.x (need to add Build-Depends against
# python3-all-dev in debian/control), pending upstream release with
# python3 support
# cdbs_python_supported_versions += $(shell py3versions -vr)

# Install egg-info directories
DEB_PYTHON_INSTALL_ARGS_ALL += --single-version-externally-managed \
	--install-layout=deb

DEB_PYTHON_BUILDDIR := $(CURDIR)/$(DEB_BUILDDIR)/build

binary-post-install/python-cheetah::
	sed -i 's#\#!/usr/bin/python[0-9].[0-9]#\#!/usr/bin/python#' \
		$(cdbs_python_destdir)usr/bin/*

	# Run the tests with all the versions of Python, but do not
	# fail if the tests fail, just display an error message
	#
	# Any better way to run the tests as this is very ugly?
	for buildver in $(cdbs_python_flavors:python%=%); do \
		echo "Running tests with python$$buildver..." && \
		cd $(DEB_SRCDIR) && \
		PATH=$(DEB_PYTHON_BUILDDIR)/scripts-$${buildver}:$$PATH \
		PYTHONPATH=$$(echo $(DEB_PYTHON_BUILDDIR)/lib.linux-*-$$buildver) \
		python$$buildver $(DEB_SRCDIR)/cheetah/Tests/Test.py || \
		echo "FAILED with python$$buildver"; \
	done
