#!/usr/bin/make -f

PATH:=/usr/bin/dh7:/usr/bin:$(PATH)
export PATH
SBOX_REDIRECT_IGNORE=/usr/bin/perl:/usr/bin/python:/usr/bin/env:/usr/bin/help2man
export SBOX_REDIRECT_IGNORE
SBOX_REDIRECT_BINARES:=/scratchbox/tools/bin/python:/usr/bin/python2.5,$(SBOX_REDIRECT_BINARES)
export SBOX_REDIRECT_BINARIES

include /usr/share/quilt/quilt.make

PY_DEFAULT = $(strip $(shell pyversions -d))
UPSTREAM_VERSION=$(shell dpkg-parsechangelog | grep ^Version | cut -d ' ' -f 2 | cut -d '-' -f 1)

clean: unpatch
	dh clean --with=python-central
	-rm -rf api
	-rm -rf CherryPy.egg-info/
	-rm -f debian/cherryd.1

build: $(QUILT_STAMPFN)
#	PYTHONPATH=. /usr/bin/help2man -n cherryd -s 1 -o debian/cherryd.1 --version-string=$(UPSTREAM_VERSION)  ./cherrypy/cherryd
#	/usr/bin/env PYTHONPATH=`pwd` epydoc --name CherryPy3 --url http://www.cherrypy.org/ -o api cherrypy
	dh build --with=python-central


install: build
	dh install --with=python-central --before dh_pycentral

	# the 'daemonization' helper should be made available properly
	mv debian/python-cherrypy3/usr/lib/$(PY_DEFAULT)/*/cherrypy/cherryd \
		debian/python-cherrypy3/usr/sbin/
	chmod a+x debian/python-cherrypy3/usr/sbin/cherryd
	rm -f debian/python-cherrypy3/usr/lib/*/*/cherrypy/cherryd

	# no additional licensing files wanted =)
	find debian/python-cherrypy3/ -name LICENSE.txt -exec rm {} \;

	dh install --remaining --with=python-central


binary-indep: build install
	dh binary-indep --before dh_compress --with=python-central
	dh_compress -X.py -X.pdf --with=python-central
	dh binary-indep --remaining --with=python-central

override_dh_gencontrol:
	dh_gencontrol
	maemo-optify


binary-arch: build install


binary: build binary-indep binary-arch


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