# -*- 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.70.4
revision            0

categories          net aqua
maintainers         nomaintainer
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

# Developer 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 Arch Linux archive.
# master_sites        https://download.filezilla-project.org/client

master_sites        https://sources.archlinux.org/other/filezilla

use_xz              yes
distname            filezilla-${version}

checksums           rmd160  0da3d7124bf7c512c0e9033e3f5fca1107742df6 \
                    sha256  419de75f523e4d1bcd5d588c99f53b1c4eac0b52c6cc7923fbc442f04b3c4c30 \
                    size    3564240

# 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
    patchfiles-append \
                    patch-src-interface-dropsource-mac.diff
} elseif {${os.platform} eq "darwin" && ${os.major} > 11} {
    wxWidgets.use   wxWidgets-3.0-cxx11
} else {
    wxWidgets.use   wxGTK-3.0-cxx11

    depends_build-append \
                    port:xdg-utils

    depends_lib-append \
                    port:dbus

    depends_run-append \
                    port:xdg-utils \
                    port:desktop-file-utils

    legacysupport.redirect_bins filezilla

    patchfiles-append   patch-gtk-configure.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
}

# For patches
use_autoreconf      yes

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

depends_lib-append  \
                    port:fzssh \
                    port:libfilezilla \
                    port:libiconv \
                    port:pugixml \
                    port:libidn \
                    port:sqlite3 \
                    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.
    PortGroup           boost 1.0

    boost.depends_type  build
}

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

# Don't copy system dylibs
post-patch {
    system "> ${worksrcpath}/data/dylibcopy.sh"
}

compiler.cxx_standard   2017
compiler.thread_local_storage   yes

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

configure.env       WXRC=${wxWidgets.wxrc}

configure.args-append \
                    --disable-manualupdatecheck \
                    --disable-autoupdatecheck \
                    --with-wxdir=${wxWidgets.wxdir}

# We only override destroot for app bundle build.
if {${os.platform} eq "darwin" && ${os.major} > 11} {
    post-destroot {
        delete ${destroot}${prefix}/bin ${destroot}${prefix}/share
        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     filezilla-(\[0-9.\]+)\\.tar\\.xz
