# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:et:sw=4:ts=4:sts=4

PortSystem              1.0
PortGroup               github 1.0
PortGroup               xcode 1.0

github.setup            idawnlight ShichiZip 0.1.6 v
name                    [string tolower ${github.project}]
github.tarball_from     releases
distname                ${name}-${github.tag_prefix}${version}-source
revision                0
platforms               {darwin >= 23}
categories              archivers aqua
maintainers             {i0ntempest @i0ntempest} openmaintainer
license                 LGPL-2.1
platforms               macosx
distname                ${name}-${github.tag_prefix}${version}-source

description             7-Zip FM derivative intended for macOS
long_description        ${github.project} is the missing 7-Zip derivative intended for macOS aiming\
                        to provide the 7-Zip File Manager experience, rebuilt natively for macOS.

checksums               rmd160  6af0c5bf74df0c48ebfc7fd815da163743e02ec0 \
                        sha256  2a905eb40027078e39125f404c411738dd8ef009dbb3406ee3cef5ecc92d7968 \
                        size    10260211

# switch to zig once emutls bug is fixed: https://trac.macports.org/ticket/73950
depends_build-append    port:zig-bootstrap

extract.rename          yes

if {![variant_isset zstd]} {
    # 7zip standard
    set variant_suffix  ""
    set zig_variant_arg ""
} else {
    # 7zip zstandard variant
    set variant_suffix  zs
    set zig_variant_arg -Dvariant=${variant_suffix}
}

# bundled sfx stub is always Windows x86
pre-build {
    system -W ${worksrcpath} "${prefix}/bin/zig-bootstrap build -j${build.jobs} lib ${zig_variant_arg} -Doptimize=ReleaseFast --verbose --verbose-link --verbose-cc --summary all -p build"
    system -W ${worksrcpath} "${prefix}/bin/zig-bootstrap build -j${build.jobs} sfx ${zig_variant_arg} -Doptimize=ReleaseSmall --verbose --verbose-link --verbose-cc --summary all -p build"
}

universal_variant       no
xcode.scheme            "${github.project}[string toupper ${variant_suffix}]"
xcode.configuration     Release
xcode.build.settings-append \
                        CODE_SIGN_IDENTITY=- \
                        -derivedDataPath ./DerivedData

destroot {
    file copy {*}[glob ${worksrcpath}/build/${xcode.configuration}/${github.project}*.app] ${destroot}${applications_dir}
}

variant zstd description {use 7zip Zstandard variant, add support for Zstd/Brotli/Lizard/Fast LZMA2 codecs} {}
