-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.js
More file actions
74 lines (64 loc) · 1.87 KB
/
build.js
File metadata and controls
74 lines (64 loc) · 1.87 KB
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
const os = require('os');
const { spawnSync } = require('child_process');
const platform = os.platform();
const moduleName = 'Milky2018/moon_rodio';
if (platform !== 'darwin' && platform !== 'linux' && platform !== 'win32') {
throw new Error(`Unsupported platform: ${platform}`);
}
function pkg(path) {
return path.length === 0 ? moduleName : `${moduleName}/${path}`;
}
const linkConfigs = [];
function addLinkConfig(path, config) {
linkConfigs.push({
package: pkg(path),
...config,
});
}
function probePkgConfig(packages) {
const cflags = spawnSync('pkg-config', ['--cflags', ...packages], {
encoding: 'utf8',
});
const libs = spawnSync('pkg-config', ['--libs', ...packages], {
encoding: 'utf8',
});
if (cflags.status !== 0 || libs.status !== 0) {
return null;
}
return {
cflags: cflags.stdout.trim(),
libs: libs.stdout.trim(),
};
}
let decoderStubCcFlags = '';
let decoderLinkFlags = '';
const envFfmpegCflags = process.env.MOON_RODIO_FFMPEG_CFLAGS || '';
const envFfmpegLibs = process.env.MOON_RODIO_FFMPEG_LIBS || '';
if (platform === 'darwin') {
decoderLinkFlags =
'-framework CoreAudio -framework CoreFoundation -framework AudioToolbox';
} else if (envFfmpegCflags !== '' && envFfmpegLibs !== '') {
decoderStubCcFlags = `${envFfmpegCflags} -DMOON_RODIO_ENABLE_FFMPEG=1`;
decoderLinkFlags = envFfmpegLibs;
} else if (platform === 'linux') {
const ffmpeg = probePkgConfig([
'libavformat',
'libavcodec',
'libavutil',
'libswresample',
]);
if (ffmpeg) {
decoderStubCcFlags = `${ffmpeg.cflags} -DMOON_RODIO_ENABLE_FFMPEG=1`;
decoderLinkFlags = ffmpeg.libs;
}
}
if (decoderLinkFlags !== '') {
addLinkConfig('decoder', { link_flags: decoderLinkFlags });
}
const output = {
vars: {
MOON_RODIO_DECODER_STUB_CC_FLAGS: decoderStubCcFlags,
},
link_configs: linkConfigs,
};
console.log(JSON.stringify(output));