PortSystem              1.0

name                    tightvnc
conflicts               vnc tigervnc
version                 1.3.10
revision        2
categories              x11 vnc
maintainers             nomaintainer
platforms               darwin
license                 GPL-2
description             Enhanced version of VNC
long_description        This is an enhanced version of VNC, called TightVNC, \
                        which includes a lot of new features, improvements, \
                        optimizations and bugfixes over the original VNC \
                        version. Note that TightVNC is still free, \
                        cross-platform and compatible with the standard VNC. \
                        Many users agree that TightVNC is the most advanced \
                        free remote desktop package.

homepage                http://www.tightvnc.com/
master_sites            sourceforge:vnc-tight
distname                ${name}-${version}_unixsrc
use_bzip2               yes

checksums               md5     397b35faad32d5246b6d44b142f8304f \
                        sha1    ab4ed3d8e9d5188edf0ff27fce3027495f1a8851 \
                        rmd160  0c24207ec13c1d41f445ccbdea16ce2b5d0729a7

depends_build           port:gccmakedep

depends_lib             port:xorg-libXaw \
                        port:xorg-libXp \
                        path:include/turbojpeg.h:libjpeg-turbo \
                        port:zlib

depends_run             path:bin/perl:perl5

if {${os.platform} eq "darwin" && ${os.major} >= 12} {
    depends_build-append port:tradcpp
    set cppcmd ${prefix}/bin/tradcpp
} else {
    set cppcmd /usr/bin/cpp
}

worksrcdir              vnc_unixsrc

patchfiles              patch-Xvnc.diff \
                        patch-vncviewer.diff \
                        patch-vncserver.diff \
                        patch-vncconnect_vncconnect.c.diff \
                        patch-include_vncauth.h.diff \
                        return-types.patch

post-patch {
    reinplace "s|@PREFIX@|${prefix}|g" \
        ${worksrcpath}/Xvnc/config/cf/vnclibs.def \
        ${worksrcpath}/vncserver \
        ${worksrcpath}/vncviewer/Imakefile
    if {[catch {set perl [binaryInPath "perl"]}] == 0} {
        reinplace "s|@PERL@|${perl}|g" ${worksrcpath}/vncserver
    }
    # The Vncviewer sample configuration file conflicts with the vncviewer binary
    # on case-insensitive filesystems like Mac OS X's default Mac OS Extended.
    move ${worksrcpath}/vncviewer/Vncviewer ${worksrcpath}/vncviewer/Vncviewer.sample

    reinplace "s|::CPPCMD::|${cppcmd}|" ${worksrcpath}/Xvnc/config/imake/imakemdep.h
}

use_xmkmf               yes

build.target            World
build.args              CC=${configure.cc}

post-build {
    system -W ${worksrcpath}/Xvnc "./configure"
    system -W ${worksrcpath}/Xvnc "make World CC=${configure.cc}"
}

destroot.cmd            ./vncinstall
destroot.target         ${destroot}${prefix}/bin ${destroot}${prefix}/share/man
destroot.destdir

post-destroot {
    xinstall -d -m 0755 ${destroot}${prefix}/share/vnc/classes
    foreach f [glob ${worksrcpath}/classes/*] {
        xinstall -m 0644 $f ${destroot}${prefix}/share/vnc/classes
    }
}

variant no_server {
    depends_run-delete  path:bin/perl:perl5
    patchfiles-append   patch-no_server.diff
}
