#!/usr/bin/make -f

here = $(dir $(firstword $(MAKEFILE_LIST)))/..
upstream_version = $(shell cd $(here) && dpkg-parsechangelog | sed -n -r -e '/^Version: (.+)([+]dfsg).*/ { s//\1/; p; q; }')

.PHONY: override_dh_auto_build
override_dh_auto_build:
	$(MAKE) cmap
	dh_auto_build
	echo '#' > pdfminer/cmap/__init__.py

.PHONY: override_dh_install
override_dh_install:
	rename.ul .py '' debian/tmp/usr/bin/*.py
	dh_install

.PHONY: override_dh_installman
override_dh_installman:
	$(MAKE) -C debian/manpages/
	dh_installman

.PHONY: override_dh_auto_test
override_dh_auto_test:
ifeq ($(filter nocheck,$(DEB_BUILD_OPTIONS)),)
	set -e -x; \
	for python in $(shell pyversions -r); do \
		$$python /usr/bin/nosetests --with-doctest --verbose pdfminer/*.py; \
		$(MAKE) -C samples clean; \
		$(MAKE) -C samples PYTHON=$$python CMP="diff -u" HTMLS_NONFREE= TEXTS_NONFREE= XMLS_NONFREE= test; \
	done
endif

.PHONY: override_dh_installchangelogs
override_dh_installchangelogs:
	elinks -config-file /dev/null -dump -no-numbering -no-references docs/index.html \
	| sed -n -e '/^Changes/,/^  ---/ { /^     / s/// p }' \
	> docs/changelog
	dh_installchangelogs docs/changelog

.PHONY:
get-orig-source:
	sh -x $(here)/debian/get-orig-source.sh $(upstream_version)

.PHONY: build build-arch build-indep binary binary-arch binary-indep clean
build build-arch build-indep binary binary-indep clean:
	dh $(@) --with python2 -Spython_distutils
# In order not to confuse lintian, binary-arch is a separate target:
binary-arch:

# vim:ts=4 sw=4 noet
