# -*- 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/lxc/incus 6.23.0 v
revision            0

homepage            https://linuxcontainers.org/incus/

description         CLI client for the Incus container and VM manager

long_description    Incus is a community fork of Canonical LXD. This port \
                    installs only the incus CLI, which connects to an Incus \
                    server running on a Linux host. The server daemon \
                    (incusd) is Linux-only and is not included.

categories          net sysutils
installs_libs       no
license             Apache-2
maintainers         {@vijay8i} \
                    openmaintainer

checksums           ${distname}${extract.suffix} \
                        rmd160  bade197f021ea558084ace4967fb5e342de6ef6a \
                        sha256  b44addaa328d9560071f34fd64eda77b4e5500e0450cc83efbe33f02ce363834 \
                        size    5114374

# FIXME: This port currently can't be built without allowing go mod to fetch
# dependencies at build time. go2port does not support go.sum and the
# dependency tree includes non-GitHub domains that go.vendors cannot handle.
go.offline_build    no

# CGO_ENABLED=0 prevents linking against Linux-only C libraries (liblxc,
# libcowsql) that are pulled in by the daemon but not the client.
build.env-append    CGO_ENABLED=0

# Build only the CLI. The daemon (cmd/incusd) and agent (cmd/incus-agent)
# have Linux-only build constraints and will not compile on macOS.
build.args          -o ${worksrcpath}/${name} ./cmd/incus

post-build {
    file mkdir ${worksrcpath}/completions

    foreach _shell {bash fish zsh} {
        system -W ${worksrcpath} \
            "./${name} completion ${_shell} > ./completions/${name}.${_shell}"
    }
}

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

    set bash_comp_dir ${destroot}${prefix}/share/bash-completion/completions
    xinstall -d ${bash_comp_dir}
    copy ${worksrcpath}/completions/${name}.bash ${bash_comp_dir}/${name}

    set fish_comp_dir ${destroot}${prefix}/share/fish/vendor_completions.d
    xinstall -d ${fish_comp_dir}
    copy ${worksrcpath}/completions/${name}.fish ${fish_comp_dir}/

    set zsh_comp_dir ${destroot}${prefix}/share/zsh/site-functions
    xinstall -d ${zsh_comp_dir}
    copy ${worksrcpath}/completions/${name}.zsh ${zsh_comp_dir}/_${name}
}

github.livecheck.regex {([0-9]+\.[0-9]+\.[0-9]+)}
