# -*- 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        Kruszoneq macUSB 2.5 v
github.tarball_from archive
name                [string tolower ${github.project}]
revision            0
categories          sysutils aqua
platforms           {macosx >= 23}
supported_archs     arm64 x86_64
maintainers         {i0ntempest @i0ntempest} openmaintainer
license             MIT

description         Create bootable USB installers for macOS, Windows, and Linux
long_description    macUSB is a native macOS application for creating bootable \
                    USB media from macOS installers, Windows and Linux ISO \
                    images, and raw disk images. It also includes a macOS \
                    installer downloader.

checksums           rmd160  42dcac7c8a71b51fecf5bb22dba40d084a0706c1 \
                    sha256  46f0d1742cd5e4fa6db64cb4718a9c1b65db3d9dd10e374f2ef8f9449860a416 \
                    size    37211757


# https://github.com/Kruszoneq/macUSB/pull/132
patchfiles-append   patch-pr-132.diff
# add compatibility with adhoc signing
patchfiles-append   patch-macports-signing.diff
# Application updates are managed by MacPorts.
patchfiles-append   patch-disable-updates.diff
patch.pre_args      -p1

depends_run-append  port:wimlib

post-patch {
    reinplace "s|@APPLICATIONS_DIR@|${applications_dir}|g" \
        ${worksrcpath}/macUSBHelper/Security/HelperConnectionSecurityPolicy.swift
    reinplace "s|@PREFIX@|${prefix}|g" \
        ${worksrcpath}/macUSB/Shared/Services/Windows/WindowsToolchainProbeService.swift \
        ${worksrcpath}/macUSBHelper/Workflow/Windows/HelperWorkflowWindowsSourceLogic.swift
}

# The project uses Icon Composer and Swift concurrency settings from Xcode 26.
pre-fetch {
    if {[vercmp ${xcodeversion} 26.0] < 0} {
        return -code error "macUSB requires Xcode 26 or later."
    }
}

xcode.project       macUSB.xcodeproj
xcode.scheme        macUSB
xcode.configuration Release

# Keep Xcode/Swift caches in the build directory and allow compiler plugins
# inside the MacPorts sandbox (as in the macursor and shichizip ports).
build.pre_args-append \
                    -derivedDataPath ${workpath}/DerivedData \
                    -IDEPackageSupportDisableManifestSandbox=1 \
                    -IDEPackageSupportDisablePluginExecutionSandbox=1
xcode.build.settings-append \
                    ENABLE_USER_SCRIPT_SANDBOXING=NO \
                    OTHER_SWIFT_FLAGS='-disable-sandbox' \
                    CLANG_MODULE_CACHE_PATH=${workpath}/ModuleCache \
                    CODE_SIGN_STYLE=Manual \
                    CODE_SIGN_IDENTITY=- \
                    DEVELOPMENT_TEAM=

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

notes "
    Enable macUSB in System Settings > General > Login Items & Extensions,
    and grant Full Disk Access in Privacy & Security before creating media.
"
