#!/usr/bin/make -f

# output every command that modifies files on the build system.
#DH_VERBOSE = 1

# the following lines look redundant, but are actually needed because of ../build
.PHONY: build
build:
	dh $@

%:
	dh $@

override_dh_auto_configure:
	mkdir -p node_modules/qunit
	ln -sf /usr/share/javascript/qunit -t node_modules/qunit

override_dh_auto_build:
	mkdir -p build
	rollup -c utils/build/rollup.config.js
	rollup -c utils/build/rollup-examples.config.js
	# remove build paths
	find examples/js -name '*.js' -execdir sed -i -e 's|'"$(CURDIR)"'/||g' '{}' \;
	rollup -c test/rollup.unit.config.js
	uglifyjs -o build/three.min.js build/three.js

# Debian's qunit is too old, so this doesn't work yet.
# You can try running it manually, if you install qunit 2 locally.
_override_dh_auto_test:
	python3 -m http.server & \
	qunit-selenium open http://localhost:8000/test/unit/UnitTests.html; \
	echo $$? > test.exitcode; \
	wait
	exit $$(cat test.exitcode)

override_dh_auto_clean:
	rm -rf build
	rm -rf node_modules
