# -*- 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            FNA-XNA FAudio 24.12
revision                0

license                 zlib
categories              audio
maintainers             nomaintainer
description             XAudio reimplementation
long_description        an XAudio reimplementation that focuses solely on developing \
                        fully accurate DirectX Audio runtime libraries for the FNA project,\
                        including XAudio2, X3DAudio, XAPO, and XACT3.

depends_lib-append      port:libsdl2

checksums               rmd160  22c7687ba90a2e3f2374eb230d0be34623d4261b \
                        sha256  82feeb58301c4b7316ff6ee2201310073d8c9698ceb3f6f2cf5cc533dee0a415 \
                        size    1126609
github.tarball_from     archive

# remove set deployment target and hard-coded RPATH setting
patchfiles              patch-faudio-remove-deployment-target.diff

configure.args          -DBUILD_UTILS=OFF \
                        -DBUILD_TESTS=ON \
                        -DXNASONG=ON \
                        -DCMAKE_INSTALL_INCLUDEDIR=include/FAudio

# https://github.com/FNA-XNA/FAudio/issues/321
# Xcode clang on 10.6 also fails to build it.
# FAudio.h: error: wrong number of arguments specified for ‘deprecated’ attribute
compiler.blacklist-append \
                        *gcc-4.* {clang < 421}

# On macOS 23+ this fails at the moment:
# ld: warning: alignment (4) of atom '_FACT3DCalculate.DefaultCurve'
# from '/opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_audio_FAudio/FAudio/work/build/CMakeFiles/FAudio.dir/src/FACT3D.c.o'
# is too small and may result in unaligned pointers.
# Temporary fix by setting deployment target to Big Sur.
# https://github.com/FNA-XNA/FAudio/issues/362
# Related: https://github.com/ldc-developers/ldc/issues/3864
platform darwin arm {
    if {${os.major} > 22} {
        macosx_deployment_target    11.0
    }
}

#pre-destroot {
#    there are some utilities to consider, but the facttool segfaulted when I tried to open an audio engine
#    they are not installed by default with the cmake install script, and other pkg systems don't install them
#    they can be re-enabled by toggling -DBUILD_UTILS=ON, and manually installed like so if desired
#    file copy ${workpath}/build/facttool ${destroot}${prefix}/bin/
#}

test.run                 yes
# Otherwise it looks in prefix, and if the port has not been installed earlier, that fails:
# dyld: Library not loaded: /opt/local/lib/libFAudio.0.dylib
# On PowerPC tests do not run: https://github.com/FNA-XNA/FAudio/issues/319
test.env-append          DYLD_LIBRARY_PATH=${cmake.build_dir}
test.cmd                 ./faudio_tests
test.target
