### this file is sourced not run
PKGVER=1.11.0
PKGBUILD=1
PKGARCH=x86_64

# source: BLFS 2021-02-21
TARBALL=tigervnc-$PKGVER.tar.gz
MD5SUM=07f5e217f288c515effb083896e65054
SRC_URL=https://github.com/TigerVNC/tigervnc/archive/v${PKGVER}/$TARBALL
BUNDLE=

XORG_TARBALL=xorg-server-1.20.6.tar.bz2 # originally 1.19.{3,6}
XORG_MD5SUM=a98170084f2c8fed480d2ff601f8a14b
XORG_SRC_URL=https://www.x.org/pub/individual/xserver/$XORG_TARBALL

SLACKREQ="fltk
libgnutls >= 3.6.12
libgcrypt
libjpeg-turbo
pixman"
SLACKSUG="perl" # required for vncserver script
SLACKDESC="tigervnc: tigervnc $PKGVER (TigerVNC server)
tigervnc:
tigervnc: Tigervnc is an advanced VNC (Virtual Network Computing)
tigervnc: implementation. It allows creation of an Xorg server not tied to a
tigervnc: physical console and also provides a client for viewing of the remote
tigervnc: graphical desktop.
tigervnc:
tigervnc:
tigervnc:
tigervnc:
tigervnc:
"
SLACKCONF=turbovnc

### default pkg_download
### prepare
pkg_prepare() {
	pkg_prepare_default &&
	SRC_URL=$XORG_SRC_URL &&
	pkg_check $SRC_DIR $XORG_TARBALL $XORG_MD5SUM &&
	cp $SRC_DIR/$XORG_TARBALL tmp/pkg &&
	cd tmp/tigervnc* &&
	patch -Np0 -i ../pkg/XserverDesktop.cc.patch &&
	patch -Np1 -i ../pkg/tigervnc-1.11.0-configuration_fixes-1.patch &&
	patch -Rp1 -i ../pkg/reverse-make-PAM-mandatory.patch
}

### default pkg_package
### build
pkg_build() {
	cd /tmp/tigervnc* &&

	pushd unix/xserver &&
		tar -xf /tmp/pkg/$XORG_TARBALL --strip-components=1 &&
		patch -Np1 -i ../xserver120.patch
	popd &&

	# Don't build vncsession, which needs PAM
	sed -i -e '/add_executable(vncsession/d' \
		-e '/target_link_libraries(vncsession/d' \
		-e '/configure_file(vncsession/d' \
		-e '/install(TARGETS vncsession/d' \
		-e '/install(.*vncsession-start/d' \
		unix/vncserver/CMakeLists.txt &&

	# Build viewer
	# -DENABLE_PAM needs reverse-make-PAM-mandatory.patch reversed
	cmake -G "Unix Makefiles"         \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_BUILD_TYPE=Release  \
		-DENABLE_PAM:BOOL=OFF \
		-Wno-dev . &&

	make $MAKEFLAGS &&

	# Build server
	pushd unix/xserver &&
		autoreconf -fiv   &&

		CFLAGS="$CFLAGS -I/usr/include/drm" \
		./configure $XORG_CONFIG \
		  --disable-xwayland    --disable-dri        --disable-dmx         \
		  --disable-xorg        --disable-xnest      --disable-xvfb        \
		  --disable-xwin        --disable-xephyr     --disable-kdrive      \
		  --disable-devel-docs  --disable-config-hal --disable-config-udev \
		  --disable-unit-tests  --disable-selective-werror                 \
		  --disable-static      --enable-dri3                              \
		  --without-dtrace      --enable-dri2        --enable-glx          \
		  --with-pic &&
		make $MAKEFLAGS &&
	popd

	#Install viewer
	make install &&

	#Install server
	pushd unix/xserver/hw/vnc &&
		make install &&
	popd &&

	#[ -e /usr/bin/Xvnc ] || ln -svf $XORG_PREFIX/bin/Xvnc /usr/bin/Xvnc

	# desktop file
	install -vm644 media/icons/tigervnc_24.png /usr/share/pixmaps &&
	ln -sfv tigervnc_24.png /usr/share/pixmaps/tigervnc.png	&&

	# We don't have PAM
	#sed -i 's/pam_systemd.so/pam_elogind.so/' /etc/pam.d/tigervnc &&

	# Replace the new vncserver script and its man page with the old one because
	# the new one is predicated on vncsession and doesn't work for us

	rm /usr/libexec/vncserver /usr/share/man/man8/vncserver.8 &&
	install -m755 ../pkg/vncserver-1.10.1 /usr/bin/vncserver &&
	install -m644 ../pkg/vncserver-1.10.1.man /usr/share/man/man1/vncserver.1 &&

	pkg_build_slackdesc
}

# vim:ft=sh:

