# Copyright 2003, Matthias A. Benkard.

# This program 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; either version 2 of the License, or
# (at your option) any later version.
#
# This program 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.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA


.PHONY: all clean po po-update pot-update domains install

INTLTOOL_EXTRACT = intltool-extract
XGETTEXT = xgettext
MSGFMT = msgfmt -v
MSGMERGE = msgmerge
MSGMERGE_UPDATE = msgmerge --update
CP = cp
MV = mv
RM = rm -f
MKDIR = mkdir
SED = sed
INSTALL = install
PREFIX = /usr/local
LOCALEDIR = $(PREFIX)/share/locale
DESTDIR = $(PREFIX)
LOCALEDEST = $(DESTDIR)/share/locale

LANGUAGES = de en la sv
MOFILES = $(patsubst %,%.mo,$(LANGUAGES))
DOMAINFILES = $(patsubst %,.%.domain,$(LANGUAGES))
POUPDATEFILES = $(patsubst %,.%.po-update,$(LANGUAGES))

POTFILES = \
	../core/__init__.py \
	../core/common.py \
	../core/main.py \
	../core/maxima.py \
	../core/parser.py \
	\
	../gui/__init__.py \
	../gui/algebra.py \
	../gui/infodialog.py \
	../gui/main.py \
	../gui/mainwindow.py \
	../gui/plot.py \
	\
	../wxgui/__init__.py \
	../wxgui/common.py \
	../wxgui/main.py \
	../wxgui/mainwindow.py \
	../wxgui/util.py \
	../wxgui/xrcwidgets.py

all: pot-update po-update po domains

po: $(MOFILES)

%.mo: %.po
	$(MSGFMT) -o $@ $<

.%.po-update: %.po mascyma.pot
	$(MSGMERGE) $< mascyma.pot -o $<.new
	$(MV) $<.new $<
	$(RM) $<.new
	touch $@

po-update: .de.po-update .en.po-update .la.po-update .sv.po-update

pot-update: mascyma.pot

mascyma.pot: $(POTFILES) ../mascyma.glade ../mascyma.xrc
	$(INTLTOOL_EXTRACT) --type=gettext/glade --srcdir=.. mascyma.glade
	$(SED) 's,<label>,<_label>,g;s,</label>,</_label>,g' < ../mascyma.xrc > mascyma.xrc.in
	$(INTLTOOL_EXTRACT) --type=gettext/xml --srcdir=. mascyma.xrc.in
	$(XGETTEXT) --default-domain=mascyma --directory=. \
		--add-comments=TRANSLATORS: --keyword=_ --keyword=N_:1,2 \
		--copyright-holder='Stefan F. Richter and Matthias A. Benkard' \
		--msgid-bugs-address='mascyma-l10n@mbenkard.de' \
		$(POTFILES) mascyma.glade.h mascyma.xrc.in.h
	-$(RM) mascyma.glade.h
	-$(RM) mascyma.xrc.in.h
	-$(RM) mascyma.xrc.in
	$(MV) mascyma.po mascyma.pot

domains: .de.domain .en.domain .la.domain .sv.domain

.%.domain: lang=$(patsubst .%.domain,%,$@)
.%.domain: %.mo
	if test -d $(lang); then :; else $(MKDIR) $(lang); fi
	if test -d $(lang)/LC_MESSAGES; then :; else $(MKDIR) $(lang)/LC_MESSAGES; fi
	$(CP) $(lang).mo $(lang)/LC_MESSAGES/mascyma.mo
	touch $@

install: all
	for ll in $(LANGUAGES); do \
		$(INSTALL) -d $(LOCALEDEST)/$${ll}/LC_MESSAGES; \
		$(INSTALL) --mode=644 $${ll}.mo $(LOCALEDEST)/$${ll}/LC_MESSAGES/mascyma.mo; \
	done

clean:
	rm -f $(MOFILES)
	rm -f $(patsubst %,%/LC_MESSAGES/mascyma.mo,$(LANGUAGES))
	-rmdir -p $(patsubst %,%/LC_MESSAGES,$(LANGUAGES))
	rm -f $(DOMAINFILES)
	rm -f $(POUPDATEFILES)

