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

github.setup        scriptingosx diskspace 1 v
revision            0
github.tarball_from releases
platforms           macosx >= 20
supported_archs     arm64 x86_64

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

description         macOS command line tool to return the available disk space on APFS volumes
long_description    ${name} is a ${description}. With the various APFS features the value for free disk space returned\
                    from tools such as du or df will not be accurate. This tool uses system functions to get various\
                    measures of available disk space.

checksums           rmd160  a19a218178f3a9caecb681a9199be6159c2ee013 \
                    sha256  918e9796e3390b2644efd4deb36d4095599be5372fddc8536f91bfeba01f66ee \
                    size    586871

# Building from source impossible: SwiftPM unsupported by base
set pkg_path        ${workpath}/pkg

extract.cmd         pkgutil
extract.pre_args    --expand
extract.post_args   ${pkg_path}
extract.mkdir       yes
extract.suffix      .pkg

post-extract {
    system -W ${pkg_path} "cat ./Payload | gzip -d > ./Payload.cpio"
    system -W ${pkg_path} "cat ./Payload.cpio | cpio -i"
}

use_configure       no
universal_variant   yes

build {
    if {![variant_isset universal]} {
        system -W ${pkg_path} "lipo -thin ${build_arch} usr/local/bin/${name} -o ${worksrcpath}/${name}"
    } else {
        copy ${pkg_path}/usr/local/bin/${name} ${worksrcpath}/${name}
    }
}

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