# -*- 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           cmake 1.0

name                Vidalia
categories          security net aqua
maintainers         {@barracuda156 gmail.com:vital.had} openmaintainer
description         ${name} is a controller GUI for the Tor software
long_description    ${name} is a cross-platform controller GUI for the Tor software, \
                    built using the Qt framework. Vidalia runs on most platforms \
                    supported by Qt 4.2 or later.

license             {GPL-2+ OpenSSLException}
homepage            https://www.torproject.org/projects/vidalia.html.en

if {${os.arch} eq "arm"} {
    PortGroup       github 1.0
    PortGroup       qt5 1.0

    qt5.depends_component   qtscript qttools
    # No support for Qt5 in releases. Qt4 is broken on aarch64.
    github.setup    a-ilin vidalia 8240540188062a168a66b25ca61b852cc89140ad
    version         0.3.3-alpha
    revision        0
    github.tarball_from archive
    checksums       rmd160  2107d50a7d72fd93ed75e613515ed33af4e191ca \
                    sha256  e4c2138b43d32d9cd23282378074f94bc38065e2dc79da05a3f7fbfb61ecb2a0 \
                    size    6116757

    # https://github.com/a-ilin/vidalia/pull/3
    patchfiles-append \
                    0001-Vidalia.cpp-fix-linking.patch \
                    0002-LogFilter.cpp-fix-includes.patch

    configure.args-append \
                    -DUSE_QT5=ON
} else {
    PortGroup       qt4 1.0

    version         0.2.21
    revision        1
    master_sites    https://www.torproject.org/dist/vidalia/ \
                    https://archive.torproject.org/tor-package-archive/vidalia/
    distname        vidalia-${version}
    checksums       rmd160  a1086c98216fed09472d494c95033097ec57b43c \
                    sha256  c4008e7e7781dddf4a8670a435da6496dc9309dbdbc6125ac6d2cc871bdc1be7 \
                    size    6360390

    patchfiles      patch-TorSettings.h.diff

    configure.args-append \
                    ${qt_cmake_defines}

    livecheck.type  regexm
    livecheck.url   ${homepage}
    livecheck.regex The most recent stable release is: (\[\\d\.\]+)
}

# Accommodate tor-devel:
depends_lib-append  bin:tor:tor

configure.args-append \
                    -DUSE_MINIUPNPC=OFF

destroot {
    file copy ${worksrcpath}/src/vidalia/Vidalia.app ${destroot}${applications_dir}/Vidalia.app
}

variant miniupnpc description "Enable miniupnpc support" {
    depends_lib-append \
                    port:miniupnpc
    configure.args-replace \
                    -DUSE_MINIUPNPC=OFF -DUSE_MINIUPNPC=ON
}

default_variants-append \
                    +miniupnpc

variant tests description "Enable tests" {
    depends_build-append \
                    port:libiconv
    configure.args-append \
                    -DBUILD_TESTS=ON

    test.run        yes

    test.dir        ${worksrcpath}/src/tests
    test.cmd        ./VidaliaTestSuite
    test.target

    # https://github.com/a-ilin/vidalia/issues/4
    pre-test {
        ui_warn "At the moment tests run correctly\
            only under a regular user. You could run\
            VidaliaTestSuite binary manually."
    }
}