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

github.setup        mackron miniaudio 0.11.25
github.tarball_from archive
revision            0

categories          audio
license             public-domain
maintainers         {@herbygillot gmail.com:herby.gillot} openmaintainer

description         Audio playback and capture library
long_description    Miniaudio provides audio playback, capture, decoding, encoding, \
                    resource management, and audio processing through a C API.
homepage            https://miniaud.io/

checksums           rmd160  61ae3cf45c8e98cad60d830247a8affef0f82435 \
                    sha256  b900edcffe979816e2560a0580b9b1216d674b4f17fbadeca8f777a7f8ab0274 \
                    size    4552901

depends_build-append port:pkgconfig
depends_lib-append   port:libvorbis \
                    port:opusfile \
                    port:verblib \
                    port:voclib

patch.pre_args-replace -p0 -p1
patchfiles          patch-cmake-and-system-effects.diff

# Remove the bundled effect headers so the MacPorts copies are used.
post-extract {
    delete ${worksrcpath}/extras/nodes/ma_reverb_node/verblib.h \
           ${worksrcpath}/extras/nodes/ma_vocoder_node/voclib.h
}

# These generated private codecs use ma_dr_* APIs rather than the public dr_libs API.
# Keep upstream's built-in WAV, FLAC, and MP3 support until an external adapter exists.
configure.args-append \
                    -DBUILD_SHARED_LIBS=ON \
                    -DMINIAUDIO_BUILD_EXAMPLES=OFF \
                    -DMINIAUDIO_BUILD_TESTS=ON \
                    -DMINIAUDIO_BUILD_TOOLS=OFF \
                    -DMINIAUDIO_NO_EXTRA_NODES=OFF \
                    -DMINIAUDIO_NO_LIBVORBIS=OFF \
                    -DMINIAUDIO_NO_LIBOPUS=OFF

# These upstream tests do not open audio devices or require user interaction.
test.run            yes
test.cmd            ${prefix}/bin/ctest
test.target
test.args           --output-on-failure -R {"miniaudio_(conversion|generation|filtering)"}

post-destroot {
    set docdir ${destroot}${prefix}/share/doc/${name}
    xinstall -d ${docdir}
    xinstall -m 0644 -W ${worksrcpath} LICENSE README.md CHANGES.md ${docdir}
}
