#!/usr/bin/make -f
# Debian repack of the upstream vesktop .rpm (binary re-distributor, same
# payload policy as the RPM spec: /opt/Vesktop install, Wayland wrapper,
# Exec repointed at the wrapper, setuid chrome-sandbox like the spec).
# No network at build time: the orig tarball holds the upstream .rpm;
# debian/rpm2tree.py (stdlib-only, copy of tools/rpm2tree.py) materializes
# the payload tree.
%:
	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:
	:

override_dh_auto_install:
	python3 debian/rpm2tree.py "$$(ls *.rpm)" payload
	mkdir -p debian/vesktop/opt/Vesktop debian/vesktop/usr/bin debian/vesktop/usr/share
	cp -a payload/opt/Vesktop/* debian/vesktop/opt/Vesktop/
	cp -a payload/usr/share/applications debian/vesktop/usr/share/
	cp -a payload/usr/share/icons debian/vesktop/usr/share/
	printf '#!/bin/sh\nif [ "$$XDG_SESSION_TYPE" = "wayland" ] || [ -n "$$WAYLAND_DISPLAY" ]; then\n    export ELECTRON_OZONE_PLATFORM_HINT="auto"\nfi\nexec /opt/Vesktop/vesktop "$$@"\n' > debian/vesktop/usr/bin/vesktop
	chmod 0755 debian/vesktop/usr/bin/vesktop
	sed -i 's|^Exec=.*|Exec=/usr/bin/vesktop %U|' debian/vesktop/usr/share/applications/vesktop.desktop
	chmod 4755 debian/vesktop/opt/Vesktop/chrome-sandbox
