# Maintainer: Sergej Pupykin <pupykin.s+arch@gmail.com>
# Maintainer: Uroš Vampl <mobile.leecher at gmail dot com>

pkgname=tigervnc
pkgver=1.8.0
pkgrel=2
_xorgver=1.19.3
pkgdesc="Suite of VNC servers and clients. Based on the VNC 4 branch of TightVNC."
arch=('i686' 'x86_64')
url="http://www.tigervnc.org"
license=('GPL')
depends=('fltk' 'pam' 'gnutls' 'libjpeg-turbo' 'libxtst' 'libxfont' 'pixman'
	 'xorg-xauth' 'xorg-xsetroot' 'xkeyboard-config' 'xorg-xkbcomp'
	 'libgl' 'libgcrypt' 'perl' 'libxdamage' 'libxfont2')
makedepends=('cmake' 'nasm' 'xorg-font-util' 'xorg-util-macros' 'bigreqsproto'
	     'compositeproto' 'damageproto' 'randrproto' 'resourceproto'
	     'scrnsaverproto' 'videoproto' 'xcmiscproto' 'xf86vidmodeproto'
	     'xtrans' 'glproto' 'dri2proto' 'dri3proto' 'presentproto'
	     'mesa' 'imagemagick')
optdepends=('mesa: for OpenGL functionality in Xvnc')
conflicts=('tightvnc')
install=tiger.install
source=($pkgname-$pkgver.tar.gz::https://github.com/TigerVNC/tigervnc/archive/v${pkgver}.tar.gz
	ftp://ftp.freedesktop.org/pub/xorg/individual/xserver/xorg-server-${_xorgver}.tar.bz2
	vncserver.service
	vncsvc.rules
	vncviewer.desktop)

prepare() {
  cd "$srcdir"/${pkgname}-${pkgver}
  cd unix/xserver
  cp -r "$srcdir"/xorg-server-${_xorgver}/* .
  patch -Np1 -i ../xserver119.patch
}

build() {
  cd "$srcdir"/${pkgname}-${pkgver}

  cmake -G "Unix Makefiles" \
    -DCMAKE_INSTALL_PREFIX=/usr
  make

  cd unix/xserver
  autoreconf -fiv
  ./configure --prefix=/usr \
	--disable-static --without-dtrace \
	--disable-xorg --disable-xnest --disable-xvfb --disable-dmx \
	--disable-xwin --disable-xephyr --disable-kdrive --disable-xwayland \
	--disable-config-hal --disable-config-udev --with-pic \
	--disable-unit-tests --disable-devel-docs --disable-selective-werror \
	--disable-dri --enable-dri2 --enable-dri3 --enable-glx
  make
}

package() {
  cd "$srcdir"/${pkgname}-${pkgver}
  make DESTDIR="$pkgdir" install
  cd unix/xserver/hw/vnc
  make DESTDIR="$pkgdir" install
  install -Dm0644 "$srcdir"/${pkgname}-${pkgver}/contrib/systemd/user/vncserver@.service \
    "$pkgdir"/usr/lib/systemd/user/vncserver@.service
  install -Dm0644 "$srcdir"/vncserver.service "$pkgdir"/usr/lib/systemd/system/vncserver.service
  install -Dm0644 "$srcdir"/vncviewer.desktop "$pkgdir"/usr/share/applications/vncviewer.desktop

  #LinHES sudo rules
  mkdir -p $pkgdir/etc/sudoers.d/
  chmod 750 $pkgdir/etc/sudoers.d/
  chown -R root:root $pkgdir/etc/sudoers.d
  install -o root -g root -m 0750 $srcdir/vncsvc.rules $pkgdir/etc/sudoers.d/vncsvc-tigervnc
}
md5sums=('5c9a80dd4b99b4eb19f535db5ce5830f'
         '015d2fc4b9f2bfe7a626edb63a62c65e'
         'a8a20685c23a50f86a13c33ce96a7ba7'
         'f333a228ddbefffc6ce945754bc9c5c5'
         'b200d83c60e80c6f9693ea19a2d9f5b0')