# -*- 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.26
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  ffc69e38145819b2b470d679359f87f3086e0b5a \
                    sha256  838ba55a21c9142adf7b76bdc4351e5cd8b7ae128f46b25ec25f94ae9969c600 \
                    size    4572837

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}
}
