#!/usr/bin/make -f

%:
	dh $@

# dummy network file for leelaz, for running the tests
debian/runtest/.local/share/leela-zero/best-network:
	mkdir -p "$$(dirname "$@")"
	python3 -c 'print("1\n" + "".join(("0 " * n).strip() + "\n" for n in [31104,192,192,192] + [331776,192,192,192] * 30 + [384,2,2,2,261364,362,192,1,1,1,92416,256,256,1]), end="")' > "$@"

# give --cpu-only for leelaz, for running the tests
debian/runtest/.config/leela-zero/lizzie-config.txt:
	mkdir -p "$$(dirname "$@")"
	echo '{ "leelaz": { "engine-command": "\/usr\/games\/leelaz --cpu-only --gtp --lagbuffer 0 --weights %network-file" } }' > "$@"

override_dh_auto_test: debian/runtest/.local/share/leela-zero/best-network debian/runtest/.config/leela-zero/lizzie-config.txt
	HOME=$(CURDIR)/debian/runtest xvfb-run -a dh_auto_test -- test -Duser.home=$(CURDIR)/debian/runtest

override_dh_auto_install:
	dh_auto_install
	sed -i -re 's/libandroid-json-org-java \(>= \w+\)/libandroid-json-org-java (>= 20121204-20090211-3)/g' \
	  debian/*.substvars

override_dh_auto_clean:
	dh_auto_clean
	$(RM) -rf $(CURDIR)/debian/runtest