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

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

VERSION := $(shell dpkg-parsechangelog | grep '^Version: ' | awk '{print $$2}')

%.py: %.py.in
	sed -e 's/__CHANGELOG_VERSION__/$(VERSION)/' < $< > $@

build: build-stamp
build-stamp: setup.py
	dh_testdir

	# Add here commands to compile the package.
	python setup.py build
	python3 setup.py build
	
	# run the tests
	cd tests && ./test_deb822.py
	cd tests && ./test_debfile.py
	cd tests && ./test_debtags.py
	cd tests && ./test_changelog.py
	cd tests && ./test_debian_support.py
	cd tests && python3 ./test_deb822.py
	cd tests && python3 ./test_debfile.py
	cd tests && python3 ./test_debtags.py
	cd tests && python3 ./test_changelog.py
	cd tests && python3 ./test_debian_support.py

	lib/debian/doc-debtags > README.debtags

	touch $@

clean: setup.py
	dh_testdir
	dh_testroot
	rm -f build-stamp

	# Add here commands to clean up after the build process.
	python setup.py clean
	python3 setup.py clean
	rm -rf lib/python_debian.egg-info
	rm -rf build/
	rm -f README.debtags
	rm -f setup.py
	find lib/debian -type f -name '*.pyc' -exec rm {} \;

	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_clean
	dh_installdirs

	# Add here commands to install the package into debian/tmp
	python setup.py install --root="$(CURDIR)/debian/python-debian" --no-compile --install-layout=deb
	python3 setup.py install --root="$(CURDIR)/debian/python3-debian" --no-compile --install-layout=deb


# Build architecture-independent files here.
binary-indep: build install
	dh_testdir
	dh_testroot
	dh_installchangelogs
	dh_installdocs
	dh_installexamples
	# TODO: Enrico would like to keep wxssearch out of the package
	# but so far, he has no better place for it
	#rm "$(CURDIR)/debian/python-debian/usr/share/doc/python-debian/examples/wxssearch"
	rm "$(CURDIR)/debian/python-debian/usr/share/doc/python-debian/examples/debtags/wxssearch"
#	dh_install
	dh_compress -Xexamples
	dh_fixperms
	dh_python2
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

# Build architecture-dependent files here.
binary-arch: build install
# We have nothing to do by default.

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