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

# Boost 1.87 fixed for 10.6.8 powerpc, but not tested on 10.4–10.5.
if {${os.platform} ne "darwin" || ${os.major} > 9} {
    boost.version   1.88
} else {
    boost.version   1.76
}

github.setup        amule-project amule 377ec8d9d56618f1059d8705ae53a70fa4ffbe87
version             2026.05.14
revision            0
categories          net p2p www
maintainers         {@barracuda156 macos-powerpc.org:barracuda} openmaintainer
description         aMule, the all-platform eMule p2p client
long_description    aMule is a multiplatform fork of xMule client \
                    using wxWindows class library.
license             GPL-2
homepage            https://www.amule.org

# Fetch from git instead of distfile because it needs submodules
fetch.type          git

post-fetch {
    system -W ${worksrcpath} "git submodule update --init"
}

# https://github.com/amule-project/amule/issues/641
patchfiles-append   patch-CMakeLists.txt.diff

patchfiles-append   patch-unbreak-install.diff

if {[string match *gcc* ${configure.compiler}] && ${configure.build_arch} in [list arm i386 ppc]} {
    patchfiles-append \
                    patch-libatomic.diff
}

depends_build-append \
                    port:bison \
                    port:gettext \
                    path:bin/pkg-config:pkgconfig
depends_lib-append  port:curl \
                    port:gettext-runtime \
                    path:lib/pkgconfig/glib-2.0.pc:glib2 \
                    port:libcryptopp \
                    port:libgeoip \
                    port:libiconv \
                    port:libmaxminddb \
                    port:libpng \
                    port:libupnp \
                    port:readline \
                    port:zlib
depends_run-append  port:desktop-file-utils

configure.args-append \
                    -DBUILD_ALCC=ON \
                    -DBUILD_AMULECMD=ON \
                    -DBUILD_CAS=OFF \
                    -DBUILD_DAEMON=ON \
                    -DBUILD_ED2K=ON \
                    -DBUILD_MONOLITHIC=ON \
                    -DBUILD_REMOTEGUI=OFF \
                    -DBUILD_TESTING=OFF \
                    -DBUILD_WEBSERVER=OFF \
                    -DBUILD_XAS=ON \
                    -DENABLE_IP2COUNTRY=ON \
                    -DENABLE_NLS=ON \
                    -DENABLE_UPNP=ON

compiler.cxx_standard   2011

configure.cppflags-append \
                    -Damule_HAVE_LIBCURL

# May not be needed, but keep for now:
configure.cxxflags-append \
                    "-framework CoreFoundation -framework CoreServices -framework ApplicationServices -framework IOKit"
configure.ldflags-append \
                    "-framework CoreFoundation -framework CoreServices -framework ApplicationServices -framework IOKit"

# This variant does not work on 10.11 and earlier:
variant wxwidgets32 conflicts wxgtk32 description "Use Cocoa-based wxWidgets 3.2" {
    wxWidgets.use           wxWidgets-3.2
    depends_lib-append      port:${wxWidgets.port}

    configure.args-append   -DwxWidgets_CONFIG_EXECUTABLE=${wxWidgets.wxconfig} \
                            -DwxWidgets_wxrc_EXECUTABLE=${wxWidgets.wxrc}
}

# wx < 3.2 is not supported now: https://github.com/amule-project/amule/issues/407
variant wxgtk32 conflicts wxwidgets32 description "Use GTK-based wxWidgets 3.2" {
    wxWidgets.use           wxGTK-3.2
    depends_lib-append      port:${wxWidgets.port}

    configure.args-append   -DwxWidgets_CONFIG_EXECUTABLE=${wxWidgets.wxconfig} \
                            -DwxWidgets_wxrc_EXECUTABLE=${wxWidgets.wxrc}
}

# We prefer wxGTK, since no testing is done for wxWidgets-3.2.
# Upstream MacPorts maintains wxWidgets-3.2 port. If you wish to use it,
# install amule with +wxwidgets32.
if {![variant_isset wxwidgets32] && ![variant_isset wxgtk32]} {
    default_variants        +wxgtk32
}

post-destroot {
    move ${destroot}${prefix}/aMule.app ${destroot}${applications_dir}/aMule.app
}

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