#!/usr/bin/make -f
# Debian repack of the upstream stoat .zip (binary re-distributor, same
# payload policy as the RPM spec: /opt/Stoat install, Wayland wrapper,
# setuid chrome-sandbox, static desktop/icon/metainfo from debian/).
# No network at build time: the orig tarball holds the upstream .zip.
%:
	dh $@

override_dh_auto_configure:
	:

override_dh_auto_build:
	:

# Prebuilt upstream binaries are already stripped and carry no
# usable debuginfo -- dwz aborts on them (exit 25). Skip it; same
# class as the RPM-side debuginfo exclusion for repackaged binaries.
# Binary repack: the payload is prebuilt upstream, so automatic
# shlibdeps analysis cannot run (buildroot holds none of the
# runtime libs) and its ${shlib:Depends} output is unused -- the
# manually maintained Depends above (derived from the payload's
# ELF DT_NEEDED union) IS the dependency declaration.
override_dh_shlibdeps:
	:

override_dh_dwz:
	:

override_dh_auto_test:
	desktop-file-validate debian/chat.stoat.StoatDesktop.desktop

override_dh_auto_install:
	unzip -q "$$(ls *.zip)" -d ziproot
	mkdir -p debian/stoat-desktop/opt/Stoat debian/stoat-desktop/usr/bin debian/stoat-desktop/usr/share/applications debian/stoat-desktop/usr/share/metainfo
	cp -a ziproot/Stoat-linux-x64/* debian/stoat-desktop/opt/Stoat/
	install -Dm0644 debian/chat.stoat.StoatDesktop.desktop debian/stoat-desktop/usr/share/applications/chat.stoat.StoatDesktop.desktop
	install -Dm0644 icon.png debian/stoat-desktop/usr/share/icons/hicolor/256x256/apps/chat.stoat.StoatDesktop.png
	install -Dm0644 debian/chat.stoat.StoatDesktop.metainfo.xml debian/stoat-desktop/usr/share/metainfo/chat.stoat.StoatDesktop.metainfo.xml
	printf '#!/bin/sh\nif [ "$$XDG_SESSION_TYPE" = "wayland" ] || [ -n "$$WAYLAND_DISPLAY" ]; then\n    export ELECTRON_OZONE_PLATFORM_HINT="auto"\nfi\nexec /opt/Stoat/stoat-desktop "$$@"\n' > debian/stoat-desktop/usr/bin/stoat-desktop
	chmod 0755 debian/stoat-desktop/usr/bin/stoat-desktop
	chmod 4755 debian/stoat-desktop/opt/Stoat/chrome-sandbox
