#!/usr/bin/make -f

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

ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
        MAKEARGS += OPTFLAGS=-O0
endif

VERSION = $(shell dpkg-parsechangelog | sed -n 's/^Version: //p')

PO_FILES = $(wildcard po/*.po)
MO_FILES = $(PO_FILES:.po=.mo)

DEST = debian/debreaper
DESTLOCALE = $(DEST)/usr/share/locale

build: $(MO_FILES) debreaper.png
	$(MAKE) -C viaticum $(MAKEARGS)

%.mo: %.po
	msgfmt -o $@ $<
%.png: %.svg
	rsvg $< $@

install: build
	dh_testdir
	dh_testroot
	dh_install
	sed -i s/@VERSION@/$(VERSION)/g $(DEST)/usr/share/debreaper/*
	for i in $(MO_FILES); do \
		lang=$$(basename $$i | sed s/\.mo$$//) ; \
		install -d -m 755 $(DESTLOCALE)/$$lang/LC_MESSAGES ; \
		install -m 644 $$i $(DESTLOCALE)/$$lang/LC_MESSAGES/debreaper.mo ; \
	done

clean:
	dh_testdir
	dh_testroot
	-$(MAKE) -C viaticum clean
	xgettext -LPython -k_ -o po/debreaper.pot *.py debreaper
	dh_clean debreaper.png po/*.mo *.pyc
	debconf-updatepo

binary-indep:
binary-arch: build install
	dh_testdir
	dh_testroot
	dh_installdocs TODO
	dh_installchangelogs
	dh_installdebconf
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
	dh_pysupport
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

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