#!/usr/bin/make -f

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

VERSION := $(shell dpkg-parsechangelog | egrep '^Version:' | sed 's/^Version: \([^+]*\).*/\1/')
DISTRO := $(shell dpkg-parsechangelog | egrep '^Distribution:' | sed 's/^Distribution: \([^+]*\).*/\1/')
REPORTBUG_VERSION := $(shell python -c "import reportbug; print reportbug.VERSION_NUMBER")

build: build-arch build-indep
build-arch: build-stamp
build-indep: build-stamp
build-stamp:
	dh_testdir

	# Test if versions are synchronized (only if releasing); this will bomb if not synced
	if [ "$(DISTRO)" != "UNRELEASED" -a "$(REPORTBUG_VERSION)" != "$(VERSION)" ] ; \
	then \
		echo 'Please update VERSION_NUMBER variable in reportbug/__init__.py'; exit 1 ; \
	fi

	python setup.py build

	touch build-stamp

clean:
	dh_testdir
	dh_testroot

	python setup.py clean

	rm -rf `find . -name '*~' -o -name '.#*' -o -name '*.orig' -o -name '*.rej' -o -name '*.py[co]'` sed-script
	rm -rf build
	rm -rf reportbug.egg-info

	dh_clean

install: install-stamp
install-stamp: build-stamp
	dh_testdir
	dh_testroot
	dh_prep
	dh_installdirs

	# Add here commands to install the package into debian/reportbug.
	python setup.py install --root $(CURDIR)/debian/reportbug --install-layout=deb
	mv $(CURDIR)/debian/reportbug/usr/lib $(CURDIR)/debian/python-reportbug/usr
	chmod 0755 $(CURDIR)/debian/reportbug/usr/bin/*
	cp -p conf/reportbug.conf $(CURDIR)/debian/reportbug/etc

	touch install-stamp

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

# Build architecture-independent files here.
binary-indep: build install
	dh_testdir
	dh_testroot
	dh_installdocs
	dh_installmenu
	dh_installman man/*
	dh_installchangelogs
	dh_compress
	dh_fixperms
	dh_pysupport
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

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