# Copyright (C) 2001-2007 by the Free Software Foundation, Inc.
#
# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

# NOTE: Makefile.in is converted into Makefile by the configure script
# in the parent directory.  Once configure has run, you can recreate
# the Makefile by running just config.status.
#
# NOTE: You should ordinarily never need to run "make catalogs", but
# if you find you do, you will need GNU make, and the GNU gettext
# suite (e.g. msgfmt, msgmerge).

# Variables set by configure

VPATH=		@srcdir@
srcdir= 	@srcdir@
bindir= 	@bindir@
prefix=   	@prefix@
exec_prefix=	@exec_prefix@
DESTDIR=

CC=		@CC@
CHMOD=  	@CHMOD@
INSTALL=	@INSTALL@

DEFS=   	@DEFS@

# Customizable but not set by configure

OPT=		@OPT@
CFLAGS=		$(OPT) $(DEFS)
PACKAGEDIR= 	$(prefix)/messages
SHELL=		/bin/sh
DIRSETGID=	chmod g+s
MSGFMT= 	@PYTHON@ ../build/bin/msgfmt.py
MSGMERGE=	msgmerge

# CVS available languages
LANGUAGES=	ar ast ca cs da de el es et eu fi fr gl he hr hu ia it ja ko \
		lt nl no pl pt pt_BR ro ru sk sl sr sv tr uk vi zh_CN zh_TW
LANGDIRS=	$(LANGUAGES:%=messages/%/LC_MESSAGES)
# Human readable po file
POFILES=	$(LANGUAGES:%=%/LC_MESSAGES/mailman.po)
# Binary generated mo file
MOFILES=	$(LANGUAGES:%=%/LC_MESSAGES/mailman.mo)
TARGETS=	$(MOFILES)

# Modes for directories and executables created by the install
# process.  Default to group-writable directories but
# user-only-writable for executables.
DIRMODE=	775
EXEMODE=	755
FILEMODE=	644
INSTALL_PROGRAM=$(INSTALL) -m $(EXEMODE)
PROG=		@PYTHON@ build/bin/pygettext.py

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

# Rules

all: mofiles

catalogs: $(TARGETS)

check:
	@for file in $(POFILES); \
	do \
		echo "Checking $$file"; \
		msgfmt -o /dev/null --statistics -v $$file; \
	done

install: doinstall

doinstall: mofiles
	@for d in $(LANGDIRS); \
	do \
	    dir=$(DESTDIR)$(prefix)/$$d; \
	    echo "Creating language directory $$dir"; \
	    $(srcdir)/../mkinstalldirs $$dir; \
	    chmod $(DIRMODE) $$dir; \
	    $(DIRSETGID) $$dir; \
	done
	@for d in $(LANGUAGES); \
	do \
	    readme=$(srcdir)/$$d/README.$$d; \
	    if test -f $$readme; \
	    then \
		$(INSTALL) -m $(FILEMODE) $$readme $(DESTDIR)$(prefix)/messages/$$d; \
	    fi; \
	done
	@for d in $(LANGUAGES); \
	do \
	    po=$(srcdir)/$$d/LC_MESSAGES/mailman.po; \
	    mo=$(srcdir)/$$d/LC_MESSAGES/mailman.mo; \
	    dir=$(DESTDIR)$(prefix)/messages/$$d/LC_MESSAGES; \
	    $(INSTALL) -m $(FILEMODE) $$po $$dir; \
 	    $(INSTALL) -m $(FILEMODE) $$mo $$dir; \
	done

mofiles: $(MOFILES)

finish:

clean:
	-rm -f */LC_MESSAGES/mailman.mo

fileclean:
	-rm -f marked.files docstring.files

potclean: fileclean
	-rm -f Makefile $(POTFILE)

distclean: clean potclean
	-rm -f Makefile

marked.files:
	@echo "Calculating marked input files for pygettext"
	(cd ..; find Mailman -path '*pythonlib' -prune -o -path '*Commands/cmd_*.py' -prune -o -name '*.py' -print >| messages/$@)

docstring.files:
	@echo "Calculating script input files for pygettext"
	(cd ..; grep -d skip -l -i '^#! .*python.*' `find bin cron scripts -name ".#*" -prune -o -print` | grep -v pygettext >| messages/$@)
	(cd ..; ls Mailman/Commands/cmd_*.py >> messages/$@)

potfile: marked.files docstring.files
	@echo "Running pygettext on $@; this make take a while."
	(cd ..; $(PROG) -p messages -d mailman -D -X messages/marked.files `cat messages/marked.files messages/docstring.files`)

# Update the individual mailman.po files with the new changes to the
# .pot file
%/LC_MESSAGES/mailman.po: mailman.pot
	@echo "Merging new template file with existing translations"
	$(MSGMERGE) -U $@ mailman.pot || touch $@


FORCE:
