#!/usr/bin/make -f

# emcc writes its compiler cache to $HOME/.emscripten_cache by default, and
# $HOME is not writable in the build chroot, so keep it inside the source tree.
export EM_CACHE = $(CURDIR)/debian/emcache

# Where upstream's compile.sh puts its output.
export OUTPUT = $(CURDIR)/debian/build
export OUTPUT_FILE = quickjs-eval.js
export INPUT = $(CURDIR)/src
# The interpreter is taken from the qjs-src package: it is copied in at build
# time so that upstream's compile.sh, which compiles the sources directly, can
# be used unchanged.  debian/clean removes the copy again.
export QUICKJS = $(CURDIR)/quickjs

%:
	dh $@

override_dh_auto_configure:
	# Nothing to configure; the build is a single compiler invocation.

override_dh_auto_build:
	mkdir -p $(OUTPUT) $(QUICKJS)
	cp -a /usr/src/quickjs-ng/. $(QUICKJS)/
	# Upstream's patch for the interpreter, applied here rather than by
	# quilt: the file it patches is not part of this source package.
	patch -p1 --batch --forward < debian/quickjs-interpreter-extra-stuff.patch
	sh compile.sh

override_dh_auto_install:
	# Nothing to do; debian/install lists the files built above.

override_dh_auto_test:
	# The generated module needs a browser environment to run in.

override_dh_clean:
	dh_clean
	rm -rf $(QUICKJS)
