srcdir = @srcdir@
VPATH = $(srcdir)

include $(srcdir)/../Makefile.inc

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

MSGMERGE = msgmerge

NLSPACKAGE = rpm

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

POTFILES  = $(topdir)/rpm.c 		$(topdir)/query.c 		\
	    $(topdir)/install.c 	$(topdir)/verify.c 		\
	    $(topdir)/checksig.c 					\
	    $(topdir)/lib/uninstall.c	$(topdir)/lib/rpmdb.c		\
	    $(topdir)/lib/signature.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//'`; \
		mv $$lang.po $$lang.old.po; \
		echo "$$lang:"; \
		if $(MSGMERGE) $$lang.old.po $(NLSPACKAGE).pot -o $$lang.po; then \
		rm -f $$lang.old.po; \
	else \
    		echo "msgmerge for $$cat failed!"; \
		rm -f $$lang.po; \
		mv $$lang.old.po $$lang.po; \
	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 $@ $<
