# -*- 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/lima-vm/lima 2.0.2 v
go.offline_build    no
revision            0

homepage            https://lima-vm.io

description         Linux virtual machines

long_description    {*}{
    Lima launches Linux virtual machines with automatic file sharing
    and port forwarding (similar to WSL2). The original goal of Lima
    was to promote containerd including nerdctl (contaiNERD ctl) to
    Mac users, but Lima can be used for non-container applications as
    well. Lima also supports other container engines, such as Docker,
    Podman, Kubernetes, etc. Lima can also emulate other architectures
    if QEMU is installed.
}

categories          sysutils
installs_libs       no
license             Apache-2
maintainers         {gmail.com:herby.gillot @herbygillot} \
                    {macports.halostatue.ca:austin @halostatue} \
                    openmaintainer

checksums           rmd160  9a998333b6f4cc56e6143029b5d8824e665b685f \
                    sha256  51e0461c719c67c87310a1df4c55afe83f8379c246cd66c1c38773785f7994c8 \
                    size    7730030

build.cmd           make
build.args-append   native

patchfiles          patch-Makefile.diff \
                    patch-usrlocalgo.diff

platform darwin {
    # Lima defaults to VZ with macOS 13.5 and later; drop dependency from 14 onwards
    if {${os.major} < 23} {
        depends_run-append port:qemu
    }
}

variant additional_guestagents description {Guest agents for all architectures} {
  build.args-append  additional-guestagents
  depends_run-append port:qemu
}

notes {
    Lima has a variant (+additional_guestagents, disabled by default),\
    that builds guest agents for all supported architectures, requiring\
    qemu.
}

post-patch {
    reinplace "s|@@VERSION@@|${version}|g" ${worksrcpath}/Makefile
}

post-build {
    set limactl ${worksrcpath}/_output/bin/limactl

    set bash_completions_dir ${worksrcpath}/_output/share/bash-completion/completions
    set fish_completions_dir ${worksrcpath}/_output/share/fish/vendor_completions.d
    set zsh_completions_dir ${worksrcpath}/_output/share/zsh/site-functions

    xinstall -d ${bash_completions_dir} ${fish_completions_dir} ${zsh_completions_dir}

    system "${limactl} completion bash > ${bash_completions_dir}/${name}"
    system "${limactl} completion fish > ${fish_completions_dir}/${name}.fish"
    system "${limactl} completion zsh > ${zsh_completions_dir}/_${name}"
}

destroot {
    system -W ${worksrcpath} "make install DEST=${destroot}${prefix}"
}

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