buildMobileVLCKit.sh 22 KB

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