#!/usr/bin/make -f

RJS ?= /usr/lib/nodejs/requirejs/r.js
ALMOND ?= /usr/share/nodejs/almond/almond.js

STROPHE=strophe.js
STROPHE_MIN=strophe.min.js
STROPHE_LIGHT=strophe-no-polyfill.js

DEB_UPSTREAM_VERSION ?= $(shell dpkg-parsechangelog \
	| sed -rne 's/^Version: ([0-9.]+)[-+].*$$/\1/p')

%:
	dh $@

override_dh_auto_build:
	node $(RJS) -o build.js name=$(ALMOND) insertRequire=strophe-polyfill include=strophe-polyfill out=$(STROPHE_MIN)
	sed -i "s/@VERSION@/$(DEB_UPSTREAM_VERSION)/" $(STROPHE_MIN)
	node $(RJS) -o build.js name=$(ALMOND) optimize=none insertRequire=strophe-polyfill include=strophe-polyfill out=$(STROPHE)
	sed -i "s/@VERSION@/$(DEB_UPSTREAM_VERSION)/" $(STROPHE)
	node $(RJS) -o build.js name=$(ALMOND) optimize=none out=$(STROPHE_LIGHT)
	sed -i "s/@VERSION@/$(DEB_UPSTREAM_VERSION)/" $(STROPHE_LIGHT)

override_dh_auto_test:
	echo "Skip dh_auto_test"

override_dh_auto_clean:
	dh_auto_clean
	rm -f strophe*.js
