# -*- 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 2.5.23
revision                2
github.tarball_from     releases

conflicts               faust-devel
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.

checksums               rmd160  f0b6ebc1542e8c91c88dbba42a57296cdc2b38ce \
                        sha256  d87ef98a7a25367c12f51fe1ebb07fe4f2c0b37f27b63b7bcd074273b295e5fb \
                        size    47314425

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 6.0 instead.
    set llvm_version    6.0
}

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

depends_build           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 \
                        patch-compiler-llvm6.diff

post-patch {
    reinplace "s|/usr/local/|/usr/./local/|g" \
        ${worksrcpath}/tools/faust2appls/faust2faustvst
    reinplace -q "s|/usr/local|${prefix}|g" \
        ${worksrcpath}/compiler/parser/enrobage.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]"
build.target            world

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