# $Id: Portfile 90524 2012-03-08 05:06:29Z jmr@macports.org $

PortSystem 1.0

name           csound
set branch     5.16
version        ${branch}.6
categories     audio
license        LGPL-2.1+
maintainers    nomaintainer
description    A language that is used to describe sound synthesizers.
long_description \
    Csound is a computer programming language for dealing with sound. \
    It is called Csound because it is written in the C programming language, \
    as opposed to some of its predecessors. \
    Csound was written at MIT by Barry Vercoe, \
    based on an earlier language called Music360.

homepage       http://www.csounds.com/
platforms      darwin
master_sites   sourceforge:project/csound/csound5/csound${branch}
distname       Csound${version}
# no bz2 for 5.16.6
#use_bzip2      yes
checksums      md5 bfca0a5e521781e253fe8ae457bbb9c3 \
               sha1 28bbf5d34ee5bb11dc1d50fb122b5a706d317c33 \
               rmd160 49f3f7af3cfca6e129750564822698f4d2433329
depends_lib    path:bin/fltk-config:fltk port:libsndfile port:gettext
depends_build  port:scons

# fltk is 32-bit only
supported_archs i386 ppc

patchfiles     SConstruct.patch pluginSDK_SConstruct.patch \
               custom-osx.py.patch InOut_widgets.cpp.patch CoreMIDI_case.patch
post-patch {
    reinplace "s|__PREFIX__|${prefix}|" ${worksrcpath}/custom-osx.py
    reinplace "s|__CFLAGS__|${configure.cflags}|" ${worksrcpath}/custom-osx.py
    reinplace "s|__CXXFLAGS__|${configure.cxxflags}|" ${worksrcpath}/custom-osx.py
    reinplace "s|__ARCHFLAGS__|'[join ${configure.cc_archflags} "', '"]'|" ${worksrcpath}/custom-osx.py
    reinplace "s|__FRAMEWORKS_DIR__|${frameworks_dir}|g" ${worksrcpath}/SConstruct
    platform darwin {
        copy ${worksrcpath}/custom-osx.py ${worksrcpath}/custom.py
    }
}

use_configure  no

build.cmd      ${prefix}/bin/scons
build.target
build.args     prefix=${prefix} CC=${configure.cc} CXX=${configure.cxx} \
               usePortAudio=0 usePortMIDI=0 useJack=0 useFLTK=1 \
               buildCsound5GUI=1 buildRelease=1 dynamicCsoundLibrary=1 \
               instdir=${destroot}
build.post_args install=0
destroot.args  ${build.args}
destroot.target install=1 install
destroot.destdir

post-destroot {
    copy ${worksrcpath}/frontends/fltk_gui/Csound5GUI.app \
         ${destroot}${applications_dir}
}
