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

checksums           ${distname}${extract.suffix} \
                        rmd160  44ca47424443a5c45e3a3d26755fe1778560b9f5 \
                        sha256  e7d7abf2d4ecae7217af017a4199d555563721bf6c3ae52e68704ee8268c432b \
                        size    24207488

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

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

patchfiles          patch-defaultHelperBinariesDir-for-MacPorts.diff

post-patch {
    reinplace "s|@@PREFIX@@|${prefix}|g" \
        ${worksrcpath}/vendor/github.com/containers/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-]+)}