#!/usr/bin/make -f

export DH_VERBOSE = 1

export HOME = $(CURDIR)/.cache/home
export GOCACHE = $(CURDIR)/.cache/go-build
export GOPROXY = off
export GOFLAGS = -mod=mod
export GOTOOLCHAIN = local
export MAGEFILE_CACHE = $(CURDIR)/.cache/mage
export ZIG_BOOTSTRAP_CACHE = $(CURDIR)/.cache

ifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
export ZIG_BOOTSTRAP_JOBS = $(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
endif

%:
	dh $@ --buildsystem=none --without=single-binary

override_dh_auto_build:
	mage -v -d debian/magefiles all

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	./debian/tests/zig1-wasm-fibonacci "$(CURDIR)/zig1.wasm"
endif

override_dh_auto_install:
	install -D -m 0644 zig1.wasm debian/zig-wasm-bootstrap/usr/share/zig/zig1.wasm

override_dh_auto_clean:
	rm -rf .cache zig1.wasm
