#!/usr/bin/make -f
# Debian repack of the upstream openchamber AppImage (binary
# re-distributor, same payload policy as the RPM spec: /opt/openchamber
# install, APPDIR wrapper through AppRun, repointed desktop entry, SVG
# icon, 0755 chrome-sandbox). No network at build time: the orig tarball
# holds the upstream AppImage, extracted with --appimage-extract (no FUSE).
%:
	dh $@

override_dh_auto_configure:
	:

override_dh_auto_build:
	:

override_dh_auto_test:
	: # desktop entry is validated post-install by the RPM %check and by
	: # docker-sweep on the built .deb; validating debian/<pkg>/... here
	: # runs BEFORE auto_install stages the files (same ordering trap
	: # localsend avoids with a no-op test).

override_dh_auto_install:
	chmod +x "$$(ls *.AppImage)" && ./"$$(ls *.AppImage)" --appimage-extract >/dev/null && mv squashfs-root appimage-root
	mkdir -p debian/openchamber/opt/openchamber debian/openchamber/usr/bin debian/openchamber/usr/share/applications
	cp -ar appimage-root/* debian/openchamber/opt/openchamber/
	chmod 0755 debian/openchamber/opt/openchamber/chrome-sandbox
	printf '#!/bin/sh\nexport APPDIR="/opt/openchamber"\nexec /opt/openchamber/AppRun "$$@"\n' > debian/openchamber/usr/bin/openchamber
	chmod 0755 debian/openchamber/usr/bin/openchamber
	sed -e 's|^Exec=.*|Exec=/usr/bin/openchamber %U|' -e 's|^Icon=.*|Icon=openchamber|' \
	    appimage-root/openchamber.desktop > debian/openchamber/usr/share/applications/openchamber.desktop
	install -Dm644 appimage-root/openchamber.svg debian/openchamber/usr/share/icons/hicolor/scalable/apps/openchamber.svg

# Binary repack: the payload is prebuilt upstream, so automatic
# shlibdeps analysis cannot run (bundled Electron/Chromium tree) and its
# ${shlib:Depends} output is unused -- the manually maintained Depends
# (derived from the payload's ELF DT_NEEDED union) IS the dependency
# declaration. Same as stoat-desktop/vesktop rules.
override_dh_shlibdeps:
	:

# Prebuilt upstream binaries are already stripped and carry no usable
# debuginfo -- and the payload even contains foreign-arch (linux-arm64,
# musl) .node files that make objcopy fail. Skip stripping; same class
# as the RPM-side debuginfo exclusion for repackaged binaries.
override_dh_strip:
	:

# Prebuilt upstream binaries are already stripped and carry no
# usable debuginfo -- dwz aborts on them. Skip it; same pattern as
# stoat-desktop/vesktop/helium-browser/obsidian/fluxer rules.
override_dh_dwz:
	:
