# -*- 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           github 1.0
PortGroup           zig_toolchain 1.0

github.setup        simoarpe ziggity 0.61.0 v
github.tarball_from archive
revision            0

description         Fast keyboard-driven terminal UI for Git, written in Zig

long_description    Ziggity is a fast, keyboard-driven terminal UI for Git, \
                    inspired by lazygit and written in Zig.

categories          devel
installs_libs       no
license             MIT
maintainers         {gmail.com:herby.gillot @herbygillot} \
                    openmaintainer

# The series build.zig.zon names as minimum_zig_version. An exact pin, not a
# floor: Zig breaks the language and standard library at every minor release.
set zig_series      0.17

platforms           "darwin >= [zig_toolchain.min_darwin ${zig_series}]"

depends_build-append \
                    port:zig-${zig_series} \
                    path:bin/git:git
depends_run-append  path:bin/git:git

# Zig package dependencies, vendored. build.zig.zon fetches these over the
# network, which a MacPorts build must not do, so they are fetched as distfiles
# and passed to the build with `zig build --system`, which disables fetching.
#
# When updating, take the list from a full build rather than `zig build
# --fetch`: ziggity names only vaxis, which pulls in zigimg and uucode, and
# uucode is `lazy = true` so --fetch misses it. Each directory must be named
# for the hash Zig records, since that is how the build resolves the package.
set vaxis_commit    30c30956989939af5a919b016e56aa6f8cda26e3
set vaxis_hash      vaxis-0.6.0-BWNV_O8ODQBFLRjA4D0q75pHPh63iPu_v0yhpCwsAMaM

set zigimg_commit   734fa919fb15b7917d4eb124f53600348f4ffa30
set zigimg_hash     zigimg-0.1.0-8_eo2sBLGACBebrhQZUwRliZNSUyDn6szp99eip_6-Rw

set uucode_commit   1fb73433bba5d93366c57f23ff2e9d7939746500
set uucode_hash     uucode-0.2.0-ZZjBPm6FVgBcY-79AHV8ckQj86z0JwOyVyj89VeZrEiv

set zig_system_dir  ${workpath}/zig-system

master_sites-append https://github.com/rockorager/libvaxis/archive/:vaxis \
                    https://github.com/zigimg/zigimg/archive/:zigimg \
                    https://github.com/jacobsandlund/uucode/archive/:uucode

distfiles-append    ${vaxis_commit}.tar.gz:vaxis \
                    ${zigimg_commit}.tar.gz:zigimg \
                    ${uucode_commit}.tar.gz:uucode

checksums           ${distname}${extract.suffix} \
                    rmd160  b2af5d9ab922535cd4f8d34383b66e51c08d4d3c \
                    sha256  baf179db3ea0a458978fd1301f88d8b0c29b73d7d2a466378b4253c9e5308d05 \
                    size    37074619 \
                    ${vaxis_commit}.tar.gz \
                    rmd160  945f2186c087735f1534f2da5f8937fca400b784 \
                    sha256  c2a7cc38699a50bc5b2ad8786a3d2d6cca00a55051e22765a38b6fc536e18e58 \
                    size    1274002 \
                    ${zigimg_commit}.tar.gz \
                    rmd160  c56e35a8864c91aee60eae76a4309598524d3902 \
                    sha256  3edf278f2a57d47f7793a252a327f70f1ecc00900a15435fecf3beab59540983 \
                    size    227677 \
                    ${uucode_commit}.tar.gz \
                    rmd160  f30f6ad99518a278e58fb20275d1dd202a356e56 \
                    sha256  9e574f5b72c07f426eb31e2604860f22ba0fc5f9ccb44ef44e3212a5e9001828 \
                    size    2237452

post-extract {
    xinstall -d ${zig_system_dir}

    move ${workpath}/libvaxis-${vaxis_commit} ${zig_system_dir}/${vaxis_hash}
    move ${workpath}/zigimg-${zigimg_commit}  ${zig_system_dir}/${zigimg_hash}
    move ${workpath}/uucode-${uucode_commit}  ${zig_system_dir}/${uucode_hash}
}

use_configure       no

build.cmd           [zig_toolchain.bin ${zig_series}]
build.target        build
build.args          --system ${zig_system_dir} \
                    -Doptimize=ReleaseSafe \
                    -j${build.jobs}

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

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