#!/usr/bin/make -f

#export DH_VERBOSE=1

PYVERS=$(shell pyversions -vr)
DOCS=$(shell cd docs && find ./ -maxdepth 1 -name "*.txt" -not -name "license.txt" -printf "%p " | sed "s/.txt//g")
PKGDIR=$(CURDIR)/debian/python-pastedeploy
include /usr/share/python/python.mk

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

build: build-indep
build-indep: build-docs
build-arch:

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

install: build $(PYVERS:%=install-python%)
install-python%:
	python$* setup.py install --root $(PKGDIR) \
		--single-version-externally-managed $(py_setup_install_args)
	# pth file is not needed
	find $(PKGDIR) \( -name '*.pth' -or -name 'namespace_packages.txt' \) -delete
	# move templates outside site-packages
	if [ -d $(PKGDIR)/usr/share/paster_templates ]; \
		then rm -r $(PKGDIR)$(call py_libdir,$*)/paste/deploy/paster_templates;\
	else \
		mv $(PKGDIR)$(call py_libdir,$*)/paste/deploy/paster_templates \
		   $(PKGDIR)/usr/share/;\
	fi

binary-indep: build install
	dh_testdir -i
	dh_testroot -i
	dh_installchangelogs -i docs/news.txt
	dh_installdocs -i
	dh_link usr/share/doc/python-pastedeploy/docs /usr/share/doc/python-paste/docs/deploy
	dh_python2 -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: clean build build-arch build-indep binary binary-arch binary-indep install
