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

github.setup        XiaoYouChR Kelpie 0.2.0 v
github.tarball_from archive
name                [string tolower ${github.project}]
revision            0
categories          net
license             MIT BSD
maintainers         {i0ntempest @i0ntempest} openmaintainer

description         eD2k engine with an asyncio Python interface
long_description    Kelpie is an eD2k/eMule download engine written in Go, \
                    with Kademlia, source exchange, credit-based uploads, and \
                    SOCKS5 proxy support. A separate Python client communicates \
                    with the engine process through stdio NDJSON.

checksums           rmd160  7ee90551e8b4d668d6a5b6f22882c80c610b3688 \
                    sha256  aa0384481fd093e98d2e1a2bb73aeb3305357880e12554e13ba0eca3da69576b \
                    size    960001

if {${subport} eq ${name}} {
    PortGroup       golang 1.0

    go.setup        github.com/${github.author}/${github.project} ${github.version} ${github.tag_prefix}
    go.toolchain_min \
                    1.25.0
    installs_libs   no

    build.env-append \
                    CGO_ENABLED=0
    build.args      -trimpath \
                    -ldflags '-s -w -X main.version=${github.tag_prefix}${version}' \
                    -o build/kelpie \
                    ./cmd/kelpie

    test.run        yes
    test.target     ./...

    destroot {
        # The engine speaks NDJSON over stdio and is launched by client applications.
        xinstall -d ${destroot}${prefix}/libexec/${name}
        xinstall -m 0755 ${worksrcpath}/build/kelpie ${destroot}${prefix}/libexec/${name}/

        set docdir ${destroot}${prefix}/share/doc/${subport}
        xinstall -d ${docdir}
        xinstall -m 0644 ${worksrcpath}/LICENSE ${worksrcpath}/NOTICE \
            ${worksrcpath}/README.md ${docdir}
        # The bundled UPnP code's BSD notice is in its source header.
        xinstall -m 0644 ${worksrcpath}/internal/nat/upnp.go ${docdir}
    }
}

foreach v {311 312 313 314} {
    subport py${v}-${name} {
        PortGroup   python 1.0

        python.default_version ${v}
        github.setup ${github.author} ${github.project} ${github.version} ${github.tag_prefix}

        categories  net python
        license     MIT
        supported_archs noarch
        platforms   {darwin any}

        description Python ${python.branch} asyncio client for the Kelpie eD2k engine
        long_description \
                    ${description}. The client uses only the Python standard \
                    library and communicates with the engine through stdio NDJSON.

        depends_run-append port:${name}

        post-destroot {
            xinstall -d ${destroot}${prefix}/share/doc/${subport}
            xinstall -m 0644 ${worksrcpath}/LICENSE ${worksrcpath}/README.md \
                ${destroot}${prefix}/share/doc/${subport}
        }

        livecheck.type none
    }
}
