# bashisms in real-check
SHELL = /bin/bash

LINGUAS := $(shell cd po; ls *.po| cut -d'.' -f1)
MOFILES := $(patsubst %.po,%.mo,$(wildcard po/*.po))

all: apt-listbugs.1 $(MOFILES)

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

real-check:
	: > tests/log/SUMMARY 
	set -e; set -o pipefail; for A in test_*.rb; do echo $$A; ( ./$$A  2>&1 | tee tests/log/$${A/*\//}.log ) && echo "[OK] $$A" >> tests/log/SUMMARY || echo "[NG] $$A" >> tests/log/SUMMARY ; done
	set -e; set -o pipefail; for A in tests/???_*.sh; do echo $$A; ( bash $$A  2>&1 | tee tests/log/$${A/*\//}.log ) && echo "[OK] $$A" >> tests/log/SUMMARY || echo "[NG] $$A" >> tests/log/SUMMARY ; done
	cat tests/log/SUMMARY

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

update-po:
	xgettext --add-comments=TRANSLATORS --language=python apt-listbugs lib/apt-listbugs/logic.rb -o po/apt-listbugs.pot
	for po in $(LINGUAS); do \
	  msgmerge -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

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 $@ $<

.PHONY: update-po real-check clean all install
