# $Id: Makefile 65252 2009-05-12 15:45:05Z mihxil $


KUPU_HOME=..
XSLTPROC = /usr/bin/env xsltproc

XSL_DEBUG = --param debug true\(\)
XSLTPROC_PARAMS = --nonet --novalid --xinclude
XSL_FILE=$(KUPU_HOME)/make.xsl
XSLJSPX_FILE=$(KUPU_HOME)/make-jspx.xsl
I18N=$(KUPU_HOME)/kupu-i18n.jar

LANGS=nl de fr it eo

VERSION=`cat ../version.txt | awk '{print $$2}'`
#type in i18n: msginit -l <locale> -i messages.po


all: index.jspx body.jspx head.jspx mmbase-kupu-i18n.jar i18n.js/i18n.js


index.jspx: *.kupu  Makefile $(XSLJSPX_FILE)
	$(XSLTPROC) $(XSLTPROC_PARAMS) -o $@  $(XSLJSPX_FILE) dist-mmbase.kupu

body.jspx: *.kupu  Makefile $(XSLJSPX_FILE)
	$(XSLTPROC) $(XSLTPROC_PARAMS) -o $@  $(XSLJSPX_FILE) body-mmbase.kupu

head.jspx: *.kupu  Makefile $(XSLJSPX_FILE)
	$(XSLTPROC) $(XSLTPROC_PARAMS) -o $@  $(XSLJSPX_FILE) head-mmbase.kupu

$(I18N):
	@$(MAKE) -C $(KUPU_HOME) kupu-i18n.jar

i18n.js/i18n.js:
	wget http://johnnydebris.net/javascript/.files/i18n.js-0.1.tar.gz
	tar zxf i18n.js-0.1.tar.gz


.PHONY:
messages: *.js clean
	rm -f phony.js
	grep -r "fmt:message" *.jspx *.kupu | sed 's/.*key="\(.*\)".*/_("\1");/g' | uniq > phony.js
	mkdir -p i18n
	xgettext --from-code=UTF-8 -L java -k_ -p i18n -j *.js -o en.po
	for LOCALE in $(LANGS) ; do \
	   msgmerge --update --backup=off i18n/$${LOCALE}.po i18n/en.po; \
	done

mmbase-kupu-i18n.jar: i18n/*.po
	mkdir -p resourcebundle
	for LOCALE in $(LANGS) en ; do \
	    msgfmt --java2  -D . -d resourcebundle -r org.mmbase.kupu.Messages -l $${LOCALE} i18n/$${LOCALE}.po; \
	done
	jar cf $@ -C resourcebundle org

webapp: all deploy.jars
	mkdir -p build/mmbase/kupu/mmbase
	cp -pr *.jspx *.js *.css build/mmbase/kupu/mmbase
	cp -rpf tools build/mmbase/kupu/mmbase
	cp -rpf drawers build/mmbase/kupu/mmbase
	cp -rpf icons build/mmbase/kupu/mmbase
	cp -rpf ../common build/mmbase/kupu
	mkdir -p build/WEB-INF/lib
	cp $(HOME)/.m2/repository/org/oscom/kupu-i18n/$(VERSION)/kupu-i18n-$(VERSION).jar build/WEB-INF/lib
	cp $(HOME)/.m2/repository/org/oscom/mmbase-kupu-i18n/$(VERSION)/mmbase-kupu-i18n-$(VERSION).jar build/WEB-INF/lib


mmbase-kupu.war: webapp
	( cd build ; find . -regex '.*/\.svn.*' -o -type f -print | xargs jar cf ../mmbase-kupu.war  )


.PHONY:
deploy.jars: $(I18N) mmbase-kupu-i18n.jar
	mvn deploy:deploy-file -DgeneratePom.description='Resource bundle with translations of kupu-generic texts' -DgroupId=org.oscom -DartifactId=kupu-i18n        -Dversion=$(VERSION) -Dpackaging=jar -Dfile=$(I18N) -Durl=scp://mmbase.org/home/mmweb/web/maven2 -DrepositoryId=mmbase
	mvn deploy:deploy-file -DgeneratePom.description='Resource bundle with translations specific to kupu/mmbase' -DgroupId=org.oscom -DartifactId=mmbase-kupu-i18n -Dversion=$(VERSION) -Dpackaging=jar -Dfile=mmbase-kupu-i18n.jar -Durl=scp://mmbase.org/home/mmweb/web/maven2 -DrepositoryId=mmbase

.PHONY:
deploy: mmbase-kupu.war
	mvn deploy:deploy-file -DgeneratePom.description='WAR-overlay containing all necessary files to use kupu with MMBase. The mmbase-richtext component depends on this.' -DgroupId=org.oscom -DartifactId=mmbase-kupu      -Dversion=$(VERSION) -Dpackaging=war -Dfile=mmbase-kupu.war -Durl=scp://mmbase.org/home/mmweb/web/maven2 -DrepositoryId=mmbase


clean:
	rm -f index.jspx
	rm -f body.jspx	head.jspx
	rm -f mmbase-kupu-i18n.jar
	rm -f mmbase-kupu.war
	rm -rf resourcebundle
	rm -rf build
	@$(MAKE) -C $(KUPU_HOME) clean
