LINGUAS := $(shell cd po; ls *.po| cut -d'.' -f1)
MOFILES := $(patsubst %.po,%.mo,$(wildcard po/*.po))
VERSION := $(shell env LC_ALL=C dpkg-parsechangelog | sed -n 's/^Version: //p')

.PHONY: all
all: apt-listbugs.1 $(MOFILES)

.PHONY: clean
clean:
	find -name '*~' | xargs rm -f -- 
	rm -f tests/log/tmp
	rm -f apt-listbugs.1
	rm -f $(MOFILES)

.PHONY: check
check:
	./test_logic.rb

apt-listbugs.1: apt-listbugs
	rd2 -r rd/rd2man-lib.rb -o apt-listbugs apt-listbugs

.PHONY: update-po
update-po: po/apt-listbugs.pot
	for po in $(LINGUAS); do \
	  msgmerge --no-wrap -U po/$$po.po po/apt-listbugs.pot; \
	done
	for po in $(LINGUAS); do \
	  echo -n $$po ": "; \
	  msgfmt -v po/$$po.po -o /dev/null; \
	done

po/apt-listbugs.pot: apt-listbugs lib/apt-listbugs/logic.rb
	xgettext --add-comments=TRANSLATORS --no-wrap \
	         --copyright-holder="Masato Taruishi et al." \
	         --package-name=apt-listbugs --package-version=$(VERSION) \
	         --msgid-bugs-address=$$DEBEMAIL \
	         --language=python \
	         apt-listbugs lib/apt-listbugs/logic.rb \
	         -o po/apt-listbugs.pot

.PHONY: call-for-translation
call-for-translation:
	podebconf-report-po --call --withtranslators \
	                    --conf po/.podebconf-report-po.conf

.PHONY: install
install:
	# Add here commands to install the package into debian/apt-listbugs.
	for mo in $(MOFILES); do \
	  install -d $(DESTDIR)/usr/share/locale/`basename $$mo .mo`/LC_MESSAGES; \
	  install -m644 $$mo $(DESTDIR)/usr/share/locale/`basename $$mo .mo`/LC_MESSAGES/apt-listbugs.mo; \
	done

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

