This repository has been archived by the owner on Dec 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 59
/
vialerbuild
executable file
·801 lines (650 loc) · 24 KB
/
vialerbuild
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
#!/bin/bash
set -e
AVIALABLE_ARCHS=(
"armv7"
"armv7s"
"arm64"
"i386"
"x86_64"
)
export BASE_DIR=`pwd -P`
export MIN_IOS_VERSION="10.0"
export IOS_SDK_VERSION="13.2"
export AVIALABLE_ARCHS
export USE_ARCHS=()
export DOWNLOAD_PJSIP_SRC=true
export CLEAN_PJSIP_SRC=true
export SSL_SUPPORT=false
export OPUS_SUPPORT=false
export H264_SUPPORT=false
export INDEPENDENT_WEBRTC=false
export ENABLE_ZRTP=false
export HAS_BITCODE=true
export HAS_IPV6=false
export SHOW_HELP=false
export PJSIP_VERSION="2.10"
export PJSIP_BASE_URL="http://svn.pjsip.org/repos/pjproject"
export PJSIP_DIR="$BASE_DIR/pjsip"
export PJSIP_FINAL_LIB_DIR="$BASE_DIR/lib"
export PJSIP_SRC_DIR="$BASE_DIR/pjsip/src"
export PJSIP_LOGS_DIR="$BASE_DIR/pjsip/logs"
export PJSIP_TMP_DIR="$BASE_DIR/pjsip/temp"
export PJSIP_CONFIG_SITE_H="$PJSIP_DIR/config_site.h"
export PJSIP_LIB_PATHS=(
"pjlib/lib"
"pjlib-util/lib"
"pjmedia/lib"
"pjnath/lib"
"pjsip/lib"
"third_party/lib"
)
export PJSIP_LIB_OUTPUT="$BASE_DIR/lib"
export BUILD_DIR="$PJSIP_DIR/external"
export SSL_BUILD_DIR="$BUILD_DIR/ssl"
export ZRTP_BUILD_DIR="$BUILD_DIR/zrtp"
export OPUS_BUILD_DIR="$BUILD_DIR/opus"
export H264_BUILD_DIR="$BUILD_DIR/h264"
export XCODE_SIMULATOR_DEV_PATH="`xcrun -sdk iphonesimulator --show-sdk-platform-path`/Developer"
set -e
for i in "$@"; do
case $i in
-a=* | --arch=*)
ARCHS="${i#*=}"
while IFS=',' read -ra ARCH; do
for i in "${ARCH[@]}"; do
if [[ " ${AVIALABLE_ARCHS[@]} " =~ " ${i} " ]]; then
USE_ARCHS+=("$i")
fi
done
done <<< $ARCHS
shift
;;
--no-download-pjsip-src)
DOWNLOAD_PJSIP_SRC=false
shift
;;
--no-clean-pjsip-src)
CLEAN_PJSIP_SRC=false
shift
;;
--pjsip-version=*)
PJSIP_VERSION="${i#=}"
shift
;;
--extra-config-site-options=*)
CONFIG_SITE_OPTIONS="${i#*=}"
shift
;;
-ssl | --ssl | ssl)
SSL_SUPPORT=true
shift
;;
-opus | --opus | opus)
OPUS_SUPPORT=true
shift
;;
-h264 | --h264 | h264)
H264_SUPPORT=true
shift
;;
--independent-webrtc)
INDEPENDENT_WEBRTC=true
shift
;;
--no-bitcode)
HAS_BITCODE=false
shift
;;
--enable-zrtp)
ENABLE_ZRTP=true
shift
;;
--enable-ipv6)
HAS_IPV6=true
shift
;;
-h | --help | help)
SHOW_HELP=true
shift
;;
-v | --version | version)
echo "Vialer PJSIP Compile script version: 2.0.0"
exit 1
shift
;;
*)
;;
esac
done
function show_help () {
echo "Usage: $0 [option...]" >&2
echo "Default the script will compile for all architectures. But without ssl, opus and video support."
echo
echo " -a, --arch Compile for specific architecture. Input the architectures comma separated."
echo " If empty all architectures will be build (armv7,armv7s,arm64,i386,x86_64)"
echo
echo " -h264, --h264, h264 Wheter to include h264/video support in PJSIP. (default: not build)"
echo
echo " -ssl, --ssl, ssl Include SSL for encrypted calling. (default: not build)"
echo
echo " -opus, --opus, opus Support for the OPUS codec. (default: not build)"
echo
echo " --no-download-pjsip-src Don't download a new PJSIP source"
echo
echo " --no-clean-pjsip-src Don't clean the PJSIP source"
echo
echo " --pjsip-version Download specific PJSIP version tag. Default the newest tag is downloaded."
echo
echo " --independent-webrtc Using pjsip with WebRTC independent, otherwise WebRTC may render remote video abnormal."
echo
echo " --enable-zrtp Enable ZRTP with SSL."
echo
echo " --no-bitcode Building pjsip and dependencies without bitcode"
echo
echo " --enable-ipv6 Building pjsip with IP v6 support"
echo
echo " --extra-config-site-options Extra custom options to put in the config_site.h. "
echo " Also if SSL or H264 are given as options they will be defined in the config_site.h."
echo " Default 'PJ_CONFIG_IPHONE 1' is defined. and 'pj/config_site_sample.h' will be included."
echo
echo " -h, --help, help Show this help"
echo
echo " -v, --version, version Version info"
echo
echo " Example usage: ./vialerbuild --ssl --opus --h264 --arch=armv7,i386,arm64"
echo " This will compile the newest pjsip version for the three architectures armv7,i386,arm64. With SSL encryption, H264 and the Opus codec."
exit 1
}
function spinner() {
local pid=$1
local delay=0.5
local spinstr='|/-\'
echo "$pid" > "/tmp/.spinner.pid"
while [ "$(ps a | awk '{print $1}' | grep $pid)" ]; do
local temp=${spinstr#?}
printf " [%c] " "$spinstr"
local spinstr=$temp${spinstr%"$temp"}
# sleep $delay
printf "\b\b\b\b\b\b"
done
printf " \b\b\b\b"
}
function build_h264 () {
if [ $H264_SUPPORT = false ]; then
return
fi
echo "Use H264"
rm -rf $H264_BUILD_DIR
h264_version="2.0.0";
h264_url="https://github.com/cisco/openh264/archive/v${h264_version}.tar.gz"
h264_target_path="$H264_BUILD_DIR/src"
mkdir -p $h264_target_path
cd $h264_target_path
echo "Downloading h264-${h264_version}.tar.gz"
curl -LO $h264_url
echo "Using h264-${h264_version}.tar.gz"
tar zxf "v${h264_version}.tar.gz" --strip 1
h264_headers_dir="${h264_target_path}/include/wels"
if [ -d "${h264_headers_dir}" ]; then
rm -rf "${h264_headers_dir}"
fi
mkdir -p "${h264_headers_dir}"
h264_lipo_args=""
for arch in "${USE_ARCHS[@]}"; do
h264_makefile="Makefile"
h264_makefile_bak="Makefile.bak"
h264_prefix="${H264_BUILD_DIR}/build/${arch}"
h264_log="${h264_prefix}/build.log"
mkdir -p "${h264_prefix}/logs"
pushd . > /dev/null
cd $h264_target_path
if [ -d "${h264_prefix}" ]; then
rm -rf ${h264_prefix}
fi
mkdir -p ${h264_prefix}
echo "Building h264 for ${arch}"
cp "${h264_makefile}" "${h264_makefile_bak}"
h264_sed_src="^PREFIX=.*"
h264_sed_dst="PREFIX=${h264_prefix}"
h264_sed_dst="${h264_sed_dst//\//\\/}"
sed -i.deleteme "s/${h264_sed_src}/${h264_sed_dst}/" "${h264_makefile}"
rm ${h264_makefile}.deleteme
echo "--- Run make file for ${arch}"
make OS=ios ARCH=${arch} SDK_MIN=${MIN_IOS_VERSION} v=No >> "${h264_log}" || exit
make OS=ios ARCH=${arch} SDK_MIN=${MIN_IOS_VERSION} v=No install >> "${h264_log}" || exit
make OS=ios ARCH=${arch} SDK_MIN=${MIN_IOS_VERSION} v=No clean >> "${h264_log}" || exit
mv "${h264_makefile_bak}" "${h264_makefile}"
popd > /dev/null
h264_lipo_args="${h264_lipo_args} -arch ${arch} ${H264_BUILD_DIR}/build/${arch}/lib/libopenh264.a"
done
if [ ! -d "${H264_BUILD_DIR}/lib" ]; then
mkdir -p "${H264_BUILD_DIR}/lib"
fi
echo "--- Lipo openH264"
xcrun -sdk iphoneos lipo ${h264_lipo_args} -create -output "${H264_BUILD_DIR}/lib/libopenh264.a" || exit
echo "--- Copying header files"
cp -R "${H264_BUILD_DIR}/build/${USE_ARCHS[0]}/include/" "${H264_BUILD_DIR}/include"
echo "Done compiling openh264"
}
function build_ssl () {
if [ $SSL_SUPPORT = false ]; then
return
fi
echo "Use ssl"
rm -rf $SSL_BUILD_DIR
mkdir -p $SSL_BUILD_DIR
pushd . > /dev/null
cd $SSL_BUILD_DIR
# Download OpenSSL repo.
ssl_url="https://github.com/x2on/OpenSSL-for-iPhone/archive/master.tar.gz"
curl -LO $ssl_url
tar zxf "master.tar.gz" --strip 1
rm "master.tar.gz"
./build-libssl.sh --version=1.1.1d --archs="${USE_ARCHS[*]// /\s}" || exit
mv include include2
mkdir -p include
mv include2/openssl include/openssl
popd > /dev/null
echo "Using SSL..."
if [ $ENABLE_ZRTP = true ]; then
build_zrtp
fi
}
function build_zrtp () {
echo "Use ZRTP"
rm -rf $ZRTP_BUILD_DIR
rm -rf $PJSIP_SRC_DIR/third_party/ZRTP4PJ
mkdir -p $ZRTP_BUILD_DIR
pushd . > /dev/null
cd $ZRTP_BUILD_DIR
git clone https://github.com/wernerd/ZRTP4PJ
cd ZRTP4PJ/zsrtp
sh getzrtp.sh || exit
cd $ZRTP_BUILD_DIR
mv ZRTP4PJ $PJSIP_SRC_DIR/third_party
cd $PJSIP_SRC_DIR/third_party/ZRTP4PJ/build/zsrtp
sed -i '' -e 's#'~/devhome/pjproject.git'#'"$PJSIP_SRC_DIR"'#' Makefile
cd ../../zsrtp
sed -i '' -e 's/#define THIS_FILE "transport_zrtp.c"/#define THIS_FILE "transport_zrtp.c"\
#define DYNAMIC_TIMER 1/' transport_zrtp.c
}
function build_opus () {
if [ $OPUS_SUPPORT = false ]; then
return
fi
rm -rf $OPUS_BUILD_DIR
opus_version="1.3.1"
opus_opt_cflags="-Ofast -flto -g"
opus_opt_ldflags="-flto"
opus_opt_config_args=""
xcode_dev_path=`xcode-select -print-path`
opus_repo_dir=$OPUS_BUILD_DIR
opus_output_dir="${opus_repo_dir}/dependencies"
opus_build_build_dir="${opus_repo_dir}/build"
opus_src_dir="${opus_build_build_dir}/src"
opus_inter_dir="${opus_build_build_dir}/built"
mkdir -p "${opus_output_dir}/include"
mkdir -p "${opus_output_dir}/lib"
mkdir -p $opus_src_dir
mkdir -p $opus_inter_dir
cd $opus_src_dir
echo "Downloading opus-${opus_version}.tar.gz"
curl -LO http://downloads.xiph.org/releases/opus/opus-${opus_version}.tar.gz
echo "Using opus-${opus_version}.tar.gz"
tar zxf opus-${opus_version}.tar.gz
cd "${opus_src_dir}/opus-${opus_version}"
ccache=""
for arch in ${USE_ARCHS[@]}
do
echo "-- Opus: Compiling $arch"
opus_extra_cflags="-arch $arch"
if [ "$arch" == "i386" ] || [ "$arch" == "x86_64" ]; then
os_platform="iPhoneSimulator"
opus_extra_flags="--with-pic"
opus_extra_config="--host=$arch-apple-darwin"
else
os_platform="iPhoneOS"
opus_extra_config="--host=arm-apple-darwin"
fi
mkdir -p "${opus_inter_dir}/${os_platform}${IOS_SDK_VERSION}-${arch}.sdk"
./configure \
--enable-float-approx --disable-shared --enable-static \
--with-pic --disable-extra-programs --disable-doc ${opus_extra_config} \
--prefix="${opus_inter_dir}/${os_platform}${IOS_SDK_VERSION}-${arch}.sdk" \
${opus_extra_config} \
LDFLAGS="$LDFLAGS ${opus_opt_ldflags} -fPIE -miphoneos-version-min=${MIN_IOS_VERSION} -L${opus_output_dir}/lib" \
CFLAGS="$CFLAGS ${opus_extra_cflags} ${opus_opt_cflags} -fPIE -miphoneos-version-min=${MIN_IOS_VERSION} -I${opus_output_dir}/include -isysroot ${xcode_dev_path}/Platforms/${os_platform}.platform/Developer/SDKs/${os_platform}.sdk" || exit
make -j4 || exit
make install || exit
make clean || exit
done
echo "Building opus library..."
opus_output_libs="libopus.a"
for opus_output_lib in ${opus_output_libs}; do
opus_input_libs=""
for arch in ${USE_ARCHS[@]}; do
if [ "${arch}" == "i386" ] || [ "${arch}" == "x86_64" ]; then
os_platform="iPhoneSimulator"
else
os_platform="iPhoneOS"
fi
opus_input_arch_lib="${opus_inter_dir}/${os_platform}${IOS_SDK_VERSION}-${arch}.sdk/lib/${opus_output_lib}"
if [ -e $opus_input_arch_lib ]; then
opus_input_libs="${opus_input_libs} ${opus_input_arch_lib}"
fi
done
if [ -n "$opus_input_libs" ]; then
echo "** lipo libs"
lipo -create $opus_input_libs -output "$opus_output_dir/lib/${opus_output_lib}" || exit
else
echo "$opus_output_lib does not exist, skipping (are the dependencies installed?)"
fi
done
echo "Done lipo-ing libs"
echo "Start copying to correct directory"
for arch in ${USE_ARCHS[@]}; do
if [ "${arch}" == "i386" ] || [ "${arch}" == "x86_64" ]; then
os_platform="iPhoneSimulator"
else
os_platform="iPhoneOS"
fi
cp -R ${opus_inter_dir}/${os_platform}${IOS_SDK_VERSION}-${arch}.sdk/include/* ${opus_output_dir}/include/
if [ $? == "0" ]; then
break
fi
done
echo "Done copying files"
}
function download_pjsip () {
pjsip_url="https://github.com/pjsip/pjproject/archive/${PJSIP_VERSION}.tar.gz"
pjsip_target_path="$PJSIP_DIR/src"
mkdir -p $pjsip_target_path
cd $pjsip_target_path
echo "Downloading pjsip-${PJSIP_VERSION}.tar.gz"
curl -LO $pjsip_url
echo "Using pjsip-${PJSIP_VERSION}.tar.gz"
tar zxf "${PJSIP_VERSION}.tar.gz" --strip 1
}
function clean_pjsip () {
if [ $CLEAN_PJSIP_SRC = true ]; then
echo "Clean PJSIP source: ${CLEAN_PJSIP_SRC}"
echo "WARNING: About to clean directory: ${BASE_DIR}/pjsip"
echo "Waiting 5 seconds for sanity check... CTRL-C to abort now"
sleep 1 && echo "4..." && \
sleep 1 && echo "3..." && \
sleep 1 && echo "2..." && \
sleep 1 && echo "1..." && \
sleep 1
rm -rf $PJSIP_DIR
rm -rf $PJSIP_FINAL_LIB_DIR
rm -rf "${BASE_DIR}/VialerPJSIP.framework"
echo "Done cleaning PJSIP source"
echo "============================="
fi
}
function config_site () {
echo "Creating config_site.h"
if [ -f $PJSIP_CONFIG_SITE_H ]; then
rm -rf $PJSIP_CONFIG_SITE_H
fi
echo "#define PJ_CONFIG_IPHONE 1" >> $PJSIP_CONFIG_SITE_H
if [ $INDEPENDENT_WEBRTC = true ]; then
echo "#define PJMEDIA_HAS_SRTP 0" >> $PJSIP_CONFIG_SITE_H
fi
if [ $H264_SUPPORT = true ]; then
echo "#define PJMEDIA_HAS_VIDEO 1" >> $PJSIP_CONFIG_SITE_H
echo "#define PJMEDIA_HAS_OPENH264_CODEC 1" >> $PJSIP_CONFIG_SITE_H
echo "#define PJMEDIA_VIDEO_DEV_HAS_OPENGL 1" >> $PJSIP_CONFIG_SITE_H
echo "#define PJMEDIA_VIDEO_DEV_HAS_OPENGL_ES 1" >> $PJSIP_CONFIG_SITE_H
echo "#define PJMEDIA_VIDEO_DEV_HAS_IOS_OPENGL 1" >> $PJSIP_CONFIG_SITE_H
echo "#include <OpenGLES/ES3/glext.h>" >> $PJSIP_CONFIG_SITE_H
fi
if [ $HAS_IPV6 = true ]; then
echo " #define PJ_HAS_IPV6 1" >> $PJSIP_CONFIG_SITE_H
fi
while IFS=',' read -ra CONFIG_SITE_OPTION; do
for i in "${CONFIG_SITE_OPTION[@]}"; do
echo "#define $i" >> $PJSIP_CONFIG_SITE_H
done
done <<< $CONFIG_SITE_OPTIONS
echo "#include <pj/config_site_sample.h>" >> $PJSIP_CONFIG_SITE_H
echo "Done creating new config_site.h"
echo "============================="
}
function build_archs () {
echo "Building ABIs"
for arch in "${USE_ARCHS[@]}"; do
configure_"$arch"
_build $arch
_collect $arch
done
echo "Done building the ABIs"
echo "============================="
}
function configure_armv7 () {
echo "Configure for armv7"
export CFLAGS="-miphoneos-version-min=$MIN_IOS_VERSION"
export LDFLAGS=
}
function configure_armv7s () {
echo "Configure for armv7s"
export CFLAGS="-miphoneos-version-min=$MIN_IOS_VERSION"
export LDFLAGS=
}
function configure_arm64 () {
echo "Configure for arm64"
export CFLAGS="-miphoneos-version-min=$MIN_IOS_VERSION"
export LDFLAGS=
}
function configure_i386 () {
echo "Configure for i386"
export DEVPATH=$XCODE_SIMULATOR_DEV_PATH
export CFLAGS="-O2 -m32 -mios-simulator-version-min=$MIN_IOS_VERSION"
export LDFLAGS="-O2 -m32 -mios-simulator-version-min=$MIN_IOS_VERSION -Wl,-no_compact_unwind"
}
function configure_x86_64 () {
echo "Configure for x86_64"
export DEVPATH=$XCODE_SIMULATOR_DEV_PATH
export CFLAGS="-O2 -m32 -mios-simulator-version-min=$MIN_IOS_VERSION"
export LDFLAGS="-O2 -m32 -mios-simulator-version-min=$MIN_IOS_VERSION -Wl,-no_compact_unwind"
}
function _build () {
pushd . > /dev/null
cd $PJSIP_SRC_DIR
mkdir -p $PJSIP_LOGS_DIR
arch=$1
arch_log="$PJSIP_LOGS_DIR/$arch.log"
clean_pjsip_libs $arch
configure="./configure-iphone"
if [ $HAS_BITCODE = true ]; then
export CFLAGS="${CFLAGS} -fembed-bitcode"
fi
if [ $SSL_SUPPORT = true ]; then
configure="$configure --with-ssl=${SSL_BUILD_DIR}"
export CFLAGS="${CFLAGS} -I${SSL_BUILD_DIR}/include"
export LDFLAGS="${LDFLAGS} -L${SSL_BUILD_DIR}/lib"
fi
if [ $OPUS_SUPPORT = true ]; then
configure="$configure --with-opus=${OPUS_BUILD_DIR}/dependencies"
fi
if [ $H264_SUPPORT = true ]; then
configure="$configure --with-openh264=${H264_BUILD_DIR}"
export CFLAGS="${CFLAGS} -I${H264_BUILD_DIR}/include"
export LDFLAGS="${LDFLAGS} -L${H264_BUILD_DIR}/lib"
fi
export LDFLAGS="${LDFLAGS} -lstdc++"
export MIN_IOS="-miphoneos-version-min=${MIN_IOS_VERSION}"
echo "Building for $arch"
cp $PJSIP_CONFIG_SITE_H "$BASE_DIR/pjsip/src/pjlib/include/pj"
ARCH="-arch $arch" $configure >> $arch_log 2>&1 || exit
make dep >> $arch_log 2>&1 &
spinner $!
make clean >> $arch_log &
spinner $!
make >> $arch_log 2>&1 &
spinner $!
if [ $SSL_SUPPORT = true ]; then
if [ $ENABLE_ZRTP = true ]; then
cd $PJSIP_SRC_DIR/third_party/ZRTP4PJ/build/zsrtp
make dep >> $arch_log 2>&1 &
spinner $!
make >> $arch_log 2>&1 &
spinner $!
fi
fi
echo "Done building for $arch"
echo "============================="
popd > /dev/null
}
function _collect () {
echo "COLLECT for $1"
cd $BASE_DIR
mkdir -p "pjsip/temp/$1"
for x in `find pjsip/src -name *$1*.a`; do
cp -v ./$x ./pjsip/temp/$1
done | tee "$BASE_DIR"/pjsip/logs/collect.log
if [ $INDEPENDENT_WEBRTC = true ]; then
rm ./pjsip/temp/$1/libsrtp*.a
fi
}
function _merge () {
echo "MERGE"
cd $BASE_DIR
mkdir -p "$BASE_DIR"/Pod
a_files=`find ./pjsip/temp -name *darwin_ios.a -exec printf '%s ' {} +`
if [ $SSL_SUPPORT = true ]; then
a_files="${a_files} ${SSL_BUILD_DIR}/lib/libssl.a ${SSL_BUILD_DIR}/lib/libcrypto.a"
fi
if [ $OPUS_SUPPORT = true ]; then
a_files="${a_files} ${OPUS_BUILD_DIR}/dependencies/lib/libopus.a"
fi
if [ $H264_SUPPORT = true ]; then
a_files="${a_files} ${H264_BUILD_DIR}/lib/libopenh264.a"
fi
libtool -o Pod/VialerPJSIP.a $a_files
}
function clean_pjsip_libs_temp () {
rm -rf "$BASE_DIR/pjsip/temp/$arch"
rm -rf "$BASE_DIR/Pod"
}
function clean_pjsip_libs () {
arch=$1
echo "Clean $arch lib direcotry"
for src_dir in ${PJSIP_LIB_PATHS[*]}; do
dir="$PJSIP_SRC_DIR/${src_dir}"
if [ -d $dir ]; then
rm -rf $dir
fi
dir="$PJSIP_SRC_DIR/${src_dir}-${arch}"
if [ -d $dir ]; then
rm -rf $dir
fi
done
}
function copy_headers () {
echo "Copying header files to temporary location"
cd "$BASE_DIR/pjsip/src"
find . -path "./third_party" -prune -o -path "./pjsip-apps" -prune -o -path "./include" -prune -o -type f -wholename "*include/*.h*" -exec bash -c 'copy_to_lib_dir "{}"' ';' 2>&1
if [ $H264_SUPPORT = true ]; then
find ${H264_BUILD_DIR}/include/wels -type f -exec bash -c 'copy_to_lib_dir "{}"' ';'
fi
if [ $OPUS_SUPPORT = true ]; then
find ${OPUS_BUILD_DIR}/dependencies/include/opus -type f -exec bash -c 'copy_to_lib_dir "{}"' ';'
fi
if [ $SSL_SUPPORT = true ]; then
find ${SSL_BUILD_DIR}/include/openssl -type f -exec bash -c 'copy_to_lib_dir "{}"' ';'
if [ $ENABLE_ZRTP = true ]; then
cp ${PJSIP_SRC_DIR}/third_party/ZRTP4PJ/zsrtp/include/ZsrtpCWrapper.h "$BASE_DIR/Pod/vialer-pjsip-include/"
cp ${PJSIP_SRC_DIR}/third_party/ZRTP4PJ/zsrtp/include/transport_zrtp.h "$BASE_DIR/Pod/vialer-pjsip-include/"
cp -R ${PJSIP_SRC_DIR}/third_party/ZRTP4PJ/zsrtp/zrtp/zrtp/libzrtpcpp/ "$BASE_DIR/Pod/vialer-pjsip-include/libzrtpcpp/"
fi
fi
cd "$BASE_DIR"
echo "Done copying header files to temporay location"
echo "============================="
}
function copy_to_lib_dir () {
old_path=$1
new_path=()
path_parts=(`echo $1 | tr '/' '\n'`)
for x in "${path_parts[@]}"; do
if [ "$x" = "include" ] || [ "${#new_path[@]}" -ne "0" ]; then
new_path+=("$x")
fi
done
new_path="${new_path[@]:1}"
new_path="${new_path// //}"
d="$BASE_DIR/Pod/vialer-pjsip-include/"$(dirname $new_path)
mkdir -p $d
cp $old_path $d
}
function create_framework {
PRODUCT_NAME="VialerPJSIP"
PUBLIC_HEADERS_FOLDER_PATH="${BASE_DIR}/Pod/vialer-pjsip-include"
LIBRARY_LOCATION="${BASE_DIR}/Pod/"
FRAMEWORK_LOCN="${BASE_DIR}/${PRODUCT_NAME}.framework"
echo "Creating the $PRODUCT_NAME framework in $FRAMEWORK_LOCN"
copy_headers
# Remove old framework.
echo "Remove old Framework"
rm -rf ${FRAMEWORK_LOCN}
# Create the path to the real Headers dir
mkdir -p "${FRAMEWORK_LOCN}/Versions/A/Headers"
# Create the required symlinks
ln -sfh A "${FRAMEWORK_LOCN}/Versions/Current"
ln -sfh "Versions/Current/Headers" "${FRAMEWORK_LOCN}/Headers"
ln -sfh "Versions/Current/${PRODUCT_NAME}" "${FRAMEWORK_LOCN}/${PRODUCT_NAME}"
# Copy the public headers into the framework
cp -a "${PUBLIC_HEADERS_FOLDER_PATH}/" "${FRAMEWORK_LOCN}/Versions/A/Headers"
cp -a "${LIBRARY_LOCATION}/${PRODUCT_NAME}.a" "${FRAMEWORK_LOCN}/Versions/A/${PRODUCT_NAME}"
echo "Adapting the framework's header files"
# Now, replace the include statements of the framework headers
i=0
while IFS= read -r -d '' file; do
LC_ALL=C sed -i '' "s/include\ </include <$PRODUCT_NAME\//" "$file"
# To prevent $product_name is inserted multiple times, run a second sed command
LC_ALL=C sed -i '' "s/<$PRODUCT_NAME\/$PRODUCT_NAME\//<$PRODUCT_NAME\//" "$file"
# DO NOT REPLACE the default C++ lib's, undo the change
LC_ALL=C sed -i '' "s/include\ <$PRODUCT_NAME\/stdio.h/include\ <stdio.h/" "$file"
LC_ALL=C sed -i '' "s/include\ <$PRODUCT_NAME\/stddef.h/include\ <stddef.h/" "$file"
LC_ALL=C sed -i '' "s/include\ <$PRODUCT_NAME\/stdarg.h/include\ <stdarg.h/" "$file"
LC_ALL=C sed -i '' "s/include\ <$PRODUCT_NAME\/string.h/include\ <string.h/" "$file"
LC_ALL=C sed -i '' "s/include\ <$PRODUCT_NAME\/stdlib.h/include\ <stdlib.h/" "$file"
LC_ALL=C sed -i '' "s/include\ <$PRODUCT_NAME\/stdint.h/include\ <stdint.h/" "$file"
LC_ALL=C sed -i '' "s/include\ <$PRODUCT_NAME\/assert.h/include\ <assert.h/" "$file"
LC_ALL=C sed -i '' "s/include\ <$PRODUCT_NAME\/math.h/include\ <math.h/" "$file"
LC_ALL=C sed -i '' "s/include\ <$PRODUCT_NAME\/ctype.h/include\ <ctype.h/" "$file"
LC_ALL=C sed -i '' "s/include\ <$PRODUCT_NAME\/setjmp.h/include\ <setjmp.h/" "$file"
LC_ALL=C sed -i '' "s/include\ <$PRODUCT_NAME\/stdarg.h/include\ <stdarg.h/" "$file"
LC_ALL=C sed -i '' "s/include\ <$PRODUCT_NAME\/stdarg.h/include\ <stdarg.h/" "$file"
LC_ALL=C sed -i '' "s/include\ <$PRODUCT_NAME\/inttypes.h/include\ <inttypes.h/" "$file"
LC_ALL=C sed -i '' "s/include\ <$PRODUCT_NAME\/OpenGLES\/ES3\/glext.h/include\ <OpenGLES\/ES3\/glext.h/" "$file"
EXIT_CODE=$?
if [[ $EXIT_CODE != 0 ]]; then
echo "Error processing file ${file}"
fi
i=$((i+1))
done < <(find "${FRAMEWORK_LOCN}/Versions/A/Headers" -type f -name "*.h" -print0)
# echo "$i files processed"
echo "Done create framework $PRODUCT_NAME"
echo "============================="
}
export -f copy_to_lib_dir
if [ -z ${USE_ARCHS} ]; then
for arch in "${AVIALABLE_ARCHS[@]}"; do
USE_ARCHS+=($arch)
done
fi
if [ $SHOW_HELP = true ]; then
show_help
else
clean_pjsip
download_pjsip
build_h264
build_ssl
build_opus
config_site
build_archs
_merge
create_framework
fi