-
Notifications
You must be signed in to change notification settings - Fork 510
/
Copy pathbuild_sdk.sh
executable file
·1608 lines (1394 loc) · 52.3 KB
/
build_sdk.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
##
# @file contrib/build_sdk.sh
# @brief Builds MEGA SDK static library and static examples
#
# (c) 2013-2014 by Mega Limited, Auckland, New Zealand
#
# This file is part of the MEGA SDK - Client Access Engine.
#
# Applications using the MEGA API must present a valid application key
# and comply with the the rules set forth in the Terms of Service.
#
# The MEGA SDK is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# @copyright Simplified (2-clause) BSD License.
#
# You should have received a copy of the license along with this
# program.
##
# Warn about /bin/sh ins't bash.
if [ -z "$BASH_VERSION" ] ; then
echo "WARNING: The shell running this script isn't bash."
fi
# global vars
verbose=1
use_local=0
use_dynamic=0
disable_freeimage=0
disable_ssl=0
disable_zlib=0
download_only=0
only_build_dependencies=0
enable_megaapi=0
make_opts=""
config_opts=""
no_examples=""
enable_drive_notifications=""
configure_only=0
disable_posix_threads=""
enable_sodium=0
enable_cares=0
enable_curl=0
enable_libuv=0
enable_libraw=0
android_build=0
readline_build=0
enable_cryptopp=0
disable_mediainfo=0
incremental=0
no_optimisation=0
extra_openssl_params=""
cross_compiling=0
configure_cross_options=""
openssl_cross_option=""
status_dir=""
persistent_path="/opt/persistent"
warning_as_error=0
build_gtest=0
build_tests=0
on_exit_error() {
echo "ERROR! Please check log files. Exiting.."
}
on_exit_ok() {
if [ $configure_only -eq 1 ]; then
echo "Successfully configured MEGA SDK!"
elif [ $download_only -eq 1 ]; then
echo "Successfully downloaded MEGA SDK dependencies!"
elif [ $only_build_dependencies -eq 1 ]; then
echo "Successfully built MEGA SDK dependencies!"
else
echo "Successfully compiled MEGA SDK!"
fi
}
print_distro_help()
{
# yum: CentOS, Fedora, RedHat
type yum >/dev/null 2>&1
local exit_code=$?
if [ $exit_code -eq 0 ]; then
echo "Please execute the following command: sudo yum install gcc gcc-c++ libtool unzip autoconf make wget glibc-devel-static"
return
fi
# apt-get: Debian, Ubuntu
type apt-get >/dev/null 2>&1
local exit_code=$?
if [ $exit_code -eq 0 ]; then
echo "Please execute the following command: sudo apt-get install gcc g++ libtool-bin unzip autoconf m4 make wget"
echo " (or 'libtool' on older Debian / Ubuntu distro versions)"
return
fi
}
check_apps()
{
if [ -z "${BASH}" ]
then
echo "Please run this script with the BASH shell"
exit 1
elif [ ${BASH_VERSINFO} -lt 3 ]
then
printf "BASH version 3 or greater is required"
exit 1
fi
APPS=(bash gcc c++ libtool tar unzip autoconf make autoreconf wget automake m4)
for app in ${APPS[@]}; do
type ${app} >/dev/null 2>&1 || { echo "${app} is not installed. Please install it first and re-run the script."; print_distro_help; exit 1; }
hash ${app} 2>/dev/null || { echo "${app} is not installed. Please install it first and re-run the script."; print_distro_help; exit 1; }
done
}
package_download() {
local name=$1
local url=$2
local file=$local_dir/$3
local md5sum=$4
if [ $use_local -eq 1 ]; then
echo "Using local file for $name"
return
fi
if [ -f $file ]; then
rm -f $file || true
fi
# use packages previously downloaded in /tmp/megasdkbuild folder
# if not present download from URL specified
# if wget fails, try curl
mkdir -p /tmp/megasdkbuild/
# cp /srv/dependencies_manually_downloaded/$3 $file 2>/dev/null || \
if [ -e /tmp/megasdkbuild/$3 ] ; then
echo "Using cached file /tmp/megasdkbuild/$3"
cp /tmp/megasdkbuild/$3 $file
else
echo "Downloading $name to get $3"
wget --secure-protocol=TLSv1_2 --no-check-certificate -c $url -O $file --progress=bar:force -t 2 -T 30 || \
curl -k $url > $file || exit 1
fi
echo "Checking MD5SUM for $file"
if ! echo $md5sum \*$file | md5sum -c - ; then
echo "Downloading $3 again"
#rm /tmp/megasdkbuild/$3
rm $file #this prevents unexpected "The file is already fully retrieved; nothing to do."
wget --no-check-certificate -c $url -O $file --progress=bar:force -t 2 -T 30 || \
curl -k $url > $file || exit 1
echo "Checking (again) MD5SUM for $file"
if ! echo $md5sum \*$file | md5sum -c - ; then
echo "Aborting execution due to incorrect MD5SUM for $file. Expected: $md5sum. Calculated:"
md5sum $file
exit 1
fi
fi
#copy to tmp download folder for next constructions
cp $file /tmp/megasdkbuild/$3
echo "Cached package file at /tmp/megasdkbuild/$3"
}
package_extract() {
local name=$1
local file=$local_dir/$2
local dir=$3
echo "Extracting $name"
local filename=$(basename "$file")
local extension="${filename##*.}"
if [ ! -f $file ]; then
echo "File $file does not exist!"
fi
if [ -d $dir ]; then
rm -fr $dir || exit 1
fi
if [ $extension == "gz" ]; then
tar -xzf $file &> $name.extract.log || exit 1
elif [ $extension == "zip" ]; then
unzip $file -d $dir &> $name.extract.log || exit 1
else
echo "Unsupported extension!"
exit 1
fi
}
exitwithlog() {
local logname=$1
local exitcode=$2
if [ $verbose -eq 1 ]; then
cat $logname
fi
exit $exitcode
}
package_configure() {
local name=$1
local dir=$2
local install_dir="$3"
local params="$4"
local extralibs="$5"
local conf_f0="./Configure" #OpenSSL has ./config which first guesses a cross-compiling then calls Configure. To support reliable cross-compiling, we can call Configure directly with $CC $CXX set appropriately already
local conf_f1="./config"
local conf_f2="./configure"
local conf=""
local autogen="./autogen.sh"
echo "Configuring $name"
local cwd=$(pwd)
cd $dir || exit 1
if [ -f $autogen ]; then
$autogen
fi
if [ $cross_compiling -eq 1 ] && [ -f $conf_f0 ]; then
conf="$conf_f0 $openssl_cross_option"
elif [ $cross_compiling -eq 0 ] && [ -f $conf_f1 ]; then # ./config is used to figure out which compiler; if we are cross compiling then skip that and use configure directly, $CC $CXX etc specify the tools
conf="$conf_f1"
elif [ -f $conf_f2 ]; then
conf="$conf_f2 $configure_cross_options"
else
local exit_code=$?
echo "Failed to configure $name, exit status: $exit_code"
exit 1
fi
echo -n "configuring $name with : $conf $config_opts --prefix=$install_dir $params"
[ -z "$extralibs" ] && echo "" || echo " LIBS=$extralibs"
if [ -z "$extralibs" ]; then
$conf $config_opts --prefix=$install_dir $params &> ../$name.conf.log || exitwithlog ../$name.conf.log 1
else
$conf $config_opts --prefix=$install_dir $params LIBS="$extralibs" &> ../$name.conf.log || exitwithlog ../$name.conf.log 1
fi
if [ $no_optimisation -eq 1 ]; then
# this one works for OpenSSL, other files may need to be adjusted differently
sed -i -e "s/\(C[XP]*FLAGS\? *=.*\)-O[1-3]/\1-O0/" ./Makefile
fi
cd $cwd
}
package_build() {
local name=$1
local dir=$2
if [ "$#" -eq 3 ]; then
local target=$3
else
local target=""
fi
echo "Building $name"
local cwd=$(pwd)
cd $dir
echo make $make_opts $target
make $make_opts $target &> ../$name.build.log
local exit_code=$?
if [ $exit_code -ne 0 ]; then
echo "Failed to build $name, exit status: $exit_code"
exitwithlog ../$name.build.log 1
fi
cd $cwd
}
package_install() {
local name=$1
local dir=$2
local install_dir=$3
local md5=$4
if [ "$#" -eq 5 ]; then
local target=$5
else
local target=""
fi
echo "Installing $name"
local cwd=$(pwd)
cd $dir
if [ $android_build -eq 1 ] && [[ $name == "Crypto++"* ]]; then
echo make install-lib $target
make install-lib $target &> ../$name.install.log || make install $target &> ../$name.install.log
else
echo make install $target
make install $target &> ../$name.install.log
fi
local exit_code=$?
if [ $exit_code -ne 0 ]; then
echo "Failed to install $name, exit status: $exit_code"
exitwithlog ../$name.install.log 1
cd $cwd
else
cd $cwd
echo $md5 > $status_dir/$name.success
fi
# some packages install libraries to "lib64" folder
local lib64=$install_dir/lib64
local lib=$install_dir/lib
if [ -d $lib64 ]; then
cp -f $lib64/* $lib/
fi
}
openssl_pkg() {
local build_dir=$1
local install_dir=$2
local name="OpenSSL"
local openssl_ver="1.1.1"
local openssl_rel="d"
local openssl_url="https://www.openssl.org/source/old/${openssl_ver}/openssl-$openssl_${openssl_ver}${openssl_rel}.tar.gz"
local openssl_md5="3be209000dbc7e1b95bcdf47980a3baa"
local openssl_file="openssl-${openssl_ver}${openssl_rel}.tar.gz"
local openssl_dir="openssl-${openssl_ver}${openssl_rel}"
if [ $use_dynamic -eq 1 ]; then
local openssl_params="--openssldir=$install_dir shared $extra_openssl_params"
else
local openssl_params="--openssldir=$install_dir no-shared $extra_openssl_params"
fi
local loc_make_opts=$make_opts
if [ $incremental -eq 1 ] && [ -e $status_dir/$name.success ] && [ `cat $status_dir/$name.success` = $openssl_md5 ]; then
echo "$name already built"
return
else
rm -f $status_dir/$name.success
fi
package_download $name $openssl_url $openssl_file $openssl_md5
if [ $download_only -eq 1 ]; then
return
fi
package_extract $name $openssl_file $openssl_dir
if [ $android_build -eq 1 ]; then
echo "Configuring $name"
local cwd=$(pwd)
cd $openssl_dir
perl -pi -e 's/install: all install_docs install_sw/install: install_docs install_sw/g' Makefile.org
./config shared no-ssl2 no-ssl3 no-comp no-hw no-engine --prefix=$install_dir
make depend || exit 1
cd $cwd
else
# handle MacOS
if [ "$(uname)" == "Darwin" ]; then
# OpenSSL compiles 32bit binaries, we need to explicitly tell to use x86_64 mode
if [ "$(uname -m)" == "x86_64" ]; then
echo "Configuring $name"
local cwd=$(pwd)
cd $openssl_dir
./Configure darwin64-x86_64-cc --prefix=$install_dir $openssl_params &> ../$name.conf.log || exit 1
cd $cwd
else
package_configure $name $openssl_dir $install_dir "$openssl_params"
fi
else
package_configure $name $openssl_dir $install_dir "$openssl_params" || exit 1
fi
fi
# OpenSSL has issues with parallel builds, let's use the default options
make_opts=""
package_build $name $openssl_dir
make_opts=$loc_make_opts
package_install $name $openssl_dir $install_dir $openssl_md5
}
cryptopp_pkg() {
local build_dir=$1
local install_dir=$2
local name="Crypto++"
local cryptopp_ver="820"
local cryptopp_url="http://www.cryptopp.com/cryptopp$cryptopp_ver.zip"
local cryptopp_md5="8a8bcb436af83e16d2227bd4ac642243"
local cryptopp_file="cryptopp$cryptopp_ver.zip"
local cryptopp_dir="cryptopp$cryptopp_ver"
if [ $incremental -eq 1 ] && [ -e $status_dir/$name.success ] && [ `cat $status_dir/$name.success` = $cryptopp_md5 ]; then
echo "$name already built"
return
else
rm -f $status_dir/$name.success
fi
package_download $name $cryptopp_url $cryptopp_file $cryptopp_md5
if [ $download_only -eq 1 ]; then
return
fi
package_extract $name $cryptopp_file $cryptopp_dir
#modify Makefile so that it does not use specific cpu architecture optimizations
sed "s#CXXFLAGS += -march=native#CXXFLAGS += #g" -i $cryptopp_dir/GNUmakefile
sed -i -e "160,165d" $cryptopp_dir/GNUmakefile
if [ $android_build -eq 1 ]; then
cp ${ANDROID_NDK_ROOT}/sources/android/cpufeatures/cpu-features.h $cryptopp_dir/
cp ${ANDROID_NDK_ROOT}/sources/android/cpufeatures/cpu-features.c $cryptopp_dir/
package_build $name $cryptopp_dir "static -f GNUmakefile-cross"
package_install $name $cryptopp_dir $install_dir $cryptopp_md5 "-f GNUmakefile-cross"
else
package_build $name $cryptopp_dir static
package_install $name $cryptopp_dir $install_dir $cryptopp_md5
fi
}
sodium_pkg() {
local build_dir=$1
local install_dir=$2
local name="Sodium"
local sodium_ver="1.0.18"
local sodium_url="https://github.com/jedisct1/libsodium/archive/$sodium_ver.tar.gz"
local sodium_md5="94a783f33ff8a97a09708bc61370d280"
local sodium_file="$sodium_ver.tar.gz"
local sodium_dir="libsodium-$sodium_ver"
if [ $use_dynamic -eq 1 ]; then
local sodium_params="--enable-shared"
else
local sodium_params="--disable-shared --enable-static --disable-pie"
fi
if [ $incremental -eq 1 ] && [ -e $status_dir/$name.success ] && [ `cat $status_dir/$name.success` = $sodium_md5 ]; then
echo "$name already built"
return
else
rm -f $status_dir/$name.success
fi
package_download $name $sodium_url $sodium_file $sodium_md5
if [ $download_only -eq 1 ]; then
return
fi
package_extract $name $sodium_file $sodium_dir
package_configure $name $sodium_dir $install_dir "$sodium_params"
package_build $name $sodium_dir
package_install $name $sodium_dir $install_dir $sodium_md5
}
libuv_pkg() {
local build_dir=$1
local install_dir=$2
local name="libuv"
local libuv_ver="1.34.2"
local libuv_url="https://github.com/libuv/libuv/archive/v${libuv_ver}.tar.gz"
local libuv_md5="5b57d93320a4aac3e66de94a1d4da98d"
local libuv_file="v${libuv_ver}.tar.gz"
local libuv_dir="libuv-$libuv_ver"
if [ $use_dynamic -eq 1 ]; then
local libuv_params="--enable-shared"
else
local libuv_params="--disable-shared --enable-static"
fi
if [ $incremental -eq 1 ] && [ -e $status_dir/$name.success ] && [ `cat $status_dir/$name.success` = $libuv_md5 ]; then
echo "$name already built"
return
else
rm -f $status_dir/$name.success
fi
package_download $name $libuv_url $libuv_file $libuv_md5
if [ $download_only -eq 1 ]; then
return
fi
package_extract $name $libuv_file $libuv_dir
local OLD_CFLAGS="$CFLAGS"
# linking with static library requires -fPIC
if [ $use_dynamic -eq 0 ]; then
export CFLAGS="$CFLAGS -fPIC"
fi
package_configure $name $libuv_dir $install_dir "$libuv_params"
export CFLAGS="$OLD_CFLAGS"
package_build $name $libuv_dir
package_install $name $libuv_dir $install_dir $libuv_md5
}
libraw_pkg() {
local build_dir=$1
local install_dir=$2
local name="libraw"
local libraw_ver="0.19.5"
local libraw_url="https://www.libraw.org/data/LibRaw-$libraw_ver.tar.gz"
local libraw_md5="865ab9a40910709ff86988e8c0a7d146"
local libraw_file="libraw-$libraw_ver.tar.gz"
local libraw_dir="LibRaw-$libraw_ver"
if [ $use_dynamic -eq 1 ]; then
local libraw_params="--enable-shared"
else
local libraw_params="--disable-shared --enable-static"
fi
if [ $incremental -eq 1 ] && [ -e $status_dir/$name.success ] && [ `cat $status_dir/$name.success` = $libraw_md5 ]; then
echo "$name already built"
return
else
rm -f $status_dir/$name.success
fi
package_download $name $libraw_url $libraw_file $libraw_md5
if [ $download_only -eq 1 ]; then
return
fi
package_extract $name $libraw_file $libraw_dir
local OLD_LIBS="$LIBS"
# linking with static library requires -lstdc++
if [ $use_dynamic -eq 0 ]; then
export LIBS="$LIBS -lstdc++"
fi
package_configure $name $libraw_dir $install_dir "$libraw_params"
export LIBS="$OLD_LIBS"
package_build $name $libraw_dir
package_install $name $libraw_dir $install_dir $libraw_md5
}
zlib_pkg() {
local build_dir=$1
local install_dir=$2
local name="Zlib"
local zlib_ver="1.2.13"
local zlib_url="https://zlib.net/fossils/zlib-$zlib_ver.tar.gz"
local zlib_md5="9b8aa094c4e5765dabf4da391f00d15c"
local zlib_file="zlib-$zlib_ver.tar.gz"
local zlib_dir="zlib-$zlib_ver"
local loc_conf_opts=$config_opts
local loc_configure_cross_options=$configure_cross_options
if [ $use_dynamic -eq 1 ]; then
local zlib_params=""
else
local zlib_params="--static"
fi
if [ $incremental -eq 1 ] && [ -e $status_dir/$name.success ] && [ `cat $status_dir/$name.success` = $zlib_md5 ]; then
echo "$name already built"
return
else
rm -f $status_dir/$name.success
fi
package_download $name $zlib_url $zlib_file $zlib_md5
if [ $download_only -eq 1 ]; then
return
fi
package_extract $name $zlib_file $zlib_dir
# doesn't recognize --host=xxx
config_opts=""
configure_cross_options=""
# Windows must use Makefile.gcc
if [ "$(expr substr $(uname -s) 1 10)" != "MINGW32_NT" ]; then
package_configure $name $zlib_dir $install_dir "$zlib_params"
package_build $name $zlib_dir
package_install $name $zlib_dir $install_dir $zlib_md5
else
export BINARY_PATH=$install_dir/bin
export INCLUDE_PATH=$install_dir/include
export LIBRARY_PATH=$install_dir/lib
package_build $name $zlib_dir "-f win32/Makefile.gcc"
package_install $name $zlib_dir $install_dir $zlib_md5 "-f win32/Makefile.gcc"
unset BINARY_PATH
unset INCLUDE_PATH
unset LIBRARY_PATH
fi
config_opts=$loc_conf_opts
configure_cross_options=$loc_configure_cross_options
}
sqlite_pkg() {
local build_dir=$1
local install_dir=$2
local name="SQLite"
local sqlite_ver="3300100"
local sqlite_url="http://www.sqlite.org/2019/sqlite-autoconf-$sqlite_ver.tar.gz"
local sqlite_md5="51252dc6bc9094ba11ab151ba650ff3c"
local sqlite_file="sqlite-$sqlite_ver.tar.gz"
local sqlite_dir="sqlite-autoconf-$sqlite_ver"
if [ $use_dynamic -eq 1 ]; then
local sqlite_params="--enable-shared"
else
local sqlite_params="--disable-shared --enable-static"
fi
if [ $incremental -eq 1 ] && [ -e $status_dir/$name.success ] && [ `cat $status_dir/$name.success` = $sqlite_md5 ]; then
echo "$name already built"
return
else
rm -f $status_dir/$name.success
fi
package_download $name $sqlite_url $sqlite_file $sqlite_md5
if [ $download_only -eq 1 ]; then
return
fi
package_extract $name $sqlite_file $sqlite_dir
package_configure $name $sqlite_dir $install_dir "$sqlite_params"
package_build $name $sqlite_dir
package_install $name $sqlite_dir $install_dir $sqlite_md5
}
cares_pkg() {
local build_dir=$1
local install_dir=$2
local name="c-ares"
local cares_ver="1.14.0"
local cares_url="http://c-ares.haxx.se/download/c-ares-$cares_ver.tar.gz"
local cares_md5="e57b37a7c46283e83c21cde234df10c7"
local cares_file="cares-$cares_ver.tar.gz"
local cares_dir="c-ares-$cares_ver"
if [ $use_dynamic -eq 1 ]; then
local cares_params="--enable-shared"
else
local cares_params="--disable-shared --enable-static"
fi
if [ $incremental -eq 1 ] && [ -e $status_dir/$name.success ] && [ `cat $status_dir/$name.success` = $cares_md5 ]; then
echo "$name already built"
return
else
rm -f $status_dir/$name.success
fi
package_download $name $cares_url $cares_file $cares_md5
if [ $download_only -eq 1 ]; then
return
fi
package_extract $name $cares_file $cares_dir
package_configure $name $cares_dir $install_dir "$cares_params"
package_build $name $cares_dir
package_install $name $cares_dir $install_dir $cares_md5
}
curl_pkg() {
local build_dir=$1
local install_dir=$2
local name="cURL"
local curl_ver="7.68.0"
local curl_url="http://curl.haxx.se/download/curl-$curl_ver.tar.gz"
local curl_md5="f68d6f716ff06d357f476ea4ea57a3d6"
local curl_file="curl-$curl_ver.tar.gz"
local curl_dir="curl-$curl_ver"
local openssl_flags=""
# use local or system OpenSSL
if [ $disable_ssl -eq 0 ]; then
openssl_flags="--with-ssl=$install_dir"
else
openssl_flags="--with-ssl"
fi
if [ $use_dynamic -eq 1 ]; then
local curl_params="--disable-ftp --disable-file --disable-ldap --disable-ldaps --disable-rtsp --disable-dict \
--disable-telnet --disable-tftp --disable-pop3 --disable-imap --disable-smtp --disable-gopher --disable-sspi \
--without-librtmp --without-libidn --without-libidn2 --without-libssh2 --enable-ipv6 --disable-manual --without-nghttp2 --without-libpsl \
--without-brotli --with-zlib=$install_dir --enable-ares=$install_dir $openssl_flags"
else
local curl_params="--disable-ftp --disable-file --disable-ldap --disable-ldaps --disable-rtsp --disable-dict \
--disable-telnet --disable-tftp --disable-pop3 --disable-imap --disable-smtp --disable-gopher --disable-sspi \
--without-librtmp --without-libidn --without-libidn2 --without-libssh2 --enable-ipv6 --disable-manual --without-nghttp2 --without-libpsl \
--without-brotli --disable-shared --with-zlib=$install_dir --enable-ares=$install_dir $openssl_flags"
fi
if [ $incremental -eq 1 ] && [ -e $status_dir/$name.success ] && [ `cat $status_dir/$name.success` = $curl_md5 ]; then
echo "$name already built"
return
else
rm -f $status_dir/$name.success
fi
package_download $name $curl_url $curl_file $curl_md5
if [ $download_only -eq 1 ]; then
return
fi
package_extract $name $curl_file $curl_dir
package_configure $name $curl_dir $install_dir "$curl_params" "-ldl"
package_build $name $curl_dir
package_install $name $curl_dir $install_dir $curl_md5
}
readline_pkg() {
local build_dir=$1
local install_dir=$2
local name="Readline"
local readline_ver="7.0"
local readline_url="https://ftp.gnu.org/gnu/readline/readline-$readline_ver.tar.gz"
local readline_md5="205b03a87fc83dab653b628c59b9fc91"
local readline_file="readline-$readline_ver.tar.gz"
local readline_dir="readline-$readline_ver"
if [ $use_dynamic -eq 1 ]; then
local readline_params="--enable-shared"
else
local readline_params="--disable-shared --enable-static"
fi
if [ $incremental -eq 1 ] && [ -e $status_dir/$name.success ] && [ `cat $status_dir/$name.success` = $readline_md5 ]; then
echo "$name already built"
return
else
rm -f $status_dir/$name.success
fi
package_download $name $readline_url $readline_file $readline_md5
if [ $download_only -eq 1 ]; then
return
fi
package_extract $name $readline_file $readline_dir
package_configure $name $readline_dir $install_dir "$readline_params"
package_build $name $readline_dir
package_install $name $readline_dir $install_dir $readline_md5
}
termcap_pkg() {
local build_dir=$1
local install_dir=$2
local name="Termcap"
local termcap_ver="1.3.1"
local termcap_url="http://ftp.gnu.org/gnu/termcap/termcap-$termcap_ver.tar.gz"
local termcap_md5="ffe6f86e63a3a29fa53ac645faaabdfa"
local termcap_file="termcap-$termcap_ver.tar.gz"
local termcap_dir="termcap-$termcap_ver"
if [ $use_dynamic -eq 1 ]; then
local termcap_params="--enable-shared"
else
local termcap_params="--disable-shared --enable-static"
fi
if [ $incremental -eq 1 ] && [ -e $status_dir/$name.success ] && [ `cat $status_dir/$name.success` = $termcap_md5 ]; then
echo "$name already built"
return
else
rm -f $status_dir/$name.success
fi
package_download $name $termcap_url $termcap_file $termcap_md5
if [ $download_only -eq 1 ]; then
return
fi
package_extract $name $termcap_file $termcap_dir
local OLD_CPPFLAGS="$CPPFLAGS"
# linking with static library requires -fPIC
if [ $use_dynamic -eq 0 ]; then
export CPPFLAGS="$CPPFLAGS -fPIC"
fi
package_configure $name $termcap_dir $install_dir "$termcap_params"
package_build $name $termcap_dir
export CPPFLAGS="$OLD_CPPFLAGS"
package_install $name $termcap_dir $install_dir $termcap_md5
}
freeimage_pkg() {
local build_dir=$1
local install_dir=$2
local cwd=$3
local name="FreeImage"
local freeimage_ver="3180"
local freeimage_url="http://downloads.sourceforge.net/freeimage/FreeImage$freeimage_ver.zip"
local freeimage_md5="f8ba138a3be233a3eed9c456e42e2578"
local freeimage_file="freeimage-$freeimage_ver.zip"
local freeimage_dir_extract="freeimage-$freeimage_ver"
local freeimage_dir="freeimage-$freeimage_ver/FreeImage"
if [ $incremental -eq 1 ] && [ -e $status_dir/$name.success ] && [ `cat $status_dir/$name.success` = $freeimage_md5 ]; then
echo "$name already built"
return
else
rm -f $status_dir/$name.success
fi
package_download $name $freeimage_url $freeimage_file $freeimage_md5
if [ $download_only -eq 1 ]; then
return
fi
package_extract $name $freeimage_file $freeimage_dir_extract
#Fix issue with powf64 redefined in mathcalls.h in glibc 2.27
find $freeimage_dir_extract/FreeImage/ -type f -print0 | xargs -0 sed -i "s#powf64#powf64freeimage#g"
#patch to fix problem with raw strings
find $freeimage_dir_extract/FreeImage/Source/LibWebP -type f -exec sed -i -e 's/"#\([A-X]\)"/" #\1 "/g' {} \;
sed -i "s#CFLAGS ?=#CFLAGS +=#g" $freeimage_dir_extract/FreeImage/Makefile.gnu
#patch to fix problem with newest compilers
sed -i "s#CXXFLAGS ?=#CXXFLAGS += -std=c++98#g" $freeimage_dir_extract/FreeImage/Makefile.gnu
#freeimage uses some macros with a dollarsign in the name, and also has some constants that don't fit in a long
#as gcc building for 32 bit linux has long as 32 bit. Also some files have the utf-8 BOM which old gcc doesn't like
export CFLAGS="$CFLAGS -fdollars-in-identifiers"
export CXXFLAGS="$CXXFLAGS -fdollars-in-identifiers"
find $freeimage_dir/Source/OpenEXR/IlmImf/ -name "*.cpp" | xargs sed -i -e "s/0xffffffffffffffffL/0xffffffffffffffffull/"
if command -v dos2unix; then
find $freeimage_dir/Source/LibRawLite/internal/ -name "*.cpp" | xargs dos2unix
find $freeimage_dir/Source/LibRawLite/internal/ -name "*.h" | xargs dos2unix
else
echo "Command dos2unix not found, skipping some fixes for FreeImage"
fi
# replace Makefile on MacOS
if [ "$(uname)" == "Darwin" ]; then
cp $cwd/contrib/FreeImage.Makefile.osx $freeimage_dir/Makefile.osx
fi
if [ $android_build -eq 1 ]; then
sed -i '/#define HAVE_SEARCH_H 1/d' $freeimage_dir/Source/LibTIFF4/tif_config.h
fi
if [ $use_dynamic -eq 0 ]; then
export FREEIMAGE_LIBRARY_TYPE=STATIC
fi
# freeimage's LibPNG has a problem with deciding to use neon on 64 bit arm, resulting in a missing symbol
if [ "$ARCH" == "aarch64" -o "$ARCH" == "arm64" ]; then
export CFLAGS="$CFLAGS -DPNG_ARM_NEON_OPT=0"
fi
if [ "$(expr substr $(uname -s) 1 10)" != "MINGW32_NT" ]; then
package_build $name $freeimage_dir
# manually copy header and library
cp $freeimage_dir/Dist/FreeImage.h $install_dir/include || exit 1
cp $freeimage_dir/Dist/libfreeimage* $install_dir/lib || exit 1
echo $freeimage_md5 > $status_dir/$name.success
# MinGW
else
package_build $name $freeimage_dir "-f Makefile.mingw"
# manually copy header and library
cp $freeimage_dir/Dist/FreeImage.h $install_dir/include || exit 1
# ignore if not present
cp $freeimage_dir/Dist/FreeImage.dll $install_dir/lib || 1
cp $freeimage_dir/Dist/FreeImage.lib $install_dir/lib || 1
cp $freeimage_dir/Dist/libFreeImage.a $install_dir/lib || 1
echo $freeimage_md5 > $status_dir/$name.success
fi
}
mediainfo_pkg() {
local build_dir=$1
local install_dir=$2
local cwd=$3
local zenlib_name="ZenLib"
local zenlib_ver="6694a744d82d942c4a410f25f916561270381889"
local zenlib_url="https://github.com/MediaArea/ZenLib/archive/${zenlib_ver}.tar.gz"
local zenlib_md5="02a78d1d18ce163483d8e01961f983f4"
local zenlib_file="$zenlib_ver.tar.gz"
local zenlib_dir_extract="ZenLib-$zenlib_ver"
local zenlib_dir="ZenLib-$zenlib_ver/Project/GNU/Library"
local mediainfolib_name="MediaInfoLib"
local mediainfolib_ver="4ee7f77c087b29055f48d539cd679de8de6f9c48"
local mediainfolib_url="https://github.com/meganz/MediaInfoLib/archive/${mediainfolib_ver}.tar.gz"
local mediainfolib_md5="5214341153298077b9e711c181742fe3"
local mediainfolib_file="$mediainfolib_ver.tar.gz"
local mediainfolib_dir_extract="MediaInfoLib-$mediainfolib_ver"
local mediainfolib_dir="MediaInfoLib-$mediainfolib_ver/Project/GNU/Library"
if [ $incremental -eq 1 ] && [ -e $status_dir/$mediainfolib_name.success ] && [ `cat $status_dir/$mediainfolib_name.success` = $mediainfolib_md5 ]; then
echo "$mediainfolib_name already built"
return
else
rm -f $status_dir/$mediainfolib_name.success
fi
package_download $zenlib_name $zenlib_url $zenlib_file $zenlib_md5
package_download $mediainfolib_name $mediainfolib_url $mediainfolib_file $mediainfolib_md5
if [ $download_only -eq 1 ]; then
return
fi
package_extract $zenlib_name $zenlib_file $zenlib_dir_extract
ln -sfr $zenlib_dir_extract $build_dir/ZenLib || ln -sf $zenlib_dir_extract $build_dir/ZenLib
package_extract $mediainfolib_name $mediainfolib_file $mediainfolib_dir_extract
local zenlib_params="--enable-static --disable-shared"
local mediainfolib_params="--disable-shared --enable-minimize-size --enable-minimal --disable-archive \
--disable-image --disable-tag --disable-text --disable-swf --disable-flv --disable-hdsf4m --disable-cdxa \
--disable-dpg --disable-pmp --disable-rm --disable-wtv --disable-mxf --disable-dcp --disable-aaf --disable-bdav \
--disable-bdmv --disable-dvdv --disable-gxf --disable-mixml --disable-skm --disable-nut --disable-tsp \
--disable-hls --disable-dxw --disable-dvdif --disable-dashmpd --disable-aic --disable-avsv --disable-canopus \
--disable-ffv1 --disable-flic --disable-huffyuv --disable-prores --disable-y4m --disable-adpcm --disable-amr \
--disable-amv --disable-ape --disable-au --disable-la --disable-celt --disable-midi --disable-mpc --disable-openmg \
--disable-pcm --disable-ps2a --disable-rkau --disable-speex --disable-tak --disable-tta --disable-twinvq \
--disable-references --enable-staticlibs"
if [ $disable_zlib -eq 0 ]; then
mediainfolib_params="$mediainfolib_params --with-libz-static"
mkdir -p $build_dir/Shared/Source/zlib
#~ ln -sfr $(find $install_dir -name zlib.a) $build_dir/Shared/Source/zlib/libz.a
ln -sfr $install_dir/lib/libz.a $build_dir/Shared/Source/zlib/libz.a || ln -sf $install_dir/lib/libz.a $build_dir/Shared/Source/zlib/libz.a
ln -sfr $install_dir/include/zlib.h $build_dir/Shared/Source/zlib/zlib.h || ln -sf $install_dir/include/zlib.h $build_dir/Shared/Source/zlib/zlib.h
ln -sfr $install_dir/include/zconf.h $build_dir/Shared/Source/zlib/zconf.h || ln -sf $install_dir/include/zconf.h $build_dir/Shared/Source/zlib/zconf.h
fi
package_configure $zenlib_name $zenlib_dir $install_dir "$zenlib_params" #TODO: tal vez install dir ha de ser ./ZenLib!!! casi 100% seguro
#~ package_configure $zenlib_name $zenlib_dir "$build_dir/ZenLib" "$zenlib_params" #TODO: tal vez install dir ha de ser ./ZenLib!!! casi 100% seguro
package_build $zenlib_name $zenlib_dir
#package_install $zenlib_name $zenlib_dir $install_dir
package_install $zenlib_name $zenlib_dir "$build_dir/ZenLib" $zenlib_md5
package_configure $mediainfolib_name $mediainfolib_dir $install_dir "$mediainfolib_params" #TODO: tal vez install dir ha de ser ./ZenLib!!! casi 100% seguro
CR=$(printf '\r')
cat << EOF > $build_dir/mediainfopatch
--- MediaInfo_Config.cpp
+++ MediaInfo_Config_new.cpp
@@ -1083,7 +1083,7 @@
}$CR
if (Option_Lower==__T("maxml_fields"))$CR
{$CR
- #if MEDIAINFO_ADVANCED$CR
+ #if MEDIAINFO_ADVANCED && defined(MEDIAINFO_XML_YES)$CR
return MAXML_Fields_Get(Value);$CR
#else // MEDIAINFO_ADVANCED$CR
return __T("advanced features are disabled due to compilation options");$CR
@@ -2652,6 +2652,7 @@
#endif // MEDIAINFO_ADVANCED$CR
$CR
#if MEDIAINFO_ADVANCED$CR
+#ifdef MEDIAINFO_XML_YES$CR
extern Ztring Xml_Name_Escape_0_7_78 (const Ztring &Name);$CR
Ztring MediaInfo_Config::MAXML_Fields_Get (const Ztring &StreamKind_String)$CR
{$CR
@@ -2691,6 +2692,7 @@
List.Separator_Set(0, __T(","));$CR
return List.Read();$CR
}$CR
+#endif$CR
#endif // MEDIAINFO_ADVANCED$CR
$CR
//***************************************************************************$CR
EOF
(cd $mediainfolib_dir/../../../Source/MediaInfo; patch MediaInfo_Config.cpp < $build_dir/mediainfopatch)
package_build $mediainfolib_name $mediainfolib_dir
pushd $build_dir/ZenLib >/dev/null
package_install $mediainfolib_name $build_dir/$mediainfolib_dir $install_dir $mediainfolib_md5
popd
}
# we can't build vanilla ReadLine under MinGW
readline_win_pkg() {
local build_dir=$1
local install_dir=$2
local name="Readline"
local readline_ver="5.0.1"
local readline_url="http://downloads.sourceforge.net/project/gnuwin32/readline/5.0-1/readline-5.0-1-bin.zip?r=&ts=1468492036&use_mirror=freefr"
local readline_md5="91beae8726edd7ad529f67d82153e61a"
local readline_file="readline-bin.zip"
local readline_dir="readline-bin"