buildMobileVLCKit.sh 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017
  1. #!/bin/sh
  2. # Copyright (C) Pierre d'Herbemont, 2010
  3. # Copyright (C) Felix Paul Kühne, 2012-2017
  4. set -e
  5. BUILD_DEVICE=yes
  6. BUILD_SIMULATOR=yes
  7. BUILD_STATIC_FRAMEWORK=no
  8. SDK_VERSION=`xcrun --sdk iphoneos --show-sdk-version`
  9. SDK_MIN=7.0
  10. VERBOSE=no
  11. DEBUG=no
  12. CONFIGURATION="Release"
  13. NONETWORK=no
  14. SKIPLIBVLCCOMPILATION=no
  15. SCARY=yes
  16. TVOS=no
  17. BITCODE=no
  18. OSVERSIONMINCFLAG=miphoneos-version-min
  19. OSVERSIONMINLDFLAG=ios_version_min
  20. ROOT_DIR=empty
  21. FARCH="all"
  22. TESTEDHASH=4d3db1203
  23. if [ -z "$MAKE_JOBS" ]; then
  24. CORE_COUNT=`sysctl -n machdep.cpu.core_count`
  25. let MAKE_JOBS=$CORE_COUNT+1
  26. fi
  27. usage()
  28. {
  29. cat << EOF
  30. usage: $0 [-s] [-v] [-k sdk]
  31. OPTIONS
  32. -k Specify which sdk to use (see 'xcodebuild -showsdks', current: ${SDK})
  33. -v Be more verbose
  34. -s Build for simulator
  35. -f Build framework for device and simulator
  36. -d Enable Debug
  37. -n Skip script steps requiring network interaction
  38. -l Skip libvlc compilation
  39. -t Build for tvOS
  40. -w Build a limited stack of non-scary libraries only
  41. -y Build universal static libraries
  42. -b Enable bitcode
  43. -a Build framework for specific arch (all|i386|x86_64|armv7|armv7s|aarch64)
  44. EOF
  45. }
  46. while getopts "hvwsfbdntlk:a:" OPTION
  47. do
  48. case $OPTION in
  49. h)
  50. usage
  51. exit 1
  52. ;;
  53. v)
  54. VERBOSE=yes
  55. ;;
  56. s)
  57. BUILD_DEVICE=no
  58. BUILD_SIMULATOR=yes
  59. BUILD_STATIC_FRAMEWORK=no
  60. ;;
  61. f)
  62. BUILD_DEVICE=yes
  63. BUILD_SIMULATOR=yes
  64. BUILD_STATIC_FRAMEWORK=yes
  65. ;;
  66. d) CONFIGURATION="Debug"
  67. DEBUG=yes
  68. ;;
  69. w) SCARY="no"
  70. ;;
  71. n)
  72. NONETWORK=yes
  73. ;;
  74. l)
  75. SKIPLIBVLCCOMPILATION=yes
  76. ;;
  77. k)
  78. SDK=$OPTARG
  79. ;;
  80. a)
  81. BUILD_DEVICE=yes
  82. BUILD_SIMULATOR=yes
  83. BUILD_STATIC_FRAMEWORK=yes
  84. FARCH=$OPTARG
  85. ;;
  86. b)
  87. BITCODE=yes
  88. ;;
  89. t)
  90. TVOS=yes
  91. BITCODE=yes
  92. SDK_VERSION=`xcrun --sdk appletvos --show-sdk-version`
  93. SDK_MIN=9.0
  94. OSVERSIONMINCFLAG=mtvos-version-min
  95. OSVERSIONMINLDFLAG=tvos_version_min
  96. ;;
  97. ?)
  98. usage
  99. exit 1
  100. ;;
  101. esac
  102. done
  103. shift $(($OPTIND - 1))
  104. out="/dev/null"
  105. if [ "$VERBOSE" = "yes" ]; then
  106. out="/dev/stdout"
  107. fi
  108. if [ "x$1" != "x" ]; then
  109. usage
  110. exit 1
  111. fi
  112. get_actual_arch() {
  113. if [ "$1" = "aarch64" ]; then
  114. echo "arm64"
  115. else
  116. echo "$1"
  117. fi
  118. }
  119. get_arch() {
  120. if [ "$1" = "arm64" ]; then
  121. echo "aarch64"
  122. else
  123. echo "$1"
  124. fi
  125. }
  126. is_simulator_arch() {
  127. if [ "$1" = "i386" -o "$1" = "x86_64" ];then
  128. return 0
  129. else
  130. return 1
  131. fi
  132. }
  133. spushd()
  134. {
  135. pushd "$1" 2>&1> /dev/null
  136. }
  137. spopd()
  138. {
  139. popd 2>&1> /dev/null
  140. }
  141. info()
  142. {
  143. local green="\033[1;32m"
  144. local normal="\033[0m"
  145. echo "[${green}info${normal}] $1"
  146. }
  147. buildxcodeproj()
  148. {
  149. local target="$2"
  150. local PLATFORM="$3"
  151. info "Building $1 ($target, ${CONFIGURATION}, $PLATFORM)"
  152. local architectures=""
  153. if [ "$FARCH" = "all" ];then
  154. if [ "$TVOS" != "yes" ]; then
  155. if [ "$PLATFORM" = "iphonesimulator" ]; then
  156. architectures="i386 x86_64"
  157. else
  158. architectures="armv7 armv7s arm64"
  159. fi
  160. else
  161. if [ "$PLATFORM" = "appletvsimulator" ]; then
  162. architectures="x86_64"
  163. else
  164. architectures="arm64"
  165. fi
  166. fi
  167. else
  168. architectures=`get_actual_arch $FARCH`
  169. fi
  170. local bitcodeflag=""
  171. if [ "$BITCODE" = "yes" ]; then
  172. bitcodeflag="BITCODE_GENERATION_MODE=bitcode"
  173. fi
  174. local defs="$GCC_PREPROCESSOR_DEFINITIONS"
  175. if [ "$SCARY" = "no" ]; then
  176. defs="$defs NOSCARYCODECS"
  177. fi
  178. xcodebuild -project "$1.xcodeproj" \
  179. -target "$target" \
  180. -sdk $PLATFORM$SDK \
  181. -configuration ${CONFIGURATION} \
  182. ARCHS="${architectures}" \
  183. IPHONEOS_DEPLOYMENT_TARGET=${SDK_MIN} \
  184. GCC_PREPROCESSOR_DEFINITIONS="$defs" \
  185. ${bitcodeflag} \
  186. > ${out}
  187. }
  188. # Get root dir
  189. spushd .
  190. ROOT_DIR=`pwd`
  191. spopd
  192. info "Preparing build dirs"
  193. mkdir -p libvlc
  194. spushd libvlc
  195. echo `pwd`
  196. if [ "$NONETWORK" != "yes" ]; then
  197. if ! [ -e vlc ]; then
  198. git clone git://git.videolan.org/vlc.git vlc
  199. info "Applying patches to vlc.git"
  200. cd vlc
  201. git checkout -B localBranch ${TESTEDHASH}
  202. git branch --set-upstream-to=origin/master localBranch
  203. git am ${ROOT_DIR}/Resources/MobileVLCKit/patches/*.patch
  204. if [ $? -ne 0 ]; then
  205. git am --abort
  206. info "Applying the patches failed, aborting git-am"
  207. exit 1
  208. fi
  209. cd ..
  210. else
  211. cd vlc
  212. git pull --rebase
  213. git reset --hard ${TESTEDHASH}
  214. git am ${ROOT_DIR}/Resources/MobileVLCKit/patches/*.patch
  215. cd ..
  216. fi
  217. fi
  218. spopd
  219. #
  220. # Build time
  221. #
  222. out="/dev/null"
  223. if [ "$VERBOSE" = "yes" ]; then
  224. out="/dev/stdout"
  225. fi
  226. if [ "$SKIPLIBVLCCOMPILATION" != "yes" ]; then
  227. info "Building tools"
  228. spushd ${ROOT_DIR}/libvlc/vlc/extras/tools
  229. ./bootstrap
  230. make
  231. make .gas
  232. spopd #libvlc/vlc/extras/tools
  233. fi
  234. buildLibVLC() {
  235. VERBOSE="$1"
  236. DEBUG="$2"
  237. SCARY="$3"
  238. BITCODE="$4"
  239. ARCH="$5"
  240. TVOS="$6"
  241. SDK_VERSION="$7"
  242. PLATFORM="$8"
  243. OSSTYLE=iPhone
  244. VLCROOT=${ROOT_DIR}/libvlc/vlc
  245. if [ "$DEBUG" = "yes" ]; then
  246. OPTIM="-O0 -g"
  247. else
  248. OPTIM="-O3 -g"
  249. fi
  250. if [ "$TVOS" = "yes" ]; then
  251. OSSTYLE=AppleTV
  252. fi
  253. ACTUAL_ARCH=`get_actual_arch $ARCH`
  254. info "Compiling ${ARCH} with SDK version ${SDK_VERSION}, platform ${PLATFORM}"
  255. SDKROOT=`xcode-select -print-path`/Platforms/${OSSTYLE}${PLATFORM}.platform/Developer/SDKs/${OSSTYLE}${PLATFORM}${SDK_VERSION}.sdk
  256. if [ ! -d "${SDKROOT}" ]
  257. then
  258. echo "*** ${SDKROOT} does not exist, please install required SDK, or set SDKROOT manually. ***"
  259. exit 1
  260. fi
  261. BUILDDIR="${VLCROOT}/build-${OSSTYLE}${PLATFORM}/${ACTUAL_ARCH}"
  262. PREFIX="${VLCROOT}/install-${OSSTYLE}${PLATFORM}/${ACTUAL_ARCH}"
  263. TARGET="${ARCH}-apple-darwin14"
  264. # clean the environment
  265. export PATH="${VLCROOT}/extras/tools/build/bin:${VLCROOT}/contrib/${TARGET}/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:${PATH}"
  266. export CFLAGS=""
  267. export CPPFLAGS=""
  268. export CXXFLAGS=""
  269. export OBJCFLAGS=""
  270. export LDFLAGS=""
  271. export PLATFORM=$PLATFORM
  272. export SDK_VERSION=$SDK_VERSION
  273. export VLCSDKROOT=$SDKROOT
  274. CFLAGS="-isysroot ${SDKROOT} -arch ${ACTUAL_ARCH} ${OPTIM}"
  275. OBJCFLAGS="${OPTIM}"
  276. if [ "$PLATFORM" = "OS" ]; then
  277. if [ "$ARCH" != "aarch64" ]; then
  278. CFLAGS+=" -mcpu=cortex-a8 -${OSVERSIONMINCFLAG}=${SDK_MIN}"
  279. else
  280. CFLAGS+=" -${OSVERSIONMINCFLAG}=${SDK_MIN}"
  281. fi
  282. else
  283. CFLAGS+=" -${OSVERSIONMINCFLAG}=${SDK_MIN}"
  284. fi
  285. if [ "$BITCODE" = "yes" ]; then
  286. CFLAGS+=" -fembed-bitcode"
  287. fi
  288. export CFLAGS="${CFLAGS}"
  289. export CXXFLAGS="${CFLAGS}"
  290. export CPPFLAGS="${CFLAGS}"
  291. export OBJCFLAGS="${OBJCFLAGS}"
  292. if [ "$PLATFORM" = "Simulator" ]; then
  293. # Use the new ABI on simulator, else we can't build
  294. export OBJCFLAGS="-fobjc-abi-version=2 -fobjc-legacy-dispatch ${OBJCFLAGS}"
  295. fi
  296. export LDFLAGS="-isysroot ${SDKROOT} -L${SDKROOT}/usr/lib -arch ${ACTUAL_ARCH}"
  297. if [ "$PLATFORM" = "OS" ]; then
  298. EXTRA_CFLAGS="-arch ${ACTUAL_ARCH}"
  299. EXTRA_LDFLAGS="-arch ${ACTUAL_ARCH}"
  300. if [ "$ARCH" != "aarch64" ]; then
  301. EXTRA_CFLAGS+=" -mcpu=cortex-a8"
  302. EXTRA_CFLAGS+=" -${OSVERSIONMINCFLAG}=${SDK_MIN}"
  303. EXTRA_LDFLAGS+=" -Wl,-${OSVERSIONMINLDFLAG},${SDK_MIN}"
  304. export LDFLAGS="${LDFLAGS} -Wl,-${OSVERSIONMINLDFLAG},${SDK_MIN}"
  305. else
  306. EXTRA_CFLAGS+=" -${OSVERSIONMINCFLAG}=${SDK_MIN}"
  307. EXTRA_LDFLAGS+=" -Wl,-${OSVERSIONMINLDFLAG},${SDK_MIN}"
  308. export LDFLAGS="${LDFLAGS} -Wl,-${OSVERSIONMINLDFLAG},${SDK_MIN}"
  309. fi
  310. else
  311. EXTRA_CFLAGS="-arch ${ARCH}"
  312. EXTRA_CFLAGS+=" -${OSVERSIONMINCFLAG}=${SDK_MIN}"
  313. EXTRA_LDFLAGS=" -Wl,-${OSVERSIONMINLDFLAG},${SDK_MIN}"
  314. export LDFLAGS="${LDFLAGS} -v -Wl,-${OSVERSIONMINLDFLAG},${SDK_MIN}"
  315. fi
  316. spushd ${VLCROOT}/contrib
  317. info "Compiling third-party libraries"
  318. mkdir -p "${VLCROOT}/contrib/${OSSTYLE}${PLATFORM}-${ARCH}"
  319. cd "${VLCROOT}/contrib/${OSSTYLE}${PLATFORM}-${ARCH}"
  320. if [ "$PLATFORM" = "OS" ]; then
  321. export AS="gas-preprocessor.pl ${CC}"
  322. export ASCPP="gas-preprocessor.pl ${CC}"
  323. export CCAS="gas-preprocessor.pl ${CC}"
  324. if [ "$ARCH" = "aarch64" ]; then
  325. export GASPP_FIX_XCODE5=1
  326. fi
  327. else
  328. export ASCPP="xcrun as"
  329. fi
  330. if [ "$TVOS" = "yes" ]; then
  331. TVOSOPTIONS="--disable-libarchive"
  332. else
  333. TVOSOPTIONS=""
  334. fi
  335. if [ "${TARGET}" = "x86_64-apple-darwin14" ];then
  336. BUILD=""
  337. else
  338. BUILD="--build=x86_64-apple-darwin14"
  339. fi
  340. # The following symbols do not exist on the minimal iOS version (7.0), so they are disabled
  341. # here. This allows compilation also with newer iOS SDKs
  342. # Added symbols between 7.x and 10.x
  343. export ac_cv_func_basename_r=no
  344. export ac_cv_func_clock_getres=no
  345. export ac_cv_func_clock_gettime=no
  346. export ac_cv_func_clock_settime=no
  347. export ac_cv_func_dirname_r=no
  348. export ac_cv_func_getentropy=no
  349. export ac_cv_func_mkostemp=no
  350. export ac_cv_func_mkostemps=no
  351. ../bootstrap ${BUILD} --host=${TARGET} --prefix=${VLCROOT}/contrib/${OSSTYLE}-${TARGET}-${ARCH} --disable-gpl \
  352. --disable-disc --disable-sout \
  353. --disable-sdl \
  354. --disable-SDL_image \
  355. --disable-iconv \
  356. --enable-zvbi \
  357. --disable-kate \
  358. --disable-caca \
  359. --disable-gettext \
  360. --disable-mpcdec \
  361. --disable-upnp \
  362. --disable-gme \
  363. --disable-tremor \
  364. --enable-vorbis \
  365. --disable-sidplay2 \
  366. --disable-samplerate \
  367. --disable-goom \
  368. --disable-vncserver \
  369. --disable-orc \
  370. --disable-schroedinger \
  371. --disable-libmpeg2 \
  372. --disable-chromaprint \
  373. --disable-mad \
  374. --enable-fribidi \
  375. --enable-libxml2 \
  376. --enable-freetype2 \
  377. --enable-ass \
  378. --disable-fontconfig \
  379. --disable-gpg-error \
  380. --disable-vncclient \
  381. --disable-gnutls \
  382. --disable-lua \
  383. --disable-luac \
  384. --disable-protobuf \
  385. --disable-aribb24 \
  386. --disable-aribb25 \
  387. --enable-vpx \
  388. --enable-libdsm \
  389. ${TVOSOPTIONS} \
  390. --enable-taglib > ${out}
  391. echo "EXTRA_CFLAGS += ${EXTRA_CFLAGS}" >> config.mak
  392. echo "EXTRA_LDFLAGS += ${EXTRA_LDFLAGS}" >> config.mak
  393. make fetch -j$MAKE_JOBS
  394. make -j$MAKE_JOBS > ${out}
  395. spopd # ${VLCROOT}/contrib
  396. if ! [ -e ${VLCROOT}/configure ]; then
  397. info "Bootstraping vlc"
  398. ${VLCROOT}/bootstrap > ${out}
  399. fi
  400. mkdir -p ${BUILDDIR}
  401. spushd ${BUILDDIR}
  402. if [ "$DEBUG" = "yes" ]; then
  403. DEBUGFLAG="--enable-debug"
  404. else
  405. export CFLAGS="${CFLAGS} -DNDEBUG"
  406. fi
  407. if [ "$SCARY" = "yes" ]; then
  408. SCARYFLAG="--enable-dvbpsi --enable-avcodec --disable-vpx"
  409. else
  410. SCARYFLAG="--disable-dca --disable-dvbpsi --disable-avcodec --disable-avformat --disable-zvbi --enable-vpx"
  411. fi
  412. if [ "$TVOS" != "yes" -a \( "$ARCH" = "armv7" -o "$ARCH" = "armv7s" \) ];then
  413. export ac_cv_arm_neon=yes
  414. else
  415. export ac_cv_arm_neon=no
  416. fi
  417. # Available but not authorized
  418. export ac_cv_func_daemon=no
  419. export ac_cv_func_fork=no
  420. if [ "${VLCROOT}/configure" -nt config.log -o \
  421. "${THIS_SCRIPT_PATH}" -nt config.log ]; then
  422. info "Configuring vlc"
  423. ${VLCROOT}/configure \
  424. --prefix="${PREFIX}" \
  425. --host="${TARGET}" \
  426. --with-contrib="${VLCROOT}/contrib/${OSSTYLE}-${TARGET}-${ARCH}" \
  427. --enable-static \
  428. ${DEBUGFLAG} \
  429. ${SCARYFLAG} \
  430. --disable-macosx \
  431. --disable-macosx-qtkit \
  432. --disable-macosx-avfoundation \
  433. --disable-shared \
  434. --enable-opus \
  435. --disable-faad \
  436. --disable-lua \
  437. --disable-a52 \
  438. --enable-fribidi \
  439. --disable-qt --disable-skins2 \
  440. --disable-vcd \
  441. --disable-vlc \
  442. --disable-vlm \
  443. --disable-httpd \
  444. --disable-nls \
  445. --disable-sse \
  446. --disable-notify \
  447. --enable-live555 \
  448. --enable-realrtsp \
  449. --enable-swscale \
  450. --disable-projectm \
  451. --enable-libass \
  452. --enable-libxml2 \
  453. --disable-goom \
  454. --disable-dvdread \
  455. --disable-dvdnav \
  456. --disable-bluray \
  457. --disable-linsys \
  458. --disable-libva \
  459. --disable-gme \
  460. --disable-tremor \
  461. --enable-vorbis \
  462. --disable-fluidsynth \
  463. --disable-jack \
  464. --disable-pulse \
  465. --disable-mtp \
  466. --enable-ogg \
  467. --enable-speex \
  468. --enable-theora \
  469. --enable-flac \
  470. --disable-screen \
  471. --enable-freetype \
  472. --enable-taglib \
  473. --disable-mmx \
  474. --disable-addonmanagermodules \
  475. --disable-mad > ${out}
  476. fi
  477. info "Building libvlc"
  478. make -j$MAKE_JOBS > ${out}
  479. info "Installing libvlc"
  480. make install > ${out}
  481. find ${PREFIX}/lib/vlc/plugins -name *.a -type f -exec cp '{}' ${PREFIX}/lib/vlc/plugins \;
  482. rm -rf "${PREFIX}/contribs"
  483. cp -R "${VLCROOT}/contrib/${OSSTYLE}-${TARGET}-${ARCH}" "${PREFIX}/contribs"
  484. info "Removing unneeded modules"
  485. blacklist="
  486. stats
  487. access_bd
  488. shm
  489. access_imem
  490. oldrc
  491. real
  492. hotkeys
  493. gestures
  494. dynamicoverlay
  495. rss
  496. ball
  497. marq
  498. magnify
  499. audiobargraph_
  500. clone
  501. mosaic
  502. osdmenu
  503. puzzle
  504. mediadirs
  505. t140
  506. ripple
  507. motion
  508. sharpen
  509. grain
  510. posterize
  511. mirror
  512. wall
  513. scene
  514. blendbench
  515. psychedelic
  516. alphamask
  517. netsync
  518. audioscrobbler
  519. motiondetect
  520. motionblur
  521. export
  522. smf
  523. podcast
  524. bluescreen
  525. erase
  526. stream_filter_record
  527. speex_resampler
  528. remoteosd
  529. magnify
  530. gradient
  531. logger
  532. visual
  533. fb
  534. aout_file
  535. dummy
  536. invert
  537. sepia
  538. wave
  539. hqdn3d
  540. headphone_channel_mixer
  541. gaussianblur
  542. gradfun
  543. extract
  544. colorthres
  545. antiflicker
  546. anaglyph
  547. remap
  548. oldmovie
  549. vhs
  550. demuxdump
  551. fingerprinter
  552. output_udp
  553. output_http
  554. output_livehttp
  555. libmux
  556. stream_out
  557. "
  558. if [ "$SCARY" = "no" ]; then
  559. blacklist="${blacklist}
  560. dts
  561. dvbsub
  562. svcd
  563. hevc
  564. packetizer_mlp
  565. a52
  566. vc1
  567. uleaddvaudio
  568. librar
  569. libvoc
  570. avio
  571. chorus_flanger
  572. smooth
  573. cvdsub
  574. libmod
  575. libdash
  576. libmpgv
  577. dolby_surround
  578. mpegaudio"
  579. fi
  580. echo ${blacklist}
  581. for i in ${blacklist}
  582. do
  583. find ${PREFIX}/lib/vlc/plugins -name *$i* -type f -exec rm '{}' \;
  584. done
  585. spopd
  586. }
  587. buildMobileKit() {
  588. PLATFORM="$1"
  589. if [ "$SKIPLIBVLCCOMPILATION" != "yes" ]; then
  590. if [ "$TVOS" = "yes" ]; then
  591. info "Building libvlc for tvOS"
  592. else
  593. info "Building libvlc for iOS"
  594. fi
  595. export AR=`xcrun -f ar`
  596. export RANLIB=`xcrun -f ranlib`
  597. export CC=`xcrun -f clang`
  598. export OBJC=`xcrun -f clang`
  599. export CXX=`xcrun -f clang++`
  600. export LD=`xcrun -f ld`
  601. export STRIP=`xcrun -f strip`
  602. export CPPFLAGS=-E
  603. export CXXCPPFLAGS=-E
  604. unset AS
  605. unset CCAS
  606. if [ "$FARCH" = "all" ];then
  607. if [ "$TVOS" = "yes" ]; then
  608. if [ "$PLATFORM" = "iphonesimulator" ]; then
  609. buildLibVLC $VERBOSE $DEBUG $SCARY $BITCODE "x86_64" $TVOS $SDK_VERSION "Simulator"
  610. else
  611. buildLibVLC $VERBOSE $DEBUG $SCARY $BITCODE "aarch64" $TVOS $SDK_VERSION "OS"
  612. fi
  613. else
  614. if [ "$PLATFORM" = "iphonesimulator" ]; then
  615. buildLibVLC $VERBOSE $DEBUG $SCARY $BITCODE "i386" $TVOS $SDK_VERSION "Simulator"
  616. buildLibVLC $VERBOSE $DEBUG $SCARY $BITCODE "x86_64" $TVOS $SDK_VERSION "Simulator"
  617. else
  618. buildLibVLC $VERBOSE $DEBUG $SCARY $BITCODE "armv7" $TVOS $SDK_VERSION "OS"
  619. buildLibVLC $VERBOSE $DEBUG $SCARY $BITCODE "armv7s" $TVOS $SDK_VERSION "OS"
  620. buildLibVLC $VERBOSE $DEBUG $SCARY $BITCODE "aarch64" $TVOS $SDK_VERSION "OS"
  621. fi
  622. fi
  623. else
  624. if [ "$FARCH" != "x86_64" -a "$FARCH" != "aarch64" -a "$FARCH" != "i386" \
  625. -a "$FARCH" != "armv7" -a "$FARCH" != "armv7s" ];then
  626. echo "*** Framework ARCH: ${FARCH} is invalid ***"
  627. exit 1
  628. fi
  629. local buildPlatform=""
  630. if [ "$PLATFORM" = "iphonesimulator" ]; then
  631. if [ "$FARCH" == "x86_64" -o "$FARCH" == "i386" ];then
  632. buildPlatform="Simulator"
  633. fi
  634. else
  635. if [ "$FARCH" == "armv7" -o "$FARCH" == "armv7s" -o "$FARCH" == "aarch64" ];then
  636. buildPlatform="OS"
  637. fi
  638. fi
  639. if [ ! -z "$buildPlatform" ];then
  640. buildLibVLC $VERBOSE $DEBUG $SCARY $BITCODE $FARCH $TVOS $SDK_VERSION $buildPlatform
  641. fi
  642. fi
  643. fi
  644. }
  645. if [ "$BUILD_DEVICE" != "no" ]; then
  646. buildMobileKit iphoneos
  647. fi
  648. if [ "$BUILD_SIMULATOR" != "no" ]; then
  649. buildMobileKit iphonesimulator
  650. fi
  651. DEVICEARCHS=""
  652. SIMULATORARCHS=""
  653. doVLCLipo() {
  654. FILEPATH="$1"
  655. FILE="$2"
  656. PLUGIN="$3"
  657. OSSTYLE="$4"
  658. files=""
  659. info "...$FILEPATH$FILE"
  660. for i in $DEVICEARCHS
  661. do
  662. actual_arch=`get_actual_arch $i`
  663. files="install-"$OSSTYLE"OS/$actual_arch/lib/$FILEPATH$FILE $files"
  664. done
  665. for i in $SIMULATORARCHS
  666. do
  667. actual_arch=`get_actual_arch $i`
  668. files="install-"$OSSTYLE"Simulator/$actual_arch/lib/$FILEPATH$FILE $files"
  669. done
  670. if [ "$PLUGIN" != "no" ]; then
  671. lipo $files -create -output install-$OSSTYLE/plugins/$FILE
  672. else
  673. lipo $files -create -output install-$OSSTYLE/core/$FILE
  674. fi
  675. }
  676. doContribLipo() {
  677. LIBNAME="$1"
  678. OSSTYLE="$2"
  679. files=""
  680. info "...$LIBNAME"
  681. for i in $DEVICEARCHS $SIMULATORARCHS
  682. do
  683. files="contrib/$OSSTYLE-$i-apple-darwin14-$i/lib/$LIBNAME $files"
  684. done
  685. lipo $files -create -output install-$OSSTYLE/contrib/$LIBNAME
  686. }
  687. get_symbol()
  688. {
  689. echo "$1" | grep vlc_entry_$2|cut -d" " -f 3|sed 's/_vlc/vlc/'
  690. }
  691. build_universal_static_lib() {
  692. PROJECT_DIR=`pwd`
  693. OSSTYLE="$1"
  694. info "building universal static libs for OS style $OSSTYLE"
  695. # remove old module list
  696. rm -f $PROJECT_DIR/Resources/MobileVLCKit/vlc-plugins-$OSSTYLE.h
  697. rm -f $PROJECT_DIR/Resources/MobileVLCKit/vlc-plugins-$OSSTYLE.xcconfig
  698. touch $PROJECT_DIR/Resources/MobileVLCKit/vlc-plugins-$OSSTYLE.h
  699. touch $PROJECT_DIR/Resources/MobileVLCKit/vlc-plugins-$OSSTYLE.xcconfig
  700. spushd libvlc/vlc
  701. rm -rf install-$OSSTYLE
  702. mkdir install-$OSSTYLE
  703. mkdir install-$OSSTYLE/core
  704. mkdir install-$OSSTYLE/contrib
  705. mkdir install-$OSSTYLE/plugins
  706. spopd # vlc
  707. VLCMODULES=""
  708. VLCNEONMODULES=""
  709. SIMULATORARCHS=""
  710. CONTRIBLIBS=""
  711. DEVICEARCHS=""
  712. # arm64 got the lowest number of modules
  713. arch="aarch64"
  714. if [ "$FARCH" != "all" ];then
  715. arch="$FARCH"
  716. fi
  717. actual_arch=`get_actual_arch $arch`
  718. if [ -d libvlc/vlc/install-"$OSSTYLE"OS ];then
  719. spushd libvlc/vlc/install-"$OSSTYLE"OS
  720. for i in `ls .`
  721. do
  722. local iarch="`get_arch $i`"
  723. if [ "$FARCH" == "all" -o "$FARCH" = "$iarch" ];then
  724. DEVICEARCHS="$DEVICEARCHS $iarch"
  725. fi
  726. done
  727. if (! is_simulator_arch $arch);then
  728. echo "IPHONE OS: $arch"
  729. spushd $actual_arch/lib/vlc/plugins
  730. for i in `ls *.a`
  731. do
  732. VLCMODULES="$i $VLCMODULES"
  733. done
  734. spopd # $actual_arch/lib/vlc/plugins
  735. fi
  736. if [ "$OSSTYLE" != "AppleTV" -a \
  737. \( "$FARCH" = "all" -o "$FARCH" = "armv7" -o "$FARCH" = "armv7s" \) ]; then
  738. # collect ARMv7/s specific neon modules
  739. spushd armv7/lib/vlc/plugins
  740. for i in `ls *.a | grep neon`
  741. do
  742. VLCNEONMODULES="$i $VLCNEONMODULES"
  743. done
  744. spopd # armv7/lib/vlc/plugins
  745. fi
  746. spopd # vlc-install-"$OSSTYLE"OS
  747. fi
  748. if [ -d libvlc/vlc/install-"$OSSTYLE"Simulator ];then
  749. spushd libvlc/vlc/install-"$OSSTYLE"Simulator
  750. if (is_simulator_arch $arch);then
  751. echo "SIMU OS: $arch"
  752. spushd $actual_arch/lib/vlc/plugins
  753. for i in `ls *.a`
  754. do
  755. VLCMODULES="$i $VLCMODULES"
  756. done
  757. spopd # $actual_arch/lib/vlc/plugins
  758. fi
  759. for i in `ls .`
  760. do
  761. local iarch="`get_arch $i`"
  762. if [ "$FARCH" == "all" -o "$FARCH" = "$iarch" ];then
  763. SIMULATORARCHS="$SIMULATORARCHS $iarch"
  764. fi
  765. done
  766. spopd # vlc-install-"$OSSTYLE"Simulator
  767. fi
  768. spushd libvlc/vlc
  769. # lipo all the vlc libraries and its plugins
  770. doVLCLipo "" "libvlc.a" "no" $OSSTYLE
  771. doVLCLipo "" "libvlccore.a" "no" $OSSTYLE
  772. doVLCLipo "vlc/" "libcompat.a" "no" $OSSTYLE
  773. for i in $VLCMODULES
  774. do
  775. doVLCLipo "vlc/plugins/" $i "yes" $OSSTYLE
  776. done
  777. # lipo contrib libraries
  778. spushd contrib/$OSSTYLE-$arch-apple-darwin14-$arch/lib
  779. for i in `ls *.a`
  780. do
  781. CONTRIBLIBS="$i $CONTRIBLIBS"
  782. done
  783. spopd # contrib/$OSSTYLE-$arch-apple-darwin14-$arch/lib
  784. for i in $CONTRIBLIBS
  785. do
  786. doContribLipo $i $OSSTYLE
  787. done
  788. if [ "$OSSTYLE" != "AppleTV" ]; then
  789. # lipo the remaining NEON plugins
  790. DEVICEARCHS=""
  791. for i in armv7 armv7s; do
  792. local iarch="`get_arch $i`"
  793. if [ "$FARCH" == "all" -o "$FARCH" = "$iarch" ];then
  794. DEVICEARCHS="$DEVICEARCHS $iarch"
  795. fi
  796. done
  797. SIMULATORARCHS=""
  798. for i in $VLCNEONMODULES
  799. do
  800. doVLCLipo "vlc/plugins/" $i "yes" $OSSTYLE
  801. done
  802. fi
  803. # create module list
  804. info "creating module list"
  805. echo "// This file is autogenerated by $(basename $0)\n\n" > $PROJECT_DIR/Resources/MobileVLCKit/vlc-plugins-$OSSTYLE.h
  806. echo "// This file is autogenerated by $(basename $0)\n\n" > $PROJECT_DIR/Resources/MobileVLCKit/vlc-plugins-$OSSTYLE.xcconfig
  807. # arm64 got the lowest number of modules
  808. BUILTINS="const void *vlc_static_modules[] = {\n"; \
  809. LDFLAGS=""
  810. DEFINITIONS=""
  811. # add contrib libraries to LDFLAGS
  812. for file in $CONTRIBLIBS
  813. do
  814. LDFLAGS+="\$(PROJECT_DIR)/libvlc/vlc/install-"$OSSTYLE"/contrib/$file "
  815. done
  816. for file in $VLCMODULES
  817. do
  818. symbols=$(nm -g -arch $actual_arch install-$OSSTYLE/plugins/$file)
  819. entryname=$(get_symbol "$symbols" _)
  820. DEFINITIONS+="int $entryname (int (*)(void *, void *, int, ...), void *);\n";
  821. BUILTINS+=" $entryname,\n"
  822. LDFLAGS+="\$(PROJECT_DIR)/libvlc/vlc/install-"$OSSTYLE"/plugins/$file "
  823. info "...$entryname"
  824. done;
  825. if [ "$OSSTYLE" != "AppleTV" ]; then
  826. BUILTINS+="#ifdef __arm__\n"
  827. DEFINITIONS+="#ifdef __arm__\n"
  828. for file in $VLCNEONMODULES
  829. do
  830. symbols=$(nm -g -arch armv7 install-$OSSTYLE/plugins/$file)
  831. entryname=$(get_symbol "$symbols" _)
  832. DEFINITIONS+="int $entryname (int (*)(void *, void *, int, ...), void *);\n";
  833. BUILTINS+=" $entryname,\n"
  834. LDFLAGS+="\$(PROJECT_DIR)/libvlc/vlc/install-"$OSSTYLE"/plugins/$file "
  835. info "...$entryname"
  836. done;
  837. BUILTINS+="#endif\n"
  838. DEFINITIONS+="#endif\n"
  839. fi
  840. BUILTINS="$BUILTINS NULL\n};\n"
  841. echo "$DEFINITIONS\n$BUILTINS" > $PROJECT_DIR/Resources/MobileVLCKit/vlc-plugins-$OSSTYLE.h
  842. echo "VLC_PLUGINS_LDFLAGS=$LDFLAGS" > $PROJECT_DIR/Resources/MobileVLCKit/vlc-plugins-$OSSTYLE.xcconfig
  843. spopd # vlc
  844. }
  845. if [ "$TVOS" != "yes" ]; then
  846. build_universal_static_lib "iPhone"
  847. else
  848. build_universal_static_lib "AppleTV"
  849. fi
  850. info "all done"
  851. if [ "$BUILD_STATIC_FRAMEWORK" != "no" ]; then
  852. if [ "$TVOS" != "yes" ]; then
  853. info "Building static MobileVLCKit.framework"
  854. lipo_libs=""
  855. if [ "$FARCH" = "all" ] || (! is_simulator_arch $FARCH);then
  856. buildxcodeproj MobileVLCKit "MobileVLCKit" iphoneos
  857. lipo_libs="$lipo_libs ${CONFIGURATION}-iphoneos/libMobileVLCKit.a"
  858. fi
  859. if [ "$FARCH" = "all" ] || (is_simulator_arch $arch);then
  860. buildxcodeproj MobileVLCKit "MobileVLCKit" iphonesimulator
  861. lipo_libs="$lipo_libs ${CONFIGURATION}-iphonesimulator/libMobileVLCKit.a"
  862. fi
  863. # Assumes both platforms were built currently
  864. spushd build
  865. rm -rf MobileVLCKit.framework && \
  866. mkdir MobileVLCKit.framework && \
  867. lipo -create ${lipo_libs} -o MobileVLCKit.framework/MobileVLCKit && \
  868. chmod a+x MobileVLCKit.framework/MobileVLCKit && \
  869. cp -pr ${CONFIGURATION}-iphoneos/MobileVLCKit MobileVLCKit.framework/Headers
  870. spopd # build
  871. info "Build of static MobileVLCKit.framework completed"
  872. else
  873. info "Building static TVVLCKit.framework"
  874. lipo_libs=""
  875. if [ -d libvlc/vlc/install-AppleTVOS ];then
  876. buildxcodeproj MobileVLCKit "TVVLCKit" appletvos
  877. lipo_libs="$lipo_libs ${CONFIGURATION}-appletvos/libTVVLCKit.a"
  878. fi
  879. if [ -d libvlc/vlc/install-AppleTVSimulator ];then
  880. buildxcodeproj MobileVLCKit "TVVLCKit" appletvsimulator
  881. lipo_libs="$lipo_libs ${CONFIGURATION}-appletvsimulator/libTVVLCKit.a"
  882. fi
  883. # Assumes both platforms were built currently
  884. spushd build
  885. rm -rf TVVLCKit.framework && \
  886. mkdir TVVLCKit.framework && \
  887. lipo -create ${lipo_libs} -o TVVLCKit.framework/TVVLCKit && \
  888. chmod a+x TVVLCKit.framework/TVVLCKit && \
  889. cp -pr ${CONFIGURATION}-appletvos/TVVLCKit TVVLCKit.framework/Headers
  890. spopd # build
  891. info "Build of static TVVLCKit.framework completed"
  892. fi
  893. fi