srcdir = @srcdir@
VPATH = $(srcdir)

include ../Makefile.inc

INSTALL= @INSTALL@
INSTALL_PROGRAM= @INSTALL_PROGRAM@
INSTALL_DATA= @INSTALL_DATA@
CC = @CC@

MSGMERGE = msgmerge

NLSPACKAGE = rpm

CATALOGS = sv.mo fr.mo de.mo pt-br.mo tr.mo fi.mo

POTFILES  = $(topsrcdir)/rpm.c 		$(topsrcdir)/query.c 		\
	$(topsrcdir)/install.c 		$(topsrcdir)/verify.c 		\
	$(topsrcdir)/checksig.c 	$(topsrcdir)/url.c		\
	$(topsrcdir)/ftp.c 	        	                  	\
	$(topsrcdir)/lib/uninstall.c	$(topsrcdir)/lib/rpmdb.c	\
	$(topsrcdir)/lib/signature.c	$(topsrcdir)/lib/dbindex.c	\
	$(topsrcdir)/lib/depends.c	$(topsrcdir)/lib/formats.c	\
	$(topsrcdir)/lib/fs.c		$(topsrcdir)/lib/header.c	\
	$(topsrcdir)/lib/lookup.c	$(topsrcdir)/lib/rebuilddb.c	\
	$(topsrcdir)/lib/messages.c	$(topsrcdir)/lib/package.c	\
	$(topsrcdir)/lib/rpmlead.c	$(topsrcdir)/lib/rpmrc.c

all: $(NLSPACKAGE).pot $(CATALOGS)

$(NLSPACKAGE).pot: $(POTFILES)
	xgettext --default-domain=$(NLSPACKAGE) \
	    --add-comments --keyword=_ --keyword=N_ $(POTFILES)
	if cmp -s $(NLSPACKAGE).po $(NLSPACKAGE).pot; then \
	    rm -f $(NLSPACKAGE).po; \
	else \
	    mv $(NLSPACKAGE).po $(NLSPACKAGE).pot; \
	fi


update-po: Makefile
	@$(MAKE) $(NLSPACKAGE).pot
	@catalogs='$(CATALOGS)'; \
	for cat in $$catalogs; do \
		lang=`echo $$cat | sed 's/.mo//'`; \
		if tupdate $(NLSPACKAGE).pot $$lang.po > $$lang.pot ; then \
			echo "tupdate of $$lang succeeded" ; \
		else \
			echo "tupdate of $$lang failed" ; \
			rm -f $$lang.pot ; \
		fi \
	done

clean:
	rm -f *mo $(NLSPACKAGE).pot

distclean: clean
	rm -f .depend Makefile

depend:

install:
	for n in $(CATALOGS); do \
	    l=`basename $$n .mo`; \
	    $(INSTALL) -m 755 -d $(installprefix)/$(RPMNLSDIR)/$$l; \
	    $(INSTALL) -m 755 -d $(installprefix)/$(RPMNLSDIR)/$$l/LC_MESSAGES; \
	    $(INSTALL) -m 644 $$n $(installprefix)/$(RPMNLSDIR)/$$l/LC_MESSAGES/rpm.mo; \
	done

%.mo: %.po
	msgfmt -o $@ $<
