#!/usr/bin/make -f

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

PYVER=$(shell pyversions -vd)
SUPP=$(shell python$(PYVER) -c 'import pysupport; print " ".join(pysupport.py_supported)')

clean::
	rm -f debhelper/dh_pysupport.1 *.py[co]

build/python-support::
	cd debhelper && pod2man -c "python-support" -r "$(DEB_VERSION)" dh_pysupport dh_pysupport.1

binary-install/python-support::
	for ver in $(SUPP); do \
          if dpkg --compare-versions $$ver ge python2.6; then \
            subdir=dist-packages ; \
          else \
            subdir=site-packages ; \
          fi ; \
	  mkdir -p debian/python-support/usr/lib/$$ver/$$subdir ;\
	  ln -s ../../pymodules/$$ver/.path debian/python-support/usr/lib/$$ver/$$subdir/python-support.pth ;\
	done
	: # Replace all '#!' calls to python with /usr/bin/pythonX.Y
	for i in `find debian/python-support -type f`; do \
	  sed '1s,#!.*python[^ ]*\(.*\),#! /usr/bin/python$(PYVER)\1,' $$i > $$i.temp; \
	  if ! cmp --quiet $$i $$i.temp; then \
	    cat $$i.temp > $$i; \
	    echo "fixed interpreter: $$i"; \
	  fi; \
	  rm -f $$i.temp; \
	done
