# Template file for 'freerdp'
pkgname=freerdp
version=3.30.0
revision=2
build_style=cmake
build_helper=qemu
configure_args="-Wno-dev -DCMAKE_BUILD_TYPE=Release
 -DCMAKE_CXX_FLAGS_RELEASE=-DNDEBUG -DCMAKE_CXX_FLAGS_DEBUG=-DNDEBUG
 -DCMAKE_CXX_FLAGS_RELWITHDEBINFO=-DNDEBUG -DCMAKE_C_FLAGS_RELEASE=-DNDEBUG
 -DCMAKE_C_FLAGS_DEBUG=-DNDEBUG -DCMAKE_C_FLAGS_RELWITHDEBINFO=-DNDEBUG
 -DPKG_CONFIG_RELOCATABLE=OFF -DPROXY_PLUGINDIR=/usr/lib/${pkgname}/server/proxy/plugins
 -DRDTK_FORCE_STATIC_BUILD=ON -DCHANNEL_URBDRC_CLIENT=ON -DWITH_BINARY_VERSIONING=ON
 -DWITH_ALSA=ON -DWITH_CHANNELS=ON -DWITH_CLIENT_CHANNELS=ON -DWITH_CUPS=ON
 -DWITH_FREERDP_DEPRECATED_COMMANDLINE=ON -DWITH_FUSE=ON -DWITH_GSTREAMER_1_0=OFF
 -DWITH_ICU=ON -DWITH_JPEG=ON -DWITH_LIBSYSTEMD=OFF -DWITH_PULSE=ON -DWITH_SAMPLE=OFF
 -DWITH_SERVER=ON -DWITH_SERVER_CHANNELS=ON -DWITH_WINPR_TOOLS=ON -DWITH_X11=ON
 -DWITH_XCURSOR=ON -DWITH_XEXT=ON -DWITH_XI=ON -DWITH_XINERAMA=ON -DWITH_XKBFILE=ON
 -DWITH_XRENDER=ON -DWITH_XV=ON -DCHANNEL_RDPEWA=ON -DCHANNEL_RDPEWA_CLIENT=ON
 -DWITH_AAD=$(vopt_if aad ON OFF) -DWITH_CAIRO=$(vopt_if ffmpeg OFF ON)
 -DWITH_CLIENT_SDL=$(vopt_if sdl3 ON OFF) -DWITH_DSP_FFMPEG=$(vopt_if ffmpeg ON OFF)
 -DWITH_FFMPEG=$(vopt_if ffmpeg ON OFF) -DWITH_PCSC=$(vopt_if smartcard ON OFF)
 -DWITH_PKCS11=$(vopt_if smartcard ON OFF) -DWITH_SWSCALE=$(vopt_if ffmpeg ON OFF)
 -DWITH_WAYLAND=OFF -DWITH_WEBVIEW=$(vopt_if webview ON OFF) -DWITH_PAM=ON
 -DWITH_CLIENT_SDL_VERSIONED=$(vopt_if sdl3 ON OFF) -DWITH_VERBOSE_WINPR_ASSERT=OFF"
hostmakedepends="pkg-config"
makedepends="alsa-lib-devel cups-devel fuse3-devel icu-devel libXcursor-devel
 libXdamage-devel libXinerama-devel libXrandr-devel libXv-devel pam-devel
 libjpeg-turbo-devel libusb-devel libxkbfile-devel mit-krb5-devel openssl-devel
 pulseaudio-devel uriparser-devel $(vopt_if aad cJSON-devel)
 $(vopt_if ffmpeg ffmpeg6-devel cairo-devel) $(vopt_if sdl3 SDL3_ttf-devel)
 $(vopt_if smartcard 'pcsclite-devel pkcs11-helper-devel')
 $(vopt_if webview libwebkit2gtk41-devel) libfido2-devel"
short_desc="Free RDP (Remote Desktop Protocol) client"
maintainer="chrysos349 <chrysostom349@gmail.com>"
license="Apache-2.0"
homepage="https://www.freerdp.com/"
changelog="https://raw.githubusercontent.com/FreeRDP/FreeRDP/master/ChangeLog"
distfiles="https://github.com/FreeRDP/FreeRDP/archive/${version}.tar.gz"
checksum=21b3f72bd688fcd1dbbef37b7129bfc9701906705572fce2a5a80b1e85ecc0ee

replaces="freerdp3>=0"

build_options="aad ffmpeg sdl3 smartcard webview"
build_options_default="aad ffmpeg sdl3 smartcard"

desc_option_aad="Compile with support for Azure AD authentication"
desc_option_sdl3="Enable support for SDL (3.x)"
desc_option_smartcard="Build with smartcard support"
desc_option_webview="Build with WebView support for AAD login popup browser"

if [ "$build_option_webview" -a -z "$build_option_sdl3" ]; then
	broken="WebView requires SDL"
fi

case "$XBPS_TARGET_MACHINE" in
	arm*) configure_args+=" -DUSE_UNWIND=OFF -DWITH_SIMD=OFF" ;;
esac

if [ "$CROSS_BUILD" ]; then
	configure_args+="
	 -DCMAKE_CXX_COMPILER_AR=/usr/bin/${XBPS_CROSS_TRIPLET}-ar
	 -DCMAKE_CXX_COMPILER_RANLIB=/usr/bin/${XBPS_CROSS_TRIPLET}-ranlib"
fi

pre_configure() {
	if [ "$CROSS_BUILD" ]; then
		export CXX="$XBPS_WRAPPERDIR/${XBPS_CROSS_TRIPLET}-c++"
	fi
}

# first we want to separate -server, everything else then goes to client
subpackages="libfreerdp-server freerdp-server libfreerdp freerdp-devel
 freerdp-server-devel freerdp3 libfreerdp3-server freerdp3-server libfreerdp3 freerdp3-devel"

freerdp3_package() {
	metapackage=yes
	short_desc+=" - (transitional dummy package)"
	depends="freerdp"
}

freerdp3-devel_package() {
	metapackage=yes
	short_desc+=" - (transitional dummy package)"
	depends="freerdp3-devel"
}

freerdp3-server_package() {
	metapackage=yes
	short_desc+=" - (transitional dummy package)"
	depends="freerdp3-server"
}

freerdp-server-devel_package() {
	metapackage=yes
	short_desc+=" - (transitional dummy package)"
	depends="freerdp-devel"
}

libfreerdp3-server_package() {
	metapackage=yes
	short_desc+=" - (transitional dummy package)"
	depends="libfreerdp-server"
}

libfreerdp3_package() {
	metapackage=yes
	short_desc+=" - (transitional dummy package)"
	depends="libfreerdp"
}

libfreerdp_package() {
	short_desc+=" - runtime libraries"
	replaces="libfreerdp3>=0"
	pkg_install() {
		vmove "usr/lib/*.so.*"
	}
}

freerdp-devel_package() {
	short_desc+=" - development files"
	depends="cJSON-devel libfreerdp-server>=${version}_${revision}
	 libfreerdp>=${version}_${revision} openssl-devel"
	replaces="freerdp-server-devel>=0 freerdp3-devel>=0"
	pkg_install() {
		vmove "usr/lib/*.so"
		vmove usr/include
		vmove usr/lib/cmake
		vmove usr/lib/pkgconfig
	}
}

libfreerdp-server_package() {
	short_desc="Free RDP (Remote Desktop Protocol) server - runtime libraries"
	replaces="libfreerdp3-server>=0"
	pkg_install() {
		vmove "usr/lib/freerdp/server/proxy/plugins"
		vmove "usr/lib/libfreerdp-server*.so.*"
		vmove "usr/lib/libfreerdp-shadow*.so.*"
	}
}

freerdp-server_package() {
	short_desc="Free RDP (Remote Desktop Protocol) server"
	replaces="freerdp-server>=0"
	pkg_install() {
		vmove usr/bin/freerdp-proxy3
		vmove usr/bin/freerdp-shadow-cli3
		vmove usr/share/man/man1/freerdp-proxy3.1
		vmove usr/share/man/man1/freerdp-shadow-cli3.1
	}
}
