nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 lib,
3 stdenv,
4 coreutils,
5 fetchFromGitHub,
6 makeWrapper,
7 pkg-config,
8 cmake,
9 llvm,
10 emscripten,
11 openssl,
12 libsndfile,
13 libmicrohttpd,
14 gnutls,
15 libtasn1,
16 libtool,
17 libxml2,
18 p11-kit,
19 vim,
20 which,
21 ncurses,
22 fetchpatch,
23}:
24
25let
26
27 version = "2.83.1";
28
29 src = fetchFromGitHub {
30 owner = "grame-cncm";
31 repo = "faust";
32 tag = version;
33 hash = "sha256-DojqKLoGb6aGpqpeTAXyLFsbWs/UgYr9nA+JMGa712A=";
34 fetchSubmodules = true;
35 };
36
37 meta = {
38 homepage = "https://faust.grame.fr/";
39 downloadPage = "https://github.com/grame-cncm/faust/";
40 license = lib.licenses.gpl2;
41 platforms = lib.platforms.unix;
42 maintainers = with lib.maintainers; [
43 magnetophon
44 pmahoney
45 ];
46 };
47
48 faust =
49 let
50 ncurses_static = ncurses.override { enableStatic = true; };
51 in
52 stdenv.mkDerivation {
53
54 pname = "faust";
55 inherit version;
56
57 inherit src;
58
59 nativeBuildInputs = [
60 makeWrapper
61 pkg-config
62 cmake
63 libtool
64 vim
65 which
66 ];
67 buildInputs = [
68 llvm
69 emscripten
70 openssl
71 libsndfile
72 libmicrohttpd
73 gnutls
74 libtasn1
75 p11-kit
76 ncurses_static
77 libxml2
78 ];
79
80 passthru = { inherit wrap wrapWithBuildEnv faust2ApplBase; };
81
82 preConfigure = ''
83 # include llvm-config in path
84 export PATH="${lib.getDev llvm}/bin:$PATH"
85 cd build
86
87 ''
88 + lib.optionalString stdenv.hostPlatform.isDarwin ''
89 # Darwin cannot use 'libtool -static'
90 echo "Disabling static LLVM build on Darwin"
91 # Replace the whole static target with a no-op
92 printf 'all:\n\t@echo "Static LLVM build disabled on Darwin"\n' > Make.llvm.static
93 ''
94 + lib.optionalString stdenv.hostPlatform.isLinux ''
95 substituteInPlace Make.llvm.static \
96 --replace-fail 'mkdir -p $@ && cd $@ && ar -x ../../$<' \
97 'mkdir -p $@ && cd $@ && ar -x ../source/build/lib/libfaust.a && cd ../source/build/'
98 substituteInPlace Make.llvm.static \
99 --replace-fail 'rm -rf $(TMP)' ' ' \
100 --replace-fail " ar " " ${stdenv.cc.targetPrefix}ar "
101 sed -i \
102 's@LIBNCURSES_PATH ?= .*@LIBNCURSES_PATH ?= ${ncurses_static}/lib/libncurses.a@' \
103 Make.llvm.static
104 ''
105 + ''
106
107 cd ..
108 shopt -s globstar
109 for f in **/Makefile **/Makefile.library **/CMakeLists.txt build/Make.llvm.static embedded/faustjava/faust2engine architecture/autodiff/autodiff.sh source/tools/faust2appls/* **/llvm.cmake tools/benchmark/faust2object; do
110 echo $f "llvm-config${lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) "-native"}"
111 substituteInPlace $f \
112 --replace-quiet "llvm-config" "llvm-config${
113 lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) "-native"
114 }"
115 done
116 shopt -u globstar
117 cd build
118 '';
119
120 cmakeFlags = [
121 "-C../backends/all.cmake"
122 "-C../targets/all.cmake"
123 ];
124
125 postInstall = ''
126 # syntax error when eval'd directly
127 pattern="faust2!(*@(atomsnippets|graph|graphviewer|md|plot|sig|sigviewer|svg))"
128 (shopt -s extglob; rm "$out"/bin/$pattern)
129 '';
130
131 postFixup = ''
132 # The 'faustoptflags' is 'source'd into other faust scripts and
133 # not used as an executable, so patch 'uname' usage directly
134 # rather than use makeWrapper.
135 substituteInPlace "$out"/bin/faustoptflags \
136 --replace-fail uname "${coreutils}/bin/uname"
137
138 # wrapper for scripts that don't need faust.wrap*
139 for script in "$out"/bin/faust2*; do
140 wrapProgram "$script" \
141 --prefix PATH : "$out"/bin
142 done
143 '';
144
145 meta = meta // {
146 description = "Functional programming language for realtime audio signal processing";
147 longDescription = ''
148 FAUST (Functional Audio Stream) is a functional programming
149 language specifically designed for real-time signal processing
150 and synthesis. FAUST targets high-performance signal processing
151 applications and audio plug-ins for a variety of platforms and
152 standards.
153 The Faust compiler translates DSP specifications into very
154 efficient C++ code. Thanks to the notion of architecture,
155 FAUST programs can be easily deployed on a large variety of
156 audio platforms and plugin formats (jack, alsa, ladspa, maxmsp,
157 puredata, csound, supercollider, pure, vst, coreaudio) without
158 any change to the FAUST code.
159
160 This package has just the compiler, libraries, and headers.
161 Install faust2* for specific faust2appl scripts.
162 '';
163 };
164
165 };
166
167 # Default values for faust2appl.
168 faust2ApplBase =
169 {
170 baseName,
171 dir ? "tools/faust2appls",
172 scripts ? [ baseName ],
173 ...
174 }@args:
175
176 args
177 // {
178 pname = baseName;
179
180 inherit src version;
181
182 dontBuild = true;
183
184 installPhase = ''
185 runHook preInstall
186
187 mkdir -p "$out/bin"
188 for script in ${lib.concatStringsSep " " scripts}; do
189 cp "${dir}/$script" "$out/bin/"
190 done
191
192 runHook postInstall
193 '';
194
195 postInstall = ''
196 # For the faust2appl script, change 'faustpath' and
197 # 'faustoptflags' to absolute paths.
198 for script in "$out"/bin/*; do
199 substituteInPlace "$script" \
200 --replace-quiet " error " "echo"
201 done
202 '';
203
204 meta = meta // {
205 description = "The ${baseName} script, part of faust functional programming language for realtime audio signal processing";
206 };
207 };
208
209 # Some 'faust2appl' scripts, such as faust2alsa, run faust to
210 # generate cpp code, then invoke the c++ compiler to build the code.
211 # This builder wraps these scripts in parts of the stdenv such that
212 # when the scripts are called outside any nix build, they behave as
213 # if they were running inside a nix build in terms of compilers and
214 # paths being configured (e.g. rpath is set so that compiled
215 # binaries link to the libs inside the nix store)
216 #
217 # The function takes two main args: the appl name (e.g.
218 # 'faust2alsa') and an optional list of propagatedBuildInputs. It
219 # returns a derivation that contains only the bin/${appl} script,
220 # wrapped up so that it will run as if it was inside a nix build
221 # with those build inputs.
222 #
223 # The build input 'faust' is automatically added to the
224 # propagatedBuildInputs.
225 wrapWithBuildEnv =
226 {
227 baseName,
228 propagatedBuildInputs ? [ ],
229 ...
230 }@args:
231
232 stdenv.mkDerivation (
233 (faust2ApplBase args)
234 // {
235
236 nativeBuildInputs = [
237 pkg-config
238 makeWrapper
239 ];
240
241 propagatedBuildInputs = [ faust ] ++ propagatedBuildInputs;
242
243 libPath = lib.makeLibraryPath propagatedBuildInputs;
244
245 postFixup = ''
246
247 # export parts of the build environment
248 for script in "$out"/bin/*; do
249 # e.g. NIX_CC_WRAPPER_TARGET_HOST_x86_64_unknown_linux_gnu
250 nix_cc_wrapper_target_host="$(printenv | grep ^NIX_CC_WRAPPER_TARGET_HOST | sed 's/=.*//')"
251
252 # e.g. NIX_BINTOOLS_WRAPPER_TARGET_HOST_x86_64_unknown_linux_gnu
253 nix_bintools_wrapper_target_host="$(printenv | grep ^NIX_BINTOOLS_WRAPPER_TARGET_HOST | sed 's/=.*//')"
254
255 wrapProgram "$script" \
256 --set FAUSTLDDIR "${faust}/lib" \
257 --set FAUSTLIB "${faust}/share/faust" \
258 --set FAUSTINC "${faust}/include/faust" \
259 --set FAUSTARCH "${faust}/share/faust" \
260 --prefix PATH : "$PATH" \
261 --prefix PKG_CONFIG_PATH : "$PKG_CONFIG_PATH" \
262 --set NIX_CFLAGS_COMPILE "$NIX_CFLAGS_COMPILE" \
263 --set NIX_LDFLAGS "$NIX_LDFLAGS -lpthread" \
264 --set "$nix_cc_wrapper_target_host" "''${!nix_cc_wrapper_target_host}" \
265 --set "$nix_bintools_wrapper_target_host" "''${!nix_bintools_wrapper_target_host}" \
266 --prefix LIBRARY_PATH "$libPath"
267 done
268 '';
269 }
270 );
271
272 # Builder for 'faust2appl' scripts, such as faust2firefox that
273 # simply need to be wrapped with some dependencies on PATH.
274 #
275 # The build input 'faust' is automatically added to the PATH.
276 wrap =
277 {
278 baseName,
279 runtimeInputs ? [ ],
280 ...
281 }@args:
282
283 let
284
285 runtimePath = lib.concatStringsSep ":" (map (p: "${p}/bin") ([ faust ] ++ runtimeInputs));
286
287 in
288 stdenv.mkDerivation (
289 (faust2ApplBase args)
290 // {
291
292 nativeBuildInputs = [ makeWrapper ];
293
294 postFixup = ''
295 for script in "$out"/bin/*; do
296 wrapProgram "$script" --prefix PATH : "${runtimePath}"
297 done
298 '';
299
300 }
301 );
302
303in
304faust