#!/usr/bin/make -f
# Build sshpilot with pybuild (Debian Python Library Style Guide), plus the
# desktop-app bits (launcher, .desktop, AppStream metainfo, icon) that live
# outside the Python wheel.

#export DH_VERBOSE = 1
export PYBUILD_NAME = sshpilot

%:
	dh $@ --with python3 --buildsystem=pybuild

# The upstream test suite is a GUI/integration suite that imports optional
# backends (e.g. vendor/pyxtermjs → flask) and needs a display; it is not a
# build-time check. Skip it so the package builds in a clean chroot.
override_dh_auto_test:

# The wheel ships the importable package (incl. resources/*.gresource); these
# extra files are installed by the Flatpak manifest at pack time, so we replay
# them here for the .deb.
override_dh_install:
	dh_install
	install -D -m0644 io.github.mfat.sshpilot.desktop \
	  debian/sshpilot/usr/share/applications/io.github.mfat.sshpilot.desktop
	install -D -m0644 io.github.mfat.sshpilot.metainfo.xml \
	  debian/sshpilot/usr/share/metainfo/io.github.mfat.sshpilot.metainfo.xml
	install -D -m0644 sshpilot/resources/sshpilot.svg \
	  debian/sshpilot/usr/share/icons/hicolor/scalable/apps/io.github.mfat.sshpilot.svg
	install -D -m0755 sshpilot-agent debian/sshpilot/usr/bin/sshpilot-agent
	# /usr/bin/sshpilot launcher: run the installed module. Unlike the Flatpak
	# launcher it does NOT export SSHPILOT_FLATPAK, so system behaviour is used.
	install -d debian/sshpilot/usr/bin
	printf '#!/bin/sh\nexec python3 -m sshpilot.main "$$@"\n' \
	  > debian/sshpilot/usr/bin/sshpilot
	chmod 0755 debian/sshpilot/usr/bin/sshpilot

# Use the system xterm.js from libjs-xterm rather than the bundled copy: drop
# the bundled assets from the binary package (the app resolves the system
# /usr/share/javascript/xterm at runtime). Runs after dh_python3 has finalised
# the dist-packages layout so the path is stable. Keeps the .deb free of
# embedded JavaScript.
execute_after_dh_python3:
	rm -rf debian/sshpilot/usr/lib/python3*/dist-packages/sshpilot/vendor/pyxtermjs/xterm
