# Contributor: Jean-Charles de Longueville <jch@hellea.eu>
# Maintainer: Francesco Colista <fcolista@alpinelinux.org>
pkgname=nx-libs
pkgver=3.5.99.27
pkgrel=1
pkgdesc="NoMachine libraries (redistributed by x2go)"
url="http://x2go.org"
# riscv64 is not supported
arch="all !riscv64"
license="GPL-2.0-or-later"
depends="font-cursor-misc font-misc-misc"
makedepends="libx11-dev zlib-dev libjpeg-turbo-dev
	libpng-dev libfontenc-dev linux-headers
	libxml2-dev xkbcomp-dev imake
	bash automake autoconf libtool
	libxext-dev libxdamage-dev libxrandr-dev
	libxtst-dev pixman-dev gccmakedep
	libxfont2-dev libxpm-dev libxcomposite-dev
	libxinerama-dev"
subpackages="$pkgname-dev $pkgname-doc"
source="https://github.com/ArcticaProject/nx-libs/archive/$pkgver/nx-libs-$pkgver.tar.gz
	xf86bigfont.patch
	Add-support-for-new-arch-Loongarch.patch
	gcc14.patch
	gcc14-ilp32.patch
	"

prepare() {
	# Every Makefile has /usr/local as PREFIX, so replace that
	sed -i -e 's,/usr/local,/usr,' nx-X11/config/cf/site.def
	default_prepare
}

build() {
	make -j1 \
		PREFIX=/usr \
		USRLIBDIR=/usr/lib \
		SHLIBDIR=/usr/lib \
		CONFIGURE="./configure --prefix=/usr --libdir=/usr/lib --includedir=/usr/include"
}

package() {
	make -j1 \
		PREFIX=/usr \
		DESTDIR="$pkgdir" \
		NXLIBDIR=/usr/lib/nx \
		SHLIBDIR=/usr/lib \
		CONFIGURE="./configure --prefix=/usr --libdir=/usr/lib --includedir=/usr/include" \
		install

	# remove extras, GL, and other unneeded headers
	rm -rf "$pkgdir"/usr/include/GL
	rm -rf "$pkgdir"/usr/include/nx-X11
	rm -rf "$pkgdir"/usr/include/nx-X11/extensions/XK*.h
	rm -rf "$pkgdir"/usr/include/nx-X11/extensions/*Xv*.h
	rm -rf "$pkgdir"/usr/include/nx-X11/extensions/Xres*.h
	rm -rf "$pkgdir"/usr/include/nx-X11/extensions/XIproto.h
	rm -rf "$pkgdir"/usr/include/nx-X11/extensions/XI.h
	rm -rf "$pkgdir"/usr/include/nx-X11/Xtrans
}

sha512sums="
bfba1eea6f4debe90fa020276079027c3716daaff91bded72297ecab2a8c9f56d07630ca8bc9084c319d2c674304ad80131190ec1272c161c05221d6f19089d0  nx-libs-3.5.99.27.tar.gz
904aadbf0200cb8d96e5512bcbccf7da21af553f292ce4af56df035fa33e7e4b98fcf385a281a316d0c533bc2917cc7fde523b8212c8de7f4e825d776a43c576  xf86bigfont.patch
a1908db1133f7a499263a98ef209c84078264d3b535e4caeb4066e8957e310ef9b0d543785e84e248c41fd893ce73ded92432d19d2352a5fa875d2b2a4cd50ea  Add-support-for-new-arch-Loongarch.patch
7fe8deb0ab74a4e165a183789fbdb019967a82dc34de6e769486eb4370887b83a16f01c1b2665c18a15051bacffcb7e2fcf71584f782d95e06325ef8ebb8af0d  gcc14.patch
b361671d58a8b276dbae5c1e19c6a53da5062ff5d7f7d625609399640d7b27f3108f90028abe7ebe6f6c8b1bca83bbc7f41c131fc8ca8383ea113923ba833844  gcc14-ilp32.patch
"
