# -*- 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           meson 1.0

name                rubberband
version             4.0.0
revision            0
categories          audio
maintainers         {ryandesign @ryandesign} openmaintainer
license             GPL-2+

description         audio time-stretching and pitch-shifting library and utility program

long_description    Rubber Band is a library and utility program that permits \
                    changing the tempo and pitch of an audio recording \
                    independently of one another.

homepage            https://breakfastquay.com/rubberband/
master_sites        https://breakfastquay.com/files/releases/
use_bzip2           yes
checksums           rmd160  759bee5ea67aadafc2365ec41e97b0be8bcaeb73 \
                    sha256  af050313ee63bc18b35b2e064e5dce05b276aaf6d1aa2b8a82ced1fe2f8028e9 \
                    size    236705

depends_build-append \
                    port:cctools \
                    path:bin/pkg-config:pkgconfig

depends_lib-append  port:libsamplerate \
                    port:libsndfile

patchfiles          arch.patch \
                    src_common_mathmisc.h.patch

# /usr/bin/../lib/c++/v1/atomic:535:2: error: <atomic> is not implemented
# https://hg.sr.ht/~breakfastquay/rubberband/rev/812a666b042abf0e41465bee9924c7ffc8532bbf
compiler.cxx_standard   2014

configure.args      -Dauto_features=disabled \
                    -Dcmdline=enabled \
                    -Djni=disabled \
                    -Dresampler=libsamplerate

# Uses Accelerate on macOS by default:
if {${os.platform} eq "darwin"} {
    configure.args-append \
                    -Dfft=builtin
} else {
    depends_lib-append \
                    port:fftw-3
    configure.args-append \
                    -Dfft=fftw
}

if {[string match *clang* ${configure.cxx}] && ${configure.cxx_stdlib} ne ""} {
    configure.ldflags-append -stdlib=${configure.cxx_stdlib}
}

if {[string match *gcc* ${configure.compiler}]} {
    # ___atomic_is_lock_free, ___atomic_load_8, ___atomic_store_8
    # https://todo.sr.ht/~breakfastquay/rubberband/28
    configure.ldflags-append -latomic
}

post-destroot {
    set docdir ${prefix}/share/doc/${subport}
    xinstall -d ${destroot}${docdir}
    xinstall -m 0644 -W ${worksrcpath} \
        CHANGELOG \
        COPYING \
        README.md \
        ${destroot}${docdir}
}

platform darwin {
    configure.args-replace -Dfft=builtin -Dfft=vdsp

    # meson.build sets -mmacosx-version-min to a value we didn't ask for
    # unless we set it ourselves.
    configure.cxxflags-append -mmacosx-version-min=${macosx_deployment_target}
}

livecheck.type      regex
livecheck.regex     ${name}-(\[0-9.\]+)${extract.suffix}
