#
# Generic PHP gettext .mo extractor and .po compiler makefile
#

SRCDIRS = ../www
DESTDIR = ../www/lib/locale
PODIR = .
APPLICATION = ftpstats

MSGFMT = msgfmt --statistics -c -v -o
MSGMERGE = msgmerge -i

all: clean install

install:
	@echo " >> Compiling locales:";

	@for LOCALE in `ls *.po | grep -v 'messages\.po' | sed 's/\..*//g'`; do \
		echo " >> $${LOCALE}"; \
			if ./shtool mkdir -p ${DESTDIR}/$${LOCALE}/LC_MESSAGES; then \
				if ${MSGFMT} ${DESTDIR}/$${LOCALE}/LC_MESSAGES/${APPLICATION}.mo ${PODIR}/$${LOCALE}.po; then \
					echo " >> $${LOCALE} OK"; \
				else \
					echo; \
					echo " >> >> >> $${LOCALE} FAILED"; \
					echo; \
				fi \
			else \
				echo; \
				echo " >> >> >> Error creating locale directory for ${LOCALE}."; \
			fi \
	done;

# Update the .po files so they are in sync with the source tree
update:
	@echo " >> Generating messages.po..."
	@if perl php2po.pl ${SRCDIRS}; then \
		echo " >> messages.po OK"; \
	else \
		echo " >> >> >> messages.po FAILED"; \
	fi;

	@echo " >> Updating locales: "

	@for LOCALE in `ls *.po | grep -v 'messages\.po' | sed 's/\..*//g'`; do \
		echo " >> $${LOCALE} "; \
		if ${MSGMERGE} -o ${PODIR}/$${LOCALE}.po ${PODIR}/$${LOCALE}.po messages.po; then \
			echo " >> $${LOCALE} OK"; \
		else \
			echo; \
			echo " >> >> >> $${LOCALE} FAILED"; \
		fi; \
	done;


# delete all generated files
clean:
	rm -rf ${DESTDIR}

