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

# MX Linux releases are named after their base Debian codename (e.g. MX 25 is
# based on Trixie); OBS builds the same source for multiple Debian repos, so
# append that release suffix to the version here on Trixie builds only.
override_dh_auto_configure:
	if [ "$$(sed -n 's/^VERSION_CODENAME=//p' /etc/os-release 2>/dev/null)" = "trixie" ] && \
	   ! grep -q 'mx25)' debian/changelog; then \
		sed -i '1s/^\(mx-tools ([^)]*\))/\1mx25)/' debian/changelog; \
	fi
	dh_auto_configure -- \
		-G Ninja \
		-DCMAKE_BUILD_TYPE=Release \
		-DCMAKE_EXPORT_COMPILE_COMMANDS=ON

override_dh_auto_clean:
	dh_auto_clean
	rm -rf build/
	rm -f translations/*.qm

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

# Do not create package-private .dwz debug data.
override_dh_dwz:
	@:

override_dh_auto_install:
	# Install is handled by debian/install file
	dh_auto_install

override_dh_gencontrol:
	# Mirror CMakeLists.txt: Settings moved from Qt.labs.settings into QtCore
	# in Qt 6.5, so the package must depend on whichever module the build
	# actually embedded into Main.qml.
	QT6_VERSION=$$(dpkg-query -W -f='$${Version}' qt6-base-dev); \
	if dpkg --compare-versions "$$QT6_VERSION" ge 6.5; then \
		SETTINGS_DEP=qml6-module-qtcore; \
	else \
		SETTINGS_DEP=qml6-module-qt-labs-settings; \
	fi; \
	echo "qml:SettingsDepends=$$SETTINGS_DEP" >> debian/mx-tools.substvars; \
	dh_gencontrol

%:
	dh $@ --buildsystem=cmake+ninja --no-automatic-dbgsym
