#!/usr/bin/make -f

build: build-arch build-indep
build-arch: build-stamp
build-indep: build-stamp

build-stamp:
	dh_testdir
	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp
	dh_clean

binary-indep: build

binary-arch: build
	dh_testdir
	dh_testroot
	dh_prep
	dh_installdirs
	cp -a usr/* debian/imageviewer/opt/ImageViewer
	ln -s /opt/ImageViewer/share/applications/com.github.aliencoweatcake.imageviewer.desktop debian/imageviewer/usr/share/applications/com.github.aliencoweatcake.imageviewer.desktop
	sed -i 's|^Exec=ImageViewer|Exec=/opt/ImageViewer/bin/ImageViewer|' debian/imageviewer/opt/ImageViewer/share/applications/com.github.aliencoweatcake.imageviewer.desktop
	find debian/imageviewer/opt/ImageViewer/share/icons -name 'com.github.aliencoweatcake.imageviewer.*' -print | while read -r ICON_PATH ; do \
		ICON_LINK_TARGET=$$(echo $${ICON_PATH} | sed 's|^debian/imageviewer||') ; \
		ICON_LINK_PATH=$$(echo $${ICON_PATH} | sed 's|/opt/ImageViewer/|/usr/|') ; \
		mkdir -p $$(dirname $${ICON_LINK_PATH}) ; \
		ln -s $${ICON_LINK_TARGET} $${ICON_LINK_PATH} ; \
	done
	dh_fixperms
	dh_installdeb
	dh_shlibdeps \
		--exclude=debian/imageviewer/opt/ImageViewer/lib/libQt6Qml.so.6 \
		--exclude=debian/imageviewer/opt/ImageViewer/lib/libQt6QmlModels.so.6 \
		--exclude=debian/imageviewer/opt/ImageViewer/lib/libQt6Quick.so.6 \
		--exclude=debian/imageviewer/opt/ImageViewer/lib/libQt6QuickControls2.so.6 \
		--exclude=debian/imageviewer/opt/ImageViewer/lib/libQt6QuickTemplates2.so.6 \
		--exclude=debian/imageviewer/opt/ImageViewer/lib/libQt6VirtualKeyboard.so.6 \
		--exclude=debian/imageviewer/opt/ImageViewer/lib/libQt6WaylandClient.so.6 \
		--exclude=debian/imageviewer/opt/ImageViewer/lib/libQt6WaylandEglClientHwIntegration.so.6 \
		--exclude=debian/imageviewer/opt/ImageViewer/lib/libQt6WlShellIntegration.so.6 \
		--exclude=debian/imageviewer/opt/ImageViewer/lib/libadwaitaqt6.so.1 \
		--exclude=debian/imageviewer/opt/ImageViewer/lib/libadwaitaqt6priv.so.1 \
		--exclude=debian/imageviewer/opt/ImageViewer/lib/libqgnomeplatform6.so \
		--exclude=debian/imageviewer/opt/ImageViewer/lib/libqt5ct-common.so.1 \
		--exclude=debian/imageviewer/opt/ImageViewer/lib/libqt6ct-common.so.0 \
		--exclude=debian/imageviewer/opt/ImageViewer/plugins/audio \
		--exclude=debian/imageviewer/opt/ImageViewer/plugins/bearer \
		--exclude=debian/imageviewer/opt/ImageViewer/plugins/mediaservice \
		--exclude=debian/imageviewer/opt/ImageViewer/plugins/networkinformation \
		--exclude=debian/imageviewer/opt/ImageViewer/plugins/platforminputcontexts/libqtvirtualkeyboardplugin.so \
		--exclude=debian/imageviewer/opt/ImageViewer/plugins/platforms/libqwayland-egl.so \
		--exclude=debian/imageviewer/opt/ImageViewer/plugins/platforms/libqwayland-generic.so \
		--exclude=debian/imageviewer/opt/ImageViewer/plugins/platformthemes \
		--exclude=debian/imageviewer/opt/ImageViewer/plugins/styles \
		--exclude=debian/imageviewer/opt/ImageViewer/plugins/wayland-decoration-client \
		--exclude=debian/imageviewer/opt/ImageViewer/plugins/wayland-graphics-integration-client \
		--exclude=debian/imageviewer/opt/ImageViewer/plugins/wayland-shell-integration
	sed -i 's|\(libpulse-mainloop-glib0\) (>= \([0-9]*\):\([0-9\.]*\))|\1 (>= \2:\3) \| \1 (>= \3)|' debian/imageviewer.substvars
	sed -i 's|\(libpulse0\) (>= \([0-9]*\):\([0-9\.]*\))|\1 (>= \2:\3) \| \1 (>= \3)|' debian/imageviewer.substvars
	dh_gencontrol
	dh_md5sums
	dh_builddeb

source diff:
	@echo >&2 'source and diff are obsolete - use dpkg-source -b'; false

binary: binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary
