# Template file for 'nx-libs'
pkgname=nx-libs
version=3.5.99.26
revision=2
build_style=gnu-configure
# The rpath for nxagent is USRLIBDIRPATH, which must be where this package
# provides a symlink to the custom libX11 with NX features
make_build_args='CONFIGURE=echo IMAKE_DEFINES=-DUseTIRPC=YES
 USRLIBDIRPATH=\$$ORIGIN/../lib/nx/X11'
make_install_args="PREFIX=/usr"
hostmakedepends="autoconf automake libtool pkg-config which imake xkbcomp gccmakedep"
makedepends="xorgproto zlib-devel libjpeg-turbo-devel libpng-devel
 libXext-devel libXdamage-devel libXrandr-devel libXtst-devel pixman-devel
 libXfont2-devel libxml2-devel libXcomposite-devel libXinerama-devel
 libtirpc-devel libXpm-devel font-util xkbcomp"
short_desc="NX X11 protocol compression libraries"
maintainer="eoli3n <jonathan.kirszling@runbox.com>"
license="GPL-2.0-or-later"
homepage="https://github.com/ArcticaProject/nx-libs"
distfiles="${homepage}/archive/$version/$pkgname-$version.tar.gz"
checksum=3ce7ca4e6b57b3a2d7588b2d0f4009036d2566a8925ca2c62f08a8dc0df50357
python_version=3
nocross="imake attempts to run target executables on host"
conf_files="/etc/nxagent/*"

post_patch() {
	# Replace hard-coded /usr/local ProjectRoot
	vsed -e '/ProjectRoot/s,/usr/local,/usr,' -i nx-X11/config/cf/site.def
	# Manually run autoreconf in pre_configure, disable in Makefile
	vsed -e 's/autoreconf/echo &-disabled/' -i Makefile
}

pre_configure() {
	# Create configure scripts for all subprojects
	local _subdir
	for _subdir in nxcomp nx-X11/lib nxcompshad nxproxy nxdialog; do
		( cd ${_subdir} && autoreconf -vfsi )
	done
}

do_configure() {
	# Configure all subprojects in advance of build
	local _subdir
	for _subdir in nxcomp nxcompshad nxproxy nxdialog; do
		( cd ${_subdir} && ./configure ${configure_args} )
	done

	# nx-X11 configure has an extra argument
	( cd nx-X11/lib && ./configure ${configure_args} --disable-poll )
}

post_install() {
	# Remove conflicting GL headers
	rm -rf ${DESTDIR}/usr/include/GL
}

nx-libs-devel_package() {
	depends="${sourcepkg}>=${version}_${revision}"
	short_desc+=" - development files"
	pkg_install() {
		vmove usr/include
		vmove "usr/lib/*.a"
		vmove "usr/lib/*.so"
		vmove usr/lib/pkgconfig
	}
}