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

checksums                   rmd160  ee36c51f9ff8dd52f577d7888808b80d1ffd8683 \
                            sha256  f3df339661a9ff626c0dedc00abd9a0fb381d6d9091b851d0a95cd5c88d592c1 \
                            size    751004

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}/
    }
}
