#!/usr/bin/make -f
# Sample debian/rules that uses debhelper.
# GNU copyright 1997 to 1999 by Joey Hess.

PYVERS=$(shell pyversions -r debian/control)

configure: configure-stamp
configure-stamp:
	dh_testdir
	rm -f configure
	touch configure-stamp

build: configure build-stamp
build-stamp: 
	dh_testdir
	for python in $(PYVERS); do \
		$$python setup.py build ; \
	done
	for python in $(PYVERS); do \
		$$python-dbg setup.py build ; \
	done
	touch build-stamp

clean: configure
	dh_testdir
	dh_testroot 
	rm -fr *-stamp build
	for python in $(PYVERS); do \
		$$python setup.py clean ; \
	done
	dh_clean

install-arch: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs
	# psycopg2
	for python in $(PYVERS); do \
            $$python setup.py install \
		--root=$(CURDIR)/debian/python-psycopg2 --no-compile; \
	done
	for python in $(PYVERS); do \
	    $$python-dbg setup.py install \
		--root=$(CURDIR)/debian/python-psycopg2-dbg --no-compile; \
	done
	find debian/python-*-dbg ! -type d ! -name '*.so' | xargs rm -f
	find debian/python-*-dbg -depth -empty -exec rmdir {} \;

install-indep: build
	# Zope package
	dh_installzope -p zope-psycopgda2 ZPsycopgDA
	# Zope3 package
	dh_installzope -p python-psycopg2da psycopg2da

# Build architecture-independent files here.
binary-indep: build install-indep
	dh_testdir
	dh_testroot
	dh_installdocs -i AUTHORS
	dh_installchangelogs -i
	dh_link -i
	dh_compress -i
	dh_fixperms -i
	dh_pycentral -p python-psycopg2da
	dh_installdeb -i
	dh_gencontrol -i
	dh_md5sums -i
	dh_builddeb -i

# Build architecture-dependent files here.
binary-arch: build install-arch
	dh_testdir
	dh_testroot
	dh_installdocs -a README AUTHORS doc tests
	dh_installchangelogs -a ChangeLog
	dh_link -a
	dh_strip -ppython-psycopg2 --dbg-package=python-psycopg2-dbg
	rm -rf debian/python-psycopg2-dbg/usr/share/doc/python-psycopg2-dbg
	ln -s python-psycopg2 debian/python-psycopg2-dbg/usr/share/doc/python-psycopg2-dbg
	dh_compress -a
	dh_fixperms -a
	dh_makeshlibs -a
	dh_pycentral -a
	dh_python -a
	dh_installdeb -a
	dh_shlibdeps -a
	dh_gencontrol -a
	dh_md5sums -a
	dh_builddeb -a

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