#!/usr/bin/make -f
# -*- makefile -*-
# Sample debian/rules that uses debhelper.
#
# This file was originally written by Joey Hess and Craig Small.
# As a special exception, when this file is copied by dh-make into a
# dh-make output file, you may use that output file without restriction.
# This special exception was added by Craig Small in version 0.37 of dh-make.
#
# Modified to make a template file for a multi-binary package with separated
# build-arch and build-indep targets  by Bill Allombert 2001

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

# This has to be exported to make some magic below work.
export DH_OPTIONS

# setuptools doesn't handle translated messages
export LC_ALL=C

PYVERS	:= 2.5
PYVER   := 2.5
SETUPTOOLSVER=$(shell dpkg-parsechangelog | grep 'Version:' | sed 's,Version: \(.*\)-.*,\1,g')
export PYVERS

d = debian/python2.5-setuptools

build: build-stamp
build-stamp: $(PYVERS:%=build-python%)
	touch $@
build-python%:
	python$* setup.py build
	touch $@

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp
	rm -rf build dist
	#rm -rf setuptools.egg-info
	-find -name '*.py[co]' | xargs rm -f
	dh_clean

install: build install-prereq $(PYVERS:%=install-python%)
	-find debian -name 'setuptools_boot.py*' | xargs rm -f
	-find debian -name '*.py[co]' | xargs rm -f

install-prereq:
	dh_testdir
	dh_testroot
	dh_clean -k

install-python%:
	dh_installdirs usr/bin usr/lib/python$*/site-packages
	python$* setup.py install --root=$(CURDIR)/$(d)

	mv $(d)/usr/lib/python$*/site-packages/setuptools-$(SETUPTOOLSVER)-py$*.egg-info \
	  $(d)/usr/lib/python$*/site-packages/setuptools.egg-info
	echo setuptools-$(SETUPTOOLSVER).egg-info \
	  > $(d)/usr/lib/python$*/site-packages/setuptools.pth


binary-indep: build install
binary-arch: build install
	dh_testdir
	dh_testroot
	dh_installchangelogs -i
	dh_installdocs -i -A setuptools.txt EasyInstall.txt
	dh_compress -i
	dh_fixperms -i
	: # Replace all '#!' calls to python with $(PYTHON)
	: # and make them executable
	for i in \
	  $(d)/usr/bin/easy_install \
	  `find $(d)/usr/lib -type f`; \
	do \
	  case "$$i" in *-[0-9].[0-9]) continue; esac; \
	  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
	sed -i -e 's/python2\../python2.5/g' \
		$(d)/usr/bin/easy_install-2.5
	dh_installdeb 
	dh_gencontrol 
	dh_md5sums 
	dh_builddeb

binary: binary-arch binary-indep
.PHONY: build clean binary-indep binary-arch binary install
