# -*- 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 f8633c0c9217ed5499fdda391946d416c52e6809
# Change github.tarball_from to 'releases' or 'archive' next update
github.tarball_from tarball
version             20250325
revision            0

description         Cross platform audio library

long_description    {*}${description}

categories          audio
license             ISC
maintainers         {gmail.com:herby.gillot @herbygillot} \
                    openmaintainer

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_SHARED_LIBS=ON \
                    -DBUILD_TESTS=OFF \
                    -DENABLE_JACK=OFF \
                    -DENABLE_PULSE=OFF \
                    -DLAZY_LOAD_LIBS=OFF \
                    -DUSE_AUDIOUNIT=OFF

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

platform darwin powerpc {
    # Rust is not built by default, but just to make sure.
    # libsanitizer is not supported on powerpc*-*-darwin.
    configure.args-append \
                    -DBUILD_RUST_LIBS=OFF \
                    -DUSE_SANITIZERS=OFF
}

variant jack description "Enable pusleaudio" {
    # Should not be used with gcc:
    # 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" {
    depends_lib-append \
                    port:pulseaudio
    configure.args-replace \
                    -DENABLE_PULSE=OFF -DENABLE_PULSE=ON
}
