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

name                deluge
version             2.1.1
revision            0

set branch          [join [lrange [split ${version} .] 0 1] .]
categories          net gnome python
license             {GPL-3+ OpenSSLException}
maintainers         {devans @dbevans} openmaintainer
supported_archs     noarch
platforms           {darwin any}

description         A GNOME BitTorrent client.
long_description    Deluge is a GNOME client for the BitTorrent network written in python.
homepage            http://www.deluge-torrent.org

master_sites        https://ftp.osuosl.org/pub/deluge/source/${branch}/
use_xz              yes

checksums           rmd160  bdee3ddf7e9dffd3fa150fcb4d1c433ceebef682 \
                    sha256  768dd319802e42437ab3794ebe75b497142e08ed5b0fb2503bad62cef442dff7 \
                    size    2541968

boost.version       1.81

depends_lib-append \
                    port:gettext \
                    path:lib/pkgconfig/gtk+-3.0.pc:gtk3 \
                    port:libtorrent-rasterbar

# ensures SVG pixbufs can be loaded
depends_lib-append \
                    path:lib/pkgconfig/gdk-pixbuf-2.0.pc:gdk-pixbuf2 \
                    path:lib/pkgconfig/librsvg-2.0.pc:librsvg

depends_run-append \
                    port:adwaita-icon-theme

patchfiles-append   install-icons-manpages.patch
patchfiles-append   pass-full-mp-libpath.patch

post-patch {
    reinplace "s|@@MP_PREFIX@@|${prefix}|" \
        ${worksrcpath}/deluge/i18n/util.py
}

build.env-append \
                   "PYTHON_CFLAGS=-I${prefix}/include -I[boost::include_dir]" \
                    PYTHON_LDFLAGS=-L${prefix}/lib -L[boost::lib_dir]\
                    "CFLAGS=-I${prefix}/include -I$[boost::include_dir]" \
                    CC=${configure.cc} CXX=${configure.cxx} CPP=${configure.cpp}

proc py_setup {python_branch} {
    global prefix
    set python_version       [string map {"." ""} ${python_branch}]
    python.default_version   ${python_version}
    configure.python         ${prefix}/bin/python${python_branch}
    python.link_binaries     no
    require_active_variants  libtorrent-rasterbar python${python_version}

    depends_build-append \
                    port:py${python_version}-setuptools \
                    port:py${python_version}-wheel
    depends_lib-append \
                    port:py${python_version}-asn1 \
                    port:py${python_version}-chardet \
                    port:py${python_version}-gobject3 \
                    port:py${python_version}-ifaddr \
                    port:py${python_version}-mako \
                    port:py${python_version}-openssl \
                    port:py${python_version}-Pillow \
                    port:py${python_version}-rencode \
                    port:py${python_version}-service_identity \
                    port:py${python_version}-setproctitle \
                    port:py${python_version}-six \
                    port:py${python_version}-twisted \
                    port:py${python_version}-pyxdg \
                    port:py${python_version}-zopeinterface
}

variant python38 conflicts python39 python310 python311 python312 description {Build for Python 3.8} {
    py_setup 3.8
}

variant python39 conflicts python38 python310 python311 python312 description {Build for Python 3.9} {
    py_setup 3.9
}

variant python310 conflicts python38 python39 python311 python312 description {Build for Python 3.10} {
    py_setup 3.10
}

variant python311 conflicts python38 python39 python310 python312 description {Build for Python 3.11} {
    py_setup 3.11
}

variant python312 conflicts python38 python39 python310 python311 description {Build for Python 3.12} {
    py_setup 3.12
}

if {![variant_isset python38] && ![variant_isset python39] && ![variant_isset python310] && ![variant_isset python311] && ![variant_isset python312]} {
    default_variants +python312
}

post-destroot {
    foreach bin [glob -nocomplain -tails -directory "${destroot}${python.prefix}/bin" *] {
        ln -s "${python.prefix}/bin/${bin}" "${destroot}${prefix}/bin/${bin}${python.link_binaries_suffix}"
    }
}