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

github.setup            grame-cncm faust 96f22a55e86dac30cbf2e38ba115f5723ed6b096
# Change github.tarball_from to 'releases' or 'archive' next update
github.tarball_from     tarball
# When updating faust-devel to a new version, please rebuild faustlive-devel
# simultaneously by increasing its revision or updating it to a new version.
version                 2.11-20181109
revision                2

name                    faust-devel
conflicts               faust
categories              audio lang
platforms               darwin
maintainers             {ryandesign @ryandesign} {gmail.com:aggraef @agraef}
license                 GPL-2
homepage                http://faust.grame.fr/

description             functional programming language for realtime audio

long_description        Faust is a functional programming language \
                        specifically designed for realtime audio applications \
                        and plugins. The latest version also offers \
                        additional backends for C, Java and LLVM bitcode.

fetch.type              git
post-fetch {
    system -W ${worksrcpath} "git submodule update --init"
}

set llvm_version        3.4
if {${os.platform} eq "darwin" && ${os.major} > 14} {
    # clang 3.4 isn't supported in the latest macOS versions any more, go with LLVM 7.0 instead.
    set llvm_version    7.0
}

set llvm_prefix         ${prefix}/libexec/llvm-${llvm_version}
build.env               PATH=${llvm_prefix}/bin:$env(PATH)

depends_build           path:bin/cmake:cmake \
                        port:pkgconfig

depends_lib             port:clang-${llvm_version} \
                        port:libmicrohttpd \
                        port:libsndfile \
                        port:llvm-${llvm_version} \
                        path:lib/libssl.dylib:openssl

patchfiles              patch-compiler-Makefile.unix.diff

post-patch {
    reinplace "s|/usr/local/|/usr/./local/|g" \
        ${worksrcpath}/tools/faust2appls/faust2faustvst
    reinplace "s|/usr/local|${prefix}|g" \
        ${worksrcpath}/compiler/libcode.cpp \
        ${worksrcpath}/compiler/tlib/compatibility.cpp \
        ${worksrcpath}/tools/scbuilder/scbuilder \
        {*}[glob ${worksrcpath}/tools/faust2appls/faust2*]
    fs-traverse f ${worksrcpath} {
        switch [file rootname [file tail ${f}]] {
            Makefile {
                reinplace -q "s|/usr/local|${prefix}|g" ${f}
                reinplace -q "s|/opt/local|${prefix}|g" ${f}
            }
        }
    }
    reinplace "s|/usr/\./local/|/usr/local/|g" \
        ${worksrcpath}/tools/faust2appls/faust2faustvst
}

compiler.cxx_standard   2011
configure.cxxflags-append -std=gnu++11
if {[string match *clang* ${configure.compiler}] && ${configure.cxx_stdlib} ne ""} {
    configure.cxxflags-append -stdlib=${configure.cxx_stdlib}
}

use_configure           no

variant universal {}

build.args-append       ARCHFLAGS="[get_canonical_archflags cxx]" \
                        CXX="${configure.cxx} ${configure.cxxflags} [get_canonical_archflags cxx]" \
                        VERBOSE=1
build.target            world

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

# fixme
livecheck.type          none
