# -*- 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 www aqua
maintainers         {@barracuda156 gmail.com:vital.had} openmaintainer
license             GPL-2+
homepage            https://filezilla-project.org
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.

# 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.
# master_sites        https://download.filezilla-project.org/client
# master_sites        https://deb.debian.org/debian/pool/main/f/filezilla/
master_sites        https://sources.archlinux.org/other/filezilla/

use_xz              yes
distname            filezilla-${version}

checksums           rmd160  0da3d7124bf7c512c0e9033e3f5fca1107742df6 \
                    sha256  419de75f523e4d1bcd5d588c99f53b1c4eac0b52c6cc7923fbc442f04b3c4c30 \
                    size    3564240

wxWidgets.use       wxGTK-3.2

legacysupport.redirect_bins filezilla

# 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

# Specifically uses libidn, not libidn2.
depends_lib-append  port:dbus \
                    port:fzssh \
                    port:libfilezilla \
                    port:libiconv \
                    port:libidn \
                    port:pugixml \
                    port:sqlite3 \
                    port:${wxWidgets.port}

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

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.version   1.81
    boost.depends_type build
}

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

# Generic patches:
patchfiles-append   patch-src-commonui-buildinfo.cpp.diff \
                    patch-src-interface-mainfrm.cpp.diff \
                    patch-src-interface-toolbar.mm.diff \
                    patch-powermanagement.diff \
                    patch-dnd.diff \
                    patch-paths-1050.diff

# This has been broken forever:
patchfiles-append   patch-fix-pugixml-linking.diff

# FIXME, minor: while the app is perfectly working, terminal output
# displays the following on start-up:
# 2025-05-06 19:25:06.623 filezilla-orig[4219:60f] *** __NSAutoreleaseNoPool():
# Object 0x61538b0 of class NSPathStore2 autoreleased with no pool in place - just leaking
# Find out what causes this in the source, add a fix.

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
}

configure.args-append \
                    --disable-autoupdatecheck \
                    --disable-manualupdatecheck \
                    --with-pugixml=system \
                    --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}

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
