-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathRakefile
137 lines (118 loc) · 3.2 KB
/
Rakefile
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
require 'fileutils'
LIBOGG_VER = '1.3.2'
LIBVORBIS_VER = '1.3.5'
LIBOGG = "libogg-#{LIBOGG_VER}"
LIBVORBIS = "libvorbis-#{LIBVORBIS_VER}"
LIBOGG_TARBALL = "#{LIBOGG}.tar.gz"
LIBVORBIS_TARBALL = "#{LIBVORBIS}.tar.gz"
BASE_URL = 'http://downloads.xiph.org/releases'
LIBOGG_URL = "#{BASE_URL}/ogg/#{LIBOGG_TARBALL}"
LIBVORBIS_URL = "#{BASE_URL}/vorbis/#{LIBVORBIS_TARBALL}"
task :libogg do
sh "wget #{LIBOGG_URL}" unless File.exist? LIBOGG_TARBALL
sh "tar zxf #{LIBOGG_TARBALL}" unless File.exist? LIBOGG
end
task :libvorbis do
sh "wget #{LIBVORBIS_URL}" unless File.exist? LIBVORBIS_TARBALL
sh "tar zxf #{LIBVORBIS_TARBALL}" unless File.exist? LIBVORBIS
end
INCLUDES = [
'include',
"#{LIBOGG}/include",
"#{LIBVORBIS}/include",
"#{LIBVORBIS}/lib"
].map {|include| "-I #{include}" }
.join ' '
EMCC_COMPILE_OPTIONS = "-O3 -ffast-math #{INCLUDES}"
EMCC_LINK_OPTIONS = [
'-s ALLOW_MEMORY_GROWTH=0',
'-s ASM_JS=1',
'-s EXPORTED_FUNCTIONS=@src/exports.json',
'--pre-js src/pre.js',
'--post-js src/post.js'
].join ' '
OUTPUT_DIR = 'output'
LIBOGG_OUTPUT_DIR = "output/#{LIBOGG}"
LIBOGG_FILES = [
'bitwise.c',
'framing.c'
]
LIBVORBIS_OUTPUT_DIR = "output/#{LIBVORBIS}"
LIBVORBIS_FILES = [
'analysis.c',
# 'barkmel.c',
'bitrate.c',
'block.c',
'codebook.c',
'envelope.c',
# 'floor0.c',
'floor1.c',
'info.c',
# 'lookup.c',
'lpc.c',
# 'lsp.c',
'mapping0.c',
'mdct.c',
'psy.c',
# 'psytune.c',
'registry.c',
'res0.c',
'sharedbook.c',
'smallft.c',
# 'synthesis.c',
# 'tone.c',
'vorbisenc.c',
# 'vorbisfile.c',
'window.c'
]
SRC_OUTPUT_DIR = "output/src"
SRC_FILES = [
'encoder.c'
]
def enum_sources(files, dir)
files.map {|file| "#{dir}/#{file}" }.sort
end
def enum_targets(sources, dir)
sources.map {|source| "#{dir}/#{File.basename(source).sub /c$/, 'o'}" }
end
LIBOGG_SOURCES = enum_sources LIBOGG_FILES, "#{LIBOGG}/src"
LIBVORBIS_SOURCES = enum_sources LIBVORBIS_FILES, "#{LIBVORBIS}/lib"
SRC_SOURCES = enum_sources SRC_FILES, 'src'
LIBOGG_OUTPUTS = enum_targets LIBOGG_SOURCES, LIBOGG_OUTPUT_DIR
LIBVORBIS_OUTPUTS = enum_targets LIBVORBIS_SOURCES, LIBVORBIS_OUTPUT_DIR
SRC_OUTPUTS = enum_targets SRC_SOURCES, SRC_OUTPUT_DIR
def compile_files(sources, target_dir)
FileUtils.makedirs target_dir
targets = enum_targets sources, target_dir
targets.each.zip(sources).each do |target, source|
sh "emcc #{EMCC_COMPILE_OPTIONS} -o #{target} #{source}"
end
end
task compile_ogg: :libogg do
compile_files LIBOGG_SOURCES, LIBOGG_OUTPUT_DIR
end
task compile_vorbis: :libvorbis do
compile_files LIBVORBIS_SOURCES, LIBVORBIS_OUTPUT_DIR
end
task :compile_src do
compile_files SRC_SOURCES, SRC_OUTPUT_DIR
end
task build_lib: [:compile_ogg, :compile_vorbis, :compile_src] do
FileUtils.makedirs 'lib'
sources = (LIBOGG_OUTPUTS + LIBVORBIS_OUTPUTS + SRC_OUTPUTS).join ' '
sh "emcc -O1 #{EMCC_LINK_OPTIONS} -o lib/OggVorbisEncoder.js #{sources}"
sh "emcc -O3 #{EMCC_LINK_OPTIONS} -o lib/OggVorbisEncoder.min.js #{sources}"
end
task :libclean do
sh 'rm -rf lib'
end
task :clean do
sh 'rm -rf output'
end
task distclean: :clean do
sh "rm -rf #{LIBOGG}"
sh "rm -rf #{LIBVORBIS}"
sh "rm -f #{LIBOGG_TARBALL}"
sh "rm -f #{LIBVORBIS_TARBALL}"
end
task default: :build_lib