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

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

PYVERS:= $(shell pyversions -v --requested debian/control)

build: build-stamp

	gzip -9 < RELEASE_NOTES.txt > changelog.gz
	gzip -9 < debian/changelog > changelog.Debian.gz

build-stamp: $(PYVERS:%=build-stamp-%)
	touch $@

build-stamp-%:
	dh_testdir
	python$* setup.py build
	touch $@


clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp* install-stamp*
	-rm -rf build
	-rm -f changelog.gz changelog.Debian.gz

	dh_clean
	: # Delete some possible dirt
	-find -name '*.py[co]' | xargs rm -f

install: install-stamp
install-stamp-%: build-stamp-%
	dh_testdir
	dh_testroot
	python$* setup.py install --prefix=$(CURDIR)/debian/python-tables/usr --no-compile
	rm -f $(CURDIR)/debian/python-tables/usr/bin/*
	touch $@

install-stamp: build $(PYVERS:%=install-stamp-%)
	dh_testdir
	dh_testroot

# Build architecture-independent files here.
binary-indep: install
	dh_testdir
	dh_testroot
	: # remove executables from doc package
	dh_installdocs -ppython-tables-doc -Xmake -Xgenerahtml.sh README.txt changelog.gz changelog.Debian.gz ANNOUNCE.txt doc/usersguide.pdf doc/html bench/ examples/
	dh_compress -i -X.py -X.h5
	dh_fixperms -i
	dh_installdeb -i
	dh_gencontrol -i
	dh_md5sums -i
	dh_builddeb -i

binary-arch: build install
	dh_testdir
	dh_testroot
	dh_install -ppython-tables --sourcedir=utils/ ptdump ptrepack /usr/bin
	gzip -9 < debian/ptdump.1 > /tmp/ptdump.1.gz
	gzip -9 < debian/ptrepack.1 > /tmp/ptrepack.1.gz
	dh_installman -ppython-tables /tmp/ptdump.1.gz /tmp/ptrepack.1.gz
	dh_installdocs -ppython-tables README.txt changelog.gz changelog.Debian.gz ANNOUNCE.txt
	dh_pycentral -ppython-tables

	dh_strip -a
	dh_compress -a -X.py -X.h5
	dh_fixperms -a
	dh_installdeb -a
	#dh_shlibdeps -a
	# In order to automatically add the Depends, Recommends & Suggests
	# fields automatically.
	dh_shlibdeps -ppython-tables -X _comp_ -- \
	    -dRecommends \
	      debian/python-tables/usr/lib/python*/site-packages/tables/_comp_bzip2.so \
	      debian/python-tables/usr/lib/python*/site-packages/tables/_comp_lzo.so \
	    -dDepends
#	    -dSuggests \
#	      debian/python-tables/usr/lib/python*/site-packages/tables/_comp_ucl.so \

	dh_gencontrol -a
	dh_md5sums -a
	dh_builddeb -a

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