-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompileAndBuildVLCKit.sh
More file actions
executable file
·545 lines (479 loc) · 14.7 KB
/
compileAndBuildVLCKit.sh
File metadata and controls
executable file
·545 lines (479 loc) · 14.7 KB
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
#!/bin/sh
# Copyright (C) Pierre d'Herbemont, 2010
# Copyright (C) Felix Paul Kühne, 2012-2021
set -e
BUILD_DEVICE=yes
BUILD_SIMULATOR=yes
BUILD_STATIC_FRAMEWORK=no
BUILD_DYNAMIC_FRAMEWORK=no
SDK_VERSION=`xcrun --sdk iphoneos --show-sdk-version`
SDK_MIN=9.0
VERBOSE=no
DISABLEDEBUG=no
CONFIGURATION="Debug"
NONETWORK=no
SKIPLIBVLCCOMPILATION=no
TVOS=no
MACOS=no
IOS=yes
BITCODE=no
OSVERSIONMINCFLAG=iphoneos
OSVERSIONMINLDFLAG=ios
ROOT_DIR=empty
FARCH="all"
if [ -z "$MAKEFLAGS" ]; then
MAKEFLAGS="-j$(sysctl -n machdep.cpu.core_count || nproc)";
fi
TESTEDHASH="9499ce0d13b15a3b35c1db0de3361c44cd82b8fa" # libvlc hash that this version of VLCKit is build on
usage()
{
cat << EOF
usage: $0 [-s] [-v] [-k sdk]
OPTIONS
-k Specify which sdk to use (see 'xcodebuild -showsdks', current: ${SDK})
-v Be more verbose
-s Build for simulator
-f Build framework for device and simulator
-r Disable Debug for Release
-n Skip script steps requiring network interaction
-l Skip libvlc compilation
-t Build for tvOS
-x Build for macOS / Mac OS X
-y Build universal static libraries
-b Enable bitcode
-a Build framework for specific arch (all|i386|x86_64|armv7|aarch64)
-e External VLC source path
EOF
}
get_actual_arch() {
if [ "$1" = "aarch64" ]; then
echo "arm64"
else
echo "$1"
fi
}
get_arch() {
if [ "$1" = "arm64" ]; then
echo "aarch64"
else
echo "$1"
fi
}
is_simulator_arch() {
if [ "$1" = "i386" -o "$1" = "x86_64" ];then
return 0
else
return 1
fi
}
spushd()
{
pushd "$1" 2>&1> /dev/null
}
spopd()
{
popd 2>&1> /dev/null
}
info()
{
local green="\033[1;32m"
local normal="\033[0m"
echo "[${green}info${normal}] $1"
}
buildxcodeproj()
{
local target="$2"
local PLATFORM="$3"
info "Building $1 ($target, ${CONFIGURATION}, $PLATFORM)"
local architectures=""
if [ "$FARCH" = "all" ];then
if [ "$TVOS" = "yes" ]; then
if [ "$PLATFORM" = "appletvsimulator" ]; then
architectures="x86_64"
else
architectures="arm64"
fi
fi
if [ "$IOS" = "yes" ]; then
if [ "$PLATFORM" = "iphonesimulator" ]; then
architectures="i386 x86_64"
else
architectures="armv7 arm64"
fi
fi
if [ "$MACOS" = "yes" ]; then
architectures="arm64 x86_64"
fi
else
architectures=`get_actual_arch $FARCH`
fi
local bitcodeflag=""
if [ "$BITCODE" = "yes" ]; then
bitcodeflag="BITCODE_GENERATION_MODE=bitcode"
fi
local verboseflag=""
if [ "$VERBOSE" = "yes" ]; then
verboseflag="-verbose"
fi
local defs="$GCC_PREPROCESSOR_DEFINITIONS"
xcodebuild -project "$1.xcodeproj" \
-target "$target" \
-sdk $PLATFORM$SDK \
-configuration ${CONFIGURATION} \
ARCHS="${architectures}" \
IPHONEOS_DEPLOYMENT_TARGET=${SDK_MIN} \
GCC_PREPROCESSOR_DEFINITIONS="$defs" \
${bitcodeflag} \
${verboseflag} \
> ${out}
}
buildLibVLC() {
ARCH="$1"
PLATFORM="$2"
if [ "$DISABLEDEBUG" = "yes" ]; then
DEBUGFLAG="--disable-debug"
else
DEBUGFLAG=""
fi
if [ "$VERBOSE" = "yes" ]; then
VERBOSEFLAG="--verbose"
else
VERBOSEFLAG=""
fi
if [ "$BITCODE" = "yes" ]; then
BITCODEFLAG="--enable-bitcode"
else
BITCODEFLAG=""
fi
info "Compiling ${ARCH} with SDK version ${SDK_VERSION}, platform ${PLATFORM}"
ACTUAL_ARCH=`get_actual_arch $ARCH`
BUILDDIR="${VLCROOT}/build-${PLATFORM}-${ACTUAL_ARCH}"
mkdir -p ${BUILDDIR}
spushd ${BUILDDIR}
../extras/package/apple/build.sh --arch=$ARCH --sdk=${PLATFORM}${SDK_VERSION} ${DEBUGFLAG} ${VERBOSEFLAG} ${BITCODEFLAG} ${MAKEFLAGS}
spopd # builddir
info "Finished compiling libvlc for ${ARCH} with SDK version ${SDK_VERSION}, platform ${PLATFORM}"
}
buildMobileKit() {
PLATFORM="$1"
if [ "$SKIPLIBVLCCOMPILATION" != "yes" ]; then
if [ "$FARCH" = "all" ];then
if [ "$TVOS" = "yes" ]; then
if [ "$PLATFORM" = "iphonesimulator" ]; then
buildLibVLC "x86_64" "appletvsimulator"
else
buildLibVLC "aarch64" "appletvos"
fi
fi
if [ "$MACOS" = "yes" ]; then
buildLibVLC "aarch64" "macosx"
buildLibVLC "x86_64" "macosx"
fi
if [ "$IOS" = "yes" ]; then
if [ "$PLATFORM" = "iphonesimulator" ]; then
buildLibVLC "i386" $PLATFORM
buildLibVLC "x86_64" $PLATFORM
else
buildLibVLC "armv7" $PLATFORM
buildLibVLC "aarch64" $PLATFORM
fi
fi
else
if [ "$FARCH" != "x86_64" -a "$FARCH" != "aarch64" -a "$FARCH" != "i386" \
-a "$FARCH" != "armv7" ];then
echo "*** Framework ARCH: ${FARCH} is invalid ***"
exit 1
fi
if (is_simulator_arch $FARCH);then
if [ "$TVOS" = "yes" ]; then
PLATFORM="appletvsimulator"
fi
if [ "$IOS" = "yes" ]; then
PLATFORM="iphonesimulator"
fi
if [ "$MACOS" = "yes" ]; then
PLATFORM="macosx"
fi
else
if [ "$TVOS" = "yes" ]; then
PLATFORM="appletvos"
fi
if [ "$IOS" = "yes" ]; then
PLATFORM="iphoneos"
fi
if [ "$MACOS" = "yes" ]; then
PLATFORM="macosx"
fi
fi
buildLibVLC $FARCH "$PLATFORM"
fi
fi
}
get_symbol()
{
echo "$1" | grep vlc_entry_$2|cut -d" " -f 3|sed 's/_vlc/vlc/'
}
build_universal_static_lib() {
PROJECT_DIR=`pwd`
OSSTYLE="$1"
info "building universal static libs for $OSSTYLE"
# remove old module list
rm -f $PROJECT_DIR/Headers/Internal/vlc-plugins-$OSSTYLE.h
touch $PROJECT_DIR/Headers/Internal/vlc-plugins-$OSSTYLE.h
spushd ${VLCROOT}
rm -rf install-$OSSTYLE
mkdir install-$OSSTYLE
spopd # vlc
VLCSTATICLIBS=""
VLCSTATICLIBRARYNAME="static-lib/libvlc-full-static.a"
VLCSTATICMODULELIST=""
# brute-force test the available architectures we could lipo
if [ -d ${VLCROOT}/build-${OSSTYLE}os-arm64 ];then
VLCSTATICLIBS+=" ${VLCROOT}/build-${OSSTYLE}os-arm64/${VLCSTATICLIBRARYNAME}"
VLCSTATICMODULELIST="${VLCROOT}/build-${OSSTYLE}os-arm64/static-lib/static-module-list.c"
fi
if [ -d ${VLCROOT}/build-${OSSTYLE}os-armv7 ];then
VLCSTATICLIBS+=" ${VLCROOT}/build-${OSSTYLE}os-armv7/${VLCSTATICLIBRARYNAME}"
VLCSTATICMODULELIST="${VLCROOT}/build-${OSSTYLE}os-armv7/static-lib/static-module-list.c"
fi
if [ -d ${VLCROOT}/build-${OSSTYLE}simulator-x86_64 ];then
VLCSTATICLIBS+=" ${VLCROOT}/build-${OSSTYLE}simulator-x86_64/${VLCSTATICLIBRARYNAME}"
VLCSTATICMODULELIST="${VLCROOT}/build-${OSSTYLE}simulator-x86_64/static-lib/static-module-list.c"
fi
if [ -d ${VLCROOT}/build-${OSSTYLE}simulator-i386 ];then
VLCSTATICLIBS+=" ${VLCROOT}/build-${OSSTYLE}simulator-i386/${VLCSTATICLIBRARYNAME}"
VLCSTATICMODULELIST="${VLCROOT}/build-${OSSTYLE}simulator-i386/static-lib/static-module-list.c"
fi
if [ -d ${VLCROOT}/build-${OSSTYLE}-x86_64 ];then
VLCSTATICLIBS+=" ${VLCROOT}/build-${OSSTYLE}-x86_64/${VLCSTATICLIBRARYNAME}"
VLCSTATICMODULELIST="${VLCROOT}/build-${OSSTYLE}-x86_64/static-lib/static-module-list.c"
fi
if [ -d ${VLCROOT}/build-${OSSTYLE}-arm64 ];then
VLCSTATICLIBS+=" ${VLCROOT}/build-${OSSTYLE}-arm64/${VLCSTATICLIBRARYNAME}"
VLCSTATICMODULELIST="${VLCROOT}/build-${OSSTYLE}-arm64/static-lib/static-module-list.c"
fi
spushd ${VLCROOT}
lipo $VLCSTATICLIBS -create -output install-$OSSTYLE/libvlc-full-static.a
cp $VLCSTATICMODULELIST $PROJECT_DIR/Headers/Internal/vlc-plugins-$OSSTYLE.h
spopd # VLCROOT
}
while getopts "hvsfbrxntlk:a:e:" OPTION
do
case $OPTION in
h)
usage
exit 1
;;
v)
VERBOSE=yes
;;
s)
BUILD_DEVICE=no
BUILD_SIMULATOR=yes
BUILD_STATIC_FRAMEWORK=no
;;
f)
BUILD_DEVICE=yes
BUILD_SIMULATOR=yes
BUILD_STATIC_FRAMEWORK=yes
;;
r) CONFIGURATION="Release"
DISABLEDEBUG=yes
;;
n)
NONETWORK=yes
;;
l)
SKIPLIBVLCCOMPILATION=yes
;;
k)
SDK=$OPTARG
;;
a)
BUILD_DEVICE=yes
BUILD_SIMULATOR=yes
BUILD_STATIC_FRAMEWORK=yes
FARCH=$OPTARG
;;
b)
BITCODE=yes
;;
t)
TVOS=yes
IOS=no
BITCODE=yes
SDK_VERSION=`xcrun --sdk appletvos --show-sdk-version`
SDK_MIN=10.2
OSVERSIONMINCFLAG=tvos
OSVERSIONMINLDFLAG=tvos
;;
x)
MACOS=yes
IOS=no
BITCODE=no
SDK_VERSION=`xcrun --sdk macosx --show-sdk-version`
SDK_MIN=10.11
OSVERSIONMINCFLAG=macosx
OSVERSIONMINLDFLAG=macosx
BUILD_DEVICE=yes
BUILD_DYNAMIC_FRAMEWORK=yes
BUILD_STATIC_FRAMEWORK=no
;;
e)
VLCROOT=$OPTARG
;;
?)
usage
exit 1
;;
esac
done
shift $(($OPTIND - 1))
out="/dev/null"
if [ "$VERBOSE" = "yes" ]; then
out="/dev/stdout"
fi
if [ "x$1" != "x" ]; then
usage
exit 1
fi
# Get root dir
spushd .
ROOT_DIR=`pwd`
spopd
if [ "$VLCROOT" = "" ]; then
VLCROOT=${ROOT_DIR}/libvlc/vlc
info "Preparing build dirs"
mkdir -p libvlc
spushd libvlc
if [ "$NONETWORK" != "yes" ]; then
if ! [ -e vlc ]; then
git clone https://github.com/iOSDevLog/vlc.git vlc
info "Applying patches to vlc.git"
cd vlc
git checkout -B localBranch ${TESTEDHASH}
git branch --set-upstream-to=origin/master localBranch
git am ${ROOT_DIR}/libvlc/patches/*.patch
if [ $? -ne 0 ]; then
git am --abort
info "Applying the patches failed, aborting git-am"
exit 1
fi
cd ..
else
cd vlc
git fetch --all
git reset --hard ${TESTEDHASH}
git am ${ROOT_DIR}/libvlc/patches/*.patch
cd ..
fi
fi
spopd
fi
fetch_python3_path() {
PYTHON3_PATH=$(echo /Library/Frameworks/Python.framework/Versions/3.*/bin | awk '{print $1;}')
if [ ! -d "${PYTHON3_PATH}" ]; then
PYTHON3_PATH=""
fi
}
#
# Build time
#
out="/dev/null"
if [ "$VERBOSE" = "yes" ]; then
out="/dev/stdout"
fi
if [ "$SKIPLIBVLCCOMPILATION" != "yes" ]; then
info "Building tools"
fetch_python3_path
export PATH="${PYTHON3_PATH}:${VLCROOT}/extras/tools/build/bin:${VLCROOT}/contrib/${TARGET}/bin:$VLC_PATH:/usr/bin:/bin:/usr/sbin:/sbin"
spushd ${VLCROOT}/extras/tools
./bootstrap
make
make .buildgas
make .buildxz
make .buildtar
make .buildmeson
make .buildninja
spopd #${VLCROOT}/extras/tools
fi
if [ "$BUILD_DEVICE" != "no" ]; then
buildMobileKit iphoneos
fi
if [ "$BUILD_SIMULATOR" != "no" ]; then
buildMobileKit iphonesimulator
fi
DEVICEARCHS=""
SIMULATORARCHS=""
if [ "$TVOS" = "yes" ]; then
build_universal_static_lib "appletv"
fi
if [ "$MACOS" = "yes" ]; then
build_universal_static_lib "macosx"
fi
if [ "$IOS" = "yes" ]; then
build_universal_static_lib "iphone"
fi
info "all done"
if [ "$BUILD_STATIC_FRAMEWORK" != "no" ]; then
if [ "$TVOS" = "yes" ]; then
info "Building static TVVLCKit.framework"
lipo_libs=""
platform=""
if [ "$FARCH" = "all" ] || (! is_simulator_arch $FARCH);then
platform="appletvos"
buildxcodeproj VLCKit "TVVLCKit" ${platform}
lipo_libs="$lipo_libs ${CONFIGURATION}-appletvos/libTVVLCKit.a"
fi
if [ "$FARCH" = "all" ] || (is_simulator_arch $ARCH);then
platform="appletvsimulator"
buildxcodeproj VLCKit "TVVLCKit" ${platform}
lipo_libs="$lipo_libs ${CONFIGURATION}-appletvsimulator/libTVVLCKit.a"
fi
# Assumes both platforms were built currently
spushd build
rm -rf TVVLCKit.framework && \
mkdir TVVLCKit.framework && \
lipo -create ${lipo_libs} -o TVVLCKit.framework/TVVLCKit && \
chmod a+x TVVLCKit.framework/TVVLCKit && \
cp -pr ${CONFIGURATION}-${platform}/TVVLCKit TVVLCKit.framework/Headers
cp -pr ${CONFIGURATION}-${platform}/Modules TVVLCKit.framework/Modules
cp -pr ${PROJECT_DIR}/Resources/Info.plist TVVLCKit.framework/
spopd # build
info "Build of static TVVLCKit.framework completed"
fi
if [ "$IOS" = "yes" ]; then
info "Building static MobileVLCKit.framework"
lipo_libs=""
platform=""
if [ "$FARCH" = "all" ] || (! is_simulator_arch $FARCH);then
platform="iphoneos"
buildxcodeproj VLCKit "MobileVLCKit" ${platform}
lipo_libs="$lipo_libs ${CONFIGURATION}-iphoneos/libMobileVLCKit.a"
fi
if [ "$FARCH" = "all" ] || (is_simulator_arch $ARCH);then
platform="iphonesimulator"
buildxcodeproj VLCKit "MobileVLCKit" ${platform}
lipo_libs="$lipo_libs ${CONFIGURATION}-iphonesimulator/libMobileVLCKit.a"
fi
# Assumes both platforms were built currently
spushd build
rm -rf MobileVLCKit.framework && \
mkdir MobileVLCKit.framework && \
lipo -create ${lipo_libs} -o MobileVLCKit.framework/MobileVLCKit && \
chmod a+x MobileVLCKit.framework/MobileVLCKit && \
cp -pr ${CONFIGURATION}-${platform}/MobileVLCKit MobileVLCKit.framework/Headers
cp -pr ${CONFIGURATION}-${platform}/Modules MobileVLCKit.framework/Modules
cp -pr ${PROJECT_DIR}/Resources/Info.plist MobileVLCKit.framework/
spopd # build
info "Build of static MobileVLCKit.framework completed"
fi
fi
if [ "$BUILD_DYNAMIC_FRAMEWORK" != "no" ]; then
if [ "$MACOS" = "yes" ]; then
CURRENT_DIR=`pwd`
info "Building VLCKit.framework in ${CURRENT_DIR}"
buildxcodeproj VLCKit "VLCKit" "macosx"
info "Build of VLCKit.framework completed"
fi
fi