# Create Portable Object Template

# Because of the way variables are evaluated, one need to build the
# "init" target before to build the .pot file

FILES_SOURCES = $(shell find sources -type f -iname "*.js")
FILES_TRANSFORMED = $(FILES_SOURCES:sources/%.js=transformed/%.php)
PACKAGE=czmr
POT_FILE=$(PACKAGE).pot
LANGS=fr_FR it_IT es_ES
PO_FILES=$(LANGS:%=%.po)

.PHONY: all clean init

all: $(POT_FILE) $(PO_FILES)

init:
	rsync -a --delete-excluded --include="*.js" --exclude="po/" --exclude="CVS" --include="*/" --exclude="*" ../ sources
	rsync -a --delete-excluded --include="*/" --exclude="*" sources/ transformed


transformed/%.php: sources/%.js
	(echo "<?php"; cat $^; echo "?>") > $@

$(POT_FILE): $(FILES_TRANSFORMED)
	xgettext -o $@ $(FILES_TRANSFORMED)

%.po: $(POT_FILE)
	for i in $(LANGS); do\
		if msgmerge $$i.po czmr.pot > $$i.tmp; then\
			mv $$i.tmp $$i.po;\
		else\
			echo "msgmerge failed with $$i.po";\
		fi\
	done

clean:
	rm -f $(POT_FILE)
	rm -rf sources transformed
	rm -f *~
