#!/usr/bin/make -f
#this file was shamelessly copied and adapted from python-imaging 

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

PYVERS=$(shell pyversions -vr)
PYVER   := $(shell python -c 'import sys; print sys.version[:3]')


clean:
	dh_testdir
	dh_testroot
	rm -f *-stamp xdelta3 *.o *.so
	rm -rf compile build
	find -name '*.py[co]' -or -name semantic.cache -exec rm -f {} \;
	dh_clean

build:
	make xdelta3

install-prereq:
	dh_testdir
	dh_testroot
	dh_clean -k

install-python%:
	make xdelta3module.so PYVER=$*
	mkdir -p debian/python-xdelta3/usr/lib/python$*/site-packages
	install -o root -g root -m 644 \
		xdelta3module.so xdelta3.py \
                debian/python-xdelta3/usr/lib/python$*/site-packages
	rm  -f 	*.o *.so 


install: build install-prereq $(PYVERS:%=install-python%)
	: # Replace all '#!' calls to python with /usr/bin/python
	: # and make them executable
	for i in `find debian -mindepth 3 -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

# Build architecture-independent files here.
# Pass -i to all debhelper commands in this target to reduce clutter.
binary-indep: build install
	dh_testdir -i
	dh_testroot -i
#	dh_installdebconf -i
	dh_installdocs -i
	dh_installexamples -i
#	dh_installmenu -i
#	dh_installman -i
#	dh_installinfo -i
#	dh_undocumented -i
	dh_installchangelogs -i
	dh_python2 -i
	dh_link -i
	dh_compress -i -X.py
	dh_fixperms -i
	dh_installdeb -i
	dh_gencontrol -i
	dh_md5sums -i
	dh_builddeb -i

# Build architecture-dependent files here.
binary-arch: build install
	dh_testdir -a
	dh_testroot -a
	dh_install -a
#	dh_installdebconf -a
	dh_installdocs -a
	dh_installexamples -a
#	dh_installmenu -a
	dh_installman -a xdelta3.1
#	dh_installinfo -a
#	dh_undocumented -a
	dh_installchangelogs -a
	dh_python2 -a -ppython-xdelta3
	dh_strip -a
	dh_link -a
	dh_compress -a -X.py
	dh_fixperms -a
	dh_installdeb -a
	dh_shlibdeps -a
	dh_gencontrol -a
	dh_md5sums -a
	dh_builddeb -a

binary: binary-arch
# no binary-indep so far
.PHONY: build clean binary-indep binary-arch binary install
