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

github.setup        amule-org amule 3.0.1
github.tarball_from releases
revision            1
categories          net p2p www
maintainers         {i0ntempest @i0ntempest} openmaintainer
set cs_name         aMule
description         ${cs_name}, the all-platform eMule p2p client
long_description    ${cs_name} is a multiplatform fork of xMule client \
                    using wxWidgets.
license             GPL-2
homepage            https://amule-org.github.io/

distname            ${cs_name}-${version}-src
checksums           rmd160  9bac4010639f9e94899876c64fbc3446bff01b9a \
                    sha256  44484f2b003e2e9de2e86f6a9e57c948401aa24d6d398e2af73e563fd66a3413 \
                    size    6011817

extract.rename      yes

# upstream builds at Aug 2026 use boost 1.90
boost.version       1.88
wxWidgets.use       wxWidgets-3.2

depends_build-append \
                    port:gettext \
                    port:pkgconfig
depends_lib-append  port:${wxWidgets.port} \
                    port:curl \
                    port:gettext-runtime \
                    port:libcryptopp \
                    port:libmaxminddb \
                    port:libupnp \
                    port:readline \
                    port:zlib

post-patch {
    # The upstream release tarball is assembled without git archive, so its
    # archival metadata placeholders are not expanded. Set the release version
    # explicitly for the binaries and the app bundle's Info.plist.
    reinplace -E "s|project \\(amule\\)|project (amule VERSION ${version})|" \
                    ${worksrcpath}/CMakeLists.txt
    reinplace -E "s|set \\(PACKAGE_STRING \"aMule GIT\"\\)|set (PACKAGE_STRING \"aMule ${version}\")|" \
                    ${worksrcpath}/CMakeLists.txt
    reinplace -E "s|set \\(PACKAGE_VERSION \"GIT\"\\)|set (PACKAGE_VERSION \"${version}\")|" \
                    ${worksrcpath}/CMakeLists.txt
    reinplace -E "s|set \\(VERSION \"GIT\"\\)|set (VERSION \"${version}\")|" \
                    ${worksrcpath}/CMakeLists.txt
    # Change app bundle install location
    reinplace -E "s|BUNDLE DESTINATION \\.|BUNDLE DESTINATION \"${applications_dir}\"|" \
                    ${worksrcpath}/src/CMakeLists.txt

    # Readline 8.3 no longer exposes the obsolete Function typedef unless
    # explicitly requested. The callback already has rl_compentry_func_t's
    # signature, which is also the type of rl_completion_entry_function.
    reinplace -E {s|\(Function \*\)&command_completion|\&command_completion|} \
                    ${worksrcpath}/src/ExternalConnector.cpp
}

compiler.cxx_standard \
                    2011

cmake.set_cxx_standard \
                    yes

configure.args-append \
                    -DAMULE_TAGGED_RELEASE=ON \
                    -DBUILD_ALC=OFF \
                    -DBUILD_ALCC=ON \
                    -DBUILD_AMULECMD=ON \
                    -DBUILD_CAS=OFF \
                    -DBUILD_DAEMON=ON \
                    -DBUILD_ED2K=ON \
                    -DBUILD_EVERYTHING=OFF \
                    -DBUILD_FILEVIEW=OFF \
                    -DBUILD_MONOLITHIC=ON \
                    -DBUILD_REMOTEGUI=OFF \
                    -DBUILD_TESTING=OFF \
                    -DBUILD_WEBSERVER=OFF \
                    -DBUILD_WXCAS=OFF \
                    -DDEFAULT_VERSION_CHECK=OFF \
                    -DDOWNLOAD_AND_BUILD_DEPS=OFF \
                    -DENABLE_BFD=OFF \
                    -DENABLE_CCACHE=OFF \
                    -DENABLE_IP2COUNTRY=ON \
                    -DENABLE_NLS=ON \
                    -DENABLE_UPNP=ON \
                    -DTRANSLATED_MANPAGES=OFF \
                    -DwxWidgets_CONFIG_EXECUTABLE=${wxWidgets.wxconfig}

# wxcrt.h:656:14: error: call to 'wcsstr' is ambiguous
if {${os.major} <= 15} {
    configure.cxxflags-append \
                    -D_WCHAR_H_CPLUSPLUS_98_CONFORMANCE_ 
}

# GetTickCount.cpp:80:16: error: use of undeclared identifier 'CLOCK_MONOTONIC'
legacysupport.newest_darwin_requires_legacy \
                    15

post-build {
    system -W ${build.dir}/src "/usr/bin/codesign --sign - ${cs_name}.app"
}

post-destroot {
    ln -s ${applications_dir}/${cs_name}.app/Contents/MacOS/${cs_name} ${destroot}${prefix}/bin/${name}
}
