#!/usr/bin/make -f
# -*- makefile -*-

UPVER=$(shell dpkg-parsechangelog  | grep ^Version | cut -d\  -f2 | cut -d- -f1)

VERSION = __import__('pkg_resources').get_distribution('CouchDB').version

%:
	dh $@ \
		-Spython_distutils \
		--with python2

override_dh_auto_build:
	sed -i -e "s/$(VERSION)/\"$(UPVER)\"/" couchdb/__init__.py
	touch couchdb/tools/__init__.py
	dh_auto_build -- build_sphinx
	
	chmod 755 couchdb-* couchpy
	help2man -N -n "a CouchDB dump utility" ./couchdb-dump > couchdb-dump.1
	help2man -N -n "a CouchDB load utility" ./couchdb-load > couchdb-load.1
	help2man -N -n "a CouchDB Python view server" ./couchpy > couchpy.1

override_dh_auto_install:
	dh_auto_install -- --single-version-externally-managed

	-rm -rf $(CURDIR)/debian/usr/share/doc/python-couchdb/html/_static/jquery.js

override_dh_clean:
	dh_clean
	-rm -rf doc/build
	-rm -rf CouchDB.egg-info/

	sed -i -e "s/\"$(UPVER)\"/$(VERSION)/" couchdb/__init__.py

.PHONY: get-orig-source
get-orig-source:
	uscan --force-download --rename --download-version=$(UPVER) --destdir .
