forked from zz85/wild-web-midi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake.js
110 lines (86 loc) · 2.08 KB
/
make.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*
* Simple script for running emcc on wildmidi
* @author zz85 github.com/zz85
*/
var NODEJS = 0;
var EMCC = '/usr/lib/emsdk_portable/emscripten/master/emcc';
var OPTIMIZE_FLAGS = ' -O2 ';
var sources = [
'wm_error.c',
'file_io.c',
'lock.c',
'wildmidi_lib.c',
'reverb.c',
'gus_pat.c',
'internal_midi.c',
'patches.c',
'f_xmidi.c',
'f_mus.c',
'f_hmp.c',
'f_midi.c',
'f_hmi.c',
'sample.c',
'mus2mid.c',
'xmi2mid.c',
// 'wm_tty.c',
// 'wildmidi.c',
].map(function(include) {
return 'wildmidi/src/' + include;
});
sources.push('src/wildwebmidi.c');
console.log('sources: ' + sources);
var DEFINES = '';
var FLAGS = OPTIMIZE_FLAGS;
var MEM = 64 * 1024 * 1024; // 64MB
FLAGS += ' -s TOTAL_MEMORY=' + MEM + ' ';
if (NODEJS) {
DEFINES += ' -DNODEJS=1'
}
else {
// browser
FLAGS += ' --preload-file freepats ';
FLAGS += ' --pre-js pre.js --post-js post.js '
}
FLAGS += ' -s EMTERPRETIFY=1 ';
FLAGS += ' -s EMTERPRETIFY_ASYNC=1 ';
FLAGS += ' -s EMTERPRETIFY_WHITELIST="[\'_wildwebmidi\']" ';
/* DEBUG FLAGS */
// var DEBUG_FLAGS = ' -g '; FLAGS += DEBUG_FLAGS;
// FLAGS += ' -s ASSERTIONS=2 '
// FLAGS += ' --profiling-funcs '
// FLAGS += ' -s EMTERPRETIFY_ADVISE=1 '
// FLAGS += ' -s ALLOW_MEMORY_GROWTH=1';
// FLAGS += ' -s DEMANGLE_SUPPORT=1 ';
var INCLUDES = '';
INCLUDES += '-Isrc ';
// INCLUDES += '-I/System/Library/Frameworks/OpenAL.framework/Headers ';
INCLUDES += '-Iwildmidi/include ';
var compile_all = EMCC + ' ' + INCLUDES
+ sources.join(' ')
+ FLAGS + ' ' + DEFINES + ' -o wildwebmidi.js '
+ ' -s EXPORTED_FUNCTIONS="[\'_wildwebmidi\']"' ;
var
exec = require('child_process').exec,
child;
function onExec(error, stdout, stderr) {
if (stdout) console.log('stdout: ' + stdout);
if (stderr) console.log('stderr: ' + stderr);
if (error !== null) {
console.log('exec error: ' + error);
} else {
nextJob();
}
}
function nextJob() {
if (!jobs.length) {
console.log('jobs done');
return;
}
var cmd = jobs.shift();
console.log('running ' + cmd);
exec(cmd, onExec);
}
var jobs = [
compile_all
];
nextJob();