#!/usr/bin/make -f
# -*- makefile -*-

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

%:
	dh $@

# this is quite fragile here --ie8 is needed
_prelude.js: prelude.js
	uglifyjs --wrap-iife -c side_effects=false -c screw_ie8=false --verbose --ie8 --passes=5 -m --source-map -o _prelude.js -- prelude.js
	sed -i 's/;[[:space:]]*$$//g' _prelude.js

override_dh_auto_build: _prelude.js

ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS) $(DEB_BUILD_PROFILES)))
override_dh_auto_test:
	tap -R spec test/*.js
else
override_dh_auto_test:
	@echo '**********************************************************'
	@echo 'Skip test                  '
	@echo '**********************************************************'
endif

override_dh_fixperms:
	dh_fixperms
	chmod a+x debian/node-browser-pack/usr/lib/nodejs/browser-pack/bin/cmd.js

example/output.js: _prelude.js example/input.json
	./bin/cmd.js < example/input.json > example/output.js

example/sourcemap/output.js: _prelude.js example/sourcemap/input.json
	./bin/cmd.js < example/sourcemap/input.json > example/sourcemap/output.js


override_dh_installexamples: example/output.js example/sourcemap/output.js
	dh_installexamples


override_dh_auto_clean:
	dh_auto_clean
	rm -f _prelude.js
	rm -f example/output.js
	rm -f example/sourcemap/output.js
