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

SHAREDIR=debian/unity-mail/usr/share
LOCALEDIR=$(SHAREDIR)/locale

# python3 should be last so that scripts get a correct shebang
PY3REQUESTED=$(shell py3versions -r)
PY3DEFAULT=$(shell py3versions -d)
PYTHON3=$(filter-out $(PY3DEFAULT),$(PY3REQUESTED)) python3

%:
	dh $@ --with python3

override_dh_auto_clean:
	rm -rf build UnityMail/__pycache__

override_dh_auto_build:
	set -ex; for python in $(PYTHON3); do \
		$$python setup.py build; \
	done

override_dh_auto_install:
	set -ex; for python in $(PYTHON3); do \
		$$python setup.py install --install-layout=deb --install-lib=/usr/share/unity-mail \
		--install-scripts=/usr/share/unity-mail --root=debian/tmp; \
	done
	ls po --hide *.pot | sed 's/\.po//g' | xargs -I {} -t sh -c \
	"mkdir -p $(LOCALEDIR)/{}/LC_MESSAGES/ && msgfmt po/{}.po -o $(LOCALEDIR)/{}/LC_MESSAGES/unity-mail.mo"
