#!/usr/bin/make -f

NULL =

DEB_HOST_ARCH=$(shell dpkg-architecture -qDEB_HOST_ARCH)
DEB_FDK_SUPPORT=$(shell dpkg-query -s libfdk-aac-dev 2>&1 >/dev/null; echo $$?)
DEB_SDL3_SUPPORT=$(shell dpkg-query -s libsdl3-dev libsdl3-image-dev libsdl3-ttf-dev 2>&1 >/dev/null; echo $$?)

ifeq ($(DEB_FDK_SUPPORT),0)
	AAC_SUPPORT = -DWITH_FDK_AAC=ON
endif
ifeq ($(DEB_SDL3_SUPPORT),0)
	SDL3_SUPPORT = -DWITH_CLIENT_SDL3=ON
else
	SDL3_SUPPORT = -DWITH_CLIENT_SDL3=OFF
endif
SANITIZE_ADDRESS = -DWITH_SANITIZE_ADDRESS=ON

DEB_CMAKE_EXTRA_FLAGS := \
						  -DCMAKE_BUILD_TYPE="Debug" \
						  -DCMAKE_INSTALL_PREFIX=/opt/freerdp-nightly/ \
						  -DCMAKE_C_FLAGS="-O1" \
						  -DCMAKE_CXX_FLAGS="-O1" \
						  -DCMAKE_INSTALL_INCLUDEDIR=include \
						  -DCMAKE_INSTALL_LIBDIR=lib \
						  -DCMAKE_CTEST_ARGUMENTS="-DExperimentalTest;--output-on-failure;--no-compress-output" \
						  $(AAC_SUPPORT) \
						  $(SDL3_SUPPORT) \
						  $(SANITIZE_ADDRESS) \
						  $(NULL)

%:
	dh $@ --parallel

override_dh_auto_configure:
	dh_auto_configure -- -DCMAKE_MODULE_PATH=$(PWD)/cmake -GNinja -C $(PWD)/packaging/deb/freerdp-nightly/cmake-preload.cmake $(DEB_CMAKE_EXTRA_FLAGS)

override_dh_shlibdeps:
	dh_shlibdeps -l /opt/freerdp-nightly/lib/

override_dh_strip:
	dh_strip --dbg-package=freerdp-nightly-dbg

override_dh_missing:
	dh_missing --fail-missing
