forked from strukturag/VLCKit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
buildMobileVLCKit.sh
executable file
·419 lines (352 loc) · 9.36 KB
/
buildMobileVLCKit.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
#!/bin/sh
# Copyright (C) Pierre d'Herbemont, 2010
# Copyright (C) Felix Paul Kühne, 2012-2015
set -e
BUILD_DEVICE=yes
BUILD_SIMULATOR=yes
BUILD_STATIC_FRAMEWORK=no
SDK=`xcrun --sdk iphoneos --show-sdk-version`
SDK_MIN=7.0
VERBOSE=no
CONFIGURATION="Release"
NONETWORK=no
SKIPLIBVLCCOMPILATION=no
SCARY=yes
TESTEDHASH=bfd01076
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
-d Enable Debug
-n Skip script steps requiring network interaction
-l Skip libvlc compilation
-w Build a limited stack of non-scary libraries only
-y Build universal static libraries
EOF
}
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 [ "$PLATFORM" = "iphonesimulator" ]; then
architectures="i386 x86_64"
else
architectures="armv7 armv7s arm64"
fi
local defs="$GCC_PREPROCESSOR_DEFINITIONS"
if [ "$SCARY" = "no" ]; then
defs="$defs NOSCARYCODECS"
fi
xcodebuild -project "$1.xcodeproj" \
-target "$target" \
-sdk $PLATFORM$SDK \
-configuration ${CONFIGURATION} \
ARCHS="${architectures}" \
IPHONEOS_DEPLOYMENT_TARGET=${SDK_MIN} \
GCC_PREPROCESSOR_DEFINITIONS="$defs" \
> ${out}
}
while getopts "hvwsfdnlk:" 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
;;
d) CONFIGURATION="Debug"
;;
w) SCARY="no"
;;
n)
NONETWORK=yes
;;
l)
SKIPLIBVLCCOMPILATION=yes
;;
k)
SDK=$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 .
aspen_root_dir=`pwd`
spopd
info "Preparing build dirs"
mkdir -p MobileVLCKit/ImportedSources
spushd MobileVLCKit/ImportedSources
if [ "$NONETWORK" != "yes" ]; then
if ! [ -e vlc ]; then
git clone git://git.videolan.org/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 ../../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 pull --rebase
git reset --hard ${TESTEDHASH}
git am ../../patches/*.patch
cd ..
fi
fi
spopd
#
# Build time
#
buildMobileKit() {
PLATFORM="$1"
info "Building for $PLATFORM"
spushd MobileVLCKit/ImportedSources
if [ "$SKIPLIBVLCCOMPILATION" != "yes" ]; then
spushd vlc/extras/package/ios
info "Building vlc"
args=""
if [ "$VERBOSE" = "yes" ]; then
args="${args} -v"
fi
if [ "$CONFIGURATION" = "Debug" ]; then
args="${args} -d"
fi
if [ "$SCARY" = "no" ]; then
args="${args} -w"
fi
if [ "$PLATFORM" = "iphonesimulator" ]; then
args="${args} -s"
./build.sh -a i386 ${args} -k "${SDK}" && ./build.sh -a x86_64 ${args} -k "${SDK}"
else
./build.sh -a armv7 ${args} -k "${SDK}" && ./build.sh -a armv7s ${args} -k "${SDK}" && ./build.sh -a aarch64 ${args} -k "${SDK}"
fi
spopd
fi
spopd # MobileVLCKit/ImportedSources
info "Build for $PLATFORM completed"
}
if [ "$BUILD_DEVICE" != "no" ]; then
buildMobileKit iphoneos
fi
if [ "$BUILD_SIMULATOR" != "no" ]; then
buildMobileKit iphonesimulator
fi
DEVICEARCHS=""
SIMULATORARCHS=""
doVLCLipo() {
FILEPATH="$1"
FILE="$2"
PLUGIN="$3"
files=""
info "...$FILEPATH$FILE"
for i in $DEVICEARCHS
do
files="install-ios-OS/$i/lib/$FILEPATH$FILE $files"
done
for i in $SIMULATORARCHS
do
files="install-ios-Simulator/$i/lib/$FILEPATH$FILE $files"
done
if [ "$PLUGIN" != "no" ]; then
lipo $files -create -output install-ios/plugins/$FILE
else
lipo $files -create -output install-ios/core/$FILE
fi
}
doContribLipo() {
LIBNAME="$1"
files=""
info "...$LIBNAME"
for i in $DEVICEARCHS
do
if [ "$i" != "arm64" ]; then
files="contrib/$i-apple-darwin11-$i/lib/$LIBNAME $files"
else
files="contrib/aarch64-apple-darwin11-aarch64/lib/$LIBNAME $files"
fi
done
for i in $SIMULATORARCHS
do
files="contrib/$i-apple-darwin11-$i/lib/$LIBNAME $files"
done
lipo $files -create -output install-ios/contrib/$LIBNAME
}
get_symbol()
{
echo "$1" | grep vlc_entry_$2|cut -d" " -f 3|sed 's/_vlc/vlc/'
}
info "building universal static libs"
PROJECT_DIR=`pwd`
# remove old module list
rm -f $PROJECT_DIR/MobileVLCKit/vlc-plugins.h
rm -f $PROJECT_DIR/MobileVLCKit/vlc-plugins.xcconfig
spushd MobileVLCKit/ImportedSources/vlc
rm -rf install-ios
mkdir install-ios
mkdir install-ios/core
mkdir install-ios/contrib
mkdir install-ios/plugins
spopd # vlc
spushd MobileVLCKit/ImportedSources/vlc/install-ios-OS
for i in `ls .`
do
DEVICEARCHS="$DEVICEARCHS $i"
done
spopd # vlc-install-ios-OS
spushd MobileVLCKit/ImportedSources/vlc/install-ios-Simulator
for i in `ls .`
do
SIMULATORARCHS="$SIMULATORARCHS $i"
done
spopd # vlc-install-ios-Simulator
# arm64 got the lowest number of modules
VLCMODULES=""
spushd MobileVLCKit/ImportedSources/vlc/install-ios-OS/arm64/lib/vlc/plugins
for i in `ls *.a`
do
VLCMODULES="$i $VLCMODULES"
done
spopd # vlc/install-ios-OS/arm64/lib/vlc/plugins
# collect ARMv7/s specific neon modules
VLCNEONMODULES=""
spushd MobileVLCKit/ImportedSources/vlc/install-ios-OS/armv7/lib/vlc/plugins
for i in `ls *.a | grep neon`
do
VLCNEONMODULES="$i $VLCNEONMODULES"
done
spopd # vlc/install-ios-OS/armv7/lib/vlc/plugins
spushd MobileVLCKit/ImportedSources/vlc
# lipo all the vlc libraries and its plugins
doVLCLipo "" "libvlc.a" "no"
doVLCLipo "" "libvlccore.a" "no"
doVLCLipo "vlc/" "libcompat.a" "no"
for i in $VLCMODULES
do
doVLCLipo "vlc/plugins/" $i "yes"
done
# lipo contrib libraries
CONTRIBLIBS=""
spushd contrib/armv7-apple-darwin11-armv7/lib
for i in `ls *.a`
do
CONTRIBLIBS="$i $CONTRIBLIBS"
done
spopd # contrib/armv7-apple-darwin11-armv7/lib
for i in $CONTRIBLIBS
do
doContribLipo $i
done
# lipo the remaining NEON plugins
DEVICEARCHS="armv7 armv7s"
SIMULATORARCHS=""
for i in $VLCNEONMODULES
do
doVLCLipo "vlc/plugins/" $i "yes"
done
# create module list
info "creating module list"
echo "// This file is autogenerated by $(basename $0)\n\n" > $PROJECT_DIR/MobileVLCKit/vlc-plugins.h
echo "// This file is autogenerated by $(basename $0)\n\n" > $PROJECT_DIR/MobileVLCKit/vlc-plugins.xcconfig
# arm64 got the lowest number of modules
BUILTINS="const void *vlc_static_modules[] = {\n"; \
LDFLAGS=""
DEFINITIONS=""
# add contrib libraries to LDFLAGS
for file in $CONTRIBLIBS
do
LDFLAGS+="\$(PROJECT_DIR)/MobileVLCKit/ImportedSources/vlc/install-ios/contrib/$file "
done
for file in $VLCMODULES
do
symbols=$(nm -g -arch armv7 install-ios/plugins/$file)
entryname=$(get_symbol "$symbols" _)
DEFINITIONS+="int $entryname (int (*)(void *, void *, int, ...), void *);\n";
BUILTINS+=" $entryname,\n"
LDFLAGS+="\$(PROJECT_DIR)/MobileVLCKit/ImportedSources/vlc/install-ios/plugins/$file "
info "...$entryname"
done;
BUILTINS+="#ifdef __arm__\n"
DEFINITIONS+="#ifdef __arm__\n"
for file in $VLCNEONMODULES
do
symbols=$(nm -g -arch armv7 install-ios/plugins/$file)
entryname=$(get_symbol "$symbols" _)
DEFINITIONS+="int $entryname (int (*)(void *, void *, int, ...), void *);\n";
BUILTINS+=" $entryname,\n"
LDFLAGS+="\$(PROJECT_DIR)/MobileVLCKit/ImportedSources/vlc/install-ios/plugins/$file "
info "...$entryname"
done;
BUILTINS+="#endif\n"
DEFINITIONS+="#endif\n"
BUILTINS="$BUILTINS NULL\n};\n"
echo "$DEFINITIONS\n$BUILTINS" > $PROJECT_DIR/MobileVLCKit/vlc-plugins.h
echo "VLC_PLUGINS_LDFLAGS=$LDFLAGS" > $PROJECT_DIR/MobileVLCKit/vlc-plugins.xcconfig
spopd # vlc
info "all done"
if [ "$BUILD_STATIC_FRAMEWORK" != "no" ]; then
info "Building static MobileVLCKit.framework"
buildxcodeproj MobileVLCKit "MobileVLCKit" iphoneos
buildxcodeproj MobileVLCKit "MobileVLCKit" iphonesimulator
# Assumes both platforms were built currently
spushd build
rm -rf MobileVLCKit.framework && \
mkdir MobileVLCKit.framework && \
lipo -create Release-iphoneos/libMobileVLCKit.a \
Release-iphonesimulator/libMobileVLCKit.a \
-o MobileVLCKit.framework/MobileVLCKit && \
chmod a+x MobileVLCKit.framework/MobileVLCKit && \
cp -pr Release-iphoneos/include/MobileVLCKit MobileVLCKit.framework/Headers
spopd # build
info "Build of static MobileVLCKit.framework completed"
fi