]> git.sesse.net Git - vlc/blob - extras/package/ios/build.sh
9a5aed230d752286274db1f685120578ae24afd9
[vlc] / extras / package / ios / build.sh
1 #!/bin/sh
2 set -e
3
4 PLATFORM=OS
5 VERBOSE=no
6 DEBUG=no
7 SDK_VERSION=`xcrun --sdk iphoneos --show-sdk-version`
8 SDK_MIN=6.1
9 SIXTYFOURBIT_SDK_MIN=7.0
10 ARCH=armv7
11 SCARY=yes
12
13 usage()
14 {
15 cat << EOF
16 usage: $0 [-s] [-d] [-v] [-k sdk]
17
18 OPTIONS
19    -k <sdk version>      Specify which sdk to use ('xcodebuild -showsdks', current: ${SDK_VERSION})
20    -s            Build for simulator
21    -a <arch>     Specify which arch to use (current: ${ARCH})
22    -d            Enable debug
23    -v            Enable verbose command-line output
24    -w            Build a limited stack of non-scary libraries only
25 EOF
26 }
27
28 spushd()
29 {
30     pushd "$1" 2>&1> /dev/null
31 }
32
33 spopd()
34 {
35     popd 2>&1> /dev/null
36 }
37
38 info()
39 {
40     local blue="\033[1;34m"
41     local normal="\033[0m"
42     echo "[${blue}info${normal}] $1"
43 }
44
45 while getopts "hvwdsk:a:" OPTION
46 do
47      case $OPTION in
48          h)
49              usage
50              exit 1
51              ;;
52          v)
53              VERBOSE=yes
54              ;;
55          s)
56              PLATFORM=Simulator
57              ;;
58          d)
59              DEBUG=yes
60              ;;
61          w)
62              SCARY=no
63              ;;
64          k)
65              SDK_VERSION=$OPTARG
66              ;;
67          a)
68              ARCH=$OPTARG
69              ;;
70          ?)
71              usage
72              exit 1
73              ;;
74      esac
75 done
76 shift $(($OPTIND - 1))
77
78 if [ "x$1" != "x" ]; then
79     usage
80     exit 1
81 fi
82
83 out="/dev/null"
84 if [ "$VERBOSE" = "yes" ]; then
85    out="/dev/stdout"
86 fi
87
88 info "Building libvlc for iOS"
89
90 TARGET="${ARCH}-apple-darwin11"
91
92 # apple doesn't call AArch64 that way, but arm64 (a contrario to all libraries)
93 # so we need to translate it..
94 if [ "$ARCH" = "aarch64" ]; then
95         ACTUAL_ARCH="arm64"
96 else
97         ACTUAL_ARCH="$ARCH"
98 fi
99
100 if [ "$DEBUG" = "yes" ]; then
101     OPTIM="-O0 -g"
102 else
103     OPTIM="-O3 -g"
104 fi
105
106 info "Using ${ARCH} with SDK version ${SDK_VERSION}"
107
108 THIS_SCRIPT_PATH=`pwd`/$0
109
110 spushd `dirname ${THIS_SCRIPT_PATH}`/../../..
111 VLCROOT=`pwd` # Let's make sure VLCROOT is an absolute path
112 spopd
113
114 if test -z "$SDKROOT"
115 then
116     SDKROOT=`xcode-select -print-path`/Platforms/iPhone${PLATFORM}.platform/Developer/SDKs/iPhone${PLATFORM}${SDK_VERSION}.sdk
117     echo "SDKROOT not specified, assuming $SDKROOT"
118 fi
119
120 if [ ! -d "${SDKROOT}" ]
121 then
122     echo "*** ${SDKROOT} does not exist, please install required SDK, or set SDKROOT manually. ***"
123     exit 1
124 fi
125
126 BUILDDIR="${VLCROOT}/build-ios-${PLATFORM}/${ACTUAL_ARCH}"
127
128 PREFIX="${VLCROOT}/install-ios-${PLATFORM}/${ACTUAL_ARCH}"
129
130 export PATH="${VLCROOT}/extras/tools/build/bin:${VLCROOT}/contrib/${TARGET}/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin"
131
132 info "Building tools"
133 spushd "${VLCROOT}/extras/tools"
134 ./bootstrap
135 make && make .gas
136 spopd
137
138 info "Building contrib for iOS in '${VLCROOT}/contrib/iPhone${PLATFORM}-${ARCH}'"
139
140 # The contrib will read the following
141 export AR="xcrun ar"
142
143 export RANLIB="xcrun ranlib"
144 export CC="xcrun clang"
145 export OBJC="xcrun clang"
146 export CXX="xcrun clang++"
147 export LD="xcrun ld"
148 export STRIP="xcrun strip"
149
150 export PLATFORM=$PLATFORM
151 export SDK_VERSION=$SDK_VERSION
152
153 export CFLAGS="-isysroot ${SDKROOT} -arch ${ACTUAL_ARCH} ${OPTIM}"
154
155 if [ "$PLATFORM" = "OS" ]; then
156 if [ "$ARCH" != "aarch64" ]; then
157 export CFLAGS="${CFLAGS} -mcpu=cortex-a8 -miphoneos-version-min=${SDK_MIN}"
158 else
159 export CFLAGS="${CFLAGS} -miphoneos-version-min=${SIXTYFOURBIT_SDK_MIN}"
160 fi
161 else
162 export CFLAGS="${CFLAGS} -miphoneos-version-min=${SIXTYFOURBIT_SDK_MIN}"
163 fi
164
165 export CXXFLAGS="${CFLAGS} -stdlib=libstdc++"
166
167 export CPPFLAGS="${CFLAGS}"
168
169 export CPP="xcrun cc -E"
170 export CXXCPP="xcrun c++ -E"
171
172 export BUILDFORIOS="yes"
173
174 if [ "$PLATFORM" = "Simulator" ]; then
175     # Use the new ABI on simulator, else we can't build
176     export OBJCFLAGS="-fobjc-abi-version=2 -fobjc-legacy-dispatch ${OBJCFLAGS}"
177 fi
178
179 export LDFLAGS="-L${SDKROOT}/usr/lib -arch ${ACTUAL_ARCH} -isysroot ${SDKROOT}"
180
181 if [ "$PLATFORM" = "OS" ]; then
182     EXTRA_CFLAGS="-arch ${ACTUAL_ARCH}"
183     EXTRA_LDFLAGS="-arch ${ACTUAL_ARCH}"
184 if [ "$ARCH" != "aarch64" ]; then
185     EXTRA_CFLAGS+=" -mcpu=cortex-a8"
186     EXTRA_CFLAGS+=" -miphoneos-version-min=${SDK_MIN}"
187     EXTRA_LDFLAGS+=" -Wl,-ios_version_min,${SDK_MIN}"
188     export LDFLAGS="${LDFLAGS} -Wl,-ios_version_min,${SDK_MIN}"
189 else
190     EXTRA_CFLAGS+=" -miphoneos-version-min=${SIXTYFOURBIT_SDK_MIN}"
191     EXTRA_LDFLAGS+=" -Wl,-ios_version_min,${SIXTYFOURBIT_SDK_MIN}"
192     export LDFLAGS="${LDFLAGS} -Wl,-ios_version_min,${SIXTYFOURBIT_SDK_MIN}"
193 fi
194 else
195     EXTRA_CFLAGS="-arch ${ARCH}"
196     EXTRA_CFLAGS+=" -miphoneos-version-min=${SIXTYFOURBIT_SDK_MIN}"
197     EXTRA_LDFLAGS=" -Wl,-ios_version_min,${SIXTYFOURBIT_SDK_MIN}"
198     export LDFLAGS="${LDFLAGS} -Wl-ios_version_min,${SIXTYFOURBIT_SDK_MIN}"
199 fi
200
201
202 info "LD FLAGS SELECTED = '${LDFLAGS}'"
203
204 spushd ${VLCROOT}/contrib
205
206 echo ${VLCROOT}
207 mkdir -p "${VLCROOT}/contrib/iPhone${PLATFORM}-${ARCH}"
208 cd "${VLCROOT}/contrib/iPhone${PLATFORM}-${ARCH}"
209
210 if [ "$PLATFORM" = "OS" ]; then
211     export AS="gas-preprocessor.pl ${CC}"
212     export ASCPP="gas-preprocessor.pl ${CC}"
213     export CCAS="gas-preprocessor.pl ${CC}"
214     if [ "$ARCH" = "aarch64" ]; then
215         export GASPP_FIX_XCODE5=1
216     fi
217 else
218     export ASCPP="xcrun as"
219 fi
220
221 ../bootstrap --build=x86_64-apple-darwin11 --host=${TARGET} --prefix=${VLCROOT}/contrib/${TARGET}-${ARCH} --disable-gpl \
222     --disable-disc --disable-sout \
223     --disable-sdl \
224     --disable-SDL_image \
225     --disable-iconv \
226     --enable-zvbi \
227     --disable-kate \
228     --disable-caca \
229     --disable-gettext \
230     --disable-mpcdec \
231     --disable-upnp \
232     --disable-gme \
233     --disable-tremor \
234     --enable-vorbis \
235     --disable-sidplay2 \
236     --disable-samplerate \
237     --disable-goom \
238     --disable-vncserver \
239     --disable-orc \
240     --disable-schroedinger \
241     --disable-libmpeg2 \
242     --disable-chromaprint \
243     --disable-mad \
244     --enable-fribidi \
245     --enable-libxml2 \
246     --enable-freetype2 \
247     --enable-ass \
248     --disable-fontconfig \
249     --disable-gpg-error \
250     --disable-lua \
251     --disable-protobuf \
252     --disable-aribb24 \
253     --disable-aribb25 \
254     --enable-vpx \
255     --enable-taglib > ${out}
256
257 echo "EXTRA_CFLAGS += ${EXTRA_CFLAGS}" >> config.mak
258 echo "EXTRA_LDFLAGS += ${EXTRA_LDFLAGS}" >> config.mak
259 make fetch
260 make
261 spopd
262
263 info "Bootstraping vlc"
264 pwd
265 info "VLCROOT = ${VLCROOT}"
266 if ! [ -e ${VLCROOT}/configure ]; then
267     ${VLCROOT}/bootstrap  > ${out}
268 fi
269
270 info "Bootstraping vlc finished"
271
272 if [ ".$PLATFORM" != ".Simulator" ]; then
273     # FIXME - Do we still need this?
274     export AVCODEC_CFLAGS="-I${PREFIX}/include "
275     export AVCODEC_LIBS="-L${PREFIX}/lib -lavcodec -lavutil -lz"
276     export AVFORMAT_CFLAGS="-I${PREFIX}/include"
277     export AVFORMAT_LIBS="-L${PREFIX}/lib -lavcodec -lz -lavutil -lavformat"
278 fi
279
280 mkdir -p ${BUILDDIR}
281 spushd ${BUILDDIR}
282
283 info ">> --prefix=${PREFIX} --host=${TARGET}"
284
285 if [ "$DEBUG" = "yes" ]; then
286     DEBUGFLAG="--enable-debug"
287 else
288     DEBUGFLAG="--disable-debug"
289 fi
290
291 if [ "$SCARY" = "yes" ]; then
292         SCARYFLAG="--enable-dvbpsi --enable-avcodec"
293 else
294         SCARYFLAG="--disable-dca --disable-dvbpsi --disable-avcodec --disable-avformat --disable-zvbi --enable-vpx"
295 fi
296
297 # Run configure only upon changes.
298 if [ "${VLCROOT}/configure" -nt config.log -o \
299      "${THIS_SCRIPT_PATH}" -nt config.log ]; then
300 ${VLCROOT}/configure \
301     --prefix="${PREFIX}" \
302     --host="${TARGET}" \
303     --with-contrib="${VLCROOT}/contrib/${TARGET}-${ARCH}" \
304     --enable-static \
305     ${DEBUGFLAG} \
306     ${SCARYFLAG} \
307     --disable-macosx \
308     --disable-macosx-dialog-provider \
309     --disable-macosx-qtkit \
310     --disable-macosx-eyetv \
311     --disable-macosx-vlc-app \
312     --disable-macosx-avfoundation \
313     --disable-audioqueue \
314     --disable-shared \
315     --enable-macosx-quartztext \
316     --enable-mkv \
317     --enable-opus \
318     --disable-sout \
319     --disable-faad \
320     --disable-lua \
321     --disable-a52 \
322     --enable-fribidi \
323     --disable-qt --disable-skins2 \
324     --disable-vcd \
325     --disable-vlc \
326     --disable-vlm \
327     --disable-httpd \
328     --disable-nls \
329     --disable-glx \
330     --disable-sse \
331     --enable-neon \
332     --disable-notify \
333     --enable-live555 \
334     --enable-realrtsp \
335     --enable-swscale \
336     --disable-projectm \
337     --enable-libass \
338     --enable-libxml2 \
339     --disable-goom \
340     --disable-dvdread \
341     --disable-dvdnav \
342     --disable-bluray \
343     --disable-linsys \
344     --disable-libva \
345     --disable-gme \
346     --disable-tremor \
347     --enable-vorbis \
348     --disable-fluidsynth \
349     --disable-jack \
350     --disable-pulse \
351     --disable-mtp \
352     --enable-ogg \
353     --enable-speex \
354     --enable-theora \
355     --enable-flac \
356     --disable-screen \
357     --enable-freetype \
358     --enable-taglib \
359     --disable-mmx \
360     --disable-addonmanagermodules \
361     --disable-mad > ${out} # MMX and SSE support requires llvm which is broken on Simulator
362 fi
363
364 CORE_COUNT=`sysctl -n machdep.cpu.core_count`
365 let MAKE_JOBS=$CORE_COUNT+1
366
367 info "Building libvlc"
368 make -j$MAKE_JOBS > ${out}
369
370 info "Installing libvlc"
371 make install > ${out}
372
373 find ${PREFIX}/lib/vlc/plugins -name *.a -type f -exec cp '{}' ${PREFIX}/lib/vlc/plugins \;
374 rm -rf "${PREFIX}/contribs"
375 cp -R "${VLCROOT}/contrib/${TARGET}-${ARCH}" "${PREFIX}/contribs"
376
377 info "Removing unneeded modules"
378 blacklist="
379 stats
380 access_bd
381 shm
382 access_imem
383 oldrc
384 real
385 hotkeys
386 gestures
387 dynamicoverlay
388 rss
389 ball
390 marq
391 magnify
392 audiobargraph_
393 clone
394 mosaic
395 osdmenu
396 puzzle
397 mediadirs
398 t140
399 ripple
400 motion
401 sharpen
402 grain
403 posterize
404 mirror
405 wall
406 scene
407 blendbench
408 psychedelic
409 alphamask
410 netsync
411 audioscrobbler
412 motiondetect
413 motionblur
414 export
415 smf
416 podcast
417 bluescreen
418 erase
419 stream_filter_record
420 speex_resampler
421 remoteosd
422 magnify
423 gradient
424 tospdif
425 dtstofloat32
426 logger
427 visual
428 fb
429 aout_file
430 dummy
431 invert
432 sepia
433 wave
434 hqdn3d
435 headphone_channel_mixer
436 gaussianblur
437 gradfun
438 extract
439 colorthres
440 antiflicker
441 anaglyph
442 remap
443 oldmovie
444 vhs
445 demuxdump
446 fingerprinter
447 "
448
449 if [ "$SCARY" = "no" ]; then
450 blacklist="${blacklist}
451 dts
452 dvbsub
453 svcd
454 hevc
455 packetizer_mlp
456 a52
457 vc1
458 uleaddvaudio
459 librar
460 libvoc
461 avio
462 chorus_flanger
463 smooth
464 cvdsub
465 libmod
466 libdash
467 libmpgv
468 dolby_surround
469 mpeg_audio"
470 fi
471
472 echo ${blacklist}
473
474 for i in ${blacklist}
475 do
476     find ${PREFIX}/lib/vlc/plugins -name *$i* -type f -exec rm '{}' \;
477 done
478
479 popd