#!/usr/bin/make -f

DEB_PYTHON_SYSTEM = pycentral
PY_VERSIONS = $(shell pyversions --requested debian/control)

JAVA_HOME = /usr/lib/jvm/default-java

include /usr/share/cdbs/1/rules/debhelper.mk
include /usr/share/cdbs/1/class/autotools.mk

DEB_CONFIGURE_EXTRA_FLAGS = --enable-systempython --with-java-include-dir=$(JAVA_HOME)/include
DEB_MAKE_CHECK_TARGET = check

DEB_BUILDDIR := build

# These targets do allow building multiple Python versions extensions
# when autoconf is used - as in this case - instead of Distutils.

configure/python-kml:: $(addprefix configure-stamp-, $(PY_VERSIONS))

configure-stamp-%:
	mkdir build-$*
	cd build-$* && PYTHON=`which $*` $(DEB_CONFIGURE_SCRIPT_ENV) \
			$(DEB_CONFIGURE_SCRIPT) \
			$(DEB_CONFIGURE_NORMAL_ARGS) \
			--disable-maintainer-mode \
			$(cdbs_configure_flags) \
			$(DEB_CONFIGURE_EXTRA_FLAGS) \
			$(DEB_CONFIGURE_USER_FLAGS)
	touch $@

build-stamp-%:
	$(MAKE) -C build-$* PYTHON=`which $*`
	touch $@

build/python-kml:: $(addprefix build-stamp-, $(PY_VERSIONS))

install-stamp-%:
	$(MAKE) -C build-$* PYTHON=`which $*` DESTDIR=$(CURDIR)/debian/tmp install
	touch $@

install/python-kml:: $(addprefix install-stamp-, $(PY_VERSIONS))

binary-install/python-kml:: install/python-kml
	# removes build-time rpaths
	for version in $(PY_VERSIONS); \
	do \
		chrpath --delete $(CURDIR)/debian/python-kml/usr/lib/$$version/*-packages/*.so ; \
	done
	dh_pycentral -ppython-kml

binary-install/libkml-dev::
	# removes autotools stuff
	find $(CURDIR)/debian/libkml-dev/usr/share/doc/libkml-dev/examples -type f -name "Makefile.*" -delete
	# removes python related stuff
	find $(CURDIR)/debian/libkml-dev/usr/lib -name "libkml*python*.so*" -delete

clean::
	-rm -rf $(addprefix build-, $(PY_VERSIONS))
	-rm -rf $(addprefix configure-stamp-, $(PY_VERSIONS))
	-rm -rf $(addprefix build-stamp-, $(PY_VERSIONS))
	-rm -rf $(addprefix install-stamp-, $(PY_VERSIONS))

