#!/usr/bin/make -f
export QT_SELECT=6

QMAKE_OPTS = DEFINES+=NO_DEBUG_ON_CONSOLE
MAKE_OPTS  = QMAKE=qmake6 QMAKE_OPTS="$(QMAKE_OPTS)"
DEB_BUILD_VERSION := $(shell dpkg-parsechangelog -S Version)

override_dh_auto_clean:
	dh_auto_clean
	-find manual src/manual -name '*.gz' -delete || true
	-find translations src/translations -name '*.qm' -delete || true

override_dh_auto_configure:
	qmake6 mx-snapshot.pro

override_dh_auto_build:
	/usr/lib/qt6/bin/lrelease translations/*.ts
	@# Backup version.h if it exists
	[ -f version.h ] && mv version.h version.h~ || true
	echo "const QString VERSION {\"$(DEB_BUILD_VERSION)\"};" > version.h
	gzip -kf manual/mx-snapshot.8 manual/iso-snapshot-cli.8
	# Build mx-snapshot
	dh_auto_build
	mv mx-snapshot mx-snapshot-binary
	# Clean, reconfigure, and build iso-snapshot-cli
	[ -f version.h~ ] && mv version.h~ version.h || true
	dh_auto_clean
	[ -f version.h ] && mv version.h version.h~ || true
	echo "const QString VERSION {\"$(DEB_BUILD_VERSION)\"};" > version.h
	rm -f mx-snapshot.pro Makefile
	qmake6 iso-snapshot-cli.pro
	dh_auto_build
	# Before installing, move binary back and make a iso-snapshot-cli copy of .list file
	mv mx-snapshot-binary mx-snapshot
	cp -f mx-snapshot-exclude.list iso-snapshot-cli-exclude.list
	dh_auto_build -- $(MAKE_OPTS)

override_dh_auto_install:
	dh_auto_install -- $(MAKE_OPTS)

override_dh_shlibdeps:
	dh_shlibdeps --dpkg-shlibdeps-params=--ignore-missing-info

execute_after_dh_builddeb:
	[ -f version.h~ ] && mv version.h~ version.h || true

%:
	dh $@ --no-automatic-dbgsym
