#!/usr/bin/make -f
# -*- mode: makefile; coding: utf-8 -*-
# Copyright © 2006 Sergio Talens-Oliag <sto@debian.org>

include /usr/share/cdbs/1/rules/debhelper.mk

# Replace version on the shell library program
binary-post-install/ssft::
	sed -i -e "s%@VERSION@%$(DEB_NOEPOCH_VERSION)%g; \
	           s%@PACKAGE@%ssft%g;                   \
		   s%@LOCALEDIR@%/usr/share/locale%g" \
	  debian/$(cdbs_curpkg)/usr/bin/ssft.sh

# Build & install locale files (the locale files should be named after the
# package they belong to, this code applies to all the packages)
$(patsubst %,binary-post-install/%,$(DEB_PACKAGES)) :: binary-post-install/%: binary-install/%
	for po in `ls po/*.po 2> /dev/null`; do \
	  lang="`echo $$po | sed -e 's@^po/@@;s@.po$$@@'`"; \
	  ldir="debian/$(cdbs_curpkg)/usr/share/locale/$$lang/LC_MESSAGES"; \
	  mkdir -p $$ldir; \
	  msgfmt "$$po" -o "$$ldir/$(cdbs_curpkg).mo"; \
	done

# Special rules for package developers (L10N)
SHELL_FILES=src/ssft.sh tests/ssft-test.sh
pot: update-pot
update-pot:
	rm -f "po/ssft.pot";
	# Generate new .pot file
	xgettext -L Shell -o "po/ssft.pot" $(SHELL_FILES);
	# Update .po files
	for f in `ls po/*.po 2> /dev/null`; do \
	  echo "Updating '$$f' file";  \
	  msgmerge -U $$f po/ssft.pot; \
          echo "$$f: `msgfmt -o /dev/null --statistics $$f 2>&1`"; \
	done
