# -*- 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

github.setup        amule-project amule e26d06a6eeaf37c716a88a47890cb85b931a0538
# Change github.tarball_from to 'releases' or 'archive' next update
github.tarball_from tarball
version             2021.12.05
revision            2
categories          net p2p www
maintainers         {@barracuda156 gmail.com:vital.had} 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"
}

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

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

configure.cxxflags-append \
                    "-framework CoreFoundation -framework CoreServices -framework IOKit"
configure.ldflags-append \
                    "-framework CoreFoundation -framework CoreServices -framework IOKit"

# Notice, that the same compiler should be used for amule and wxWidgets.
variant wxwidgets30 conflicts wxgtk30 description "Use Cocoa-based wxWidgets 3.0" {
    # This variant does not seem to work on 10.6 and earlier. It does build,
    # but interface is broken. It is confirmed to work on 10.8 though.
    wxWidgets.use           wxWidgets-3.0
    depends_lib-append      port:${wxWidgets.port}
    configure.args-append   -DwxWidgets_CONFIG_EXECUTABLE=${wxWidgets.wxconfig}
}

variant wxgtk30 conflicts wxwidgets30 description "Use wxWidgets 3.0 with GTK" {
    # There are some warnings when running this, but unlike wxwidgets30,
    # this one actually works on 10.6 and not just builds.
    # In pixman_region32_init_rect: Invalid rectangle passed
    # Gtk-CRITICAL **: gtk_box_gadget_distribute: assertion 'size >= 0' failed in GtkScrollbar
    wxWidgets.use           wxGTK-3.0
    depends_lib-append      port:${wxWidgets.port}
    configure.args-append   -DwxWidgets_CONFIG_EXECUTABLE=${wxWidgets.wxconfig}
}

if {![variant_isset wxwidgets30] && ![variant_isset wxgtk30]} {
    if {${os.platform} eq "darwin" && ${os.major} > 11} {
        default_variants    +wxwidgets30
    } else {
        default_variants    +wxgtk30
    }
}

# TODO: implement support for PlasmaMule in CMake build.
# variant plasma description "Build PlasmaMule module" {
#     PortGroup               qt4 1.0
# 
#     configure.args-replace  -DBUILD_PLASMAMULE=OFF -DBUILD_PLASMAMULE=ON
# }

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