# -*- 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               xcode 1.0
PortGroup               github 1.0

github.setup            jordanbaird Ice 0.11.12
github.tarball_from     archive
revision                0

homepage                https://icemenubar.app/

categories              aqua
license                 GPL-3
platforms               {macosx >= 14}
maintainers             {gmail.com:herby.gillot @herbygillot} \
                        openmaintainer

description             Powerful menu bar manager for macOS

long_description        \
    Ice is a powerful menu bar management tool for macOS.  While its primary \
    function is hiding and showing menu bar items, it offers a wide range of \
    features to manage the menu bar. Items can be hidden or shown on demand, \
    rearranged via drag-and-drop, and searched. The menu bar appearance can \
    also be fully customized.

checksums               rmd160  c02a7a7f7839254c5cac1ffa941abefcb43378a2 \
                        sha256  6de28150c65d03bc17f80dc745eff15680903679a4dfe3b4bc88d46651761bb3 \
                        size    16700295

patchfiles              patch-disable-sparkle.diff

post-patch {
    # Remove Sparkle feed URL and public key from Info.plist
    set plist ${worksrcpath}/Ice/Info.plist
    system "/usr/libexec/PlistBuddy -c 'Delete :SUFeedURL' ${plist}"
    system "/usr/libexec/PlistBuddy -c 'Delete :SUPublicEDKey' ${plist}"
}

xcode.scheme            Ice
xcode.configuration     Release

# SPM generates sandbox profile temp files outside ${workpath}, which the
# MacPorts build sandbox blocks from being read, causing sandbox_apply to fail.
# Redirect all of Xcode's working state into ${workpath} to keep everything
# within the sandbox-allowed tree.
build.pre_args-append   -derivedDataPath ${workpath}/derived-data \
                        -clonedSourcePackagesDirPath ${workpath}/spm-packages

build.env-append        TMPDIR=${workpath}/tmp \
                        HOME=${workpath}/home

pre-build {
    file mkdir ${workpath}/tmp
    file mkdir ${workpath}/home/Library/Caches

    # SPM sandboxes its manifest-loading subprocesses via sandbox-exec, but
    # macOS rejects nested sandbox_apply calls when the process is already
    # sandboxed by MacPorts.  Allow sandbox-exec to run without inheriting
    # the MacPorts profile so it can apply its own profile successfully.
    append portsandbox_profile " (allow process-exec (literal \"/usr/bin/sandbox-exec\") (with no-profile))"
}

xcode.build.settings-append \
                        SDKROOT=macosx \
                        DEVELOPMENT_TEAM= \
                        CODE_SIGN_IDENTITY= \
                        CODE_SIGNING_REQUIRED=NO \
                        CODE_SIGN_ENTITLEMENTS= \
                        ENABLE_USER_SCRIPT_SANDBOXING=NO \
                        OTHER_SWIFT_FLAGS='-Xfrontend -disable-availability-checking'

destroot {
    copy ${worksrcpath}/build/${xcode.configuration}/Ice.app \
        ${destroot}${applications_dir}/Ice.app
}
