#!/usr/bin/make -f

#export DH_VERBOSE=1

PYVERS=$(shell pyversions -vr)
DOCS=$(shell cd docs && find ./ -name "*.txt" -printf "%p " | sed "s/.txt//g")

clean:
	dh_testdir
	dh_testroot
	rm -rf dist build
	find . -name '*\.py[co]' -delete
	dh_clean build-docs $(PYVERS:%=install-python%)

build: build-docs

build-docs:
	dh_installdirs
	for NAME in $(DOCS); do \
	    rst2html --cloak-email-addresses --no-toc-backlinks "docs/$$NAME.txt" \
	      > "debian/python-pastewebkit/usr/share/doc/python-pastewebkit/docs/$$NAME.html"; \
	done
	touch $@

install: build $(PYVERS:%=install-python%)
	dh_install

install-python%:
	python$* setup.py install --prefix=/usr \
		--single-version-externally-managed \
		--root $(CURDIR)/debian/python-pastewebkit \
		--install-lib=/usr/lib/python$*/site-packages
	# pth file is not needed since all paste* packages are installed in the same directory
	rm -f debian/python-pastewebkit/usr/lib/python$*/site-packages/*.pth
	# installed to /usr/share/paster_templates/ via dh_install
	rm -rf debian/python-pastewebkit/usr/lib/python$*/site-packages/paste/webkit/paster_templates/
	# provided by paste-common package:
	rm -f debian/python-pastewebkit/usr/lib/python$*/site-packages/paste/__init__.py

binary-indep: build install
	dh_testdir -i
	dh_testroot -i
	dh_installchangelogs -i
	dh_installdocs -i
	dh_link usr/share/doc/python-pastewebkit/docs /usr/share/doc/python-paste/docs/webkit
	dh_pysupport -i
	dh_compress -i -X.py
	dh_fixperms -i
	dh_installdeb -i
	dh_gencontrol -i
	dh_md5sums -i
	dh_builddeb -i -- -Z bzip2

binary-arch:

binary: binary-indep binary-arch

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