#!/usr/bin/make -f

# Fix hardening-no-bindnow and hardening-no-pie
export DEB_BUILD_MAINT_OPTIONS = hardening=+bindnow,+pie

%:
	dh $@ --buildsystem=cmake

override_dh_auto_configure:
	# mgba-qt has to be linked with -latomic on some architectures.
	# Adding it here as a workaround until the issue is fixed upstream.
	# The library is dropped by --as-needed on arches where it isn't needed.
	# https://github.com/mgba-emu/mgba/issues/2324
	# CMAKE_POLICY_VERSION_MINIMUM is for compatibility with CMake 4 (#1113284).
	# The next upstream release will bump cmake_minimum_required.
	dh_auto_configure -- \
		-DCMAKE_INSTALL_PREFIX:PATH=/usr \
		-DLIBDIR=/usr/lib/$(DEB_HOST_MULTIARCH) \
		-DCMAKE_SKIP_RPATH=ON \
		-DBUILD_LIBRETRO=ON \
		-DCMAKE_CXX_STANDARD_LIBRARIES=-latomic \
		-DCMAKE_POLICY_VERSION_MINIMUM=3.5

override_dh_auto_install:
	dh_auto_install
	rm -rf debian/tmp/usr/include/mgba-util/platform/3ds/ \
		debian/tmp/usr/include/mgba-util/platform/psp2/ \
		debian/tmp/usr/include/mgba-util/platform/switch/ \
		debian/tmp/usr/include/mgba-util/platform/windows/

override_dh_installchangelogs:
	dh_installchangelogs -k CHANGES
