-
Notifications
You must be signed in to change notification settings - Fork 3
/
start.sh
428 lines (352 loc) · 12.9 KB
/
start.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
#!/bin/bash
# Oliver Epper <oliver.epper@gmail.com>
set -e
env -i
if [ $# -eq 0 ]
then
echo "sh ./start.sh <absolute path>"
exit 1
fi
PREFIX=$1
PJPROJECT_VERSION=2.13
IOS_ARM64_INSTALL_PREFIX="${PREFIX}/ios-arm64"
IOS_ARM64_SIMULATOR_INSTALL_PREFIX="${PREFIX}/ios-arm64-simulator"
IOS_X86_64_SIMULATOR_INSTALL_PREFIX="${PREFIX}/ios-x86_64-simulator"
IOS_ARM64_X86_64_SIMULATOR_INSTALL_PREFIX="${PREFIX}/ios-arm64_x86_64-simulator"
IOS_ARM64_MACCATALYST_INSTALL_PREFIX="${PREFIX}/ios-arm64-maccatalyst"
IOS_X86_64_MACCATALYST_INSTALL_PREFIX="${PREFIX}/ios-x86_64-maccatalyst"
IOS_ARM64_X86_64_MACCATALYST_INSTALL_PREFIX="${PREFIX}/ios-arm64_x86_64-maccatalyst"
MACOS_ARM64_INSTALL_PREFIX="${PREFIX}/macos-arm64"
MACOS_X86_64_INSTALL_PREFIX="${PREFIX}/macos-x86_64"
MACOS_ARM64_X86_64_INSTALL_PREFIX="${PREFIX}/macos-arm64_x86_64"
MACOS_ARM64_DEBUG_INSTALL_PREFIX="${PREFIX}/macos-arm64-debug"
if [ -d pjproject ]
then
pushd pjproject
git reset --hard "${PJPROJECT_VERSION}"
popd
else
git -c advice.detachedHead=false clone --depth 1 --branch "${PJPROJECT_VERSION}" https://github.com/pjsip/pjproject # > /dev/null 2>&1
fi
#
# helper function
#
function createLib {
pushd "$1"
EXTRA_LIBS=()
if [ -d "${OPUS_LATEST}" ]; then
EXTRA_LIBS+=("${OPUS_LATEST}/lib/libopus.a")
unset OPUS
unset OPUS_LATEST
fi
if [[ -d "${SDL_LATEST}" ]]; then
EXTRA_LIBS+=("${SDL_LATEST}/lib/libSDL2.a")
unset SDL
unset SDL_LATEST
fi
libtool -static -o libpjproject.a ./*.a "${EXTRA_LIBS[@]}"
ranlib libpjproject.a
popd
}
#
# create base configuration for pjproject build
#
pushd pjproject
cat << EOF > pjlib/include/pj/config_site.h
#define PJ_HAS_SSL_SOCK 1
#undef PJ_SSL_SOCK_IMP
#define PJ_SSL_SOCK_IMP PJ_SSL_SOCK_IMP_APPLE
#include <pj/config_site_sample.h>
EOF
popd
function prepare {
local WANTS_IPHONE=$1
local WANTS_VIDEO=$2
git reset --hard
git clean -fxd
cat << EOF > pjlib/include/pj/config_site.h
#define PJ_HAS_SSL_SOCK 1
#undef PJ_SSL_SOCK_IMP
#define PJ_SSL_SOCK_IMP PJ_SSL_SOCK_IMP_APPLE
#include <pj/config_site_sample.h>
EOF
if [[ "${WANTS_IPHONE}" = "YES" ]]; then
echo "🔧 adding iPhone support"
sed -i '' -e '1i\
#define PJ_CONFIG_IPHONE 1
' pjlib/include/pj/config_site.h
fi
if [[ "${WANTS_VIDEO}" = "YES" ]]; then
echo "🔧 adding video support"
sed -i '' -e '1i\
#define PJMEDIA_HAS_VIDEO 1 \
#define PJMEDIA_HAS_VID_TOOLBOX_CODEC 1
' pjlib/include/pj/config_site.h
fi
}
#
# build for iOS on arm64
#
rm -rf "${IOS_ARM64_INSTALL_PREFIX}"
pushd pjproject
prepare YES
OPUS=(/opt/homebrew/Cellar/opus-apple-platforms/*/ios-arm64)
OPUS_LATEST=${OPUS[${#OPUS[@]} - 1]}
if [[ -d "${OPUS_LATEST}" ]]
then
CONFIGURE_EXTRA_PARAMS+=("--with-opus=${OPUS_LATEST}")
fi
SDKPATH=$(xcrun -sdk iphoneos --show-sdk-path)
ARCH="arm64"
CFLAGS="-isysroot $SDKPATH -miphoneos-version-min=13 -DPJ_SDK_NAME=\"\\\"$(basename "$SDKPATH")\\\"\" -arch $ARCH" \
LDFLAGS="-isysroot $SDKPATH -framework AudioToolbox -framework Foundation -framework Network -framework Security -arch $ARCH" \
./aconfigure --prefix="${IOS_ARM64_INSTALL_PREFIX}" --host="${ARCH}"-apple-darwin_ios "${CONFIGURE_EXTRA_PARAMS[@]}" --disable-sdl
make dep && make clean
make
make install
createLib "${IOS_ARM64_INSTALL_PREFIX}/lib"
popd
#
# build for iOS simulator on arm64
#
rm -rf "${IOS_ARM64_SIMULATOR_INSTALL_PREFIX}"
pushd pjproject
prepare YES
OPUS=(/opt/homebrew/Cellar/opus-apple-platforms/*/ios-arm64-simulator)
OPUS_LATEST=${OPUS[${#OPUS[@]} - 1]}
if [[ -d "${OPUS_LATEST}" ]]
then
CONFIGURE_EXTRA_PARAMS+=("--with-opus=${OPUS_LATEST}")
fi
SDKPATH=$(xcrun -sdk iphonesimulator --show-sdk-path)
ARCH="arm64"
CFLAGS="-isysroot $SDKPATH -miphonesimulator-version-min=13 -DPJ_SDK_NAME=\"\\\"$(basename "$SDKPATH")\\\"\" -arch $ARCH" \
LDFLAGS="-isysroot $SDKPATH -framework AudioToolbox -framework Foundation -framework Network -framework Security -arch $ARCH" \
./aconfigure --prefix="${IOS_ARM64_SIMULATOR_INSTALL_PREFIX}" --host="${ARCH}"-apple-darwin_ios "${CONFIGURE_EXTRA_PARAMS[@]}" --disable-sdl
make dep && make clean
make
make install
createLib "${IOS_ARM64_SIMULATOR_INSTALL_PREFIX}/lib"
popd
#
# build for iOS simulator on x86_64
#
rm -rf "${IOS_X86_64_SIMULATOR_INSTALL_PREFIX}"
pushd pjproject
prepare YES
OPUS=(/opt/homebrew/Cellar/opus-apple-platforms/*/ios-x86_64-simulator)
OPUS_LATEST=${OPUS[${#OPUS[@]} - 1]}
if [[ -d "${OPUS_LATEST}" ]]
then
CONFIGURE_EXTRA_PARAMS+=("--with-opus=${OPUS_LATEST}")
fi
SDKPATH=$(xcrun -sdk iphonesimulator --show-sdk-path)
ARCH="x86_64"
CFLAGS="-isysroot $SDKPATH -miphonesimulator-version-min=13 -DPJ_SDK_NAME=\"\\\"$(basename "$SDKPATH")\\\"\" -arch $ARCH" \
LDFLAGS="-isysroot $SDKPATH -framework AudioToolbox -framework Foundation -framework Network -framework Security -arch $ARCH" \
./aconfigure --prefix="${IOS_X86_64_SIMULATOR_INSTALL_PREFIX}" --host="${ARCH}"-apple-darwin_ios "${CONFIGURE_EXTRA_PARAMS[@]}" --disable-sdl
make dep && make clean
make
make install
createLib "${IOS_X86_64_SIMULATOR_INSTALL_PREFIX}/lib"
popd
#
# build fat lib for simulator
#
mkdir -p "${IOS_ARM64_X86_64_SIMULATOR_INSTALL_PREFIX}/lib"
lipo -create \
"${IOS_ARM64_SIMULATOR_INSTALL_PREFIX}/lib/libpjproject.a" \
"${IOS_X86_64_SIMULATOR_INSTALL_PREFIX}/lib/libpjproject.a" \
-output \
"${IOS_ARM64_X86_64_SIMULATOR_INSTALL_PREFIX}/lib/libpjproject.a"
#
# build for Catalyst on arm64
#
rm -rf "${IOS_ARM64_MACCATALYST_INSTALL_PREFIX}"
pushd pjproject
prepare YES
OPUS=(/opt/homebrew/Cellar/opus-apple-platforms/*/ios-arm64-maccatalyst)
OPUS_LATEST=${OPUS[${#OPUS[@]} - 1]}
if [[ -d "${OPUS_LATEST}" ]]
then
CONFIGURE_EXTRA_PARAMS+=("--with-opus=${OPUS_LATEST}")
fi
SDKPATH=$(xcrun -sdk macosx --show-sdk-path)
ARCH="arm64"
CFLAGS="-isysroot $SDKPATH -isystem ${SDKPATH}/System/iOSSupport/usr/include -iframework ${SDKPATH}/System/iOSSupport/System/Library/Frameworks -miphoneos-version-min=13.1 -DPJ_SDK_NAME=\"\\\"$(basename "$SDKPATH")\\\"\" -arch $ARCH -target ${ARCH}-apple-ios-macabi" \
LDFLAGS="-isysroot $SDKPATH -isystem ${SDKPATH}/System/iOSSupport/usr/include -iframework ${SDKPATH}/System/iOSSupport/System/Library/Frameworks -framework Network -framework Security -framework Foundation -arch $ARCH -target ${ARCH}-apple-ios-macabi" \
./aconfigure --prefix="${IOS_ARM64_MACCATALYST_INSTALL_PREFIX}" --host="${ARCH}"-apple-darwin_ios "${CONFIGURE_EXTRA_PARAMS[@]}" --disable-sdl
make dep && make clean
make VERBOSE=1
make install
createLib "${IOS_ARM64_MACCATALYST_INSTALL_PREFIX}/lib"
popd
# build for Catalyst on x86_64
rm -rf "${IOS_X86_64_MACCATALYST_INSTALL_PREFIX}"
pushd pjproject
prepare YES
OPUS=(/opt/homebrew/Cellar/opus-apple-platforms/*/ios-x86_64-maccatalyst)
OPUS_LATEST=${OPUS[${#OPUS[@]} - 1]}
if [[ -d "${OPUS_LATEST}" ]]
then
CONFIGURE_EXTRA_PARAMS+=("--with-opus=${OPUS_LATEST}")
fi
SDKPATH=$(xcrun -sdk macosx --show-sdk-path)
ARCH="x86_64"
CFLAGS="-isysroot $SDKPATH -isystem ${SDKPATH}/System/iOSSupport/usr/include -iframework ${SDKPATH}/System/iOSSupport/System/Library/Frameworks -miphoneos-version-min=13.1 -DPJ_SDK_NAME=\"\\\"$(basename "$SDKPATH")\\\"\" -arch $ARCH -target ${ARCH}-apple-ios-macabi" \
LDFLAGS="-isysroot $SDKPATH -isystem ${SDKPATH}/System/iOSSupport/usr/include -iframework ${SDKPATH}/System/iOSSupport/System/Library/Frameworks -framework Network -framework Security -framework Foundation -arch $ARCH -target ${ARCH}-apple-ios-macabi" \
./aconfigure --prefix="${IOS_X86_64_MACCATALYST_INSTALL_PREFIX}" --host="${ARCH}"-apple-darwin_ios "${CONFIGURE_EXTRA_PARAMS[@]}" --disable-sdl
make dep && make clean
make VERBOSE=1
make install
createLib "${IOS_X86_64_MACCATALYST_INSTALL_PREFIX}/lib"
popd
#
# build fat lib for catalyst
#
mkdir -p "${IOS_ARM64_X86_64_MACCATALYST_INSTALL_PREFIX}/lib"
lipo -create \
"${IOS_ARM64_MACCATALYST_INSTALL_PREFIX}/lib/libpjproject.a" \
"${IOS_X86_64_MACCATALYST_INSTALL_PREFIX}/lib/libpjproject.a" \
-output \
"${IOS_ARM64_X86_64_MACCATALYST_INSTALL_PREFIX}/lib/libpjproject.a"
#
# build SDL for the mac
#
THIRD_PARTY="$(pwd)/third_party_bin"
sh ./sdl.sh ${THIRD_PARTY}
#
#
# build for macOS on arm64
#
rm -rf "${MACOS_ARM64_INSTALL_PREFIX}"
pushd pjproject
prepare NO YES
OPUS=(/opt/homebrew/Cellar/opus-apple-platforms/*/macos-arm64)
OPUS_LATEST=${OPUS[${#OPUS[@]} - 1]}
if [[ -d "${OPUS_LATEST}" ]]
then
CONFIGURE_EXTRA_PARAMS+=("--with-opus=${OPUS_LATEST}")
fi
SDL=("${THIRD_PARTY}/macos-arm64")
SDL_LATEST=${SDL[${#SDL[@]} - 1]}
if [[ -d "${SDL_LATEST}" ]]; then
CONFIGURE_EXTRA_PARAMS+=("--with-sdl=${SDL_LATEST}")
fi
SDKPATH=$(xcrun -sdk macosx --show-sdk-path)
ARCH="arm"
CFLAGS="-isysroot $SDKPATH -mmacosx-version-min=11 -DPJ_SDK_NAME=\"\\\"$(basename "$SDKPATH")\\\"\"" \
LDFLAGS="-isysroot $SDKPATH -framework AudioToolbox -framework Foundation -framework Network -framework Security" \
./aconfigure --prefix="${MACOS_ARM64_INSTALL_PREFIX}" --host="${ARCH}"-apple-darwin "${CONFIGURE_EXTRA_PARAMS[@]}"
make dep && make clean
make
make install
createLib "${MACOS_ARM64_INSTALL_PREFIX}/lib"
popd
#
# build for macOS on x86_64
#
rm -rf "${MACOS_X86_64_INSTALL_PREFIX}"
pushd pjproject
prepare NO YES
OPUS=(/opt/homebrew/Cellar/opus-apple-platforms/*/macos-x86_64)
OPUS_LATEST=${OPUS[${#OPUS[@]} - 1]}
if [[ -d "${OPUS_LATEST}" ]]
then
CONFIGURE_EXTRA_PARAMS+=("--with-opus=${OPUS_LATEST}")
fi
SDL=("${THIRD_PARTY}/macos-x86_64")
SDL_LATEST=${SDL[${#SDL[@]} - 1]}
if [[ -d "${SDL_LATEST}" ]]; then
CONFIGURE_EXTRA_PARAMS+=("--with-sdl=${SDL_LATEST}")
fi
SDKPATH=$(xcrun -sdk macosx --show-sdk-path)
ARCH="x86_64"
CFLAGS="-isysroot $SDKPATH -mmacosx-version-min=11 -DPJ_SDK_NAME=\"\\\"$(basename "$SDKPATH")\\\"\" -arch ${ARCH}" \
LDFLAGS="-isysroot $SDKPATH -framework AudioToolbox -framework Foundation -framework Network -framework Security -arch ${ARCH}" \
./aconfigure --prefix="${MACOS_X86_64_INSTALL_PREFIX}" --host="${ARCH}"-apple-darwin "${CONFIGURE_EXTRA_PARAMS[@]}"
make dep && make clean
arch -arch x86_64 make
make install
createLib "${MACOS_X86_64_INSTALL_PREFIX}/lib"
popd
#
# build fat lib for macos
#
mkdir -p "${MACOS_ARM64_X86_64_INSTALL_PREFIX}/lib"
lipo -create \
"${MACOS_ARM64_INSTALL_PREFIX}/lib/libpjproject.a" \
"${MACOS_X86_64_INSTALL_PREFIX}/lib/libpjproject.a" \
-output \
"${MACOS_ARM64_X86_64_INSTALL_PREFIX}/lib/libpjproject.a"
#
# debug build for macOS on arm64
#
rm -rf "${MACOS_ARM64_DEBUG_INSTALL_PREFIX}"
pushd pjproject
prepare NO YES
OPUS=(/opt/homebrew/Cellar/opus-apple-platforms/*/macos-arm64)
OPUS_LATEST=${OPUS[${#OPUS[@]} - 1]}
if [[ -d "${OPUS_LATEST}" ]]
then
CONFIGURE_EXTRA_PARAMS+=("--with-opus=${OPUS_LATEST}")
fi
SDL=("${THIRD_PARTY}/macos-arm64")
SDL_LATEST=${SDL[${#SDL[@]} - 1]}
if [[ -d "${SDL_LATEST}" ]]; then
CONFIGURE_EXTRA_PARAMS+=("--with-sdl=${SDL_LATEST}")
fi
SDKPATH=$(xcrun -sdk macosx --show-sdk-path)
ARCH="arm"
CFLAGS="-g -isysroot $SDKPATH -mmacosx-version-min=11 -DPJ_SDK_NAME=\"\\\"$(basename "$SDKPATH")\\\"\"" \
LDFLAGS="-isysroot $SDKPATH -framework AudioToolbox -framework Foundation -framework Network -framework Security" \
./aconfigure --prefix="${MACOS_ARM64_DEBUG_INSTALL_PREFIX}" --host="${ARCH}"-apple-darwin "${CONFIGURE_EXTRA_PARAMS[@]}"
make dep && make clean
make
make install
createLib "${MACOS_ARM64_DEBUG_INSTALL_PREFIX}/lib"
popd
#
# create xcframework
#
mkdir -p "$PREFIX"/lib
XCFRAMEWORK="$PREFIX/lib/libpjproject.xcframework"
rm -rf "$XCFRAMEWORK"
xcodebuild -create-xcframework \
-library "${IOS_ARM64_INSTALL_PREFIX}/lib/libpjproject.a" \
-headers "${IOS_ARM64_INSTALL_PREFIX}/include" \
-library "${IOS_ARM64_X86_64_SIMULATOR_INSTALL_PREFIX}/lib/libpjproject.a" \
-headers "${IOS_ARM64_SIMULATOR_INSTALL_PREFIX}/include" \
-library "${IOS_ARM64_X86_64_MACCATALYST_INSTALL_PREFIX}/lib/libpjproject.a" \
-headers "${IOS_ARM64_MACCATALYST_INSTALL_PREFIX}/include" \
-library "${MACOS_ARM64_X86_64_INSTALL_PREFIX}/lib/libpjproject.a" \
-headers "${MACOS_ARM64_INSTALL_PREFIX}/include" \
-output "${XCFRAMEWORK}"
#
# install the system version
#
cp -a "${PREFIX}/macOS-$(arch)/include" "${PREFIX}"
cp -a "${PREFIX}/macOS-$(arch)/lib" "${PREFIX}"
#
# create a sane pkg-config
#
PCFILE="${PREFIX}/lib/pkgconfig/libpjproject.pc"
cat << 'EOF' > "${PCFILE}"
Name: libpjproject
Description: Multimedia communication library
URL: http://www.pjsip.org
EOF
cat << EOF >> "${PCFILE}"
Version: ${PJPROJECT_VERSION}
Libs: -L/opt/homebrew/lib -lpjproject -framework Carbon -framework AppKit -framework Security -framework Network -framework AVFoundation -framework CoreMedia -framework CoreAudio -framework CoreVideo -framework AudioToolbox -framework VideoToolbox -framework Metal -framework IOKit
Cflags: -I/opt/homebrew/include -DPJ_AUTOCONF=1 -DPJ_IS_BIG_ENDIAN=0 -DPJ_IS_LITTLE_ENDIAN=1
EOF
#
# clean-up for now
#
rm -rf "${IOS_ARM64_X86_64_SIMULATOR_INSTALL_PREFIX}"
rm -rf "${IOS_ARM64_X86_64_MACCATALYST_INSTALL_PREFIX}"
rm -rf "${MACOS_ARM64_X86_64_INSTALL_PREFIX}"
pushd "${PREFIX}"
find . -not -path "./lib/*" -type d -name pkgconfig | xargs rm -rf
popd