# -*- 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           legacysupport 1.1
PortGroup           wxWidgets 1.0

# LegacySupport only used for providing wrappers here.
legacysupport.newest_darwin_requires_legacy 10

name                FileZilla
version             3.68.0
revision            0

categories          www net aqua
maintainers         {@barracuda156 gmail.com:vital.had} openmaintainer
license             GPL-2+

description         Open-source FTP, FTPS, and SFTP client

long_description    FileZilla Client is a fast and reliable cross-platform \
                    FTP, FTPS and SFTP client with lots of useful features \
                    and an intuitive graphical user interface.

homepage            https://filezilla-project.org

# Deleloper site seems to generate one-time link now, and direct download
# from there does not work anymore, it redirects to an html page. Even
# wget https://download.filezilla-project.org/client/FileZilla_3.67.1_src.tar.xz
# downloads a 12 KB dummy. For now, use the source from Debian archive.
# master_sites        https://download.filezilla-project.org/client

master_sites        https://deb.debian.org/debian/pool/main/f/filezilla/

use_xz              yes
distname            filezilla_${version}.orig

checksums           rmd160  8e4c67ddd1ac6ce04b2df48111ab481fa3711866 \
                    sha256  dc559b1fce98d996b49a4e8528d61da2a1cd360cf64c134b14f15848d414c356 \
                    size    4106812

# FileZilla 3.67 dropped support for wxWidgets < 3.2.1.
# However, wxWidgets-3.2 does not build on < 10.11,
# and wxWidgets-3.0* does not work correctly on < 10.8.
# So for older macOS (and non-Darwin) use wxGTK.
if {${os.platform} eq "darwin" && ${os.major} > 15} {
    wxWidgets.use   wxWidgets-3.2
} elseif {${os.platform} eq "darwin" && ${os.major} > 11} {
    wxWidgets.use   wxWidgets-3.0-cxx11
} else {
    wxWidgets.use   wxGTK-3.0-cxx11

    depends_lib-append \
                    port:desktop-file-utils

    legacysupport.redirect_bins filezilla

    # Contrary to documentation, FZ_DATADIR does nothing
    # on macOS, since assumption of app bundle is hardcoded.
    patchfiles-append \
                    patch-fix-fz_datadir.diff
}

if {${wxWidgets.version} < 3.2} {
    # Here we just restore macOS-relevant fallbacks from 3.66.4.
    patchfiles-append \
                    patch-relax-wxwidgets-version.diff \
                    patch-wx3.0.diff
}

# Build files are generated with older autotools,
# and the build fails to find automake 1.16 now.
use_autoreconf      yes

depends_build-append \
                    port:gettext \
                    path:bin/pkg-config:pkgconfig

depends_lib-append  port:dbus \
                    path:lib/pkgconfig/gnutls.pc:gnutls \
                    port:libfilezilla \
                    port:libidn \
                    port:nettle \
                    port:sqlite3 \
                    port:xdg-utils \
                    port:${wxWidgets.port}

if {[string match *gcc* ${configure.compiler}]} {
    # checking for whether we need to use Boost Regex due GCC bug 86164
    # configure: error: Boost Regex 1.76 or higher not found.
    depends_build-append \
                    port:boost
}

worksrcdir          filezilla-${version}

patchfiles-append   patch-src-commonui-buildinfo.cpp.diff \
                    patch-src-engine-version.cpp.diff \
                    patch-src-interface-mainfrm.cpp.diff \
                    patch-src-interface-toolbar.mm.diff \
                    patch-powermanagement.diff \
                    patch-dnd.diff \
                    patch-paths-1050.diff

platform darwin {
    # Condition is wrong in the source, since this object is required
    # for linking on macOS, whether or not app bundle is built.
    patchfiles-append \
                    patch-fix-mac-wxgtk.diff
}

# http://trac.filezilla-project.org/ticket/5473
# http://sourceforge.net/p/tinyxml/patches/51/
configure.args-append \
                    --with-tinyxml=builtin \
                    --with-pugixml=builtin \
                    --disable-manualupdatecheck \
                    --disable-autoupdatecheck \
                    --with-wxdir=${wxWidgets.wxdir}

configure.env       WXRC=${wxWidgets.wxrc}

compiler.cxx_standard   2017
compiler.thread_local_storage   yes

# https://trac.macports.org/ticket/59805
compiler.blacklist-append {clang < 1000}

# We only override destroot for app bundle build.
if {${os.platform} eq "darwin" && ${os.major} > 11} {
    destroot {
        copy ${worksrcpath}/FileZilla.app ${destroot}${applications_dir}
    }
} else {
    post-activate {
        system "${prefix}/bin/update-desktop-database ${prefix}/share/applications"
    }
}

depends_test-append port:cppunit

test.run            yes
test.target         check

livecheck.type      regex
livecheck.url       ${master_sites}
livecheck.regex     ${name}_(\[0-9.\]+)_src\\.tar\\.bz2
