# -*- 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.1
PortGroup           github 1.0
PortGroup           legacysupport 1.1
PortGroup           openssl 1.0
PortGroup           wxWidgets 1.0

# O_CLOEXEC, MAP_ANONYMOUS
legacysupport.newest_darwin_requires_legacy 14

# Switch to release upon next update.
github.setup        elfmz far2l 2.8.0 v_
revision            0
categories          sysutils www
license             GPL-2
maintainers         {@barracuda156 macos-powerpc.org:barracuda} openmaintainer
description         Fork of FAR Manager v2
long_description    {*}${description} for Unix-like systems.
checksums           rmd160  33db9ceb4548b44ebb3685c9c381c19da127c05e \
                    sha256  b0fddad2e3985f245f9e691e23b90fb97f7d29d9a0b131fe686aa3cbb2e4ea01 \
                    size    9011883
github.tarball_from archive

# FIXME: trash brewisms?
# https://github.com/elfmz/far2l/issues/2872

patchfiles-append   patch-CMakeLists.diff

# Adjustments for the build with wxGTK:
patchfiles-append   patch-wx.diff
# https://github.com/elfmz/far2l/issues/3366
patchfiles-append   patch-unbreak-wx-2.8.0.diff

# Fix header path:
patchfiles-append   patch-unrar.diff

post-patch {
    reinplace "s,@PREFIX@,${prefix},g" ${worksrcpath}/CMakeLists.txt
}

cmake.generator     Ninja

compiler.c_standard     1999
compiler.cxx_standard   2017

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

depends_lib-append  path:lib/pkgconfig/gnutls.pc:gnutls \
                    path:lib/pkgconfig/icu-uc.pc:icu \
                    port:libarchive \
                    port:libnfs \
                    port:libssh \
                    port:libunrar \
                    port:libxml2 \
                    port:neon \
                    port:uchardet \
                    port:xorg-libice \
                    port:xorg-libsm \
                    port:xorg-libX11 \
                    port:xorg-libXext \
                    port:xorg-libXi

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

configure.args-append \
                    -DARCLITE=ON \
                    -DICU_MODE=runtime \
                    -DMULTIARC=ON \
                    -DNETROCKS=ON \
                    -DPYTHON=OFF \
                    -DNR_AWS=OFF \
                    -DNR_SMB=OFF \
                    -DTESTING=OFF \
                    -DUNRAR=lib \
                    -DUNRAR_INCLUDE_DIR=${prefix}/include \
                    -DUSEUCD=ON \
                    -DUSEWX=OFF

# Update 2026.01: with wxGTK 3.2.9 the GUI works fine now.
variant gui description "Build with wx-based GUI" {
    wxWidgets.use   wxGTK-3.2

    depends_lib-append \
                    port:${wxWidgets.port}

    configure.args-replace \
                    -DUSEWX=OFF -DUSEWX=ON
    configure.args-append \
                    -DwxWidgets_CONFIG_EXECUTABLE:FILEPATH=${wxWidgets.wxconfig} \
                    -DwxWidgets_wxrc_EXECUTABLE:FILEPATH=${wxWidgets.wxrc}
}

variant s3 description "Enable S3 support" {
    depends_lib-append \
                    port:aws-sdk-cpp

    configure.args-replace \
                    -DNR_AWS=OFF -DNR_AWS=ON
}

variant smb description "Enable SMB support" {
    depends_lib-append \
                    path:lib/libsmbclient.dylib:samba4

    configure.args-replace \
                    -DNR_SMB=OFF -DNR_SMB=ON
}

default_variants    +s3 +smb

notes "
It is recommended to use a modern terminal for better user experience.\
Consider using contour, mlterm(-minimal) or iTerm2 ports.
"

post-activate {
    system "${prefix}/bin/update-desktop-database ${prefix}/share/applications"
}
