# -*- 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           active_variants 1.1
PortGroup           github 1.0

github.setup        ygrek mldonkey 3-2-1 release-
version             [string map {- .} ${github.version}]
revision            0
categories          net p2p
maintainers         nomaintainer
license             GPL-2+

description         OCaml/GTK client for the eDonkey p2p network

long_description    MLdonkey is a multi-platform multi-network peer-to-peer \
                    client. It supports several large networks, such as \
                    eDonkey, Overnet, Bittorrent, Gnutella (Bearshare, \
                    Limewire, etc), Gnutella2 (Shareaza), Fasttrack (Kazaa, \
                    Imesh, Grobster), Soulseek, Direct-Connect, and Opennap. \
                    Networks can be enabled/disabled, searches are performed \
                    in parallel on all enabled networks, but each file is \
                    only downloaded from one network, but from multiple \
                    clients concurrently.

homepage            https://mldonkey.sourceforge.net
github.tarball_from releases
distname            ${name}-${version}
use_bzip2           yes

checksums           rmd160  768ba12324b04604169f0c3a142f607aaa599cb9 \
                    sha256  9c0be397ab2193256f52f7bafaf210bf29c93bb4758bb1818f4633763b996bc7 \
                    size    2839613

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

depends_lib-append  port:bzip2 \
                    port:expat \
                    port:file \
                    port:fontconfig \
                    port:freetype \
                    port:gd2 \
                    path:lib/pkgconfig/gtk+-2.0.pc:gtk2 \
                    port:lablgtk2 \
                    port:libiconv \
                    path:include/turbojpeg.h:libjpeg-turbo \
                    port:libmagic \
                    port:libpng \
                    path:lib/pkgconfig/librsvg-2.0.pc:librsvg \
                    port:miniupnpc \
                    port:ocaml \
                    port:ocaml-camlp4 \
                    port:ocaml-num \
                    port:xorg-libX11 \
                    port:zlib

require_active_variants lablgtk2 rsvg

# The patch can be dropped once upstream fixes
# finding lablgtk2 via ocamlfind.
# https://github.com/ygrek/mldonkey/issues/107
patchfiles-append   patch-lablgtk.diff

compiler.blacklist-append \
                    *gcc-4.0 *gcc-4.2

# https://github.com/ygrek/mldonkey/issues/117
configure.cxxflags-append \
                    -std=c++98

configure.args-append \
                    --enable-multinet \
                    --enable-upnp-natpmp \
                    --with-libiconv-prefix=${prefix}

# Until this is fixed: https://github.com/ygrek/mldonkey/issues/108
configure.args-append \
                    --disable-gnutella2

# FIXME: Need to disable GTK GUI for now due to:
# https://github.com/ygrek/mldonkey/issues/111
# Web-based GUI works though.
# configure.args-append \
                    --enable-gui=newgui2

if {(${os.platform} eq "darwin" && ${os.major} < 11) \
    || ${os.platform} ne "darwin"} {
        depends_build-append \
                    port:gmake
        build.cmd   ${prefix}/bin/gmake
}

# ocaml is not universal
universal_variant   no

# Do not build this in parallel.
# Error: Unbound module CommonOptions
use_parallel_build  no

# There is no install target.
destroot {
    # Can be adjusted, depending on which archs OCaml
    # supports only in bytecode.
    if {${configure.build_arch} in [list ppc ppc64]} {
        copy ${worksrcpath}/mlnet.byte ${destroot}${prefix}/bin/
    } else {
        copy ${worksrcpath}/mlnet ${destroot}${prefix}/bin/
    }
    set docdir ${prefix}/share/doc/${name}
    xinstall -d ${destroot}${docdir}
    copy ${worksrcpath}/docs ${destroot}${docdir}/
    xinstall -m 0644 -W ${worksrcpath} CHANGES.md Copying.txt Developers.txt README.md ${destroot}${docdir}/
}
