#!/usr/bin/make -f
# Sample debian/rules that uses debhelper.
# GNU copyright 1997 to 1999 by Joey Hess.

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

# Include dpatch targets
include /usr/share/dpatch/dpatch.make

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

DEST=$(CURDIR)/debian/nicotine
DESTLOCALE=$(DEST)/usr/share/locale

PYVERS=$(shell pyversions -vs)


build: patch-stamp $(MO_FILES) $(PYVERS:%=build-stamp-python%)

build-stamp-python%:
	dh_testdir
	cp -r trayicon trayicon-$*
	cd trayicon-$* && python$* autogen.py && make
	touch $@

%.mo: %.po
	msgfmt -o $@ $<

clean: unpatch
	dh_testdir
	dh_testroot
	find languages -name \*.mo | xargs rm -f
	rm -rf trayicon-*
	dh_clean debian/dirs build-stamp-*

install-clean:
	dh_testdir
	dh_testroot
	dh_clean -k

install-python%: build-stamp-python%
	dh_testdir
	dh_testroot
	cd trayicon-$* && make install DESTDIR=$(DEST)

install: build install-clean $(PYVERS:%=install-python%)
	dh_install
	cd languages && \
	    for i in */; do \
	      mkdir -p $(DESTLOCALE)/$${i}LC_MESSAGES/; \
	      cp $${i}*.mo $(DESTLOCALE)/$${i}LC_MESSAGES/; \
	    done

binary-indep:

binary-arch: build install
	dh_testdir
	dh_testroot
	dh_installdocs
	dh_installmenu
	dh_installman
	dh_installchangelogs doc/CHANGELOG
	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 install-clean
