# Copyright (C) 2001,2002 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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@

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= 	msgfmt
MSGMERGE=	msgmerge

# CVS available languages
LANGUAGES=	cs de es et fi fr hu it ja ko lt nl no pt_BR ru sv
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:

catalogs: $(TARGETS)

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

install: doinstall

# we should depend on the .mo files instead of making them!
doinstall: 
	@for d in $(LANGDIRS); \
	do \
	    dir=$(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 $(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=$(prefix)/messages/$$d/LC_MESSAGES; \
	    $(INSTALL) -m $(FILEMODE) $$po $$mo $$dir; \
	done

finish:

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

distclean: clean
	-rm -f Makefile

catclean:
	-rm -f Makefile */LC_MESSAGES/mailman.mo */LC_MESSAGES/mailman.po.old $(POTFILE)
	-rm *.pot

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/$@)

mailman.pot: 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"
	-mv $@ $@.old && $(MSGMERGE) -o $@ $@.old mailman.pot


FORCE:
