-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.sh
executable file
·455 lines (396 loc) · 11.9 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
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
#!/bin/sh
set -e
set -u
jflag=
jval=2
rebuild=0
download_only=0
uname -mpi | grep -qE 'x86|i386|i686' && is_x86=1 || is_x86=0
while getopts 'j:Bd' OPTION
do
case $OPTION in
j)
jflag=1
jval="$OPTARG"
;;
B)
rebuild=1
;;
d)
download_only=1
;;
?)
printf "Usage: %s: [-j concurrency_level] (hint: your cores + 20%%) [-B] [-d]\n" $(basename $0) >&2
exit 2
;;
esac
done
shift $(($OPTIND - 1))
if [ "$jflag" ]
then
if [ "$jval" ]
then
printf "Option -j specified (%d)\n" $jval
fi
fi
[ "$rebuild" -eq 1 ] && echo "Reconfiguring existing packages..."
[ $is_x86 -ne 1 ] && echo "Not using yasm or nasm on non-x86 platform..."
cd `dirname $0`
ENV_ROOT=`pwd`
. ./env.source
# check operating system
OS=`uname`
platform="unknown"
case $OS in
'Darwin')
platform='darwin'
;;
'Linux')
platform='linux'
;;
esac
#if you want a rebuild
#rm -rf "$BUILD_DIR" "$TARGET_DIR"
mkdir -p "$BUILD_DIR" "$TARGET_DIR" "$DOWNLOAD_DIR" "$BIN_DIR"
#download and extract package
download(){
filename="$1"
if [ ! -z "$2" ];then
filename="$2"
fi
../download.pl "$DOWNLOAD_DIR" "$1" "$filename" "$3" "$4"
#disable uncompress
REPLACE="$rebuild" CACHE_DIR="$DOWNLOAD_DIR" ../fetchurl "http://cache/$filename"
}
echo "#### FFmpeg static build ####"
#this is our working directory
cd $BUILD_DIR
[ $is_x86 -eq 1 ] && download \
"yasm-1.3.0.tar.gz" \
"" \
"fc9e586751ff789b34b1f21d572d96af" \
"http://www.tortall.net/projects/yasm/releases/"
[ $is_x86 -eq 1 ] && download \
"nasm-2.15.05.tar.bz2" \
"" \
"b8985eddf3a6b08fc246c14f5889147c" \
"https://www.nasm.us/pub/nasm/releasebuilds/2.15.05/"
download \
"OpenSSL_1_0_2o.tar.gz" \
"" \
"5b5c050f83feaa0c784070637fac3af4" \
"https://github.com/openssl/openssl/archive/"
download \
"v1.2.11.tar.gz" \
"zlib-1.2.11.tar.gz" \
"0095d2d2d1f3442ce1318336637b695f" \
"https://github.com/madler/zlib/archive/"
download \
"x264-stable.tar.gz" \
"" \
"nil" \
"https://code.videolan.org/videolan/x264/-/archive/stable/"
download \
"x265_2.7.tar.gz" \
"" \
"b0d7d20da2a418fa4f53a559946ea079" \
"http://download.openpkg.org/components/cache/x265/"
download \
"v0.1.6.tar.gz" \
"fdk-aac.tar.gz" \
"223d5f579d29fb0d019a775da4e0e061" \
"https://github.com/mstorsjo/fdk-aac/archive"
# libass dependency
download \
"harfbuzz-1.4.6.tar.bz2" \
"" \
"e246c08a3bac98e31e731b2a1bf97edf" \
"https://www.freedesktop.org/software/harfbuzz/release/"
download \
"fribidi-1.0.2.tar.bz2" \
"" \
"bd2eb2f3a01ba11a541153f505005a7b" \
"https://github.com/fribidi/fribidi/releases/download/v1.0.2/"
download \
"0.13.6.tar.gz" \
"libass-0.13.6.tar.gz" \
"nil" \
"https://github.com/libass/libass/archive/"
download \
"lame-3.99.5.tar.gz" \
"" \
"84835b313d4a8b68f5349816d33e07ce" \
"http://downloads.sourceforge.net/project/lame/lame/3.99"
download \
"opus-1.1.2.tar.gz" \
"" \
"1f08a661bc72930187893a07f3741a91" \
"https://github.com/xiph/opus/releases/download/v1.1.2"
download \
"v1.6.1.tar.gz" \
"vpx-1.6.1.tar.gz" \
"b0925c8266e2859311860db5d76d1671" \
"https://github.com/webmproject/libvpx/archive"
download \
"rtmpdump-2.3.tgz" \
"" \
"eb961f31cd55f0acf5aad1a7b900ef59" \
"https://rtmpdump.mplayerhq.hu/download/"
download \
"release-2.7.4.tar.gz" \
"zimg-release-2.7.4.tar.gz" \
"1757dcc11590ef3b5a56c701fd286345" \
"https://github.com/sekrit-twc/zimg/archive/"
download \
"v2.1.2.tar.gz" \
"openjpeg-2.1.2.tar.gz" \
"40a7bfdcc66280b3c1402a0eb1a27624" \
"https://github.com/uclouvain/openjpeg/archive/"
download \
"v0.6.1.tar.gz" \
"libwebp-0.6.1.tar.gz" \
"1c3099cd2656d0d80d3550ee29fc0f28" \
"https://github.com/webmproject/libwebp/archive/"
download \
"v1.3.6.tar.gz" \
"vorbis-1.3.6.tar.gz" \
"03e967efb961f65a313459c5d0f4cbfb" \
"https://github.com/xiph/vorbis/archive/"
download \
"v1.3.3.tar.gz" \
"ogg-1.3.3.tar.gz" \
"b8da1fe5ed84964834d40855ba7b93c2" \
"https://github.com/xiph/ogg/archive/"
download \
"n4.4.tar.gz" \
"ffmpeg4.4.tar.gz" \
"8c52b3e3926fdbac1e7be3761035741d" \
"https://github.com/FFmpeg/FFmpeg/archive"
download \
"libva-2.13.0.tar.bz2" \
"libva.tar.bz2" \
"2adb2c023371dd68fe0d23e58afcf0b072b79828" \
"https://github.com/intel/libva/releases/download/2.13.0/"
[ $download_only -eq 1 ] && exit 0
TARGET_DIR_SED=$(echo $TARGET_DIR | awk '{gsub(/\//, "\\/"); print}')
echo "*** Building libva ***"
cd $BUILD_DIR/libva*
[ $rebuild -eq 1 -a -f Makefile ] && make distclane || true
./configure --prefix=$TARGET_DIR --disable-shared
make -j $jval
make install
if [ $is_x86 -eq 1 ]; then
echo "*** Building yasm ***"
cd $BUILD_DIR/yasm*
[ $rebuild -eq 1 -a -f Makefile ] && make distclean || true
[ ! -f config.status ] && ./configure --prefix=$TARGET_DIR --bindir=$BIN_DIR
make -j $jval
make install
fi
if [ $is_x86 -eq 1 ]; then
echo "*** Building nasm ***"
cd $BUILD_DIR/nasm*
[ $rebuild -eq 1 -a -f Makefile ] && make distclean || true
[ ! -f config.status ] && ./configure --prefix=$TARGET_DIR --bindir=$BIN_DIR
make -j $jval
make install
fi
echo "*** Building OpenSSL ***"
cd $BUILD_DIR/openssl*
[ $rebuild -eq 1 -a -f Makefile ] && make distclean || true
if [ "$platform" = "darwin" ]; then
PATH="$BIN_DIR:$PATH" ./Configure darwin64-x86_64-cc --prefix=$TARGET_DIR
elif [ "$platform" = "linux" ]; then
PATH="$BIN_DIR:$PATH" ./config --prefix=$TARGET_DIR
fi
PATH="$BIN_DIR:$PATH" make -j $jval
make install
echo "*** Building zlib ***"
cd $BUILD_DIR/zlib*
[ $rebuild -eq 1 -a -f Makefile ] && make distclean || true
if [ "$platform" = "linux" ]; then
[ ! -f config.status ] && PATH="$BIN_DIR:$PATH" ./configure --prefix=$TARGET_DIR
elif [ "$platform" = "darwin" ]; then
[ ! -f config.status ] && PATH="$BIN_DIR:$PATH" ./configure --prefix=$TARGET_DIR
fi
PATH="$BIN_DIR:$PATH" make -j $jval
make install
echo "*** Building x264 ***"
cd $BUILD_DIR/x264*
[ $rebuild -eq 1 -a -f Makefile ] && make distclean || true
[ ! -f config.status ] && PATH="$BIN_DIR:$PATH" ./configure --prefix=$TARGET_DIR --enable-static --disable-shared --disable-opencl --enable-pic
PATH="$BIN_DIR:$PATH" make -j $jval
make install
echo "*** Building x265 ***"
cd $BUILD_DIR/x265*
cd build/linux
[ $rebuild -eq 1 ] && find . -mindepth 1 ! -name 'make-Makefiles.bash' -and ! -name 'multilib.sh' -exec rm -r {} +
PATH="$BIN_DIR:$PATH" cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX="$TARGET_DIR" -DENABLE_SHARED:BOOL=OFF -DSTATIC_LINK_CRT:BOOL=ON -DENABLE_CLI:BOOL=OFF ../../source
sed -i 's/-lgcc_s/-lgcc_eh/g' x265.pc
make -j $jval
make install
echo "*** Building fdk-aac ***"
cd $BUILD_DIR/fdk-aac*
[ $rebuild -eq 1 -a -f Makefile ] && make distclean || true
autoreconf -fiv
[ ! -f config.status ] && ./configure --prefix=$TARGET_DIR --disable-shared
make -j $jval
make install
echo "*** Building harfbuzz ***"
cd $BUILD_DIR/harfbuzz-*
[ $rebuild -eq 1 -a -f Makefile ] && make distclean || true
./configure --prefix=$TARGET_DIR --disable-shared --enable-static
make -j $jval
make install
echo "*** Building fribidi ***"
cd $BUILD_DIR/fribidi-*
[ $rebuild -eq 1 -a -f Makefile ] && make distclean || true
./configure --prefix=$TARGET_DIR --disable-shared --enable-static --disable-docs
make -j $jval
make install
echo "*** Building libass ***"
cd $BUILD_DIR/libass-*
[ $rebuild -eq 1 -a -f Makefile ] && make distclean || true
./autogen.sh
./configure --prefix=$TARGET_DIR --disable-shared
make -j $jval
make install
echo "*** Building mp3lame ***"
cd $BUILD_DIR/lame*
# The lame build script does not recognize aarch64, so need to set it manually
uname -a | grep -q 'aarch64' && lame_build_target="--build=arm-linux" || lame_build_target=''
[ $rebuild -eq 1 -a -f Makefile ] && make distclean || true
[ ! -f config.status ] && ./configure --prefix=$TARGET_DIR --enable-nasm --disable-shared $lame_build_target
make
make install
echo "*** Building opus ***"
cd $BUILD_DIR/opus*
[ $rebuild -eq 1 -a -f Makefile ] && make distclean || true
[ ! -f config.status ] && ./configure --prefix=$TARGET_DIR --disable-shared
make
make install
echo "*** Building libvpx ***"
cd $BUILD_DIR/libvpx*
[ $rebuild -eq 1 -a -f Makefile ] && make distclean || true
[ ! -f config.status ] && PATH="$BIN_DIR:$PATH" ./configure --prefix=$TARGET_DIR --disable-examples --disable-unit-tests --enable-pic
PATH="$BIN_DIR:$PATH" make -j $jval
make install
echo "*** Building librtmp ***"
cd $BUILD_DIR/rtmpdump-*
cd librtmp
[ $rebuild -eq 1 ] && make distclean || true
# there's no configure, we have to edit Makefile directly
if [ "$platform" = "linux" ]; then
sed -i "/INC=.*/d" ./Makefile # Remove INC if present from previous run.
sed -i "s/prefix=.*/prefix=${TARGET_DIR_SED}\nINC=-I\$(prefix)\/include/" ./Makefile
sed -i "s/SHARED=.*/SHARED=no/" ./Makefile
elif [ "$platform" = "darwin" ]; then
sed -i "" "s/prefix=.*/prefix=${TARGET_DIR_SED}/" ./Makefile
fi
make install_base
echo "*** Building openjpeg ***"
cd $BUILD_DIR/openjpeg-*
[ $rebuild -eq 1 -a -f Makefile ] && make distclean || true
PATH="$BIN_DIR:$PATH" cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX="$TARGET_DIR" -DBUILD_SHARED_LIBS:bool=off
make -j $jval
make install
echo "*** Building libwebp ***"
cd $BUILD_DIR/libwebp*
[ $rebuild -eq 1 -a -f Makefile ] && make distclean || true
./autogen.sh
./configure --prefix=$TARGET_DIR --disable-shared
make -j $jval
make install
echo "*** Building libvorbis ***"
cd $BUILD_DIR/vorbis*
[ $rebuild -eq 1 -a -f Makefile ] && make distclean || true
./autogen.sh
./configure --prefix=$TARGET_DIR --disable-shared
make -j $jval
make install
echo "*** Building libogg ***"
cd $BUILD_DIR/ogg*
[ $rebuild -eq 1 -a -f Makefile ] && make distclean || true
./autogen.sh
./configure --prefix=$TARGET_DIR --disable-shared
make -j $jval
make install
# FFMpeg
echo "*** Building FFmpeg ***"
cd $BUILD_DIR/FFmpeg*
[ $rebuild -eq 1 -a -f Makefile ] && make distclean || true
if [ "$platform" = "linux" ]; then
[ ! -f config.status ] && PATH="$BIN_DIR:$PATH" \
./configure \
--prefix="$TARGET_DIR" \
--pkg-config-flags="--static" \
--extra-cflags="-I/usr/local/include" \
--extra-ldflags="-L/usr/lib" \
--extra-libs="-lpthread -lm -lz" \
--extra-ldexeflags="-static" \
--bindir="$BIN_DIR" \
--enable-pic \
--enable-fontconfig \
--enable-gpl \
--enable-version3 \
--enable-libass \
--enable-libfdk-aac \
--enable-libfreetype \
--enable-libmp3lame \
--enable-libopenjpeg \
--enable-libopus \
--enable-libtheora \
--enable-libvorbis \
--enable-libvpx \
--enable-libwebp \
--enable-libx264 \
--enable-libx265 \
--enable-libxvid \
--enable-nonfree \
--enable-openssl \
--enable-nvdec \
--enable-nvenc \
--enable-vaapi
elif [ "$platform" = "darwin" ]; then
[ ! -f config.status ] && PATH="$BIN_DIR:$PATH" \
PKG_CONFIG_PATH="${TARGET_DIR}/lib/pkgconfig:/usr/local/lib/pkgconfig:/usr/local/share/pkgconfig:/usr/local/Cellar/openssl/1.0.2o_1/lib/pkgconfig" ./configure \
--cc=/usr/bin/clang \
--prefix="$TARGET_DIR" \
--pkg-config-flags="--static" \
--extra-cflags="-I$TARGET_DIR/include" \
--extra-ldflags="-L$TARGET_DIR/lib" \
--extra-ldexeflags="-Bstatic" \
--bindir="$BIN_DIR" \
--enable-pic \
--enable-ffplay \
--enable-fontconfig \
--enable-frei0r \
--enable-gpl \
--enable-version3 \
--enable-libass \
--enable-libfribidi \
--enable-libfdk-aac \
--enable-libfreetype \
--enable-libmp3lame \
--enable-libopencore-amrnb \
--enable-libopencore-amrwb \
--enable-libopenjpeg \
--enable-libopus \
--enable-librtmp \
--enable-libsoxr \
--enable-libspeex \
--enable-libvidstab \
--enable-libvorbis \
--enable-libvpx \
--enable-libwebp \
--enable-libx264 \
--enable-libx265 \
--enable-libxvid \
--enable-libzimg \
--enable-nonfree \
--enable-openssl
fi
PATH="$BIN_DIR:$PATH" make -j $jval
make install
make distclean
hash -r