#!/usr/bin/make -f

# There is a cyclic dependency between trame and trame-client in the testsuite.
# Limit testing to the basic import test.
export PYBUILD_TEST_ARGS=tests/test_import.py

# Grab versions from changelog
PACKAGE_VERSION := $(shell dpkg-parsechangelog -S Version)
DEB_UPSTREAM_VERSION := $(shell dpkg-parsechangelog -S Version | cut -d- -f1)

%:
	dh $@ --buildsystem=pybuild

override_dh_auto_build:
	@echo "Checking upstream version..."
	@VUE_APPS_UPSTREAM_FILE=debian/vue-apps/UPSTREAM_VERSION; \
	if [ ! -f "$$VUE_APPS_UPSTREAM_FILE" ]; then \
	    echo "Error: $$VUE_APPS_UPSTREAM_FILE file not found."; \
	    echo "Did you run debian/vue-apps/update.sh ?"; \
	    exit 1; \
	fi; \
	VUE_APPS_UPSTREAM_VERSION=$$(cat "$$VUE_APPS_UPSTREAM_FILE"); \
	if [ "$$VUE_APPS_UPSTREAM_VERSION" != "$(DEB_UPSTREAM_VERSION)" ]; then \
	    echo "Error: Upstream version mismatch!"; \
	    echo "  debian/changelog: $(DEB_UPSTREAM_VERSION)"; \
	    echo "  $$VUE_APPS_UPSTREAM_FILE: $$VUE_APPS_UPSTREAM_VERSION"; \
	    echo "Did you run debian/vue-apps/update.sh after importing the new upstream release?"; \
	    exit 1; \
	fi
	# Only run build if versions match
	dh_auto_build

execute_after_dh_install:
	rm debian/*/usr/lib/python3*/dist-packages/trame/modules/__init__.py
	rm debian/*/usr/lib/python3*/dist-packages/trame/ui/__init__.py
	cp /usr/share/nodejs/vue/dist/vue.min.js debian/python3-trame-client/usr/share/python3-trame-client/vue2-www/vue.global.js
