#!/usr/bin/make -f

source = $(shell find src/ -name '*.js')
timestamp = $(shell date --iso-8601=minutes --utc --date="$(shell dpkg-parsechangelog -S Date)" | sed -e 's/+00:\?00/Z/')
version = $(shell dpkg-parsechangelog -SVersion | cut -d - -f 1)

override_dh_auto_build: dist/jquery.js dist/jquery.min.js dist/jquery.min.map
	dh_auto_build

override_dh_auto_test:
	nodejs --check dist/jquery.js
	nodejs --check dist/jquery.min.js
	./debian/tests/check-minification dist/jquery.min.js

build.js: debian/build.js
	cp $< $@

dist/jquery.js: build.js $(source)
	nodejs /usr/lib/nodejs/r.js -o build.js
	sed -i -e 's/@DATE/$(timestamp)/; s/@VERSION/$(version)/' $@

dist/jquery.min.js dist/jquery.min.map: dist/jquery.js
	uglifyjs \
		--source-map dist/jquery.min.map \
		--source-map-url jquery.min.map \
		--output dist/jquery.min.js \
		$^
	sed -i -e '/\/\/# sourceMappingURL=\S\+/ d' dist/jquery.min.js

override_dh_auto_clean:
	$(RM) -rf dist/
	$(RM) build.js
	dh_auto_clean

%:
	dh $@
