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

go.setup            github.com/digitalocean/doctl 1.109.1 v
github.tarball_from archive
revision            0

categories          www devel
license             Apache-2
maintainers         {@kritr gmail.com:krdevmail} \
                    {@judaew judaew} \
                    openmaintainer
description         A command line interface for the DigitalOcean API
long_description    ${description}

checksums           rmd160  afe7f0b1f8c0aceccb04ab8c81c91a4c46e639ce \
                    sha256  ac1c94814283e090240534f9465be7e2213c3e7952108ec0da5f6cb3ad343c98 \
                    size    7930711

set doctl_ver [split ${version} "."]
set doctl_major [lindex ${doctl_ver} 0]
set doctl_minor [lindex ${doctl_ver} 1]
set doctl_patch [lindex ${doctl_ver} 2]

set base_flag       "-X ${go.package}"
set ld_flags        "${base_flag}.Label=release"
append ld_flags     " ${base_flag}.Major=${doctl_major}"
append ld_flags     " ${base_flag}.Minor=${doctl_minor}"
append ld_flags     " ${base_flag}.Patch=${doctl_patch}"

build.cmd-append    " -ldflags \"${ld_flags}\""
build.cmd-append    " -o ${name}"

build.env-delete    GO111MODULE=off
build.env-append    GO111MODULE=on \
                    CGO_ENABLED=0

build.target        ${worksrcpath}/cmd/${name}

destroot {
    xinstall -m 0755 ${worksrcpath}/${name} ${destroot}${prefix}/bin

    set bash_completion ${prefix}/share/bash-completion/completions
    xinstall -d ${destroot}${bash_completion}
    exec ${destroot}${prefix}/bin/${name} completion bash >> \
        ${destroot}${bash_completion}/${name}

    set zsh_completion ${prefix}/share/zsh/site-functions
    xinstall -d ${destroot}${zsh_completion}
    exec ${destroot}${prefix}/bin/${name} completion zsh >> \
        ${destroot}${zsh_completion}/_${name}

    set fish_completion ${prefix}/share/fish/vendor_completions.d
    xinstall -d ${destroot}${fish_completion}
    exec ${destroot}${prefix}/bin/${name} completion fish >> \
        ${destroot}${fish_completion}/${name}.fish
}
