-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuild
executable file
·816 lines (687 loc) · 26.6 KB
/
build
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
#!/bin/bash
set -e
AVAILABLE_ARCHS=(
"armv7"
"armv7s"
"arm64"
"i386"
"x86_64"
)
export PATH_REPO="/Users/runner/work/libpjsua2-ios/libpjsua2-ios"
export BASE_DIR=`pwd -P`
export MIN_IOS_VERSION="12.2"
export IOS_SDK_VERSION="18.2"
export AVAILABLE_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 BCG729_SUPPORT=false
export INDEPENDENT_WEBRTC=false
export ENABLE_ZRTP=false
export HAS_BITCODE=false
export HAS_IPV6=false
export SHOW_HELP=false
export PJSIP_VERSION="2.15.1"
export PJSIP_BASE_URL="https://github.com/pjsip/pjproject.git"
export PJSIP_DIR="$BASE_DIR/pjsip"
export PJSIP_FINAL_LIB_DIR="$BASE_DIR/lib"
export PJSIP_SRC_DIR="$BASE_DIR/pjproject"
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 BUILD_DIR="$BASE_DIR/external"
export SSL_BUILD_DIR="$BUILD_DIR/openssl_ios"
export ZRTP_BUILD_DIR="$BUILD_DIR/zrtp"
export OPUS_BUILD_DIR="$BUILD_DIR/opus"
export H264_BUILD_DIR="$BUILD_DIR/openh264"
export BCG729_BUILD_DIR="$BUILD_DIR/bcg729"
export XCODE_SIMULATOR_DEV_PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer"
export XCODE_DEVICE_DEV_PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/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 [[ " ${AVAILABLE_ARCHS[@]} " =~ " ${i} " ]]; then
USE_ARCHS+=("$i")
fi
done
done <<< $ARCHS
shift
;;
--ci)
export BASE_DIR="$PATH_REPO"
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
;;
-bcg729 | --bcg729 | bcg729)
BCG729_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 "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 " --ci Set script to use path's of ci build server"
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 " -bcg729, --bcg729, bcg729 Include BCG729 codecs. (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: ./build --ssl --opus --h264 --arch=armv7,armv7s,arm64"
echo " This will compile the newest pjsip version for the all architectures armv7, armv7s, and 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_bcg729 () {
if [ $BCG729_SUPPORT = false ]; then
return
fi
echo "Use BCG729"
xcode_dev_path=`xcode-select -print-path`
cd $BCG729_BUILD_DIR
for arch in ${USE_ARCHS[@]}
do
if [ "$arch" == "x86_64" ]; then
os_platform="iPhoneSimulator"
C_FLAGS="$C_FLAGS -O2 -m64 -mios-simulator-version-min=${MIN_IOS_VERSION} -isysroot ${xcode_dev_path}/Platforms/${os_platform}.platform/Developer/SDKs/${os_platform}.sdk"
else
os_platform="iPhoneOS"
C_FLAGS="$C_FLAGS -O2 -miphoneos-version-min=${MIN_IOS_VERSION} -isysroot ${xcode_dev_path}/Platforms/${os_platform}.platform/Developer/SDKs/${os_platform}.sdk"
fi
rm -rf "${BCG729_BUILD_DIR}/${os_platform}${IOS_SDK_VERSION}-${arch}.sdk"
rm -rf "${BCG729_BUILD_DIR}/CMakeFiles" "${BCG729_BUILD_DIR}/CMakeCache.txt"
# Criar diretório de instalação
mkdir -p "${os_platform}${IOS_SDK_VERSION}-${arch}.sdk"
# Executar o CMake com configurações específicas para iOS
cmake -DCMAKE_OSX_ARCHITECTURES=$arch \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX="${os_platform}${IOS_SDK_VERSION}-${arch}.sdk" \
-DCMAKE_SKIP_INSTALL_RPATH="ON" \
-DCMAKE_MAKE_PROGRAM:PATH=$(which make) \
-DCMAKE_C_COMPILER=$(which clang) \
-DCMAKE_OSX_SYSROOT="${xcode_dev_path}/Platforms/${os_platform}.platform/Developer/SDKs/${os_platform}.sdk" \
.
# Compilar e instalar
make || exit 1
make install
done
}
function build_h264 () {
if [ $H264_SUPPORT = false ]; then
return
fi
echo "Use H264"
cd $H264_BUILD_DIR
h264_lipo_args=""
for arch in "${USE_ARCHS[@]}"; do
h264_makefile="Makefile"
h264_makefile_bak="Makefile.bak"
h264_prefix="${H264_BUILD_DIR}/builds/${arch}"
h264_log="${h264_prefix}/build.log"
mkdir -p "${h264_prefix}/logs"
pushd . > /dev/null
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}/builds/${arch}/lib/libopenh264.a"
done
if [ ! -d "${H264_BUILD_DIR}/lib" ]; then
mkdir -p "${H264_BUILD_DIR}/lib"
fi
echo "Done compiling openh264"
}
function build_ssl () {
if [ $SSL_SUPPORT = false ]; then
return
fi
pushd . > /dev/null
cd $SSL_BUILD_DIR
targets=""
for arch in "${USE_ARCHS[@]}"; do
if [ "$arch" == "x86_64" ]; then
targets="${targets} ios-sim-cross-$arch"
elif [ "$arch" != "i386" ]; then
targets="${targets} ios-cross-$arch"
fi
done
CURL_OPTIONS="-L" ./build-libssl.sh --version=1.1.1s --archs="${USE_ARCHS[*]// /\s}" --ios-sdk=${IOS_SDK_VERSION} --ios-min-sdk=${MIN_IOS_VERSION} --targets="$targets"|| exit
popd > /dev/null
echo "Using SSL..."
rm -rf lib
if [ $ENABLE_ZRTP = true ]; then
build_zrtp
fi
}
function build_zrtp () {
echo "Use ZRTP"
pushd . > /dev/null
cd $ZRTP_BUILD_DIR
cd 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
opus_version="1.4"
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_repo_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_inter_dir
cd "${opus_repo_dir}"
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"
./autogen.sh
./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 config_site () {
echo "Creating config_site.h"
touch $PJSIP_CONFIG_SITE_H
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
if [ $OPUS_SUPPORT = true ]; then
echo "#define PJMEDIA_HAS_OPUS_CODEC 1" >> "$PJSIP_CONFIG_SITE_H"
fi
if [ $BCG729_SUPPORT = true ]; then
echo "#define PJMEDIA_HAS_BCG729 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
_merge_archs $arch
done
echo "Done building the ABIs"
echo "============================="
}
function configure_armv7 () {
echo "Configure for armv7"
export DEVPATH=$XCODE_DEVICE_DEV_PATH
export CFLAGS="-miphoneos-version-min=$MIN_IOS_VERSION"
export LDFLAGS=
}
function configure_armv7s () {
echo "Configure for armv7s"
export DEVPATH=$XCODE_DEVICE_DEV_PATH
export CFLAGS="-miphoneos-version-min=$MIN_IOS_VERSION"
export LDFLAGS=
}
function configure_arm64 () {
echo "Configure for arm64"
export DEVPATH=$XCODE_DEVICE_DEV_PATH
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"
export LDFLAGS="-O2 -m32"
}
function configure_x86_64 () {
echo "Configure for x86_64"
export DEVPATH=$XCODE_SIMULATOR_DEV_PATH
export CFLAGS="-O2 -m64"
export LDFLAGS="-O2 -m64"
}
function _build () {
pushd . > /dev/null
cd $PJSIP_SRC_DIR
mkdir -p $PJSIP_LOGS_DIR
arch=$1
arch_log="$PJSIP_LOGS_DIR/$arch.log"
configure="./configure-iphone"
if [ $HAS_BITCODE = true ]; then
export CFLAGS="${CFLAGS} -fembed-bitcode"
fi
if [ $BCG729_SUPPORT = true ]; then
if [ "$arch" != "i386" ] && [ "$arch" != "x86_64" ]; then
configure="$configure --with-bcg729=${BCG729_BUILD_DIR}/iPhoneOS${IOS_SDK_VERSION}-${arch}.sdk"
export CFLAGS="${CFLAGS} -I${BCG729_BUILD_DIR}/iPhoneOS${IOS_SDK_VERSION}-${arch}.sdk/include"
export LDFLAGS="${LDFLAGS} -L${BCG729_BUILD_DIR}/iPhoneOS${IOS_SDK_VERSION}-${arch}.sdk/lib"
else
configure="$configure --with-bcg729=${BCG729_BUILD_DIR}/iPhoneSimulator${IOS_SDK_VERSION}-${arch}.sdk"
export CFLAGS="${CFLAGS} -I${BCG729_BUILD_DIR}/iPhoneSimulator${IOS_SDK_VERSION}-${arch}.sdk/include"
export LDFLAGS="${LDFLAGS} -L${BCG729_BUILD_DIR}/iPhoneSimulator${IOS_SDK_VERSION}-${arch}.sdk/lib"
fi
fi
if [ $SSL_SUPPORT = true ]; then
if [ "$arch" != "i386" ] && [ "$arch" != "x86_64" ]; then
configure="$configure --with-ssl=${SSL_BUILD_DIR}/bin/iPhoneOS${IOS_SDK_VERSION}-${arch}.sdk"
export CFLAGS="${CFLAGS} -I${SSL_BUILD_DIR}/bin/iPhoneOS${IOS_SDK_VERSION}-${arch}.sdk/include"
export LDFLAGS="${LDFLAGS} -L${SSL_BUILD_DIR}/bin/iPhoneOS${IOS_SDK_VERSION}-${arch}.sdk/lib"
else
configure="$configure --with-ssl=${SSL_BUILD_DIR}/bin/iPhoneSimulator${IOS_SDK_VERSION}-${arch}.sdk"
export CFLAGS="${CFLAGS} -I${SSL_BUILD_DIR}/bin/iPhoneSimulator${IOS_SDK_VERSION}-${arch}.sdk/include"
export LDFLAGS="${LDFLAGS} -L${SSL_BUILD_DIR}/bin/iPhoneSimulator${IOS_SDK_VERSION}-${arch}.sdk/lib"
fi
fi
if [ $OPUS_SUPPORT = true ]; then
if [ "$arch" != "i386" ] && [ "$arch" != "x86_64" ]; then
configure="$configure --with-opus=${OPUS_BUILD_DIR}/build/built/iPhoneOS${IOS_SDK_VERSION}-${arch}.sdk/"
else
configure="$configure --with-opus=${OPUS_BUILD_DIR}/build/built/iPhoneSimulator${IOS_SDK_VERSION}-${arch}.sdk/"
fi
fi
if [ $H264_SUPPORT = true ]; then
configure="$configure --with-openh264=${H264_BUILD_DIR}"
export CFLAGS="${CFLAGS} -I${H264_BUILD_DIR}/builds/$arch/include"
export LDFLAGS="${LDFLAGS} -L${H264_BUILD_DIR}/builds/$arch/lib"
fi
export LDFLAGS="${LDFLAGS} -lstdc++ -ld_classic"
if [ "$arch" == "i386" ] || [ "$arch" == "x86_64" ]; then
export MIN_IOS="-mios-simulator-version-min=${MIN_IOS_VERSION}"
else
export MIN_IOS="-miphoneos-version-min=${MIN_IOS_VERSION}"
fi
echo "Building for $arch"
cp $PJSIP_CONFIG_SITE_H "$PJSIP_SRC_DIR/pjlib/include/pj"
ARCH="-arch $arch " $configure #>> $arch_log 2>&1 || exit
echo "make dep"
make dep >> $arch_log 2>&1 &
spinner $! || exit
echo "make "
make >> $arch_log 2>&1 &
spinner $! || exit
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
#TODO: fix libs not found on runner path because they are in temp
echo "Making swig "
cd "$PJSIP_SRC_DIR/pjsip-apps/src/swig"
make clean >> $arch_log 2>&1 &
spinner $! || exit
make >> $arch_log 2>&1 &
spinner $! || exit
echo "Done building for $arch"
echo "============================="
popd > /dev/null
}
function _collect () {
echo "COLLECT for $1"
cd $BASE_DIR
mkdir -p "lib/$1"
if [ -d "$PJSIP_SRC_DIR/pjsip-apps/src/swig/csharp/pjsua2maui/pjsua2maui.iOS/lib/" ]; then
cp -v "$PJSIP_SRC_DIR/pjsip-apps/src/swig/csharp/pjsua2maui/pjsua2maui.iOS/lib/$1/libpjsua2.a" $BASE_DIR/lib/$1
fi
if [ -d ./external/openh264/builds/$1/lib ]; then
cp -v ./external/openh264/builds/$1/lib/*.a $BASE_DIR/lib/$1
fi
if [ -d ./external/opus/build/built/*$1.sdk/lib ]; then
cp -v ./external/opus/build/built/*$1.sdk/lib/*.a $BASE_DIR/lib/$1
fi
if [ -d ./external/openssl_ios/bin/*$1.sdk/lib ]; then
cp -v ./external/openssl_ios/bin/*$1.sdk/lib/*.a $BASE_DIR/lib/$1
fi
if [ -d ./external/bcg729/*$1.sdk/lib/ ]; then
cp -v ./external/bcg729/*$1.sdk/lib/*.a $BASE_DIR/lib/$1
fi
# if [ $INDEPENDENT_WEBRTC = true ]; then
# rm ./pjproject/third_party/lib/libsrtp*.a
# fi
}
function _merge_archs () {
echo "============================="
echo "======== MERGE LIBS ========="
cd $BASE_DIR
mkdir -p "libpjsua2/lib/$1"
libtool -static -o ./libpjsua2/lib/$1/libpjsua2.a $BASE_DIR/lib/$1/*
echo "============================="
}
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/pjproject"
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/pjsip-include/"
cp ${PJSIP_SRC_DIR}/third_party/ZRTP4PJ/zsrtp/include/transport_zrtp.h "$BASE_DIR/Pod/pjsip-include/"
cp -R ${PJSIP_SRC_DIR}/third_party/ZRTP4PJ/zsrtp/zrtp/zrtp/libzrtpcpp/ "$BASE_DIR/Pod/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/pjsip-include/"$(dirname $new_path)
mkdir -p $d
cp $old_path $d
}
function create_framework {
PRODUCT_NAME="libpjsua2"
PUBLIC_HEADERS_FOLDER_PATH="${BASE_DIR}/Pod/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
echo "replacing includes for file: $file"
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 "============================="
}
function copy_swig_bindings () {
cd $BASE_DIR
if [ -d "$PJSIP_SRC_DIR/pjsip-apps/src/swig/csharp/pjsua2maui/pjsua2maui" ]; then
cp -v -r "$PJSIP_SRC_DIR/pjsip-apps/src/swig/csharp/pjsua2maui/pjsua2maui" "libpjsua2/lib/"
fi
}
start=`date +%s`
export -f copy_to_lib_dir
if [ -z ${USE_ARCHS} ]; then
for arch in "${AVAILABLE_ARCHS[@]}"; do
USE_ARCHS+=($arch)
done
fi
if [ $SHOW_HELP = true ]; then
show_help
else
build_bcg729
build_h264
build_ssl
build_opus
config_site
build_archs
copy_swig_bindings
#create_framework
fi
end=`date +%s`
echo "End time: $end"
runtime=$((end-start))
echo "Total script runtime: $runtime"