# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4

PortSystem              1.0
PortGroup               openssl 1.0

name                    x2goclient
version                 4.1.2.3
revision                0

checksums               sha256  ab8bb3c78d31625c749e42f15f810fe3d242927a15298308c13dea3b915aca3c \
                        rmd160  65a8505d43101c9683a0699039a510b5e117e11f \
                        size    2582072

categories              aqua net
platforms               macosx
license                 {GPL-2+ OpenSSLException}
maintainers             {ionic @Ionic} openmaintainer

description             vnc-like remote desktop software
long_description        X2Go is based on the (now closed source) NX libraries which provide \
                        terminal server services. \
                        This is a client application to access the remote side.

homepage                https://www.x2go.org/
master_sites            https://code.x2go.org/releases/source/${name}/

installs_libs           no

if {${os.platform} eq "darwin" && ${os.major} < 11} {
    PortGroup           qmake 1.0

    # Apple gcc do not support -stdlib= flag. gcc10+ do, but at the moment Macports gcc on PowerPC are built without it.
    if {[string match gcc-4.* ${configure.compiler}] || [string match apple-gcc-* ${configure.compiler}] ||
        [string match macports-gcc-* ${configure.compiler}] && {configure.build_arch} in [list ppc ppc64]} {
            patchfiles-append \
                        patch-unbreak-gcc.diff
    }
} else {
    PortGroup           qmake5 1.0

    qt5.depends_component \
                        qttools qtsvg qtdeclarative
}

depends_lib-append      port:libssh \
                        port:xorg-libX11

depends_run-append      port:pulseaudio \
                        port:nxproxy \
                        port:xmodmap \
                        port:xauth

patchfiles-append       patch-x2goclient-sshsubprocess-bind.diff \
                        patch-x2go-VERSION-changes.diff

post-patch {
    file mkdir "${worksrcpath}/client_build"

    # ../../x2goclient-4.1.2.2/version:1:1: error: expected unqualified-id
    move ${worksrcpath}/VERSION ${worksrcpath}/VERSION.txt
}

configure.dir           "${worksrcpath}/client_build"
build.dir               "${worksrcpath}/client_build"
destroot.dir            "${worksrcpath}/client_build"

# avoid hundreds of deprecation warnings
configure.cppflags-append -Wno-deprecated-declarations

# To pass string defines via DEFINES to qmake, we need 7 level
# of backslashes. Since we're using TCL, parsing that and then
# are passing commands on to the shell, which handles execution,
# these 7 levels must be doubled.
# According to https://xkcd.com/1638/, this might potentially
# summon some form of lesser demon.

set qmake_project_file  "x2goclient.pro"

configure.args-append   CONFIG+=\"release\" \
                        CONFIG-=\"sdk\" \
                        OSX_STDLIB=\"${configure.cxx_stdlib}\" \
                        DEFINES+=\"MACPORTS_PREFIX=\\\\\\\\\\\\\\"${prefix}\\\\\\\\\\\\\\"\" \
                        "../${qmake_project_file}"

destroot {
    copy ${worksrcpath}/client_build/${name}.app ${destroot}${applications_dir}
    xinstall -d -m 755 ${destroot}${applications_dir}/${name}.app/Contents/exe
    ln -s ${prefix}/bin/nxproxy ${destroot}${applications_dir}/${name}.app/Contents/exe/nxproxy
    ln -s ${prefix}/bin/xauth ${destroot}${applications_dir}/${name}.app/Contents/exe/nxauth
    ln -s ${applications_dir}/${name}.app/Contents/MacOS/${name} ${destroot}${prefix}/bin/${name}

    copy ${worksrcpath}/res/audio/startup.wav ${destroot}${applications_dir}/${name}.app/Contents/Resources/
}

variant debug description {Builds a debug version. Only really useful with a debugging-enabled version of Qt.} {
    configure.args-replace  CONFIG+=\"release\" \
                            CONFIG+=\"debug\"
}

livecheck.url           https://code.x2go.org/releases/source/x2goclient/
livecheck.regex         ${name}-(\\d+(?:\\.\\d+)*)\\.tar.gz
