This repository has been archived by the owner on Oct 12, 2023. It is now read-only.
forked from Garciat/libvorbis.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·140 lines (104 loc) · 3.37 KB
/
build.sh
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
CC=emcc
CCFLAGS="-O3 -ffast-math -Iinclude"
TARGET_DIR=dist
TARGET_DIR_JS=$TARGET_DIR/js
TARGET_DIR_TS=$TARGET_DIR/ts
LIBOGG_SRCDIR=libogg/src
LIBOGG_INCLUDES="-I$LIBOGG_SRCDIR -Ilibogg/include"
LIBOGG_SRCS="bitwise.c framing.c"
LIBOGG_OUTDIR=build/libogg
LIBVORBIS_SRCDIR=libvorbis/lib
LIBVORBIS_INCLUDES="$LIBOGG_INCLUDES -I$LIBVORBIS_SRCDIR -Ilibvorbis/include"
LIBVORBIS_SRCS="analysis.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 registry.c res0.c sharedbook.c smallft.c synthesis.c vorbisenc.c window.c"
LIBVORBIS_OUTDIR=build/libvorbis
WRAPPER_SRCDIR=src/native
WRAPPER_INCLUDES="$LIBVORBIS_INCLUDES"
WRAPPER_SRCS="ogg_vbr_encoder.c"
WRAPPER_OUTDIR=build/wrapper
LIBRARY_SRCDIR=src
LIBRARY_OUTDIR=build/lib
COMPILE_PREJS=src/libvorbis.asmjs.pre
COMPILE_POSTJS=src/libvorbis.asmjs.post
COMPILE_TARGET=libvorbis.asmjs.js
COMPILE_TARGET_OPT=libvorbis.asmjs.min.js
COMPILE_OUTDIR=$TARGET_DIR_JS
COMPILE_FLAGS="-s ALLOW_MEMORY_GROWTH=0 -s ASM_JS=1 -s EXPORTED_FUNCTIONS=@exported_functions.json"
COMPILE_FLAGS="$COMPILE_FLAGS --pre-js $COMPILE_PREJS --post-js $COMPILE_POSTJS"
COMPILE_FLAGS_OPT="-O3 $COMPILE_FLAGS"
COMPILE_FLAGS="-O1 $COMPILE_FLAGS"
build_module() {
set -e
### libogg
echo ":: Compiling libogg..."
mkdir -p $LIBOGG_OUTDIR
for srcfile in $LIBOGG_SRCS; do
buildcmd="$CC $CCFLAGS $LIBOGG_INCLUDES $LIBOGG_SRCDIR/$srcfile -o $LIBOGG_OUTDIR/${srcfile%.*}.bc"
echo $buildcmd
$buildcmd
done
### libvorbis
echo ":: Compiling libvorbis..."
mkdir -p $LIBVORBIS_OUTDIR
for srcfile in $LIBVORBIS_SRCS; do
buildcmd="$CC $CCFLAGS $LIBVORBIS_INCLUDES $LIBVORBIS_SRCDIR/$srcfile -o $LIBVORBIS_OUTDIR/${srcfile%.*}.bc"
echo $buildcmd
$buildcmd
done
### wrapper
echo ":: Compiling native helpers..."
mkdir -p $WRAPPER_OUTDIR
for srcfile in $WRAPPER_SRCS; do
buildcmd="$CC $CCFLAGS $WRAPPER_INCLUDES $WRAPPER_SRCDIR/$srcfile -o $WRAPPER_OUTDIR/${srcfile%.*}.bc"
echo $buildcmd
$buildcmd
done
### compile
LIBOGG_BCS=$LIBOGG_OUTDIR/*.bc
LIBVORBIS_BCS=$LIBVORBIS_OUTDIR/*.bc
WRAPPER_BCS=$WRAPPER_OUTDIR/*.bc
mkdir -p $COMPILE_OUTDIR
echo ":: Compiling native module..."
buildcmd="$CC $COMPILE_FLAGS $LIBOGG_BCS $LIBVORBIS_BCS $WRAPPER_BCS -o $COMPILE_OUTDIR/$COMPILE_TARGET"
echo $buildcmd
$buildcmd
echo ":: Compiling native module (minified)..."
buildcmd="$CC $COMPILE_FLAGS_OPT $LIBOGG_BCS $LIBVORBIS_BCS $WRAPPER_BCS -o $COMPILE_OUTDIR/$COMPILE_TARGET_OPT"
echo $buildcmd
$buildcmd
}
build_library() {
set -e
echo ":: Building library files..."
mkdir -p $LIBRARY_OUTDIR
libbuild() {
tsc --out $LIBRARY_OUTDIR/$2.js $LIBRARY_SRCDIR/$1.ts
uglifyjs -o $LIBRARY_OUTDIR/$2.min.js $LIBRARY_OUTDIR/$2.js
}
libbuild OggVbrEncoder libvorbis.oggvbr.encoder
libbuild OggVbrAsyncEncoder libvorbis.oggvbr.asyncencoder
libbuild OggVbrAsyncEncoderWorker libvorbis.oggvbr.asyncencoder.worker
mkdir -p $TARGET_DIR_JS
mkdir -p $TARGET_DIR_TS
cp $LIBRARY_OUTDIR/* $TARGET_DIR_JS
find $LIBRARY_SRCDIR -name \*.ts -exec cp {} $TARGET_DIR_TS \;
cp -r typings $TARGET_DIR
}
build_all() {
build_module
build_library
}
case $1 in
""|"all")
build_all
;;
"module")
build_module
;;
"library")
build_library
;;
*)
echo "unknown option." > /dev/stderr
exit 1
;;
esac