···11+{ stdenv
22+, coreutils
33+, fetchgit
44+, makeWrapper
55+, pkgconfig
66+}:
77+88+with stdenv.lib.strings;
99+1010+let
1111+1212+ version = "2016-04-27";
1313+1414+ src = fetchgit {
1515+ url = "git://git.code.sf.net/p/faudiostream/code";
1616+ rev = "931fca3e649f99ef09025d37bd6a7dc70a03e6f6";
1717+ sha256 = "05yam8jfdnziysvpxa5w118k5bbl103vamyqgka6vyhjjizp1nx7";
1818+ };
1919+2020+ meta = with stdenv.lib; {
2121+ homepage = http://faust.grame.fr/;
2222+ downloadPage = http://sourceforge.net/projects/faudiostream/files/;
2323+ license = licenses.gpl2;
2424+ platforms = platforms.linux;
2525+ maintainers = with maintainers; [ magnetophon pmahoney ];
2626+ };
2727+2828+ faust = stdenv.mkDerivation {
2929+3030+ name = "faust-${version}";
3131+3232+ inherit src;
3333+3434+ buildInputs = [ makeWrapper ];
3535+3636+ passthru = {
3737+ inherit wrap wrapWithBuildEnv;
3838+ };
3939+4040+ preConfigure = ''
4141+ makeFlags="$makeFlags prefix=$out"
4242+4343+ # The faust makefiles use 'system ?= $(shell uname -s)' but nix
4444+ # defines 'system' env var, so undefine that so faust detects the
4545+ # correct system.
4646+ unset system
4747+ '';
4848+4949+ # Remove most faust2appl scripts since they won't run properly
5050+ # without additional paths setup. See faust.wrap,
5151+ # faust.wrapWithBuildEnv.
5252+ postInstall = ''
5353+ # syntax error when eval'd directly
5454+ pattern="faust2!(svg)"
5555+ (shopt -s extglob; rm "$out"/bin/$pattern)
5656+ '';
5757+5858+ postFixup = ''
5959+ # Set faustpath explicitly.
6060+ substituteInPlace "$out"/bin/faustpath \
6161+ --replace "/usr/local /usr /opt /opt/local" "$out"
6262+6363+ # The 'faustoptflags' is 'source'd into other faust scripts and
6464+ # not used as an executable, so patch 'uname' usage directly
6565+ # rather than use makeWrapper.
6666+ substituteInPlace "$out"/bin/faustoptflags \
6767+ --replace uname "${coreutils}/bin/uname"
6868+6969+ # wrapper for scripts that don't need faust.wrap*
7070+ for script in "$out"/bin/faust2*; do
7171+ wrapProgram "$script" \
7272+ --prefix PATH : "$out"/bin
7373+ done
7474+ '';
7575+7676+ meta = meta // {
7777+ description = "A functional programming language for realtime audio signal processing";
7878+ longDescription = ''
7979+ FAUST (Functional Audio Stream) is a functional programming
8080+ language specifically designed for real-time signal processing
8181+ and synthesis. FAUST targets high-performance signal processing
8282+ applications and audio plug-ins for a variety of platforms and
8383+ standards.
8484+ The Faust compiler translates DSP specifications into very
8585+ efficient C++ code. Thanks to the notion of architecture,
8686+ FAUST programs can be easily deployed on a large variety of
8787+ audio platforms and plugin formats (jack, alsa, ladspa, maxmsp,
8888+ puredata, csound, supercollider, pure, vst, coreaudio) without
8989+ any change to the FAUST code.
9090+9191+ This package has just the compiler, libraries, and headers.
9292+ Install faust2* for specific faust2appl scripts.
9393+ '';
9494+ };
9595+9696+ };
9797+9898+ # Default values for faust2appl.
9999+ faust2ApplBase =
100100+ { baseName
101101+ , dir ? "tools/faust2appls"
102102+ , scripts ? [ baseName ]
103103+ , ...
104104+ }@args:
105105+106106+ args // {
107107+ name = "${baseName}-${version}";
108108+109109+ inherit src;
110110+111111+ configurePhase = ":";
112112+113113+ buildPhase = ":";
114114+115115+ installPhase = ''
116116+ runHook preInstall
117117+118118+ mkdir -p "$out/bin"
119119+ for script in ${concatStringsSep " " scripts}; do
120120+ cp "${dir}/$script" "$out/bin/"
121121+ done
122122+123123+ runHook postInstall
124124+ '';
125125+126126+ postInstall = ''
127127+ # For the faust2appl script, change 'faustpath' and
128128+ # 'faustoptflags' to absolute paths.
129129+ for script in "$out"/bin/*; do
130130+ substituteInPlace "$script" \
131131+ --replace ". faustpath" ". '${faust}/bin/faustpath'" \
132132+ --replace ". faustoptflags" ". '${faust}/bin/faustoptflags'"
133133+ done
134134+ '';
135135+136136+ meta = meta // {
137137+ description = "The ${baseName} script, part of faust functional programming language for realtime audio signal processing";
138138+ };
139139+ };
140140+141141+ # Some 'faust2appl' scripts, such as faust2alsa, run faust to
142142+ # generate cpp code, then invoke the c++ compiler to build the code.
143143+ # This builder wraps these scripts in parts of the stdenv such that
144144+ # when the scripts are called outside any nix build, they behave as
145145+ # if they were running inside a nix build in terms of compilers and
146146+ # paths being configured (e.g. rpath is set so that compiled
147147+ # binaries link to the libs inside the nix store)
148148+ #
149149+ # The function takes two main args: the appl name (e.g.
150150+ # 'faust2alsa') and an optional list of propagatedBuildInputs. It
151151+ # returns a derivation that contains only the bin/${appl} script,
152152+ # wrapped up so that it will run as if it was inside a nix build
153153+ # with those build inputs.
154154+ #
155155+ # The build input 'faust' is automatically added to the
156156+ # propagatedBuildInputs.
157157+ wrapWithBuildEnv =
158158+ { baseName
159159+ , propagatedBuildInputs ? [ ]
160160+ , ...
161161+ }@args:
162162+163163+ stdenv.mkDerivation ((faust2ApplBase args) // {
164164+165165+ buildInputs = [ makeWrapper pkgconfig ];
166166+167167+ propagatedBuildInputs = [ faust ] ++ propagatedBuildInputs;
168168+169169+ postFixup = ''
170170+171171+ # export parts of the build environment
172172+ for script in "$out"/bin/*; do
173173+ wrapProgram "$script" \
174174+ --set FAUSTLIB "${faust}/lib/faust" \
175175+ --set FAUSTINC "${faust}/include/faust" \
176176+ --prefix PATH : "$PATH" \
177177+ --prefix PKG_CONFIG_PATH : "$PKG_CONFIG_PATH" \
178178+ --set NIX_CFLAGS_COMPILE "\"$NIX_CFLAGS_COMPILE\"" \
179179+ --set NIX_LDFLAGS "\"$NIX_LDFLAGS\""
180180+ done
181181+ '';
182182+ });
183183+184184+ # Builder for 'faust2appl' scripts, such as faust2firefox that
185185+ # simply need to be wrapped with some dependencies on PATH.
186186+ #
187187+ # The build input 'faust' is automatically added to the PATH.
188188+ wrap =
189189+ { baseName
190190+ , runtimeInputs ? [ ]
191191+ , ...
192192+ }@args:
193193+194194+ let
195195+196196+ runtimePath = concatStringsSep ":" (map (p: "${p}/bin") ([ faust ] ++ runtimeInputs));
197197+198198+ in stdenv.mkDerivation ((faust2ApplBase args) // {
199199+200200+ buildInputs = [ makeWrapper ];
201201+202202+ postFixup = ''
203203+ for script in "$out"/bin/*; do
204204+ wrapProgram "$script" --prefix PATH : "${runtimePath}"
205205+ done
206206+ '';
207207+208208+ });
209209+210210+in faust