#!/usr/bin/make -f

include /usr/share/cdbs/1/rules/debhelper.mk
include /usr/share/cdbs/1/rules/patchsys-quilt.mk

PYVERS=$(shell pyversions -vr)

build: $(PYVERS:%=build-python%)
	touch $@
build-python%: TMPDEST=debian/python-polybori$*
build-python%: PYTHON=/usr/bin/python$*
build-python%: PYTHONSITE=`/usr/bin/python$* -c 'import setuptools; print setuptools.distutils.sysconfig.get_python_lib() '`
build-python%:
	echo $(TMPDEST)
	scons prepare-install INSTALLDIR=$(TMPDEST)/usr/lib/polybori \
		PYINSTALLPREFIX=$(TMPDEST)$(PYTHONSITE) MANDIR=$(TMPDEST)/usr/share/man \
		PREFIX=$(TMPDEST)/usr EPREFIX=$(TMPDEST)/usr/bin \
		DOCDIR=$(TMPDEST)/usr/share/doc/polybori PYTHON=$(PYTHON) \
		RELATIVEPYPREFIX=/usr/lib/python$(lastword $(PYVERS))/site-packages \
		BOOST_PYTHON=boost_python-py$(subst .,,$(lastword $(PYVERS)))

	mkdir -p $(TMPDEST)
	scons install devel-install INSTALLDIR=$(TMPDEST)/usr/lib/polybori \
		PYINSTALLPREFIX=$(TMPDEST)$(PYTHONSITE) MANDIR=$(TMPDEST)/usr/share/man \
		PREFIX=$(TMPDEST)/usr EPREFIX=$(TMPDEST)/usr/bin \
		DOCDIR=$(TMPDEST)/usr/share/doc/polybori PYTHON=$(PYTHON) \
		RELATIVEPYPREFIX=/usr/lib/python$(lastword $(PYVERS))/site-packages \
		BOOST_PYTHON=boost_python-py$(subst .,,$*)
	touch $@

$(patsubst %,binary-install/%,$(DEB_PACKAGES)) :: binary-install/%:
	dh_pycentral -p$(cdbs_curpkg)

common-install-arch common-install-indep:: common-install-impl
common-install-impl::
	mkdir -p debian/tmp/
	mv debian/python-polybori$(lastword $(PYVERS))/* debian/tmp/
	mkdir -p debian/tmp/usr/lib
	$(foreach vers,$(PYVERS),if [ -e "debian/python-polybori$(vers)/usr/lib/python$(vers)" ]; then mv debian/python-polybori$(vers)/usr/lib/python$(vers) debian/tmp/usr/lib/; fi;)

clean::
	$(foreach vers,$(PYVERS),rm -rf debian/python-polybori$(vers);)
	scons . --keep-going --clean || true
	rm -f debian/stamp-scons-build
	rm -rf .sconf_temp/
	rm -f .sconsign.dblite
	rm -f build build-python*

