#!/usr/bin/make -f

DESTDIR="$(CURDIR)/debian/rhinote"
BINDIR="$(DESTDIR)/usr/bin"
ICONDIR="$(DESTDIR)/usr/share/icons/hicolor"

build: build-arch build-indep
build-arch:
build-indep: build-indep-stamp
build-indep-stamp:
	dh_testdir
	pandoc -s -w man -o rhinote.1 debian/rhinote.1.text
	touch $@

binary: binary-arch binary-indep
binary-arch: build-arch
binary-indep: build-indep
	dh_testdir
	dh_testroot
	dh_prep
	dh_install
	mv "$(BINDIR)/rhinote.py" \
	   "$(BINDIR)/rhinote"
	mv "$(ICONDIR)/32x32/apps/rhinote_32x32.png" \
	   "$(ICONDIR)/32x32/apps/rhinote.png"
	mv "$(ICONDIR)/48x48/apps/rhinote_48x48.png" \
	   "$(ICONDIR)/48x48/apps/rhinote.png"
	dh_installchangelogs 
	dh_installdocs
	dh_installman
	dh_installmenu
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_gencontrol
	dh_md5sums
	dh_builddeb

clean:
	dh_testdir
	dh_testroot
	rm -f build-indep-stamp
	dh_clean

# Rebuild the series file by looking at the contents of the patches directory.
#
# Patches with names starting with D (Debian-specific) should be applied
# after those with names starting with U (to be forwarded upstream).
rebuild-series:
	@( \
		SERIES=debian/patches/series; \
		echo "# To rebuild this file, use \`debian/rules $@'" \
			> $${SERIES}; \
		for patch in debian/patches/U*.diff debian/patches/D*.diff; \
		do \
			test -f "$${patch}" || continue; \
			patch=$$(basename $${patch}); \
			echo $${patch} \
				>> $${SERIES}; \
		done; \
	)

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