#! /usr/bin/make -f
# Made with the aid of debmake, by Christoph Lameter,
# based on the sample debian/rules file for GNU hello by Ian Jackson.

packagedoc=python-pmw-doc
source_dir=$(CURDIR)/src/Pmw
package_dir=./debian/python-pmw
pdoc=./debian/python-pmw-doc
v=Pmw_1_3
PYVERS=$(shell pyversions -vr)

build: build-arch build-indep
build-arch:
build-indep: config build-stamp
build-stamp: build-all-pythons
	touch $@

build-all-pythons: $(PYVERS:%=build-python%)
	touch $@

# Build Python extensions for each version of Python
# Since the tarball is not in standard distutils format, we need to 
# execute setup.py from the src subdirectory.
build-python%:
	dh_testdir
	python$* setup.py build
	touch $@

clean: 
	dh_testdir
	-rm -f config ./setup.py ./Pmw
	-rm -rf build build-stamp build-all-pythons build-python*
	dh_clean -i

config: 
#	Make links to conventional locations for distutils in dist root
#	otherwise build will not work properly.
	ln -s src/Pmw ./Pmw
	ln -s src/setup.py ./setup.py
	touch $@

install: build-indep install-prereq install-all-pythons install-docs

install-prereq:
	dh_testdir
	dh_testroot
	dh_prep
	dh_installdirs

install-all-pythons: $(PYVERS:%=install-python%)

install-python%:
	python$* setup.py install --install-layout=deb	\
		--prefix=$(CURDIR)/debian/python-pmw/usr
	-find $(CURDIR)/debian/ -name '*.py[co]' | xargs rm -f

install-docs:
	mkdir -p $(pdoc)/usr/share/doc/$(packagedoc)/examples
	install -m 644 $(source_dir)/$(v)/demos/* 		\
		$(pdoc)/usr/share/doc/$(packagedoc)/examples/
	cp -pr $(source_dir)/$(v)/doc				\
		$(pdoc)/usr/share/doc/$(packagedoc)/html
	chmod a+x $(pdoc)/usr/share/doc/$(packagedoc)/examples/All.py

binary-indep: build-indep install
	dh_testdir
	dh_testroot
	dh_installdirs -Ai
	dh_installdocs -Ai $(source_dir)/README
	dh_installchangelogs -i $(source_dir)/$(v)/doc/changes.html
	dh_fixperms -i
	dh_compress -AiX.py
	dh_python2 -i --package=python-pmw
	dh_installdeb -i
	dh_gencontrol -i
	dh_md5sums -i
	dh_builddeb -i

binary-arch:
# There are no architecture-dependent files to be uploaded
# generated by this package.  If there were any they would be
# made here.


# Below here is fairly generic really

binary:	binary-indep binary-arch

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