# Copyright (C) 1996,1997 Robert Hhne, see COPYING.RH for details 
# This file is part of RHIDE. 
ifeq ($(strip $(RHIDESRC)),)
error You must set the environment variable RHIDESRC
endif

srcdir=$(RHIDESRC)/po
VPATH=$(srcdir)

project=
po_files=
src_files=$(po_files) msgcat.c msgcat.gpr msgcat.mak makefile \
	$(addsuffix .po,$(LANGUAGES)) $(addsuffix .cat,$(LANGUAGES)) \
	readme.lan

update_files=msgcat.gpr msgcat.mak
cfg_files=msgcat.gpr msgcat.mak

subdirs=
po_subdirs=..
obj_subdirs=

include $(RHIDESRC)/common.mak

ifeq ($(xgettext),)
xgettext=$(top_dir)/gettext/src/xgettext.exe
endif

ifeq ($(msgmerge),)
msgmerge=$(top_dir)/gettext/src/msgmerge.exe
endif

ifeq ($(msgfmt),)
msgfmt=$(top_dir)/gettext/src/msgfmt.exe
endif

ifeq ($(libintl),)
libintl=$(top_dir)/gettext/intl/libintl.a
endif

_po_list: po_list
	sed -e 's,^../,,' -e 's, ../, ,g' po_list > _po_list
	rm -f po_list

#potfiles.po: _po_list $(xgettext)
#	$(xgettext) --default-domain=dummy --add-comments --keyword=_ \
#	  --keyword=__ --directory=$(RHIDESRC) --omit-header \
#	  --add-location @_po_list
#	touch dummy.po
#	update dummy.po $@
#	rm dummy.po _po_list

potfiles.po: _po_list $(xgettext)
	$(xgettext) --default-domain=potfiles --add-comments --keyword=_ \
	  --keyword=__ --directory=$(RHIDESRC) --omit-header \
	  --add-location @_po_list
	touch $@
	rm -f _po_list

T=$(subst /,\,$@)

#$(addsuffix .po,$(LANGUAGES)): $(msgmerge) potfiles.po
#	if not exist $(T) cp -p $(word 2,$^) $@
#	-$(msgmerge) -f -o __.pon $@ $(word 2,$^)
#	-cp -bp -V t $@ $(subst .po,.po~,$@)
#	-update __.pon $@
#	rm -f __.pon

# I'm using now my own program to merge previous translations
# the rule here translates only the exact matchings. If you 
# want translate all the needed strings, look in the file
# msgcat.c for a description of it's usage
MSGCAT_OPTIONS=-s

$(addsuffix .po,$(LANGUAGES)): potfiles.po msgcat.exe
	-cp -f $@ $(subst .po,.bak,$@)
	msgcat.exe $(MSGCAT_OPTIONS) -cat $(subst .po,.cat,$@) \
	  $(wildcard $@) $< $@
	
$(addsuffix .mo,$(LANGUAGES)): $(msgfmt)

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

languages: $(addsuffix .mo,$(LANGUAGES))

languages.src: $(addsuffix .po,$(LANGUAGES))

$(top_dir)/gettext/intl/libintl.a \
$(top_dir)/gettext/intl/libintl.h \
$(top_dir)/gettext/intl/intl-compat.o:
	$(MAKE) -C $(top_dir)/gettext/intl $(notdir $@)

$(top_dir)/gettext/src/xgettext \
$(top_dir)/gettext/src/msgfmt \
$(top_dir)/gettext/src/msgmerge: \
				$(top_dir)/gettext/intl/libintl.a \
				$(top_dir)/gettext/lib/libnlsut.a \
				$(top_dir)/gettext/intl/libintl.h \
				$(top_dir)/gettext/intl/intl-compat.o
	$(MAKE) -C $(top_dir)/gettext/src $(FLAGS_TO_PASS) $(notdir $@)

$(top_dir)/gettext/lib/libnlsut.a \
$(top_dir)/gettext/lib/fstrcmp.o: $(top_dir)/gettext/intl/libintl.h
	$(MAKE) -C $(top_dir)/gettext/lib $(FLAGS_TO_PASS) $(notdir $@)

$(top_dir)/gettext/src/xgettext.exe: $(top_dir)/gettext/src/xgettext
$(top_dir)/gettext/src/msgmerge.exe: $(top_dir)/gettext/src/msgmerge
$(top_dir)/gettext/src/msgfmt.exe: $(top_dir)/gettext/src/msgfmt

xgettext:
msgmerge:
msgfmt:
libintl:

.PHONY: needed

needed: 	$(top_dir)/gettext/intl/libintl.a \
		$(top_dir)/gettext/intl/intl-compat.o \
		$(top_dir)/gettext/intl/libintl.h \
		$(top_dir)/gettext/lib/libnlsut.a \
		$(xgettext) $(msgfmt)

%.ins: %.mo
	ginstall -d $(locale_dir)/$*/LC_MESSAGES
	ginstall $< $(locale_dir)/$*/LC_MESSAGES/$(PACKAGE).mo
	echo $(subst $(prefix)/,,$(locale_dir)/$*/LC_MESSAGES/$(PACKAGE).mo) \
	  >> $(logfile)

install.languages.start:
	rm -f $(logfile)

install.languages: languages install.languages.start \
	  $(addsuffix .ins,$(LANGUAGES))

install: install.languages

msgcat.exe: $(top_dir)/gettext/lib/fstrcmp.o

include msgcat.mak

%.zip: %.po
	rm -f $@
	zip -9j $@ $< $(subst .po,.cat,$<) potfiles.po msgcat.exe $(msgfmt) \
	  $(srcdir)/readme.lan
	
$(addsuffix .zip,$(LANGUAGES)): msgcat.exe $(msgfmt)

lang_packages: $(addsuffix .zip,$(LANGUAGES))
