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

github.setup        mozilla cubeb 1b7de400134aac33d9c6b59ac1be9ddbf86d16eb
version             20260314
revision            0
categories          audio
license             ISC
maintainers         {gmail.com:herby.gillot @herbygillot} \
                    openmaintainer

description         Cross platform audio library
long_description    {*}${description}

fetch.type          git

set py_ver          3.13
set py_ver_nodot    [string map {. {}} ${py_ver}]

depends_build-append \
                    path:bin/doxygen:doxygen \
                    path:bin/pkg-config:pkgconfig \
                    port:python${py_ver_nodot}

depends_lib-append  port:speexdsp

post-fetch {
    system -W ${worksrcpath} "git submodule update --init --recursive"
}

# https://trac.macports.org/ticket/71027
compiler.cxx_standard   2017

configure.args-append \
                    -DBUILD_RUST_LIBS=OFF \
                    -DBUILD_SHARED_LIBS=ON \
                    -DBUILD_TESTS=OFF \
                    -DENABLE_JACK=OFF \
                    -DENABLE_PULSE=OFF \
                    -DLAZY_LOAD_LIBS=OFF \
                    -DUSE_AUDIOUNIT=OFF \
                    -DUSE_SANITIZERS=OFF

# AudioUnit configure check is wrong: it only verifies the header,
# but the code requires libdispatch and uses blocks.
# https://github.com/mozilla/cubeb/issues/804
if {${os.platform} eq "darwin" && ${os.major} > 9} {
    configure.args-replace \
                    -DUSE_AUDIOUNIT=OFF -DUSE_AUDIOUNIT=ON
}

if {(${os.platform} eq "darwin" && ${os.major} < 11) \
    || [string match *gcc* ${configure.compiler}]} {
    patchfiles-append \
                    0001-audiounit-Replace-blocks-with-function-pointers-for-.patch
}

variant jack description "Enable pusleaudio" {
    # On powerpc only jack 1.x is available.
    # https://github.com/jackaudio/jack2/issues/950
    depends_lib-append \
                    port:jack
    configure.args-replace \
                    -DENABLE_JACK=OFF -DENABLE_JACK=ON
}

variant pulse description "Enable pusleaudio" {
    # Does it even work for someone?
    depends_lib-append \
                    port:pulseaudio
    configure.args-replace \
                    -DENABLE_PULSE=OFF -DENABLE_PULSE=ON
}

# ___atomic_fetch_add_8, ___atomic_load_8, ___atomic_store_8
if {[string match *gcc* ${configure.compiler}] && ${configure.build_arch} in [list arm i386 ppc]} {
    configure.ldflags-append \
                    -latomic
}
