#!/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 :=  -GNinja \
						  -DCMAKE_SKIP_RPATH=FALSE \
						  -DCMAKE_SKIP_INSTALL_RPATH=FALSE \
						  -DWITH_PULSE=ON \
						  -DWITH_CHANNELS=ON \
						  -DWITH_AAD=ON \
						  -DWITH_CUPS=ON \
						  -DWITH_KRB5=ON \
						  -DWITH_PCSC=ON \
						  -DWITH_FFMPEG=ON \
						  -DWITH_OPUS=ON \
						  -DWITH_DSP_FFMPEG=ON \
						  -DWITH_FREERDP_DEPRECATED_COMMANDLINE=ON \
						  -DWITH_SERVER=ON \
						  -DWITH_WAYLAND=ON \
						  -DWITH_CAIRO=ON \
						  -DWITH_URIPARSER=ON \
						  -DWINPR_UTILS_IMAGE_PNG=ON \
						  -DWINPR_UTILS_IMAGE_WEBP=ON \
						  -DWINPR_UTILS_IMAGE_JPEG=ON \
						  -DWITH_INTERNAL_RC4=ON \
						  -DWITH_INTERNAL_MD4=ON \
						  -DWITH_INTERNAL_MD5=ON \
						  -DWITH_WEBVIEW=ON \
						  -DBUILD_TESTING=ON \
						  -DWITH_KEYBOARD_LAYOUT_FROM_FILE=ON \
						  -DWITH_TIMEZONE_FROM_FILE=ON \
						  -DSDL_USE_COMPILED_RESOURCES=OFF \
						  -DWITH_SDL_IMAGE_DIALOGS=ON \
						  -DWITH_CLIENT_SDL_VERSIONED=ON \
						  -DRDTK_FORCE_STATIC_BUILD=ON \
						  -DUWAC_FORCE_STATIC_BUILD=ON \
						  -DWITH_BINARY_VERSIONING=ON \
						  -DWITH_RESOURCE_VERSIONING=ON \
						  -DCMAKE_BUILD_TYPE=Debug \
						  -DCMAKE_C_FLAGS="-O1" \
						  -DCMAKE_CXX_FLAGS="-O1" \
						  -DCMAKE_INSTALL_PREFIX=/opt/freerdp-nightly/ \
						  -DCMAKE_INSTALL_INCLUDEDIR=include \
						  -DCMAKE_INSTALL_LIBDIR=lib \
						  -DNO_CMAKE_PACKAGE_REGISTRY=ON \
						  -DWINPR_USE_LEGACY_RESOURCE_DIR=OFF \
						  -DWINPR_USE_VENDOR_PRODUCT_CONFIG_DIR=ON \
						  -DFREERDP_USE_VENDOR_PRODUCT_CONFIG_DIR=ON \
						  -DSAMPLE_USE_VENDOR_PRODUCT_CONFIG_DIR=ON \
						  -DSDL_USE_VENDOR_PRODUCT_CONFIG_DIR=ON \
						  -DCHANNEL_RDP2TCP=ON \
						  -DCHANNEL_RDP2TCP_CLIENT=ON \
						  -DCHANNEL_RDPECAM=ON \
						  -DCHANNEL_RDPECAM_CLIENT=ON \
						  -DCHANNEL_RDPEAR=ON \
						  -DCHANNEL_RDPEAR_CLIENT=ON \
						  -DCHANNEL_SSHAGENT=ON \
						  -DCHANNEL_SSHAGENT_CLIENT=ON \
						  $(AAC_SUPPORT) \
						  $(SDL3_SUPPORT) \
						  $(SANITIZE_ADDRESS) \
						  $(NULL)

%:
	dh $@ --parallel

override_dh_auto_configure:
	dh_auto_configure -- $(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

