# 'make languages' will build the language files
# 'make install.languages' installs the language files at the correct place

srcdir=.
LANGUAGES=es gr
PACKAGE=setedit
prefix=$(DJDIR)
locale_dir=$(prefix)/share/locale

po_subdirs=

CFLAGS=-O

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

ifeq ($(xgettext),)
xgettext=xgettext.exe
endif

ifeq ($(msgmerge),)
msgmerge=msgmerge.exe
endif

ifeq ($(msgfmt),)
msgfmt=msgfmt.exe
endif

ifeq ($(libintl),)
libintl=libintl.a
endif

po_list:
	perl makelist.pl

clean:
	rm -f potfiles.po
	rm -f $(addsuffix .mo,$(LANGUAGES))
	rm -f $(addsuffix .po,$(LANGUAGES))

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

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

$(addsuffix .po,$(LANGUAGES)): potfiles.po
	if not exist $(T) cp $^ $@
	-$(msgmerge) --force-po -o __.pon $@ $^
	-update __.pon $@
	rm -f __.pon
	
#$(addsuffix .mo,$(LANGUAGES)): $(msgfmt)

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


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

# This creates the .po files for each language from $(LANGUAGES)
# See the sample translated file de.po, how to translate
languages.src: $(addsuffix .po,$(LANGUAGES))

#if you don't have the fileutils 3.13, you must copy the files manually
%.ins: %.mo
	ginstall -d $(locale_dir)/$*/LC_MESSAGES
	-ginstall $< $(locale_dir)/$*/LC_MESSAGES/$(PACKAGE).mo

install.languages.start:
	rm -f languages.log

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

