# -*- 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.18.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.16

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    a367b89da09bfe5e1b628501940de5b4f858f5f3
set vaxis_hash      vaxis-0.6.0-BWNV_HHwCQB451KS7A8SMykALblPmGwHnzSfiJHjN3_9

set zigimg_commit   d695acd97c02e57bb151e8f659d1280f5cd6ca70
set zigimg_hash     zigimg-0.1.0-8_eo2oyaFwBZwJpmqPkCfVXWBrHcqbYwmrp1I6bTD3lI

set uucode_commit   2826a37a4562284fdacd8fa029d49509cc9bffcd
set uucode_hash     uucode-0.2.0-ZZjBPlK5VADj7fdoq7G8LIHzD5o6FSkcBXXrRWr4jnrA

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  a082026f14962bb1ef3a519c32d440bc2e3e52e8 \
                    sha256  6d5ee437af41635f56f2da157a9c6867e305afd5d31a3fefa150e825d3dd7b80 \
                    size    28321786 \
                    ${vaxis_commit}.tar.gz \
                    rmd160  1115f77507c166ba6adc348a53ffa311d2822120 \
                    sha256  8c1c43e6fdd3604893041c647426fada8ce7bbda1bb476fcd9b38beab573001f \
                    size    1220913 \
                    ${zigimg_commit}.tar.gz \
                    rmd160  822225c62b3a184774e4d07a50895c0abafec33d \
                    sha256  487794b6f28a8380d17a4960d3c53ef2f466d3075b92e8ebf3f84ec6b568545d \
                    size    222603 \
                    ${uucode_commit}.tar.gz \
                    rmd160  6b3508e8a379c5e7a0bc4b5f24d85acffce24517 \
                    sha256  7e76fc7fab1e7ac728c52b35bbb3e5b8c639841abfc7fe1a4bcb13050594bc9e \
                    size    2214904

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 \
                    {v([0-9.]+)}
