#!/usr/bin/make -f

# Copyright © 2009-2015 Jakub Wilk <jwilk@jwilk.net>
#
# This file is part of djvusmooth.
#
# djvusmooth is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 as published
# by the Free Software Foundation.
#
# djvusmooth is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.

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)

gettext_common_options = \
	--add-location=file \
	--sort-output \
	--no-wrap \

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

msgmerge_options = \
	$(gettext_common_options) \
	--update \
	--verbose \

.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 $(msgmerge_options) $(@) $(<)

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

# vim:ts=4 sts=4 sw=4 noet
