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

name                ncdu
categories          sysutils
maintainers         {snc @nerdling} {judaew @judaew} openmaintainer
license             MIT

description         NCurses Disk Usage
long_description    ncdu is an ncurses version of the famous old 'du' unix \
                    command. It provides a fast and easy interface to your \
                    harddrive. Where is your disk space going? Why is your \
                    home directory that large? ncdu can answer those questions \
                    for you in just a matter of seconds!
platforms           darwin freebsd
homepage            https://dev.yorhel.nl/ncdu
master_sites        https://dev.yorhel.nl/download/

depends_lib         port:ncurses

subport ncdu1 {
    version             1.22
    revision            0
    conflicts           ncdu

    checksums           rmd160  e7850ede52cee22410261f50a4e11e7b6f14ac98 \
                        sha256  0ad6c096dc04d5120581104760c01b8f4e97d4191d6c9ef79654fa3c691a176b \
                        size    157188

    livecheck.url       ${homepage}/changes
}

if {${subport} eq ${name}} {
    version             2.9.2
    revision            1
    conflicts           ncdu1

    checksums           rmd160  f818f2d00b823b076bca9ffdc534e8d8266d8532 \
                        sha256  e91135281cb66569f2ca4c0bac277246991e7e52524c0ca8cba3de5c8e81cec9 \
                        size    74529

    depends_build-append \
                        port:zig
    depends_lib         port:zstd

    # Remove after upstream adds compatibility
    patchfiles-append   patch-zig-0.16-comp.diff
    patch.args          -p1

    use_configure       no

    # Build manually using `zig cc`. The standard build with the patch that adds
    # the --search-prefix option doesn't work. See:
    # https://trac.macports.org/ticket/66044
    build.cmd           ${prefix}/bin/zig cc
    build.args          -I${prefix}/include -L${prefix}/lib -lncursesw -lzstd
    build.target        -o ncdu src/main.zig

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

        xinstall -m 0644 ${worksrcpath}/${name}.1 \
            ${destroot}${prefix}/share/man/man1
    }

    livecheck.url       ${homepage}/changes2
}

test.run            yes
test.cmd            ./ncdu --version

livecheck.regex     ${name}-(\\d\\.\\d+(?:\\.\\d+)*)${extract.suffix}
