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

# source: james
TARBALL=ssvnc-1.0.30.src.tar.gz
MD5SUM=33d7c2d22d80ed26803275a9a83ddbb5
SRC_URL=http://ssvnc.sourceforge.net/dev/$TARBALL
BUNDLE=

SLACKREQ=libX11
SLACKDESC='ssvnc: ssvnc 1.0.30 (Secure VNC Client)  
ssvnc:  
ssvnc: The Enhanced TightVNC Viewer, SSVNC, adds encryption security to VNC 
ssvnc: connections. The package provides a GUI that automatically starts up an 
ssvnc: STUNNEL SSL tunnel for SSL or ssh for SSH connections to any VNC 
ssvnc: server, such as x11vnc, and then launches the VNC Viewer to use the 
ssvnc: encrypted tunnel. SSVNC can make SSL encrypted VNC connections to any 
ssvnc: VNC Server if they are running an SSL tunnel, such as STUNNEL or socat, 
ssvnc: at their end. SSVNC'\''s SSH tunnel will work to any VNC Server host 
ssvnc: running sshd that you can log into. The GUI needs Tcl/Tk installed.
ssvnc: SSL requires stunnel installed.
'
SLACKSUG='stunnel tcl tk'

### default pkg_download
### prepare
pkg_prepare() {
	pkg_prepare_default &&
	cd tmp/ssvnc* &&
	patch -Np1 -i $CHROOT_DIR/tmp/pkg/ssvnc-1.0.30-auth-none.patch &&
	patch -Np1 -i $CHROOT_DIR/tmp/pkg/ssvnc-fonts.patch
}

### package - add pre-compiled ultraftp
pkg_package() {
	cp tmp/pkg/ultraftp.jar usr/$LIBDIR/ssvnc/util &&
	cp tmp/pkg/ultravnc_repeater.pl tmp/pkg/vncxfer.pl \
	   usr/$LIBDIR/ssvnc/util
}

### build
pkg_build() {
	# note: NOT using CONFFLAGS
	cd /tmp/ssvnc*
	
	# don't build ultraftp.jar, use precompiled one
	sed -i -e '/^JSRC =/d' Makefile &&
	sed -i -e 's|defined(i386Architecture) &&||' vnc_unixsrc/vncviewer/Imakefile && # enable MITSHM
	make config && make CCOPTIONS="$CFLAGS" all && 
	make install PREFIX=/usr LIB=$LIBDIR/ssvnc MANDIR=share/man &&
	pkg_build_slackdesc &&
	sed -i -e 's|Icon=.*|Icon=/usr/share/pixmaps/midi-icons/pc2pc48.png|' /usr/share/applications/ssvnc.desktop
	
	# fix desktop file if there is no tcl
	cat << EOF >> /usr/bin/ssvnc-helper && 
#!/bin/dash
if type wish > /dev/null; then
	exec $(sed '/Exec=/!d; s/.*=//' /usr/share/applications/ssvnc.desktop)
else
	exec ssvncviewer
fi
EOF
	chmod +x /usr/bin/ssvnc-helper &&
	sed -i -e '/Exec=/d' /usr/share/applications/ssvnc.desktop &&
	echo "Exec=ssvnc-helper" >> /usr/share/applications/ssvnc.desktop &&
	mkdir -p /etc/X11/app-defaults &&
	install -m644 vnc_unixsrc/vncviewer/Vncviewer /etc/X11/app-defaults/Ssvnc	
}
