#!/usr/bin/make -f

# Verbose mode
#export DH_VERBOSE=1

PYVERS := $(shell pyversions -s)

%:
	dh $@ --with python2

override_dh_auto_clean:
	find . -name "*.py[co]" -exec rm -f {} \;

override_dh_auto_install:
	set -e; \
	for PY in $(PYVERS); do \
	    $$PY setup.py install --root `pwd`/debian/python-iplib \
	         --install-scripts usr/share/doc/python-iplib/examples/ \
			 --install-layout=deb; \
	done
	# Replace all '#!' calls to python with /usr/bin/python
	# and make them executable
	set -e; \
	for i in `find debian/python-iplib -type f`; do \
	  sed '1s,#!.*python[^ ]*\(.*\),#! /usr/bin/python\1,' \
		$$i > $$i.temp; \
	  if cmp --quiet $$i $$i.temp; then \
	    rm -f $$i.temp; \
	  else \
	    mv -f $$i.temp $$i; \
	    chmod 755 $$i; \
	    echo "fixed interpreter: $$i"; \
	  fi; \
	done
