Debian Codegraph @

wasm/src/csound.nix

raw
1 { pkgs ? import <nixpkgs> { }, static ? false }:
2
3 let
4 lib = pkgs.lib;
5 wasi-sdk-dyn = pkgs.callPackage ./wasi-sdk.nix { };
6 wasi-sdk-static = pkgs.callPackage ./wasi-sdk-static.nix { };
7 wasi-sdk = if static then wasi-sdk-static else wasi-sdk-dyn;
8
9 static-link = ''
10 echo "Create libcsound.wasm standalone"
11 ${wasi-sdk}/bin/wasm-ld --lto-O2 \
12 --entry=_start --import-memory \
13 ${
14 pkgs.lib.concatMapStrings (x: " --export=" + x + " ")
15 (with builtins; fromJSON (readFile ./exports.json))
16 } \
17 -L${wasi-sdk}/share/wasi-sysroot/lib/wasm32-wasi \
18 -L${libsndfile}/lib -L${libflac}/lib -L${libogg}/lib -L${libvorbis}/lib \
19 -L${liblame}/lib -L${libmpg123}/lib \
20 -lc -lc++ -lc++abi -lrt -lutil -lxnet -lresolv -lc-printscan-long-double \
21 -lflac -logg -lvorbis -llame -lsndfile -lmpg123 -lwasi-emulated-getpid \
22 -lwasi-emulated-signal -lwasi-emulated-mman -lwasi-emulated-process-clocks \
23 ${wasi-sdk}/share/wasi-sysroot/lib/wasm32-wasi/crt1.o \
24 *.o -o csound.static.wasm
25 '';
26
27 dyn-link = ''
28 echo "Create libcsound.wasm pie"
29 ${wasi-sdk}/bin/wasm-ld --lto-O2 \
30 -z stack-size=128 \
31 --export=__data_end \
32 --experimental-pic -pie --entry=_start \
33 --import-table --import-memory \
34 ${
35 pkgs.lib.concatMapStrings (x: " --export=" + x + " ")
36 (with builtins; fromJSON (readFile ./exports.json))
37 } \
38 -L${wasi-sdk}/share/wasi-sysroot/lib/wasm32-unknown-emscripten \
39 -L${libsndfile}/lib -L${libflac}/lib -L${libogg}/lib -L${libvorbis}/lib \
40 -L${liblame}/lib -L${libmpg123}/lib \
41 -lc -lc++ -lc++abi -lrt -lutil -lxnet -lresolv -lc-printscan-long-double \
42 -lflac -logg -lvorbis -llame -lsndfile -lmpg123 -lwasi-emulated-getpid \
43 -lwasi-emulated-signal -lwasi-emulated-mman -lwasi-emulated-process-clocks \
44 ${wasi-sdk}/share/wasi-sysroot/lib/wasm32-unknown-emscripten/crt1.o \
45 *.o -o csound.dylib.wasm
46 '';
47
48 exports = with builtins; (fromJSON (readFile ./exports.json));
49 patchClock = pkgs.writeTextFile {
50 name = "patchClock";
51 executable = true;
52 destination = "/bin/patchClock";
53 text = ''
54 #!${pkgs.nodejs}/bin/node
55 const myArgs = process.argv.slice(2);
56 const myFile = myArgs[0];
57 const fs = require('fs')
58 fs.readFile(myFile, 'utf8', function (err,data) {
59 if (err) { return console.log(err); }
60 const regex = "\\/\\* find out CPU frequency based on.*" +
61 "initialise a timer structure \\*\\/";
62 const replace = `static int getTimeResolution(void) { return 0; }
63 int gettimeofday (struct timeval *__restrict, void *__restrict);
64 static inline int_least64_t get_real_time(void) {
65 struct timeval tv;
66 gettimeofday(&tv, NULL);
67 return ((int_least64_t) tv.tv_usec
68 + (int_least64_t) ((uint32_t) tv.tv_sec * (uint64_t) 1000000));}
69 clock_t clock (void);
70 static inline int_least64_t get_CPU_time(void) {
71 return ((int_least64_t) ((uint32_t) clock()));
72 }`;
73 const result = data.replace(new RegExp(regex, 'is'), replace);
74 fs.writeFile(myFile, result, 'utf8', function (err) {
75 if (err) return console.log(err);
76 });
77 });
78 '';
79 };
80
81 libsndfile = pkgs.callPackage ./libsndfile.nix { inherit static; };
82 libogg = pkgs.callPackage ./libogg.nix { inherit static; };
83 libflac = pkgs.callPackage ./libflac.nix { inherit static; };
84 libvorbis = pkgs.callPackage ./libvorbis.nix { inherit static; };
85 liblame = pkgs.callPackage ./liblame.nix { inherit static; };
86 libmpg123 = pkgs.callPackage ./libmpg123.nix { inherit static; };
87
88 csoundSrc = builtins.path {
89 path = ./. + "../../../";
90 filter = path: type:
91 ((builtins.match ".*/Engine.*" path != null ||
92 builtins.match ".*/H.*" path != null ||
93 builtins.match ".*/InOut.*" path != null ||
94 builtins.match ".*/OOps.*" path != null ||
95 builtins.match ".*/Opcodes.*" path != null ||
96 builtins.match ".*/Top.*" path != null ||
97 builtins.match ".*/include.*" path != null) &&
98 (lib.strings.hasSuffix ".c" path ||
99 lib.strings.hasSuffix ".cpp" path ||
100 lib.strings.hasSuffix ".h" path ||
101 lib.strings.hasSuffix ".h.in" path ||
102 lib.strings.hasSuffix ".hpp" path ||
103 lib.strings.hasSuffix ".hpp.in" path ||
104 lib.strings.hasSuffix ".y" path ||
105 lib.strings.hasSuffix ".lex" path ||
106 type == "directory"));
107 };
108
109 preprocFlags = ''
110 -DGIT_HASH_VALUE=HEAD \
111 -DUSE_DOUBLE=1 \
112 -DLINUX=0 \
113 -DO_NDELAY=O_NONBLOCK \
114 -DHAVE_STRLCAT=1 \
115 -D__thread='^-^' \
116 -Wno-unknown-attributes \
117 -Wno-shift-op-parentheses \
118 -Wno-bitwise-op-parentheses \
119 -Wno-many-braces-around-scalar-init \
120 -Wno-macro-redefined \
121 '';
122
123 staticPreprocFlags = ''
124 -DO_WRONLY='(0x10000000)' \
125 -DO_CREAT='(__WASI_OFLAGS_CREAT << 12)' \
126 '';
127
128 in pkgs.stdenvNoCC.mkDerivation rec {
129
130 name = "csound-wasm";
131 src = csoundSrc;
132
133 buildInputs = [ pkgs.flex pkgs.bison ];
134
135 dontStrip = true;
136 AR = "${wasi-sdk}/bin/ar";
137 CC = "${wasi-sdk}/bin/clang";
138 CPP = "${wasi-sdk}/bin/clang-cpp";
139 CXX = "${wasi-sdk}/bin/clang++";
140 LD = "${wasi-sdk}/bin/wasm-ld";
141 NM = "${wasi-sdk}/bin/nm";
142 OBJCOPY = "${wasi-sdk}/bin/objcopy";
143 RANLIB = "${wasi-sdk}/bin/ranlib";
144
145 postPatch = ''
146 # Experimental setjmp patching
147 find ./ -type f -exec sed -i -e 's/#include <setjmp.h>//g' {} \;
148 find ./ -type f -exec sed -i -e 's/csound->LongJmp(csound, retval);/return retval;/g' {} \;
149 find ./ -type f -exec sed -i -e 's/csound->LongJmp(.*)/(void)0/g' {} \;
150 find ./ -type f -exec sed -i -e 's/longjmp(.*)/(void)0/g' {} \;
151 find ./ -type f -exec sed -i -e 's/jmp_buf/int/g' {} \;
152 find ./ -type f -exec sed -i -e 's/setjmp(csound->exitjmp)/0/g' {} \;
153
154 # find ./ -type f -exec sed -i -e 's/csound->Calloc/mcalloc/g' {} \;
155
156 find ./ -type f -exec sed -i -e 's/HAVE_PTHREAD/FFS_NO_PTHREADS/g' {} \;
157 find ./ -type f -exec sed -i -e 's/#ifdef LINUX/#ifdef _NOT_LINUX_/g' {} \;
158 find ./ -type f -exec sed -i -e 's/if(LINUX)/if(_NOT_LINUX_)/g' {} \;
159 find ./ -type f -exec sed -i -e 's/if (LINUX)/if(_NOT_LINUX_)/g' {} \;
160 find ./ -type f -exec sed -i -e 's/defined(LINUX)/defined(_NOT_LINUX_)/g' {} \;
161
162
163 sed -i -e 's/csoundUDPConsole.*//g' Top/argdecode.c
164
165 # Patch 64bit integer clock
166 ${patchClock}/bin/patchClock Top/csound.c
167
168 mv include/version.h.in include/version.h
169 # see CMakeLists.txt
170 substituteInPlace include/version.h \
171 --replace "\''${CS_VERSION}" "6" \
172 --replace "\''${CS_SUBVER}" "18" \
173 --replace "\''${CS_PATCHLEVEL}" "0"
174
175 touch include/float-version.h
176 substituteInPlace Top/csmodule.c \
177 --replace '#include <dlfcn.h>' ""
178 substituteInPlace Engine/csound_orc.y \
179 --replace 'csound_orcnerrs' "0"
180 substituteInPlace include/sysdep.h \
181 --replace '#if defined(HAVE_GCC3) && !defined(SWIG)' \
182 '#if defined(HAVE_GCC3) && !defined(WASM_BUILD)'
183
184 # don't open .csound6rc
185 substituteInPlace Top/main.c \
186 --replace 'checkOptions(csound);' ""
187
188 # follow same preproc defs as emscripten
189 # when it come to filesystem calls
190 substituteInPlace OOps/diskin2.c \
191 --replace '__EMSCRIPTEN__' 'WASM_BUILD'
192
193 substituteInPlace Engine/csound_orc_compile.c \
194 --replace '#ifdef EMSCRIPTEN' '#if 1' \
195 --replace 'void sanitize(CSOUND *csound) {}' \
196 'void sanitize(CSOUND *csound);'
197
198 substituteInPlace Top/one_file.c \
199 --replace '#include "corfile.h"' \
200 '#include "corfile.h"
201 #include <sys/types.h>
202 #include <sys/stat.h>
203 #include <string.h>
204 #include <stdlib.h>
205 #include <unistd.h>
206 #include <fcntl.h>
207 #include <errno.h>' \
208 --replace 'umask(0077);' "" \
209 --replace 'mkstemp(lbuf)' \
210 'open(lbuf, 02)' \
211 --replace 'system(sys)' '-1'
212
213 substituteInPlace Engine/linevent.c \
214 --replace '#include <ctype.h>' \
215 '#include <ctype.h>
216 #include <string.h>
217 #include <stdlib.h>
218 #include <unistd.h>
219 #include <fcntl.h>'
220
221 substituteInPlace Opcodes/urandom.c \
222 --replace '__HAIKU__' \
223 'WASM_BUILD
224 #include <unistd.h>'
225
226 substituteInPlace InOut/libmpadec/mp3dec.c \
227 --replace '#include "csoundCore.h"' \
228 '#include "csoundCore.h"
229 #include <stdlib.h>
230 #include <stdio.h>
231 #include <sys/types.h>
232 #include <unistd.h>
233 '
234
235 substituteInPlace Opcodes/mp3in.c \
236 --replace '#include "mp3dec.h"' \
237 '#include "mp3dec.h"
238 #include <unistd.h>
239 #include <fcntl.h>'
240
241 substituteInPlace Top/csound.c \
242 --replace 'strcpy(s, "alsa");' 'strcpy(s, "wasi");' \
243 --replace 'strcpy(s, "hostbased");' "" \
244 --replace 'signal(sigs[i], signal_handler);' "" \
245 --replace 'static void psignal' 'static void psignal_' \
246 --replace 'HAVE_RDTSC' '__NOT_HERE___' \
247 --replace '#if !defined(WIN32)' '#if 0' \
248 --replace 'static double timeResolutionSeconds = -1.0;' \
249 'static double timeResolutionSeconds = 0.000001;'
250
251 # since we recommend n^2 number,
252 # let's make sure that it's default too
253 substituteInPlace include/csoundCore.h \
254 --replace '#define DFLT_KSMPS 10' \
255 '#define DFLT_KSMPS 16' \
256 --replace '#define DFLT_KR FL(4410.0)' \
257 '#define DFLT_KR FL(2756.25)'
258
259 substituteInPlace Top/main.c \
260 --replace 'csoundUDPServerStart(csound,csound->oparms->daemon);' "" \
261 --replace 'static void put_sorted_score' \
262 'extern void put_sorted_score'
263
264 substituteInPlace Engine/musmon.c \
265 --replace 'csoundUDPServerClose(csound);' ""
266
267 substituteInPlace Engine/new_orc_parser.c \
268 --replace 'csound_orcdebug = O->odebug;' ""
269
270 # date and fs
271 sed -i '1s/^/#include <unistd.h>\n/' Opcodes/date.c
272 sed -i -e 's/LINUX/1/g' Opcodes/date.c
273
274 echo 'extern "C" {
275 extern int pvsops_init_(CSOUND *csound) {
276 csnd::on_load((csnd::Csound *)csound);
277 return 0;
278 }
279 }' >> Opcodes/pvsops.cpp
280 '';
281
282 configurePhase = ''
283 ${pkgs.bison}/bin/bison -pcsound_orc -d --report=itemset ./Engine/csound_orc.y \
284 -o ./Engine/csound_orcparse.c
285 # ${pkgs.bison}/bin/bison -pcsound_sco -d --report=itemset ./Engine/csound_sco.y \
286 # --defines=./H/csound_scoparse.h \
287 # -o ./Engine/csound_scoparse.c
288
289 ${pkgs.flex}/bin/flex -B ./Engine/csound_orc.lex > ./Engine/csound_orclex.c
290 ${pkgs.flex}/bin/flex -B ./Engine/csound_pre.lex > ./Engine/csound_prelex.c
291 ${pkgs.flex}/bin/flex -B ./Engine/csound_prs.lex > ./Engine/csound_prslex.c
292 # ${pkgs.flex}/bin/flex -B ./Engine/csound_sco.lex > ./Engine/csound_scolex.c
293 '';
294
295 # ../Opcodes/scansyn.c \
296 # ../Opcodes/scansynx.c \
297 # expose scansyn_init_ via extern
298 # also hardcode away graph console logs
299 # as they seem to freeze the browser environment
300 # substituteInPlace Opcodes/scansyn.c \
301 # --replace 'static int32_t scansyn_init_' \
302 # 'extern int32_t scansyn_init_' \
303 # --replace '*p->i_disp' '0'
304 # substituteInPlace Opcodes/scansyn.h \
305 # --replace 'extern int32_t' \
306 # 'extern int32_t scansyn_init_(CSOUND *);
307 # extern int32_t'
308
309
310 buildPhase = ''
311 mkdir -p build && cd build
312 cp ${./csound_wasm.c} ./csound_wasm.c
313 cp ${./unsupported_opcodes.c} ./unsupported_opcodes.c
314 cp ${./staticfix.c} ./staticfix.c
315
316 # Why the wasm32-unknown-emscripten triplet:
317 # https://bugs.llvm.org/show_bug.cgi?id=42714
318 echo "Compile libcsound.wasm"
319
320 ${wasi-sdk}/bin/clang \
321 ${if (static == false) then "--target=wasm32-unknown-emscripten" else "--target=wasm32-wasi" } \
322 -fno-force-enable-int128 -femulated-tls -fno-exceptions -fno-rtti -Oz \
323 --sysroot=${wasi-sdk}/share/wasi-sysroot \
324 ${lib.optionalString (static == false) "-fPIC" } \
325 -I../H -I../Engine -I../include -I../ \
326 -I../InOut/libmpadec -I../Opcodes/emugens \
327 -I${libsndfile}/include \
328 -I${wasi-sdk}/share/wasi-sysroot/include \
329 -I${wasi-sdk}/share/wasi-sysroot/include/c++/v1 \
330 -DINIT_STATIC_MODULES=1 \
331 -U__MACH__ \
332 -UMAC \
333 -UMACOSX \
334 -D__wasi__=1 \
335 -D__wasm32__=1 \
336 -D_WASI_EMULATED_SIGNAL \
337 -D_WASI_EMULATED_MMAN \
338 -D_WASI_EMULATED_PROCESS_CLOCKS \
339 -D__BUILDING_LIBCSOUND \
340 -DWASM_BUILD=1 ${preprocFlags} -c \
341 ${lib.optionalString (static == true) "./staticfix.c" } \
342 unsupported_opcodes.c \
343 ../Engine/auxfd.c \
344 ../Engine/cfgvar.c \
345 ../Engine/corfiles.c \
346 ../Engine/csound_data_structures.c \
347 ../Engine/csound_orclex.c \
348 ../Engine/csound_orc_compile.c \
349 ../Engine/csound_orc_expressions.c \
350 ../Engine/csound_orc_optimize.c \
351 ../Engine/csound_orc_semantics.c \
352 ../Engine/csound_orcparse.c \
353 ../Engine/csound_prelex.c \
354 ../Engine/csound_prslex.c \
355 ../Engine/csound_standard_types.c \
356 ../Engine/csound_type_system.c \
357 ../Engine/entry1.c \
358 ../Engine/envvar.c \
359 ../Engine/extract.c \
360 ../Engine/fgens.c \
361 ../Engine/insert.c \
362 ../Engine/linevent.c \
363 ../Engine/memalloc.c \
364 ../Engine/memfiles.c \
365 ../Engine/musmon.c \
366 ../Engine/namedins.c \
367 ../Engine/new_orc_parser.c \
368 ../Engine/pools.c \
369 ../Engine/rdscor.c \
370 ../Engine/scope.c \
371 ../Engine/scsort.c \
372 ../Engine/scxtract.c \
373 ../Engine/sort.c \
374 ../Engine/sread.c \
375 ../Engine/swritestr.c \
376 ../Engine/symbtab.c \
377 ../Engine/symbtab.c \
378 ../Engine/twarp.c \
379 ../InOut/circularbuffer.c \
380 ../InOut/libmpadec/layer1.c \
381 ../InOut/libmpadec/layer2.c \
382 ../InOut/libmpadec/layer3.c \
383 ../InOut/libmpadec/mp3dec.c \
384 ../InOut/libmpadec/mpadec.c \
385 ../InOut/libmpadec/synth.c \
386 ../InOut/libmpadec/tables.c \
387 ../InOut/libsnd.c \
388 ../InOut/libsnd_u.c \
389 ../InOut/midifile.c \
390 ../InOut/midirecv.c \
391 ../InOut/midisend.c \
392 ../InOut/winEPS.c \
393 ../InOut/winascii.c \
394 ../InOut/windin.c \
395 ../InOut/window.c \
396 ../OOps/aops.c \
397 ../OOps/bus.c \
398 ../OOps/cmath.c \
399 ../OOps/compile_ops.c \
400 ../OOps/diskin2.c \
401 ../OOps/disprep.c \
402 ../OOps/dumpf.c \
403 ../OOps/fftlib.c \
404 ../OOps/goto_ops.c \
405 ../OOps/lpred.c \
406 ../OOps/midiinterop.c \
407 ../OOps/midiops.c \
408 ../OOps/midiout.c \
409 ../OOps/mxfft.c \
410 ../OOps/oscils.c \
411 ../OOps/pffft.c \
412 ../OOps/pstream.c \
413 ../OOps/pvfileio.c \
414 ../OOps/pvsanal.c \
415 ../OOps/random.c \
416 ../OOps/remote.c \
417 ../OOps/schedule.c \
418 ../OOps/sndinfUG.c \
419 ../OOps/str_ops.c \
420 ../OOps/ugens1.c \
421 ../OOps/ugens2.c \
422 ../OOps/ugens3.c \
423 ../OOps/ugens4.c \
424 ../OOps/ugens5.c \
425 ../OOps/ugens6.c \
426 ../OOps/ugrw1.c \
427 ../OOps/ugtabs.c \
428 ../OOps/vdelay.c \
429 ../Opcodes/Vosim.c \
430 ../Opcodes/afilters.c \
431 ../Opcodes/ambicode.c \
432 ../Opcodes/ambicode1.c \
433 ../Opcodes/arrays.c \
434 ../Opcodes/babo.c \
435 ../Opcodes/bbcut.c \
436 ../Opcodes/bilbar.c \
437 ../Opcodes/biquad.c \
438 ../Opcodes/bowedbar.c \
439 ../Opcodes/buchla.c \
440 ../Opcodes/butter.c \
441 ../Opcodes/cellular.c \
442 ../Opcodes/clfilt.c \
443 ../Opcodes/compress.c \
444 ../Opcodes/cpumeter.c \
445 ../Opcodes/cross2.c \
446 ../Opcodes/crossfm.c \
447 ../Opcodes/dam.c \
448 ../Opcodes/date.c \
449 ../Opcodes/dcblockr.c \
450 ../Opcodes/dsputil.c \
451 ../Opcodes/emugens/emugens.c \
452 ../Opcodes/emugens/scugens.c \
453 ../Opcodes/eqfil.c \
454 ../Opcodes/exciter.c \
455 ../Opcodes/fareygen.c \
456 ../Opcodes/fareyseq.c \
457 ../Opcodes/filter.c \
458 ../Opcodes/flanger.c \
459 ../Opcodes/fm4op.c \
460 ../Opcodes/follow.c \
461 ../Opcodes/fout.c \
462 ../Opcodes/framebuffer.c \
463 ../Opcodes/freeverb.c \
464 ../Opcodes/ftconv.c \
465 ../Opcodes/ftest.c \
466 ../Opcodes/ftgen.c \
467 ../Opcodes/gab/gab.c \
468 ../Opcodes/gab/hvs.c \
469 ../Opcodes/gab/newgabopc.c \
470 ../Opcodes/gab/sliderTable.c \
471 ../Opcodes/gab/tabmorph.c \
472 ../Opcodes/gab/vectorial.c \
473 ../Opcodes/gammatone.c \
474 ../Opcodes/gendy.c \
475 ../Opcodes/grain.c \
476 ../Opcodes/grain4.c \
477 ../Opcodes/harmon.c \
478 ../Opcodes/hrtfearly.c \
479 ../Opcodes/hrtferX.c \
480 ../Opcodes/hrtfopcodes.c \
481 ../Opcodes/hrtfreverb.c \
482 ../Opcodes/ifd.c \
483 ../Opcodes/liveconv.c \
484 ../Opcodes/locsig.c \
485 ../Opcodes/loscilx.c \
486 ../Opcodes/lowpassr.c \
487 ../Opcodes/lufs.c \
488 ../Opcodes/mandolin.c \
489 ../Opcodes/metro.c \
490 ../Opcodes/midiops2.c \
491 ../Opcodes/midiops3.c \
492 ../Opcodes/minmax.c \
493 ../Opcodes/modal4.c \
494 ../Opcodes/modmatrix.c \
495 ../Opcodes/moog1.c \
496 ../Opcodes/mp3in.c \
497 ../Opcodes/newfils.c \
498 ../Opcodes/nlfilt.c \
499 ../Opcodes/oscbnk.c \
500 ../Opcodes/pan2.c \
501 ../Opcodes/partials.c \
502 ../Opcodes/partikkel.c \
503 ../Opcodes/paulstretch.c \
504 ../Opcodes/phisem.c \
505 ../Opcodes/physmod.c \
506 ../Opcodes/physutil.c \
507 ../Opcodes/pinker.c \
508 ../Opcodes/pitch.c \
509 ../Opcodes/pitch0.c \
510 ../Opcodes/pitchtrack.c \
511 ../Opcodes/platerev.c \
512 ../Opcodes/pluck.c \
513 ../Opcodes/psynth.c \
514 ../Opcodes/pvadd.c \
515 ../Opcodes/pvinterp.c \
516 ../Opcodes/pvlock.c \
517 ../Opcodes/pvoc.c \
518 ../Opcodes/pvocext.c \
519 ../Opcodes/pvread.c \
520 ../Opcodes/pvs_ops.c \
521 ../Opcodes/pvsband.c \
522 ../Opcodes/pvsbasic.c \
523 ../Opcodes/pvsbuffer.c \
524 ../Opcodes/pvscent.c \
525 ../Opcodes/pvsdemix.c \
526 ../Opcodes/pvsgendy.c \
527 ../Opcodes/quadbezier.c \
528 ../Opcodes/repluck.c \
529 ../Opcodes/reverbsc.c \
530 ../Opcodes/scoreline.c \
531 ../Opcodes/select.c \
532 ../Opcodes/seqtime.c \
533 ../Opcodes/sequencer.c \
534 ../Opcodes/sfont.c \
535 ../Opcodes/shaker.c \
536 ../Opcodes/shape.c \
537 ../Opcodes/singwave.c \
538 ../Opcodes/sndloop.c \
539 ../Opcodes/sndwarp.c \
540 ../Opcodes/space.c \
541 ../Opcodes/spat3d.c \
542 ../Opcodes/spectra.c \
543 ../Opcodes/squinewave.c \
544 ../Opcodes/stdopcod.c \
545 ../Opcodes/sterrain.c \
546 ../Opcodes/syncgrain.c \
547 ../Opcodes/tabaudio.c \
548 ../Opcodes/tabsum.c \
549 ../Opcodes/tl/sc_noise.c \
550 ../Opcodes/ugakbari.c \
551 ../Opcodes/ugens7.c \
552 ../Opcodes/ugens8.c \
553 ../Opcodes/ugens9.c \
554 ../Opcodes/ugensa.c \
555 ../Opcodes/uggab.c \
556 ../Opcodes/ugmoss.c \
557 ../Opcodes/ugnorman.c \
558 ../Opcodes/ugsc.c \
559 ../Opcodes/urandom.c \
560 ../Opcodes/vaops.c \
561 ../Opcodes/vbap.c \
562 ../Opcodes/vbap1.c \
563 ../Opcodes/vbap_n.c \
564 ../Opcodes/vbap_zak.c \
565 ../Opcodes/vpvoc.c \
566 ../Opcodes/wave-terrain.c \
567 ../Opcodes/wterrain2.c \
568 ../Opcodes/wpfilters.c \
569 ../Opcodes/zak.c \
570 ../Top/argdecode.c \
571 ../Top/cscore_internal.c \
572 ../Top/cscorfns.c \
573 ../Top/csdebug.c \
574 ../Top/csmodule.c \
575 ../Top/getstring.c \
576 ../Top/init_static_modules.c \
577 ../Top/main.c \
578 ../Top/new_opts.c \
579 ../Top/one_file.c \
580 ../Top/opcode.c \
581 ../Top/threads.c \
582 ../Top/threadsafe.c \
583 ../Top/utility.c \
584 ../Top/csound.c \
585 ../Opcodes/ampmidid.cpp \
586 ../Opcodes/doppler.cpp \
587 ../Opcodes/tl/fractalnoise.cpp \
588 ../Opcodes/mixer.cpp \
589 ../Opcodes/signalflowgraph.cpp \
590 ../Opcodes/pvsops.cpp \
591 csound_wasm.c
592
593 #TODO fix ../Opcodes/ftsamplebank.cpp (why does it import thread-local?)
594 ${if (static == true) then static-link else dyn-link}
595
596 ${wasi-sdk}/bin/llvm-ar -x ${libsndfile}/lib/libsndfile.a
597 ${wasi-sdk}/bin/llvm-ar rcs libcsound-wasm.a ./*.o
598 '';
599
600 installPhase = ''
601 mkdir -p $out/lib
602 mkdir -p $out/include
603 cp ./*.wasm $out/lib
604 cp ./*.a $out/lib
605 cp -rf ../H $out/include
606 cp -rf ../Engine $out/include
607 cp -rf ../include/* $out/include
608
609 # # make a compressed version for the browser bundle
610 ${pkgs.zopfli}/bin/zopfli --zlib -c \
611 $out/lib/csound${if (static == true) then ".static" else ".dylib" }.wasm \
612 > $out/lib/csound${if (static == true) then ".static" else ".dylib" }.wasm.z
613 '';
614 }