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

# After the upgrade, it is highly recommended to test the `podman machine`.
# This port has problems with this command from time to time.
# See https://gist.github.com/judaew/85c6e8a62bf0e7f5be5188e020492e21
go.setup            github.com/containers/podman 6.0.0 v
revision            0
epoch               0

categories          sysutils
license             Apache-2
maintainers         {judaew @judaew} openmaintainer

description         Tool for managing OCI containers and pods.
long_description    \
    Podman is a tool for running Linux containers. You can do this from a \
    MacOS desktop as long as you have access to a linux box either running \
    inside of a VM on the host, or available via the network. You need to \
    install the remote client and then setup ssh connection information.

# Podman 6.0.0 moved its Go module path to go.podman.io/podman/v6 (source
# still hosted at github.com/containers/podman); internal imports use the
# new path, so go.package must match it for GOPATH-mode builds to resolve.
go.package          go.podman.io/podman/v6

checksums           ${distname}${extract.suffix} \
                    rmd160  4226c51609a4e6822c0c6d451447df8cf73ce109 \
                    sha256  f35ac7c40f0fd01bfedfe627c23ff7a577b071d50f2b0726e4734d51810f5a7d \
                    size    20510790

set py_ver          3.14
set py_ver_nodot    [string map {. {}} ${py_ver}]

depends_build-append \
                    port:go-md2man \
                    port:python${py_ver_nodot} \
                    port:pre-commit \
                    port:coreutils
depends_run         port:gvisor-tap-vsock port:vfkit

patchfiles          patch-defaultHelperBinariesDir-for-MacPorts.diff

post-patch {
    reinplace "s|@@PREFIX@@|${prefix}|g" \
        ${worksrcpath}/vendor/go.podman.io/common/pkg/config/config_darwin.go
}

build.cmd           make
build.args          PYTHON=${prefix}/bin/python${py_ver} \
                    PRE_COMMIT=${prefix}/bin/pre-commit
build.target        ${name}-remote ${name}-mac-helper docs

if {${os.platform} eq "darwin" && ${os.major} <= 21} {
    # See https://trac.macports.org/ticket/69578
    go.setup            github.com/containers/podman 4.9.4 v
    epoch               1

    checksums           ${distname}${extract.suffix} \
                        rmd160  51154051117060ccf70b68eef6112f27f7dcbf31 \
                        sha256  51ba7995fb61f2781054e5baa6d8ef931158e3bf81d198355956626a2ea18ef6 \
                        size    21733620

    depends_run-append   port:qemu
    depends_run-delete   port:vfkit

    notes-append "
    WARN: Currently using podman 4.9.4 instead of 5.0.0+. See the reasons:
    - https://trac.macports.org/ticket/69683
    "

    if {${build_arch} eq "arm64"} {
        notes-append "
        If you have an issue where podman won't run on ARM then try the following:
        - https://trac.macports.org/ticket/67731#comment:14
        "
    }
}

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

    xinstall -m 0755 ${worksrcpath}/bin/darwin/${name}-mac-helper \
        ${destroot}${prefix}/bin/

    # Add man-pages
    xinstall -d ${destroot}${prefix}/share/man/man1
    xinstall -m 640 {*}[glob ${worksrcpath}/docs/build/man/*.1] \
        ${destroot}${prefix}/share/man/man1/

    # Add shell completion
    xinstall -d ${destroot}${prefix}/share/bash-completion/completions
    xinstall -m 0644 ${worksrcpath}/completions/bash/${name} \
        ${destroot}${prefix}/share/bash-completion/completions/
    xinstall -d ${destroot}${prefix}/share/zsh/site-functions
    xinstall -m 0644 ${worksrcpath}/completions/zsh/_${name} \
        ${destroot}${prefix}/share/zsh/site-functions
    xinstall -d ${destroot}${prefix}/share/fish/vendor_completions.d
    xinstall -m 644 ${worksrcpath}/completions/fish/${name}.fish \
        ${destroot}${prefix}/share/fish/vendor_completions.d/
}

github.livecheck.regex  {([^"r-]+)}
