# -*- 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 Python-eD2k 0.2.0 v
github.tarball_from         archive
name                        [string tolower ${github.project}]
revision                    1
license                     MIT
maintainers                 {i0ntempest @i0ntempest} openmaintainer

checksums                   rmd160  54c44ceed6f050e359111400ea34eab31ced3004 \
                            sha256  0c6ceea871702fac2b0d670ffce22faaf07c69495ccfd0a664b69d6b7f6e0fe2 \
                            size    750959

set go_exec_name            goed2kd

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

    categories-append       net
    description             typed asyncio client and Go sidecar for monkeyWie/goed2k
    long_description        ${name} is a typed asyncio client for monkeyWie/goed2k.\
                            It runs goed2k in one small Go sidecar and communicates through stdio NDJSON.

    github.setup            ${github.author} ${github.project} ${github.version} ${github.tag_prefix}

    python.default_version  314

    depends_run-append      port:${name}-${go_exec_name}
}

subport ${name}-${go_exec_name} {
    PortGroup               golang 1.0

    go.setup                github.com/${github.author}/${github.project} ${github.version} ${github.tag_prefix}
    categories-append       net
    description             minimal Go sidecar daemon for monkeyWie/goed2k
    long_description        ${name} is a ${description}.

    pre-configure {
        file mkdir ${gopath}/src/github.com/monkeyWie/
        ln -s ${worksrcpath}/third_party/goed2k ${gopath}/src/github.com/monkeyWie/goed2k
    }

    build.args              -o ./${go_exec_name} \
                            -ldflags '-s -w -X main.version=${github.tag_prefix}${version}' \
                            ./cmd/${go_exec_name}

    destroot {
        # binary is meant to be called programmatically only, install into libexec
        xinstall -d ${destroot}${prefix}/libexec/${go_exec_name}
        xinstall -m 755 ${worksrcpath}/${go_exec_name} ${destroot}${prefix}/libexec/${go_exec_name}/
    }
}
