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

github.setup        ExistentialAudio BlackHole 0.7.1 v

github.tarball_from archive
categories          audio
maintainers         {hotmail.com:amtor @RobK88} openmaintainer
license             GPL-3

description         macOS virtual audio driver.

long_description    BlackHole is a modern macOS virtual audio driver that \
                    allows applications to pass audio to other applications \
                    with zero additional latency.

checksums           rmd160  6e559a68c35ddffd9d6db1a45e5c90ff5049dd2b \
                    sha256  e9de179da54ed55ff27876990f3a2dcfefa66e6bd6cfcba448a8564eabdf3e89 \
                    size    633743

xcode.configuration Release
xcode.build.settings CODE_SIGN_IDENTITY= CODE_SIGNING_ALLOWED=NO XCODEFLAGS="CACHE_ROOT=${workpath}/caches -UseNewBuildSystem=NO"

# The Xcode build system can't process an SDK that isn't its own (e.g. the CLT
# 14.x SDK with Xcode 16.2, which only ships 15.x). MacPorts falls back to the
# CLT SDK when Xcode has no SDK matching the host OS. Only in that case, use
# Xcode's default SDK; MACOSX_DEPLOYMENT_TARGET still pins the minimum OS.
if {[string match /Library/Developer/CommandLineTools/* ${configure.sdkroot}]} {
    xcode.build.settings-append SDKROOT=macosx
}

xcode.destroot.settings {*}${xcode.build.settings}
xcode.destroot.path /Library/Audio/Plug-Ins/HAL

# BlackHole violates the mtree layout by placing the driver in
# /Library/Audio/Plug-Ins/HAL
destroot.violate_mtree yes

compiler.blacklist-append {clang < 600}

variant ch8 conflicts ch16 ch64 description "Enable 8 channels" {
    post-patch {
        reinplace "s|kNumber_Of_Channels                 2|kNumber_Of_Channels                 8|" ${worksrcpath}/BlackHole/BlackHole.c
    }
}

variant ch16 conflicts ch8 ch64 description "Enable 16 channels" {
    post-patch {
        reinplace "s|kNumber_Of_Channels                 2|kNumber_Of_Channels                 16|" ${worksrcpath}/BlackHole/BlackHole.c
    }
}

variant ch64 conflicts ch8 ch16 description "Enable 64 channels" {
    post-patch {
        reinplace "s|kNumber_Of_Channels                 2|kNumber_Of_Channels                 64|" ${worksrcpath}/BlackHole/BlackHole.c
    }
}

notes "\
After installing or uninstalling BackHole using MacPorts, you will need to either reboot\
your Mac or run the following command to complete the installation or uninstallation:

    sudo killall -9 coreaudiod
"
