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

github.setup        saagarjha unxip 3.3 v
revision            0
github.tarball_from archive

categories          archivers sysutils
license             LGPL-3
maintainers         {i0ntempest @i0ntempest} {saagarjha.com:saagar @saagarjha} openmaintainer

description         A fast signed archive extractor
long_description    ${name} is a command-line tool designed for rapidly unarchiving Xcode \
                    XIP files and writing them to disk with good compression. Its goal is to \
                    outperform Bom (which powers xip and Archive Utility) in both performance \
                    and on-disk usage.

checksums           rmd160  6c1760b7fe2cf7a355f274ac67111405d2d3ff08 \
                    sha256  490c27aeabad33a8c811ada09008d24835f0f701ad40092b450c4788cdf99198 \
                    size    22776

if {${os.platform} eq "darwin" && ${os.major} < 21} {
    known_fail yes
    pre-fetch {
        ui_error "${name} requires macOS 12 or later."
        return -code error "incompatible macOS version"
    }
}

use_configure       no
universal_variant   yes

# Use MacOSX13.sdk to compile on macOS 12 Monterey
if {${os.platform} eq "darwin" && ${os.major} < 22} {
    configure.sdk_version   13
}

build.cmd           swift
build.target        build
build.args          --configuration release --disable-sandbox

if {${os.platform} ne "darwin"} {
    depends_lib     port:zlib \
                    port:xz
}

if {${universal_possible} && [variant_isset universal]} {
    foreach arch "${muniversal.architectures}" {
        build.args.${arch}-append --arch "${arch}"
    }
}

destroot {
    xinstall -m 755 ${worksrcpath}/.build/release/${name} ${destroot}${prefix}/bin/
}
