forked from taktod/ttLibJsGyp2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
libcheck.js
595 lines (560 loc) · 13.5 KB
/
libcheck.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
var fs = require("fs");
var exec = require("child_process").execSync;
// 動作ターゲット defs:定義 libs:ライブラリ includes:ヘッダファイル
var target = process.argv[2];
// 設定ファイルを読み込んでどのようなコンパイルにするかコントロールする。
/*
{
"target": "bsd" | "lgpl" | "gpl", // 動作モード指定
"disable": ["jpeg", "faac" ...], // 除外するライブラリ指定
"searchPath": ["c:¥¥hogehoge¥¥"] // 検索に追加するパス
}
*/
var setting = loadSetting();
/*
チェックすべきライブラリ
file socketについては、常に有効(emscriptenとかの別のコンパイルはしないので、考慮しない。)
opencv openalは放置
jpeg any jpeglib.h
openh264 any pkgconfig
x264 gpl pkgconfig
x265 gpl pkgconfig
theora any pkgconfig
daala any pkgconfig
mp3lame lgpl(enc) gpl(dec) lame/lame.h libmp3lame.a
faac lgpl faac.h
speexdsp any pkgconfig
speex any pkgconfig
opus any pkgconfig
faad gpl 無視
vorbis any pkgconfig
avcodec lgpl pkgconfig
apple darwin only darwin or not
webrtc any? 無視(electronで攻めるので、必要ないはず)
soundtouch lgpl pkgconfig
fdkaac lgpl
こんなところか・・・
*/
setupAvcodec();
setupApple();
setupFaac();
setupFdkaac();
setupJpeg();
setupMp3lame();
setupOpenh264();
setupOpus();
setupTheora();
setupSoundtouch();
setupSpeex();
setupSpeexdsp();
setupVorbis();
setupX264();
setupX265();
//setupDaala();
//setupFaad();
setupWin32();
function setupAvcodec() {
if(setting["targetValue"] < 1) {
// lgpl以上じゃないと動作させない
return;
}
if(setting["disable"].indexOf("avcodec") != -1) {
// avcodecは無効になってる。
return;
}
// とりあえず書くだけ書いてみよう
switch(setting["os"]) {
case "darwin":
case "linux":
if(exec("pkg-config --exists libavcodec libavutil && echo yes || echo no").toString().trim() == "yes") {
// pkg-configで存在してる。
switch(target) {
case "defs":
console.log("__ENABLE_AVCODEC__");
break;
case "libs":
console.log(exec("pkg-config --libs libavcodec libavutil").toString().trim());
break;
case "includes":
console.log(exec("pkg-config --cflags-only-I libavcodec libavutil | sed -e 's/\-I//g'").toString().trim());
break;
}
}
break;
case "windows":
case "windows_nt":
default:
break;
}
}
function setupApple() {
if(setting["disable"].indexOf("apple") != -1) {
return;
}
if(setting["os"] == "darwin") {
// osxの場合はappleのframeworkを利用可能にしておく。
switch(target) {
case "defs":
console.log("__ENABLE_APPLE__");
break;
case "libs":
console.log("'-framework AudioToolbox' '-framework AudioUnit' '-framework VideoToolbox' '-framework CoreMedia' '-framework CoreFoundation' '-framework CoreVideo' '-framework CoreAudio'");
break;
case "includes":
break;
}
}
}
function setupFaac() {
if(setting["disable"].indexOf("faac") != -1) {
return;
}
if(setting["targetValue"] == 0) {
return;
}
switch(setting["os"]) {
case "darwin":
case "linux":
if(checkFile("faac.h")
&& checkFile("faaccfg.h")
&& checkFile("libfaac.a")
&& (checkFile("libfaac.dylib") || checkFile("libfaac.so"))) {
switch(target) {
case "defs":
console.log("__ENABLE_FAAC_ENCODE__");
break;
case "libs":
setting["searchPath"].forEach(function(path) {
console.log("-L" + path);
});
console.log("-lfaac");
break;
case "includes":
setting["searchPath"].forEach(function(path) {
console.log(path);
});
break;
default:
break;
}
}
break;
case "windows":
case "windows_nt":
default:
break;
}
}
function setupFdkaac() {
}
function setupJpeg() {
if(setting["disable"].indexOf("jpeg") != -1) {
// mp3が無効
return;
}
switch(setting["os"]) {
case "darwin":
case "linux":
if(checkFile("jpeglib.h")
&& checkFile("libjpeg.a")
&& (checkFile("libjpeg.so") || checkFile("libjpeg.dylib"))) {
// mp3lameが使える
switch(target) {
case "defs":
console.log("__ENABLE_JPEG__");
break;
case "libs":
setting["searchPath"].forEach(function(path) {
console.log("-L" + path);
});
console.log("-ljpeg");
break;
case "includes":
setting["searchPath"].forEach(function(path) {
console.log(path);
});
break;
default:
break;
}
}
break;
case "windows":
case "windows_nt":
default:
break;
}
}
function setupMp3lame() {
if(setting["disable"].indexOf("mp3lame") != -1) {
// mp3が無効
return;
}
if(setting["targetValue"] == 0) {
// lgpl or gplではないので、スキップ
return;
}
switch(setting["os"]) {
case "darwin":
case "linux":
if(checkFile("lame/lame.h")
&& checkFile("libmp3lame.a")
&& (checkFile("libmp3lame.so") || checkFile("libmp3lame.dylib"))) {
// mp3lameが使える
switch(target) {
case "defs":
if(setting["targetValue"] == 2) {
console.log("__ENABLE_MP3LAME_DECODE__");
}
console.log("__ENABLE_MP3LAME_ENCODE__");
break;
case "libs":
setting["searchPath"].forEach(function(path) {
console.log("-L" + path);
});
console.log("-lmp3lame");
break;
case "includes":
setting["searchPath"].forEach(function(path) {
console.log(path);
});
break;
default:
break;
}
}
break;
case "windows":
case "windows_nt":
default:
break;
}
}
function setupOpenh264() {
if(setting["disable"].indexOf("openh264") != -1) {
// openh264は無効になってる
return;
}
switch(setting["os"]) {
case "darwin":
case "linux":
if(exec("pkg-config --exists openh264 && echo yes || echo no").toString().trim() == "yes") {
// pkg-configで存在してる。
switch(target) {
case "defs":
console.log("__ENABLE_OPENH264__");
break;
case "libs":
console.log(exec("pkg-config --libs openh264").toString().trim());
break;
case "includes":
console.log(exec("pkg-config --cflags-only-I openh264 | sed -e 's/\-I//g'").toString().trim());
break;
}
}
break;
case "windows":
case "windows_nt":
default:
break;
}
}
function setupOpus() {
if(setting["disable"].indexOf("opus") != -1) {
return;
}
switch(setting["os"]) {
case "darwin":
case "linux":
if(exec("pkg-config --exists opus && echo yes || echo no").toString().trim() == "yes") {
// pkg-configで存在してる。
switch(target) {
case "defs":
console.log("__ENABLE_OPUS__");
break;
case "libs":
console.log(exec("pkg-config --libs opus").toString().trim());
break;
case "includes":
console.log(exec("pkg-config --cflags-only-I opus | sed -e 's/\-I//g'").toString().trim());
break;
}
}
break;
case "windows":
case "windows_nt":
default:
break;
}
}
function setupTheora() {
if(setting["disable"].indexOf("theora") != -1) {
return;
}
switch(setting["os"]) {
case "darwin":
case "linux":
if(exec("pkg-config --exists theora ogg && echo yes || echo no").toString().trim() == "yes") {
// pkg-configで存在してる。
switch(target) {
case "defs":
console.log("__ENABLE_THEORA__");
break;
case "libs":
console.log(exec("pkg-config --libs theora ogg").toString().trim());
break;
case "includes":
console.log(exec("pkg-config --cflags-only-I theora ogg | sed -e 's/\-I//g'").toString().trim());
break;
}
}
break;
case "windows":
case "windows_nt":
default:
break;
}
}
function setupSoundtouch() {
if(setting["disable"].indexOf("soundtouch") != -1) {
return;
}
if(setting["targetValue"] == 0) {
return;
}
switch(setting["os"]) {
case "darwin":
case "linux":
if(exec("pkg-config --exists soundtouch && echo yes || echo no").toString().trim() == "yes") {
// pkg-configで存在してる。
switch(target) {
case "defs":
console.log("__ENABLE_SOUNDTOUCH__");
break;
case "libs":
console.log(exec("pkg-config --libs soundtouch").toString().trim());
break;
case "includes":
console.log(exec("pkg-config --cflags-only-I soundtouch | sed -e 's/\-I//g'").toString().trim());
break;
}
}
break;
case "windows":
case "windows_nt":
default:
break;
}
}
function setupSpeex() {
}
function setupSpeexdsp() {
if(setting["disable"].indexOf("speexdsp") != -1) {
return;
}
switch(setting["os"]) {
case "darwin":
case "linux":
if(exec("pkg-config --exists speexdsp && echo yes || echo no").toString().trim() == "yes") {
// pkg-configで存在してる。
switch(target) {
case "defs":
console.log("__ENABLE_SPEEXDSP__");
break;
case "libs":
console.log(exec("pkg-config --libs speexdsp").toString().trim());
break;
case "includes":
console.log(exec("pkg-config --cflags-only-I speexdsp | sed -e 's/\-I//g'").toString().trim());
break;
}
}
break;
case "windows":
case "windows_nt":
default:
break;
}
}
function setupVorbis() {
}
function setupX264() {
if(setting["disable"].indexOf("x264") != -1) {
return;
}
if(setting["targetValue"] != 2) {
return;
}
switch(setting["os"]) {
case "darwin":
case "linux":
if(exec("pkg-config --exists x264 && echo yes || echo no").toString().trim() == "yes") {
// pkg-configで存在してる。
switch(target) {
case "defs":
console.log("__ENABLE_X264__");
break;
case "libs":
console.log(exec("pkg-config --libs x264").toString().trim());
break;
case "includes":
console.log(exec("pkg-config --cflags-only-I x264 | sed -e 's/\-I//g'").toString().trim());
break;
}
}
break;
case "windows":
case "windows_nt":
default:
break;
}
}
function setupX265() {
if(setting["disable"].indexOf("x265") != -1) {
return;
}
if(setting["targetValue"] != 2) {
return;
}
switch(setting["os"]) {
case "darwin":
case "linux":
if(exec("pkg-config --exists x265 && echo yes || echo no").toString().trim() == "yes") {
// pkg-configで存在してる。
switch(target) {
case "defs":
console.log("__ENABLE_X265__");
break;
case "libs":
console.log(exec("pkg-config --libs x265").toString().trim());
break;
case "includes":
console.log(exec("pkg-config --cflags-only-I x265 | sed -e 's/\-I//g'").toString().trim());
break;
}
}
break;
case "windows":
case "windows_nt":
default:
break;
}
}
function setupWin32() {
if(setting["disable"].indexOf("win32") != -1) {
return;
}
switch(setting["os"]) {
case "darwin":
case "linux":
break;
case "windows":
case "windows_nt":
switch(target) {
case "defs":
console.log("__ENABLE_WIN32__");
break;
case "libs":
break;
case "includes":
break;
default:
break;
}
break;
default:
break;
}
}
function loadSetting() {
var os = require("os");
var setting = (function() {
try {
return JSON.parse(fs.readFileSync('../../takSetting.json'));
}
catch(e) {
try {
return JSON.parse(fs.readFileSync('takSetting.json'));
}
catch(e) {
return {};
}
}
})();
if(!setting["target"]) {
setting["target"] = "bsd";
}
switch(setting["target"]) {
case "gpl":
setting["targetValue"] = 2;
break;
case "lgpl":
setting["targetValue"] = 1;
break;
default:
setting["targetValue"] = 0;
break;
}
if(!setting["disable"]) {
setting["disable"] = [];
}
if(!setting["searchPath"]) {
setting["searchPath"] = [];
}
setting["os"] = os.type().toString().toLowerCase();
switch(setting["os"]) {
case "darwin":
case "linux":
setting["searchPath"].push("/usr/local/include");
setting["searchPath"].push("/usr/local/lib");
break;
case "windows":
case "windows_nt":
break;
default:
break;
}
return setting;
}
function checkFile(file) {
// setting["searchPath"]/fileが存在しているか確認し、ある場合はtrue、ない場合はfalseを返す
var find = false;
setting["searchPath"].forEach(function(path) {
try {
fs.statSync(path + "/" + file);
find = true;
}
catch(e) {
if(e.code === "ENOENT") {
// 見つからなかった場合
return;
}
throw e;
}
});
return find;
}
/*
switch(os.type().toString().toLowerCase()) {
case "darwin":
checkDarwin(target);
break;
case "linux":
checkLinux(target);
break;
case "windows":
case "windows_nt":
checkWindow(target);
break;
default:
return;
}
function checkDarwin(type) {
// 必要なライブラリをリストアップしておく
exec("");
}
function checkLinux(type) {
}
function checkWindow(type) {
}
*/