#!/usr/bin/make -f

# Copyright © 2009, 2011, 2012 Jakub Wilk <jwilk@jwilk.net>
#
# This package is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 dated June, 1991.

project_name = $(shell head -n1 doc/changelog | cut -d' ' -f1)
project_version = $(shell head -n1 doc/changelog | sed -n -e 's/.*(\([0-9.]\+\)).*/\1/ p')
bugs_address = $(shell sed -n -e '/ -- \(.*\)  .*/ {s//\1/p;q}' doc/changelog)

po_files = $(wildcard po/*.po)
mo_files = $(patsubst po/%.po,locale/%/LC_MESSAGES/$(project_name).mo,$(po_files))
source_files = $(shell find -name '*.py' -o -name 'build' -prune -a -false)

xgettext_options = \
	--language=python \
	--keyword=_ --keyword=N_ \
	--package-name=$(project_name) \
	--package-version=$(project_version) \
	--msgid-bugs-address='$(bugs_address)' \
	--no-location \
	--sort-output

.PHONY: all

all: po/$(project_name).pot $(po_files) $(mo_files)

po/$(project_name).pot: $(source_files)
	xgettext $(xgettext_options) $(source_files) -o $(@)

%.po: po/$(project_name).pot
	msgmerge --no-wrap -o $(@) $(@) $(<)

locale/%/LC_MESSAGES/$(project_name).mo: po/%.po
	python setup.py build_mo

# vim:ts=4 sw=4 noet
