-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·1051 lines (987 loc) · 40.2 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
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
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
# pkg configuration
PKGNAME="ffmpeg-hi"
PKGVERSION="$(ls archive | grep ffmpeg | sed 's/ffmpeg-//g;s/.tar.*//g')"
PKGSECTION="video"
PKGAUTHOR="Ronny Wegener <[email protected]>"
PKGHOMEPAGE="http://ffmpeg-hi.sourceforge.net"
PKGDEPENDS=""
PKGDESCRIPTION="Multimedia encoder
Customized ffmpeg build for use with FFmpegYAG.
Statically linked to reduce dependencies.
Supports 8 and 10 bit encoding for x264, x265 and VP9 codec.
Supports HE-AAC profiles with fdkaac."
# environment variables
export PATH="/usr/local/bin:$PATH"
export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig"
export CFLAGS="-g -O2 -I/usr/local/include"
export LDFLAGS="-s -L/usr/local/lib -L/usr/lib64"
# local variables
cd $(dirname $0)
CWD=$(pwd)
PKG_DIR=$CWD/archive
SRC_DIR=$CWD/src
DIST_DIR=$CWD/build
BIN_DIR=$DIST_DIR/usr/bin
CONFIGURE_ALL_FLAGS="--enable-static --disable-shared"
CONFIGURE_FFMPEG_LIBS="-L/usr/lib64 -L/usr/local/lib"
CONFIGURE_FFMPEG_FLAGS="\
--disable-debug \
--enable-version3 \
--enable-static \
--disable-ffplay \
--disable-indev=sndio \
--disable-outdev=sndio \
--cc=gcc \
"
CONFIGURE_FFMPEG_CODEC_FLAGS="
--enable-gpl \
--enable-nonfree \
--enable-zlib \
--enable-bzlib \
--enable-libfreetype \
--enable-fontconfig \
--enable-libass \
--enable-libfdk_aac \
--enable-libmp3lame \
--enable-libvorbis \
--enable-libtheora \
--enable-libxvid \
--enable-libx264 \
--enable-libx265 \
--enable-libvpx \
--enable-openssl \
"
#~ TODO: include additional libraries into ffmpeg build
#~
#~ [+] included (working)
#~ [o] included (incomplete)
#~ [-] excluded
#~ [ ] not included yet
#~
#~ [ ] --enable-avisynth enable reading of AVISynth script files [no]
#~ [+] --enable-bzlib enable bzlib [autodetect]
#~ [+] --enable-fontconfig enable fontconfig
#~ [ ] --enable-frei0r enable frei0r video filtering
#~ [-] --enable-gnutls enable gnutls [no]
#~ [ ] --enable-iconv enable iconv [autodetect]
#~ [-] --enable-libaacplus enable AAC+ encoding via libaacplus [no]
#~ [o] --enable-libass enable libass subtitles rendering [no]
#~ [-] --enable-libbluray enable BluRay reading using libbluray [no]
#~ [-] --enable-libcaca enable textual display using libcaca
#~ [ ] --enable-libcelt enable CELT decoding via libcelt [no]
#~ [ ] --enable-libcdio enable audio CD grabbing with libcdio
#~ [-] --enable-libdc1394 enable IIDC-1394 grabbing using libdc1394 and libraw1394 [no]
#~ [+] --enable-libfdk-aac enable AAC encoding via libfdk-aac [no]
#~ [-] --enable-libflite enable flite (voice synthesis) support via libflite [no]
#~ [+] --enable-libfreetype enable libfreetype [no]
#~ [ ] --enable-libgsm enable GSM de/encoding via libgsm [no]
#~ [-] --enable-libiec61883 enable iec61883 via libiec61883 [no]
#~ [-] --enable-libilbc enable iLBC de/encoding via libilbc [no]
#~ [-] --enable-libmodplug enable ModPlug via libmodplug [no]
#~ [+] --enable-libmp3lame enable MP3 encoding via libmp3lame [no]
#~ [-] --enable-libnut enable NUT (de)muxing via libnut, native (de)muxer exists [no]
#~ [-] --enable-libopencore-amrnb enable AMR-NB de/encoding via libopencore-amrnb [no]
#~ [-] --enable-libopencore-amrwb enable AMR-WB decoding via libopencore-amrwb [no]
#~ [ ] --enable-libopencv enable video filtering via libopencv [no]
#~ [ ] --enable-libopenjpeg enable JPEG 2000 de/encoding via OpenJPEG [no]
#~ [ ] --enable-libopus enable Opus decoding via libopus [no]
#~ [-] --enable-libpulse enable Pulseaudio input via libpulse [no]
#~ [-] --enable-librtmp enable RTMP[E] support via librtmp [no]
#~ [-] --enable-libschroedinger enable Dirac de/encoding via libschroedinger [no]
#~ [ ] --enable-libsoxr enable Include libsoxr resampling [no]
#~ [ ] --enable-libspeex enable Speex de/encoding via libspeex [no]
#~ [-] --enable-libstagefright-h264 enable H.264 decoding via libstagefright [no]
#~ [+] --enable-libtheora enable Theora encoding via libtheora [no]
#~ [ ] --enable-libtwolame enable MP2 encoding via libtwolame [no]
#~ [-] --enable-libutvideo enable Ut Video encoding and decoding via libutvideo [no]
#~ [-] --enable-libv4l2 enable libv4l2/v4l-utils [no]
#~ [-] --enable-libvo-aacenc enable AAC encoding via libvo-aacenc [no]
#~ [-] --enable-libvo-amrwbenc enable AMR-WB encoding via libvo-amrwbenc [no]
#~ [+] --enable-libvorbis enable Vorbis en/decoding via libvorbis, native implementation exists [no]
#~ [+] --enable-libvpx enable VP8 and VP9 de/encoding via libvpx [no]
#~ [+] --enable-libx264 enable H.264 encoding via x264 [no]
#~ [ ] --enable-libxavs enable AVS encoding via xavs [no]
#~ [+] --enable-libxvid enable Xvid encoding via xvidcore, native MPEG-4/Xvid encoder exists [no]
#~ [-] --enable-openal enable OpenAL 1.1 capture support [no]
#~ [+] --enable-openssl enable openssl [no]
#~ [-] --enable-x11grab enable X11 grabbing [no]
#~ [+] --enable-zlib enable zlib [autodetect]
function check_app {
echo "CHECK: $1"
$1 --version > /dev/null 2>&1
if [ $? != 0 ]
then
echo "ERROR: $1 is missing"
exit
fi
}
function check_environment {
check_app tar
#check_app bzip2
check_app xz
check_app make
check_app cmake
#check_app ld
check_app gcc
check_app perl
check_app python
}
function init_environment {
#mkdir -p $PKG_DIR
mkdir -p $SRC_DIR
mkdir -p $BIN_DIR
apt-get --version > /dev/null 2>&1
if [ $? == 0 ]
then
ENVIRONMENT="deb"
fi
yum --version > /dev/null 2>&1
if [ $? = 0 ]
then
ENVIRONMENT="fedora"
fi
zypper --version > /dev/null 2>&1
if [ $? = 0 ]
then
ENVIRONMENT="opensuse"
fi
if [ "$(uname -o)" = "Msys" ]
then
ENVIRONMENT="mingw"
set -e
else
set -e
fi
check_environment
}
get_lsb_release()
{
# FIXME: Fedora/OpenSuse/CentOS/Redhat do not use lsb-release, they use e.g. fedora-release
RELEASE_FILE=/dev/null
if [ -f /etc/os-release ]
then
RELEASE_FILE=/etc/os-release
fi
if [ -f /etc/lsb-release ]
then
RELEASE_FILE=/etc/lsb-release
fi
if [ -f /etc/upstream-release/os-release ]
then
RELEASE_FILE=/etc/upstream-release/os-release
fi
if [ -f /etc/upstream-release/lsb-release ]
then
RELEASE_FILE=/etc/upstream-release/lsb-release
fi
DIST=linux
VER=$(date +%y.%m)
if [[ $(grep '^ID=' $RELEASE_FILE | wc -l) > 1 ]]
then
DIST=$(grep '^ID=' $RELEASE_FILE | sed 's|\"||g;s|\s|-|g' | cut -d '=' -f 2 | tr '[:upper:]' '[:lower:]')
DIST=$(grep '^VERSION_ID=' $RELEASE_FILE | sed 's|\"||g' | cut -d '=' -f 2)
fi
if [[ $(grep '^DISTRIB_' $RELEASE_FILE | wc -l) > 1 ]]
then
DIST=$(grep '^DISTRIB_ID=' $RELEASE_FILE | sed 's|\"||g;s|\s|-|g' | cut -d '=' -f 2 | tr '[:upper:]' '[:lower:]')
VER=$(grep '^DISTRIB_RELEASE=' $RELEASE_FILE | sed 's|\"||g' | cut -d '=' -f 2)
fi
ARCH=x86
rpm --version > /dev/null 2>&1
if [ $? == 0 ]
then
ARCH=$(rpm --eval %_target_cpu)
fi
apt-get --version > /dev/null 2>&1
if [ $? == 0 ]
then
ARCH=$(dpkg --print-architecture)
fi
echo "${DIST}-${VER}_${ARCH}"
}
function build_zlib {
if [[ "$CONFIGURE_FFMPEG_CODEC_FLAGS" =~ "--enable-zlib" ]]
then
cd $SRC_DIR
tar -xJvf $PKG_DIR/zlib*.tar.*
cd zlib*
./configure --static
make libz.a
make install
#make clean
pkg-config zlib >/dev/null 2>&1
CONFIGURE_FFMPEG_LIBS="$CONFIGURE_FFMPEG_LIBS -lz"
# NOTE: when package config fails, export the lib dependencies to variables
if [ $? != 0 ]
then
export ZLIB_CFLAGS="-I/usr/local/include"
export ZLIB_LIBS="-L/usr/local/lib -lz"
fi
cd $SRC_DIR
rm -r -f zlib*
fi
}
function build_bzip2 {
if [[ "$CONFIGURE_FFMPEG_CODEC_FLAGS" =~ "--enable-bzlib" ]]
then
if [ "$ENVIRONMENT" == "deb" ] || [ "$ENVIRONMENT" == "fedora" ] || [ "$ENVIRONMENT" == "opensuse" ]
then
cd $SRC_DIR
tar -xzvf $PKG_DIR/bzip2*.tar.*
cd bzip2*
make
make install
#make clean
CONFIGURE_FFMPEG_LIBS="$CONFIGURE_FFMPEG_LIBS -lbz2"
elif [ "$ENVIRONMENT" == "mingw" ]
then
cd $SRC_DIR
tar -xzvf $PKG_DIR/bzip2*.tar.*
cd bzip2*
make libbz2.a
mkdir -p /usr/local/include
cp bzlib.h /usr/local/include
mkdir -p /usr/local/lib
cp libbz2.a /usr/local/lib
#make clean
else
echo "ERROR"
exit
fi
cd $SRC_DIR
rm -r -f bzip2*
fi
}
function build_expat {
if [[ "$CONFIGURE_FFMPEG_CODEC_FLAGS" =~ "--enable-fontconfig" || "$CONFIGURE_FFMPEG_CODEC_FLAGS" =~ "--enable-libass" ]]
then
if [ "$ENVIRONMENT" == "deb" ] || [ "$ENVIRONMENT" == "fedora" ] || [ "$ENVIRONMENT" == "opensuse" ]
then
cd $SRC_DIR
tar -xjvf $PKG_DIR/expat*.tar.*
cd expat*
./configure $CONFIGURE_ALL_FLAGS
make
make install
#make clean
pkg-config expat >/dev/null 2>&1
# NOTE: when package config fails, export the lib dependencies to variables
if [ $? != 0 ]
then
export EXPAT_CFLAGS="-I/usr/local/include"
export EXPAT_LIBS="-L/usr/local/lib -lexpat"
fi
elif [ "$ENVIRONMENT" == "mingw" ]
then
cd $SRC_DIR
tar -xjvf $PKG_DIR/expat*.tar.*
cd expat*
./configure $CONFIGURE_ALL_FLAGS --build=$(arch)-pc-mingw32
make
make install
#make clean
pkg-config expat >/dev/null 2>&1
# NOTE: when package config fails, export the lib dependencies to variables
if [ $? != 0 ]
then
export EXPAT_CFLAGS="-I/usr/local/include"
export EXPAT_LIBS="-L/usr/local/lib -lexpat"
fi
else
echo "ERROR"
exit
fi
cd $SRC_DIR
rm -r -f expat*
fi
}
function build_xml2 {
if [[ "$CONFIGURE_FFMPEG_CODEC_FLAGS" =~ "--enable-fontconfig" || "$CONFIGURE_FFMPEG_CODEC_FLAGS" =~ "--enable-libass" || "$CONFIGURE_FFMPEG_CODEC_FLAGS" =~ "--enable-libbluray" ]]
then
if [ "$ENVIRONMENT" == "deb" ] || [ "$ENVIRONMENT" == "fedora" ] || [ "$ENVIRONMENT" == "opensuse" ]
then
cd $SRC_DIR
tar -xzvf $PKG_DIR/libxml2*.tar.*
cd libxml2*
./configure $CONFIGURE_ALL_FLAGS --without-debug --without-python
make
make install-strip
#make clean
pkg-config libxml-2.0 >/dev/null 2>&1
# NOTE: when package config fails, export the lib dependencies to variables
if [ $? != 0 ]
then
export LIBXML2_CFLAGS="-I/usr/local/include/libxml2 -DLIBXML_STATIC"
export LIBXML2_LIBS="-L/usr/local/lib -lxml2 -lz -lws2_32"
export XML2_INCLUDEDIR="-I/usr/local/include/libxml2"
export XML2_LIBDIR="-L/usr/local/lib"
export XML2_LIBS="-lxml2 -lz -lws2_32"
else
# NOTE: modify libxml2.pc so it will return private libs even when called without --static
sed -i -e "s|Libs:.*|Libs: $(pkg-config --libs --static libxml-2.0)|g" $PKG_CONFIG_PATH/libxml-2.0.pc
fi
elif [ "$ENVIRONMENT" == "mingw" ]
then
cd $SRC_DIR
tar -xzvf $PKG_DIR/libxml2*.tar.*
cd libxml2*
./configure $CONFIGURE_ALL_FLAGS --build=$(gcc -dumpmachine) --with-zlib=/usr/local --without-debug --without-python
make
make install-strip
#make clean
pkg-config libxml-2.0 >/dev/null 2>&1
# NOTE: when package config fails, export the lib dependencies to variables
if [ $? != 0 ]
then
export LIBXML2_CFLAGS="-I/usr/local/include/libxml2 -DLIBXML_STATIC"
export LIBXML2_LIBS="-L/usr/local/lib -lxml2 -lz -lws2_32"
export XML2_INCLUDEDIR="-I/usr/local/include/libxml2"
export XML2_LIBDIR="-L/usr/local/lib"
export XML2_LIBS="-lxml2 -lz -lws2_32"
else
# NOTE: modify libxml2.pc so it will return private libs even when called without --static
sed -i -e "s|Libs:.*|Libs: $(pkg-config --libs --static libxml-2.0)|g" $PKG_CONFIG_PATH/libxml-2.0.pc
fi
else
echo "ERROR"
exit
fi
cd $SRC_DIR
rm -r -f libxml2*
fi
}
function build_freetype {
if [[ "$CONFIGURE_FFMPEG_CODEC_FLAGS" =~ "--enable-libfreetype" || "$CONFIGURE_FFMPEG_CODEC_FLAGS" =~ "--enable-fontconfig" || "$CONFIGURE_FFMPEG_CODEC_FLAGS" =~ "--enable-libass" ]]
then
if [ "$ENVIRONMENT" == "deb" ] || [ "$ENVIRONMENT" == "fedora" ] || [ "$ENVIRONMENT" == "opensuse" ]
then
cd $SRC_DIR
tar -xvf $PKG_DIR/freetype*.tar.*
cd freetype*
./configure $CONFIGURE_ALL_FLAGS --enable-shared=no
make
make install
#make clean
# pkg-config freetype2 >/dev/null 2>&1
export FREETYPE_CFLAGS="-I/usr/local/include -I/usr/local/include/freetype2"
export FREETYPE_LIBS="-L/usr/local/lib -lfreetype -lz"
CONFIGURE_FFMPEG_LIBS="${CONFIGURE_FFMPEG_LIBS} -lfreetype"
elif [ "$ENVIRONMENT" == "mingw" ]
then
cd $SRC_DIR
tar -xvf $PKG_DIR/freetype*.tar.*
cd freetype*
./configure $CONFIGURE_ALL_FLAGS --enable-shared=no
make
make install
#make clean
pkg-config freetype2 >/dev/null 2>&1
# NOTE: when package config fails, export the lib dependencies to variables
if [ $? != 0 ]
then
export FREETYPE_CFLAGS="-I/usr/local/include -I/usr/local/include/freetype2"
export FREETYPE_LIBS="-L/usr/local/lib -lfreetype -lz"
else
# NOTE: modify lfreetype.pc so it will return private libs even when called without --static
sed -i -e "s|Libs:.*|Libs: $(pkg-config --libs --static freetype2)|g" $PKG_CONFIG_PATH/freetype2.pc
fi
else
echo "ERROR"
exit
fi
cd $SRC_DIR
rm -r -f freetype*
fi
}
function build_fribidi {
if [[ "$CONFIGURE_FFMPEG_CODEC_FLAGS" =~ "--enable-libass" ]]
then
if [ "$ENVIRONMENT" == "deb" ] || [ "$ENVIRONMENT" == "fedora" ] || [ "$ENVIRONMENT" == "opensuse" ]
then
cd $SRC_DIR
tar -xvf $PKG_DIR/fribidi*.tar.*
cd fribidi*
./configure $CONFIGURE_ALL_FLAGS --disable-debug
# make -C charset
# fixing lib/Makefile directly before make -C lib, or it will be overwritten by another configure process
sed -i -e 's/am__append_1 =/#am__append_1 =/g' lib/Makefile
make -C lib
make
make install
#make clean
pkg-config fribidi >/dev/null 2>&1
CONFIGURE_FFMPEG_LIBS="${CONFIGURE_FFMPEG_LIBS} -lfribidi"
if [ $? != 0 ]
then
export FRIBIDI_CFLAGS="-I/usr/local/include/fribidi"
export FRIBIDI_LIBS="-L/usr/local/lib -lfribidi"
fi
elif [ "$ENVIRONMENT" == "mingw" ]
then
cd $SRC_DIR
tar -xjvf $PKG_DIR/fribidi*.tar.*
cd fribidi*
# fix for static build
sed -i -e 's/__declspec(dllimport)//g' lib/fribidi-common.h
./configure $CONFIGURE_ALL_FLAGS --disable-debug
make -C charset
# fixing lib/Makefile directly before make -C lib, or it will be overwritten by another configure process
sed -i -e 's/am__append_1 =/#am__append_1 =/g' lib/Makefile
make -C lib
make
make install
#make clean
pkg-config fribidi >/dev/null 2>&1
if [ $? != 0 ]
then
export FRIBIDI_CFLAGS="-I/usr/local/include/fribidi"
export FRIBIDI_LIBS="-L/usr/local/lib -lfribidi"
fi
else
echo "ERROR"
exit
fi
cd $SRC_DIR
rm -r -f fribidi*
fi
}
function build_fontconfig {
if [[ "$CONFIGURE_FFMPEG_CODEC_FLAGS" =~ "--enable-fontconfig" || "$CONFIGURE_FFMPEG_CODEC_FLAGS" =~ "--enable-libass" ]]
then
if [ "$ENVIRONMENT" == "deb" ] || [ "$ENVIRONMENT" == "fedora" ] || [ "$ENVIRONMENT" == "opensuse" ]
then
cd $SRC_DIR
tar -xzvf $PKG_DIR/fontconfig*.tar.*
cd fontconfig*
./configure $CONFIGURE_ALL_FLAGS --enable-shared=no --disable-docs --enable-libxml2
make
make install
#make clean
pkg-config fontconfig >/dev/null 2>&1
# NOTE: when package config fails, export the lib dependencies to variables
if [ $? != 0 ]
then
export FONTCONFIG_CFLAGS="-I/usr/local/include"
export FONTCONFIG_LIBS="-L/usr/local/lib -lfontconfig $XML2_LIBS $FREETYPE_LIBS"
# TODO: deceide if libxml or expat was used, and export corresponding lib dependencies...
#export FONTCONFIG_LIBS="-L/usr/local/lib -lfontconfig -lexpat -lfreetype"
else
cp -f fontconfig.pc $PKG_CONFIG_PATH/fontconfig.pc
# NOTE: modify fontconfig.pc so it will return private libs even when called without --static
sed -i -e "s|Libs:.*|Libs: $(pkg-config --libs --static fontconfig)|g" $PKG_CONFIG_PATH/fontconfig.pc
fi
elif [ "$ENVIRONMENT" == "mingw" ]
then
# TODO: important note about the font configuration directory in windows:
# http://ffmpeg.zeranoe.com/forum/viewtopic.php?f=10&t=318&start=10
cd $SRC_DIR
tar -xzvf $PKG_DIR/fontconfig*.tar.*
cd fontconfig*
./configure $CONFIGURE_ALL_FLAGS --enable-shared=no --disable-docs --enable-libxml2
make
make install
#make clean
pkg-config fontconfig >/dev/null 2>&1
# NOTE: when package config fails, export the lib dependencies to variables
if [ $? != 0 ]
then
export FONTCONFIG_CFLAGS="-I/usr/local/include"
export FONTCONFIG_LIBS="-L/usr/local/lib -lfontconfig $XML2_LIBS $FREETYPE_LIBS"
# TODO: deceide if libxml or expat was used, and export corresponding lib dependencies...
#export FONTCONFIG_LIBS="-L/usr/local/lib -lfontconfig -lexpat -lfreetype"
else
# NOTE: modify fontconfig.pc so it will return private libs even when called without --static
sed -i -e "s|Libs:.*|Libs: $(pkg-config --libs --static fontconfig)|g" $PKG_CONFIG_PATH/fontconfig.pc
fi
else
echo "ERROR"
exit
fi
cd $SRC_DIR
rm -r -f fontconfig*
fi
}
function build_harfbuzz {
if [[ "$CONFIGURE_FFMPEG_CODEC_FLAGS" =~ "--enable-libass" ]]
then
cd $SRC_DIR
tar -xvf $PKG_DIR/harfbuzz*.tar.*
cd harfbuzz*
./configure $CONFIGURE_ALL_FLAGS
make
make install
#make clean
pkg-config harfbuzz >/dev/null 2>&1
# NOTE: when package config fails, export the lib dependencies to variables
CONFIGURE_FFMPEG_LIBS="${CONFIGURE_FFMPEG_LIBS} -lharfbuzz"
if [ $? != 0 ]
then
export HARFBUZZ_CFLAGS="-I/usr/local/include"
export HARFBUZZ_LIBS="-L/usr/local/lib -L/usr/lib64 -lharfbuzz -lm"
fi
cd $SRC_DIR
rm -r -f harfbuzz*
fi
}
function build_iconv {
if [[ "$CONFIGURE_FFMPEG_CODEC_FLAGS" =~ "--enable-libass" ]]
then
cd $SRC_DIR
tar -xzvf $PKG_DIR/libiconv*.tar.*
cd libiconv*
# derivative fix for disabling gets error when glibc is undefined (http://www.itkb.ro/kb/linux/patch-libiconv-pentru-glibc-216)
# sed -i -e 's/_GL_WARN_ON_USE (gets,.*//g' srclib/stdio.in.h
if [ "$ENVIRONMENT" == "mingw" ]
then
./configure $CONFIGURE_ALL_FLAGS --build=$(arch)-pc-mingw32
else
./configure $CONFIGURE_ALL_FLAGS
fi
make
make install
#make clean
cd $SRC_DIR
rm -r -f libiconv*
fi
}
function build_libpng {
if [[ "$CONFIGURE_FFMPEG_CODEC_FLAGS" =~ "--enable-libass" ]]
then
cd $SRC_DIR
tar -xvzf $PKG_DIR/libpng*.tar.*
cd libpng*
./configure $CONFIGURE_ALL_FLAGS
make
make install
CONFIGURE_FFMPEG_LIBS="$CONFIGURE_FFMPEG_LIBS -lpng"
cd $SRC_DIR
rm -r -f libpng*
fi
}
function build_pcre {
if [[ "$CONFIGURE_FFMPEG_CODEC_FLAGS" =~ "--enable-libass" ]]
then
cd $SRC_DIR
tar -xvf $PKG_DIR/pcre*.tar.*
cd pcre*
./configure $CONFIGURE_ALL_FLAGS
make
make install
cd $SRC_DIR
rm -r -f pcre*
fi
}
function build_ass {
if [[ "$CONFIGURE_FFMPEG_CODEC_FLAGS" =~ "--enable-libass" ]]
then
cd $SRC_DIR
tar -xvf $PKG_DIR/libass*.tar.*
cd libass*
./configure $CONFIGURE_ALL_FLAGS --disable-asm --enable-harfbuzz
make
make install
#make clean
cd $SRC_DIR
rm -r -f libass*
fi
}
function build_fdkaac {
if [[ "$CONFIGURE_FFMPEG_CODEC_FLAGS" =~ "--enable-libfdk_aac" ]]
then
cd $SRC_DIR
tar -xzvf $PKG_DIR/fdk-aac*
cd fdk-aac*
./configure $CONFIGURE_ALL_FLAGS --build=$(gcc -dumpmachine)
make
make install
#make clean
cd $SRC_DIR
rm -r -f fdk-aac*
fi
}
function build_lame {
if [[ "$CONFIGURE_FFMPEG_CODEC_FLAGS" =~ "--enable-libmp3lame" ]]
then
cd $SRC_DIR
tar -xzvf $PKG_DIR/lame*.tar.*
cd lame*
if [ "$ENVIRONMENT" == "mingw" ]
then
./configure $CONFIGURE_ALL_FLAGS --build=$(arch)-pc-mingw32 --disable-frontend
make "CFLAGS=-msse"
else
./configure $CONFIGURE_ALL_FLAGS --disable-frontend
make
fi
make install
#make clean
cd $SRC_DIR
rm -r -f lame*
fi
}
function build_ogg {
if [[ "$CONFIGURE_FFMPEG_CODEC_FLAGS" =~ "--enable-libvorbis" || "$CONFIGURE_FFMPEG_CODEC_FLAGS" =~ "--enable-libtheora" ]]
then
cd $SRC_DIR
tar -xvf $PKG_DIR/libogg*.tar.*
cd libogg*
./configure $CONFIGURE_ALL_FLAGS --build=$(gcc -dumpmachine)
make
make install
#make clean
pkg-config ogg >/dev/null 2>&1
# NOTE: when package config fails, export the lib dependencies to variables
if [ $? != 0 ]
then
export OGG_CFLAGS="-I/usr/local/include"
export OGG_LIBS="-L/usr/local/lib -logg"
fi
cd $SRC_DIR
rm -r -f libogg*
fi
}
function build_vorbis {
if [[ "$CONFIGURE_FFMPEG_CODEC_FLAGS" =~ "--enable-libvorbis" || "$CONFIGURE_FFMPEG_CODEC_FLAGS" =~ "--enable-libtheora" ]]
then
cd $SRC_DIR
tar -xvf $PKG_DIR/libvorbis*.tar.*
cd libvorbis*
./configure $CONFIGURE_ALL_FLAGS --build=$(gcc -dumpmachine)
make
make install
#make clean
CONFIGURE_FFMPEG_LIBS="$CONFIGURE_FFMPEG_LIBS -lvorbis -lvorbisfile -lvorbisenc -logg"
pkg-config vorbis >/dev/null 2>&1
# NOTE: when package config fails, export the lib dependencies to variables
if [ $? != 0 ]
then
export VORBIS_CFLAGS="-I/usr/local/include"
export VORBIS_LIBS="-L/usr/local/lib -lvorbis -lm"
fi
cd $SRC_DIR
rm -r -f libvorbis*
fi
}
function build_theora {
if [[ "$CONFIGURE_FFMPEG_CODEC_FLAGS" =~ "--enable-libtheora" ]]
then
cd $SRC_DIR
tar -xjvf $PKG_DIR/libtheora*.tar.*
cd libtheora*
if [ "$ENVIRONMENT" == "mingw" ]
then
./configure $CONFIGURE_ALL_FLAGS --build=$(arch)-pc-mingw32 --disable-examples
else
./configure $CONFIGURE_ALL_FLAGS --disable-examples
fi
make
make install
#make clean
cd $SRC_DIR
rm -r -f libtheora*
fi
}
function build_xvid {
if [[ "$CONFIGURE_FFMPEG_CODEC_FLAGS" =~ "--enable-libxvid" ]]
then
if [ "$ENVIRONMENT" == "deb" ] || [ "$ENVIRONMENT" == "fedora" ] || [ "$ENVIRONMENT" == "opensuse" ]
then
cd $SRC_DIR
tar -xzvf $PKG_DIR/xvid*.tar.*
cd xvid*/build/generic
./configure $CONFIGURE_ALL_FLAGS
make
make install && :
#make clean
elif [ "$ENVIRONMENT" == "mingw" ]
then
cd $SRC_DIR
tar -xjvf $PKG_DIR/xvid*.tar.*
cd xvid*/build/generic
./configure $CONFIGURE_ALL_FLAGS --build=$(arch)-pc-mingw32
#sed -i -e 's|-mno-cygwin||g' platform.inc
make
make install
#make clean
rm -f /usr/local/lib/xvidcore.dll
ln -s -f /usr/local/lib/xvidcore.a /usr/local/lib/libxvidcore.a
else
echo "ERROR"
exit
fi
cd $SRC_DIR
rm -r -f xvid*
fi
}
function build_vpx {
if [[ "$CONFIGURE_FFMPEG_CODEC_FLAGS" =~ "--enable-libvpx" ]]
then
cd $SRC_DIR
tar -xzvf $PKG_DIR/libvpx*.tar.*
cd libvpx*
if [ "$ENVIRONMENT" == "mingw" ]
then
sed -i 's|which yasm.*AS=yasm|AS=yasm|g' ./build/make/configure.sh
#if [ "$BITDEPTH" == "10" ]
#then
# ./configure $CONFIGURE_ALL_FLAGS --target=$(arch | sed 's|i.86|x86|g')-win$(arch | sed 's|i.86|32|g;s|x86_64|64|g')-gcc --enable-runtime-cpu-detect --enable-vp8 --enable-vp9 --enable-webm-io --enable-postproc --disable-debug --disable-examples --disable-install-bins --disable-docs --disable-unit-tests --disable-dependency-tracking --enable-vp9-highbitdepth
#else
./configure $CONFIGURE_ALL_FLAGS --target=$(arch | sed 's|i.86|x86|g')-win$(arch | sed 's|i.86|32|g;s|x86_64|64|g')-gcc --enable-runtime-cpu-detect --enable-vp8 --enable-vp9 --enable-webm-io --enable-postproc --disable-debug --disable-examples --disable-install-bins --disable-docs --disable-unit-tests --disable-dependency-tracking
#fi
else
#if [ "$BITDEPTH" == "10" ]
#then
# ./configure $CONFIGURE_ALL_FLAGS --target=$(gcc -dumpmachine | sed 's|gnu|gcc|g') --enable-runtime-cpu-detect --enable-vp8 --enable-vp9 --enable-webm-io --enable-postproc --disable-debug --disable-examples --disable-install-bins --disable-docs --disable-unit-tests --enable-vp9-highbitdepth
#else
./configure $CONFIGURE_ALL_FLAGS --target=$(gcc -dumpmachine | sed 's|redhat-linux|linux-gcc|g') --enable-runtime-cpu-detect --enable-vp8 --enable-vp9 --enable-webm-io --enable-postproc --disable-debug --disable-examples --disable-install-bins --disable-docs --disable-unit-tests --disable-mmx
#fi
fi
make
make install
#make clean
cd $SRC_DIR
rm -r -f libvpx*
fi
}
function build_x264 {
if [[ "$CONFIGURE_FFMPEG_CODEC_FLAGS" =~ "--enable-libx264" ]]
then
cd $SRC_DIR
tar -xjvf $PKG_DIR/x264*.tar.*
cd x264-master*
# NOTE: x264 threads must be same regarding to ffmpeg
# i.e.
# when ffmpeg is compiled with --enable-w32threads [default on mingw]
# then x264 also needs to be compiled with --enable-win32thread
if [ "$ENVIRONMENT" == "mingw" ]
then
if [ "$BITDEPTH" == "10" ]
then
./configure $CONFIGURE_ALL_FLAGS --host=$(gcc -dumpmachine) --bit-depth=10 --enable-strip --disable-cli --disable-opencl --disable-avs --disable-ffms --enable-win32thread
else
./configure $CONFIGURE_ALL_FLAGS --host=$(gcc -dumpmachine) --enable-strip --disable-cli --disable-opencl --disable-avs --disable-ffms --enable-win32thread
fi
else
if [ "$BITDEPTH" == "10" ]
then
./configure $CONFIGURE_ALL_FLAGS --bit-depth=10 --enable-strip --disable-cli --disable-opencl --disable-avs --disable-ffms
else
./configure $CONFIGURE_ALL_FLAGS --enable-strip --disable-cli --disable-opencl --disable-avs --disable-ffms
fi
fi
make
make install
#make clean
cd $SRC_DIR
rm -r -f x264-master*
fi
}
function build_x265 {
if [[ "$CONFIGURE_FFMPEG_CODEC_FLAGS" =~ "--enable-libx265" ]]
then
cd $SRC_DIR
tar -xzvf $PKG_DIR/x265*.tar.*
cd x265*
if [ "$ENVIRONMENT" == "deb" ] || [ "$ENVIRONMENT" == "fedora" ] || [ "$ENVIRONMENT" == "opensuse" ]
then
cd build/linux
if [ "$BITDEPTH" == "10" ]
then
cmake -G "Unix Makefiles" -D "ENABLE_SHARED:BOOL=OFF" -D "ENABLE_CLI:BOOL=OFF" -D "HIGH_BIT_DEPTH:BOOL=ON" ../../source
else
cmake -G "Unix Makefiles" -D "ENABLE_SHARED:BOOL=OFF" -D "ENABLE_CLI:BOOL=OFF" -D "HIGH_BIT_DEPTH:BOOL=OFF" ../../source
fi
CONFIGURE_FFMPEG_LIBS="$CONFIGURE_FFMPEG_LIBS -lx265 -ldl -lstdc++ -lm -lrt"
elif [ "$ENVIRONMENT" == "mingw" ]
then
cd build/msys
# disable yasm, or build will fail (error in intrapred16.asm)
#mv -f /usr/local/bin/yasm.exe /usr/local/bin/_yasm.exe
# native script (32bit target/32bit msys or 64bit target/64bit msys)
if [ "$BITDEPTH" == "10" ]
then
cmake -G "Unix Makefiles" -D "ENABLE_SHARED:BOOL=OFF" -D "ENABLE_CLI:BOOL=OFF" -D "HIGH_BIT_DEPTH:BOOL=ON" -D "CMAKE_INSTALL_PREFIX:PATH=/usr/local" ../../source
else
cmake -G "Unix Makefiles" -D "ENABLE_SHARED:BOOL=OFF" -D "ENABLE_CLI:BOOL=OFF" -D "HIGH_BIT_DEPTH:BOOL=OFF" -D "CMAKE_INSTALL_PREFIX:PATH=/usr/local" ../../source
fi
# re-enable yasm
#mv -f /usr/local/bin/_yasm.exe /usr/local/bin/yasm.exe
# TODO: check why pkg-config x265 is not working for ffmpeg (reason why we need to add lib manually)
CONFIGURE_FFMPEG_LIBS="$CONFIGURE_FFMPEG_LIBS -lx265 -lstdc++"
fi
make
make install
#make clean
cd $SRC_DIR
rm -r -f x265*
fi
}
function build_openssl {
if [[ "$CONFIGURE_FFMPEG_CODEC_FLAGS" =~ "--enable-openssl" ]]
then
cd $SRC_DIR
tar -xvzf $PKG_DIR/openssl*.tar.*
cd openssl*
./config -static no-shared
make
make install
cd $SRC_DIR
rm -r -f openssl*
fi
}
function build_ffmpeg {
cd $SRC_DIR
tar -xjvf $PKG_DIR/ffmpeg*.tar.*
cd ffmpeg*
CONFIGURE_FFMPEG_LIBS="${CONFIGURE_FFMPEG_LIBS} -lpthread"
if [ "$ENVIRONMENT" == "deb" ] || [ "$ENVIRONMENT" == "fedora" ] || [ "$ENVIRONMENT" == "opensuse" ]
then
./configure $CONFIGURE_ALL_FLAGS $CONFIGURE_FFMPEG_CODEC_FLAGS $CONFIGURE_FFMPEG_FLAGS --extra-libs="$CONFIGURE_FFMPEG_LIBS" --extra-cflags="-static" --extra-ldflags="-static"
elif [ "$ENVIRONMENT" == "mingw" ]
then
./configure $CONFIGURE_ALL_FLAGS $CONFIGURE_FFMPEG_CODEC_FLAGS $CONFIGURE_FFMPEG_FLAGS --enable-w32threads --target-os=mingw32 --extra-libs="$CONFIGURE_FFMPEG_LIBS" --extra-cflags="-static" --extra-ldflags="-static"
else
echo "ERROR"
exit
fi
make
make install
#make clean
cd $SRC_DIR
rm -r -f ffmpeg*
}
function build_all {
build_zlib
build_bzip2
build_expat
build_xml2
build_freetype
build_fribidi
build_fontconfig
build_harfbuzz
# TODO: add harfbuzz shaper to libass (--enable-harfbuzz)
build_iconv
build_libpng
build_pcre
build_ass
build_fdkaac
build_lame
build_ogg
build_vorbis
build_theora
build_xvid
build_openssl
# BITDEPTH=10
# build_vpx
# build_x264
# build_x265
# build_ffmpeg
# if [ "$ENVIRONMENT" == "deb" ] || [ "$ENVIRONMENT" == "fedora" ] || [ "$ENVIRONMENT" == "opensuse" ]
# then
# mv -f /usr/local/bin/ffmpeg $BIN_DIR/ffmpeg-hi10-heaac
# elif [ "$ENVIRONMENT" == "mingw" ]
# then
# mv -f /usr/local/bin/ffmpeg.exe $BIN_DIR/ffmpeg-hi10-heaac.exe
# else
# echo "ERROR"
# fi
BITDEPTH=8
build_vpx
build_x264
build_x265
build_ffmpeg
if [ "$ENVIRONMENT" == "deb" ] || [ "$ENVIRONMENT" == "fedora" ] || [ "$ENVIRONMENT" == "opensuse" ]
then
mv -f /usr/local/bin/ffmpeg $BIN_DIR/ffmpeg
mv -f /usr/local/bin/ffprobe $BIN_DIR/ffprobe
mkdir $BIN_DIR/bin
cp $BIN_DIR/ffmpeg $BIN_DIR/bin
cp $BIN_DIR/ffprobe $BIN_DIR/bin
cd $BIN_DIR
zip -r $BIN_DIR/ffmpeg-layer.zip ./bin
cd -
rm -r -f $BIN_DIR/bin
elif [ "$ENVIRONMENT" == "mingw" ]
then
mv -f /usr/local/bin/ffmpeg.exe $BIN_DIR/ffmpeg.exe
mv -f /usr/local/bin/ffprobe.exe $BIN_DIR/ffprobe.exe
else
echo "ERROR"
fi
}
function build_pkg {
cd $CWD
if [ "$ENVIRONMENT" == "deb" ]
then
DEBPKG=$CWD/$PKGNAME\_$PKGVERSION\_$(get_lsb_release).deb
mkdir -p $DIST_DIR/DEBIAN
md5sum $(find $BIN_DIR -type f) | sed "s|$BIN_DIR|usr/bin|g" > $DIST_DIR/DEBIAN/md5sums
echo "Package: $PKGNAME" > $DIST_DIR/DEBIAN/control
echo "Version: $PKGVERSION" >> $DIST_DIR/DEBIAN/control
echo "Section: $PKGSECTION" >> $DIST_DIR/DEBIAN/control
echo "Architecture: $(dpkg --print-architecture)" >> $DIST_DIR/DEBIAN/control
echo "Installed-Size: $(du -k -c $BIN_DIR | grep 'total' | sed -e 's|\s*total||g')" >> $DIST_DIR/DEBIAN/control
echo "Depends: $PKGDEPENDS" >> $DIST_DIR/DEBIAN/control # TODO: resolve dependencies... (static build without any dependencies)
echo "Maintainer: $PKGAUTHOR" >> $DIST_DIR/DEBIAN/control
echo "Priority: optional" >> $DIST_DIR/DEBIAN/control
echo "Homepage: $PKGHOMEPAGE" >> $DIST_DIR/DEBIAN/control
echo "Description: $PKGDESCRIPTION" >> $DIST_DIR/DEBIAN/control
rm -f $DEBPKG
dpkg-deb -v -b $DIST_DIR $DEBPKG
rm -r -f $DIST_DIR/DEBIAN
lintian --profile debian $DEBPKG
elif [ "$ENVIRONMENT" == "fedora" ] || [ "$ENVIRONMENT" == "opensuse" ]
then
RPMPKG=$CWD/$PKGNAME\_$PKGVERSION\_$(get_lsb_release).rpm
mkdir -p $CWD/rpm/BUILDROOT 2> /dev/null
mkdir -p $CWD/rpm/SPECS 2> /dev/null
cp -r $DIST_DIR/* $CWD/rpm/BUILDROOT
echo "Name: $PKGNAME" > $CWD/rpm/SPECS/specfile.spec
echo "Version: $PKGVERSION" >> $CWD/rpm/SPECS/specfile.spec
echo "Release: 0" >> $CWD/rpm/SPECS/specfile.spec
echo "License: public domain" >> $CWD/rpm/SPECS/specfile.spec
echo "URL: $PKGHOMEPAGE" >> $CWD/rpm/SPECS/specfile.spec