buildMobileVLCKit.sh 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905
  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=239c560
  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:${PATH}"
  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. if [ "${TARGET}" = "x86_64-apple-darwin14" ];then
  301. BUILD=""
  302. else
  303. BUILD="--build=x86_64-apple-darwin14"
  304. fi
  305. ../bootstrap ${BUILD} --host=${TARGET} --prefix=${VLCROOT}/contrib/${OSSTYLE}-${TARGET}-${ARCH} --disable-gpl \
  306. --disable-disc --disable-sout \
  307. --disable-sdl \
  308. --disable-SDL_image \
  309. --disable-iconv \
  310. --enable-zvbi \
  311. --disable-kate \
  312. --disable-caca \
  313. --disable-gettext \
  314. --disable-mpcdec \
  315. --disable-upnp \
  316. --disable-gme \
  317. --disable-tremor \
  318. --enable-vorbis \
  319. --disable-sidplay2 \
  320. --disable-samplerate \
  321. --disable-goom \
  322. --disable-vncserver \
  323. --disable-orc \
  324. --disable-schroedinger \
  325. --disable-libmpeg2 \
  326. --disable-chromaprint \
  327. --disable-mad \
  328. --enable-fribidi \
  329. --enable-libxml2 \
  330. --enable-freetype2 \
  331. --enable-ass \
  332. --disable-fontconfig \
  333. --disable-gpg-error \
  334. --disable-vncclient \
  335. --disable-gnutls \
  336. --disable-lua \
  337. --disable-luac \
  338. --disable-protobuf \
  339. --disable-aribb24 \
  340. --disable-aribb25 \
  341. --enable-vpx \
  342. --enable-libdsm \
  343. ${TVOSOPTIONS} \
  344. --enable-taglib > ${out}
  345. echo "EXTRA_CFLAGS += ${EXTRA_CFLAGS}" >> config.mak
  346. echo "EXTRA_LDFLAGS += ${EXTRA_LDFLAGS}" >> config.mak
  347. make fetch -j$MAKE_JOBS
  348. make -j$MAKE_JOBS > ${out}
  349. spopd # ${VLCROOT}/contrib
  350. if ! [ -e ${VLCROOT}/configure ]; then
  351. info "Bootstraping vlc"
  352. ${VLCROOT}/bootstrap > ${out}
  353. fi
  354. mkdir -p ${BUILDDIR}
  355. spushd ${BUILDDIR}
  356. if [ "$DEBUG" = "yes" ]; then
  357. DEBUGFLAG="--enable-debug"
  358. else
  359. DEBUGFLAG="--disable-debug"
  360. fi
  361. if [ "$SCARY" = "yes" ]; then
  362. SCARYFLAG="--enable-dvbpsi --enable-avcodec --disable-vpx"
  363. else
  364. SCARYFLAG="--disable-dca --disable-dvbpsi --disable-avcodec --disable-avformat --disable-zvbi --enable-vpx"
  365. fi
  366. if [ "$TVOS" = "yes" ]; then
  367. TVOSOPTIONS="--disable-neon"
  368. else
  369. TVOSOPTIONS="--enable-neon"
  370. fi
  371. # Available but not authorized
  372. export ac_cv_func_daemon=no
  373. export ac_cv_func_fork=no
  374. if [ "${VLCROOT}/configure" -nt config.log -o \
  375. "${THIS_SCRIPT_PATH}" -nt config.log ]; then
  376. info "Configuring vlc"
  377. ${VLCROOT}/configure \
  378. --prefix="${PREFIX}" \
  379. --host="${TARGET}" \
  380. --with-contrib="${VLCROOT}/contrib/${OSSTYLE}-${TARGET}-${ARCH}" \
  381. --enable-static \
  382. ${DEBUGFLAG} \
  383. ${SCARYFLAG} \
  384. ${TVOSOPTIONS} \
  385. --disable-macosx \
  386. --disable-macosx-qtkit \
  387. --disable-macosx-vlc-app \
  388. --disable-macosx-avfoundation \
  389. --disable-audioqueue \
  390. --disable-shared \
  391. --enable-opus \
  392. --disable-faad \
  393. --disable-lua \
  394. --disable-a52 \
  395. --enable-fribidi \
  396. --disable-qt --disable-skins2 \
  397. --disable-vcd \
  398. --disable-vlc \
  399. --disable-vlm \
  400. --disable-httpd \
  401. --disable-nls \
  402. --disable-sse \
  403. --disable-notify \
  404. --enable-live555 \
  405. --enable-realrtsp \
  406. --enable-swscale \
  407. --disable-projectm \
  408. --enable-libass \
  409. --enable-libxml2 \
  410. --disable-goom \
  411. --disable-dvdread \
  412. --disable-dvdnav \
  413. --disable-bluray \
  414. --disable-linsys \
  415. --disable-libva \
  416. --disable-gme \
  417. --disable-tremor \
  418. --enable-vorbis \
  419. --disable-fluidsynth \
  420. --disable-jack \
  421. --disable-pulse \
  422. --disable-mtp \
  423. --enable-ogg \
  424. --enable-speex \
  425. --enable-theora \
  426. --enable-flac \
  427. --disable-screen \
  428. --enable-freetype \
  429. --enable-taglib \
  430. --disable-mmx \
  431. --disable-addonmanagermodules \
  432. --disable-mad > ${out}
  433. fi
  434. info "Building libvlc"
  435. make -j$MAKE_JOBS > ${out}
  436. info "Installing libvlc"
  437. make install > ${out}
  438. find ${PREFIX}/lib/vlc/plugins -name *.a -type f -exec cp '{}' ${PREFIX}/lib/vlc/plugins \;
  439. rm -rf "${PREFIX}/contribs"
  440. cp -R "${VLCROOT}/contrib/${OSSTYLE}-${TARGET}-${ARCH}" "${PREFIX}/contribs"
  441. info "Removing unneeded modules"
  442. blacklist="
  443. stats
  444. access_bd
  445. shm
  446. access_imem
  447. oldrc
  448. real
  449. hotkeys
  450. gestures
  451. dynamicoverlay
  452. rss
  453. ball
  454. marq
  455. magnify
  456. audiobargraph_
  457. clone
  458. mosaic
  459. osdmenu
  460. puzzle
  461. mediadirs
  462. t140
  463. ripple
  464. motion
  465. sharpen
  466. grain
  467. posterize
  468. mirror
  469. wall
  470. scene
  471. blendbench
  472. psychedelic
  473. alphamask
  474. netsync
  475. audioscrobbler
  476. motiondetect
  477. motionblur
  478. export
  479. smf
  480. podcast
  481. bluescreen
  482. erase
  483. stream_filter_record
  484. speex_resampler
  485. remoteosd
  486. magnify
  487. gradient
  488. logger
  489. visual
  490. fb
  491. aout_file
  492. dummy
  493. invert
  494. sepia
  495. wave
  496. hqdn3d
  497. headphone_channel_mixer
  498. gaussianblur
  499. gradfun
  500. extract
  501. colorthres
  502. antiflicker
  503. anaglyph
  504. remap
  505. oldmovie
  506. vhs
  507. demuxdump
  508. fingerprinter
  509. output_udp
  510. output_http
  511. output_livehttp
  512. libmux
  513. stream_out
  514. "
  515. if [ "$SCARY" = "no" ]; then
  516. blacklist="${blacklist}
  517. dts
  518. dvbsub
  519. svcd
  520. hevc
  521. packetizer_mlp
  522. a52
  523. vc1
  524. uleaddvaudio
  525. librar
  526. libvoc
  527. avio
  528. chorus_flanger
  529. smooth
  530. cvdsub
  531. libmod
  532. libdash
  533. libmpgv
  534. dolby_surround
  535. mpegaudio"
  536. fi
  537. echo ${blacklist}
  538. for i in ${blacklist}
  539. do
  540. find ${PREFIX}/lib/vlc/plugins -name *$i* -type f -exec rm '{}' \;
  541. done
  542. spopd
  543. }
  544. buildMobileKit() {
  545. PLATFORM="$1"
  546. if [ "$SKIPLIBVLCCOMPILATION" != "yes" ]; then
  547. if [ "$TVOS" = "yes" ]; then
  548. export BUILDFORTVOS="yes"
  549. info "Building libvlc for tvOS"
  550. else
  551. info "Building libvlc for iOS"
  552. fi
  553. export BUILDFORIOS="yes"
  554. export AR="xcrun ar"
  555. export RANLIB="xcrun ranlib"
  556. export CC="xcrun clang"
  557. export OBJC="xcrun clang"
  558. export CXX="xcrun clang++"
  559. export LD="xcrun ld"
  560. export STRIP="xcrun strip"
  561. export CPP="xcrun cc -E"
  562. export CXXCPP="xcrun c++ -E"
  563. unset AS
  564. unset CCAS
  565. if [ "$TVOS" = "yes" ]; then
  566. if [ "$PLATFORM" = "iphonesimulator" ]; then
  567. buildLibVLC $VERBOSE $DEBUG $SCARY $BITCODE "x86_64" $TVOS $SDK_VERSION "Simulator"
  568. else
  569. buildLibVLC $VERBOSE $DEBUG $SCARY $BITCODE "aarch64" $TVOS $SDK_VERSION "OS"
  570. fi
  571. else
  572. if [ "$PLATFORM" = "iphonesimulator" ]; then
  573. buildLibVLC $VERBOSE $DEBUG $SCARY $BITCODE "i386" $TVOS $SDK_VERSION "Simulator"
  574. buildLibVLC $VERBOSE $DEBUG $SCARY $BITCODE "x86_64" $TVOS $SDK_VERSION "Simulator"
  575. else
  576. buildLibVLC $VERBOSE $DEBUG $SCARY $BITCODE "armv7" $TVOS $SDK_VERSION "OS"
  577. buildLibVLC $VERBOSE $DEBUG $SCARY $BITCODE "armv7s" $TVOS $SDK_VERSION "OS"
  578. buildLibVLC $VERBOSE $DEBUG $SCARY $BITCODE "aarch64" $TVOS $SDK_VERSION "OS"
  579. fi
  580. fi
  581. fi
  582. }
  583. if [ "$BUILD_DEVICE" != "no" ]; then
  584. buildMobileKit iphoneos
  585. fi
  586. if [ "$BUILD_SIMULATOR" != "no" ]; then
  587. buildMobileKit iphonesimulator
  588. fi
  589. DEVICEARCHS=""
  590. SIMULATORARCHS=""
  591. doVLCLipo() {
  592. FILEPATH="$1"
  593. FILE="$2"
  594. PLUGIN="$3"
  595. OSSTYLE="$4"
  596. files=""
  597. info "...$FILEPATH$FILE"
  598. for i in $DEVICEARCHS
  599. do
  600. files="install-"$OSSTYLE"OS/$i/lib/$FILEPATH$FILE $files"
  601. done
  602. for i in $SIMULATORARCHS
  603. do
  604. files="install-"$OSSTYLE"Simulator/$i/lib/$FILEPATH$FILE $files"
  605. done
  606. if [ "$PLUGIN" != "no" ]; then
  607. lipo $files -create -output install-$OSSTYLE/plugins/$FILE
  608. else
  609. lipo $files -create -output install-$OSSTYLE/core/$FILE
  610. fi
  611. }
  612. doContribLipo() {
  613. LIBNAME="$1"
  614. OSSTYLE="$2"
  615. files=""
  616. info "...$LIBNAME"
  617. for i in $DEVICEARCHS
  618. do
  619. if [ "$i" != "arm64" ]; then
  620. files="contrib/$OSSTYLE-$i-apple-darwin14-$i/lib/$LIBNAME $files"
  621. else
  622. files="contrib/$OSSTYLE-aarch64-apple-darwin14-aarch64/lib/$LIBNAME $files"
  623. fi
  624. done
  625. for i in $SIMULATORARCHS
  626. do
  627. files="contrib/$OSSTYLE-$i-apple-darwin14-$i/lib/$LIBNAME $files"
  628. done
  629. lipo $files -create -output install-$OSSTYLE/contrib/$LIBNAME
  630. }
  631. get_symbol()
  632. {
  633. echo "$1" | grep vlc_entry_$2|cut -d" " -f 3|sed 's/_vlc/vlc/'
  634. }
  635. build_universal_static_lib() {
  636. PROJECT_DIR=`pwd`
  637. OSSTYLE="$1"
  638. info "building universal static libs for OS style $OSSTYLE"
  639. # remove old module list
  640. rm -f $PROJECT_DIR/Resources/MobileVLCKit/vlc-plugins-$OSSTYLE.h
  641. rm -f $PROJECT_DIR/Resources/MobileVLCKit/vlc-plugins-$OSSTYLE.xcconfig
  642. touch $PROJECT_DIR/Resources/MobileVLCKit/vlc-plugins-$OSSTYLE.h
  643. touch $PROJECT_DIR/Resources/MobileVLCKit/vlc-plugins-$OSSTYLE.xcconfig
  644. spushd libvlc/vlc
  645. rm -rf install-$OSSTYLE
  646. mkdir install-$OSSTYLE
  647. mkdir install-$OSSTYLE/core
  648. mkdir install-$OSSTYLE/contrib
  649. mkdir install-$OSSTYLE/plugins
  650. spopd # vlc
  651. spushd libvlc/vlc/install-"$OSSTYLE"OS
  652. for i in `ls .`
  653. do
  654. DEVICEARCHS="$DEVICEARCHS $i"
  655. done
  656. spopd # vlc-install-"$OSSTYLE"OS
  657. spushd libvlc/vlc/install-"$OSSTYLE"Simulator
  658. for i in `ls .`
  659. do
  660. SIMULATORARCHS="$SIMULATORARCHS $i"
  661. done
  662. spopd # vlc-install-"$OSSTYLE"Simulator
  663. # arm64 got the lowest number of modules
  664. VLCMODULES=""
  665. spushd libvlc/vlc/install-"$OSSTYLE"OS/arm64/lib/vlc/plugins
  666. for i in `ls *.a`
  667. do
  668. VLCMODULES="$i $VLCMODULES"
  669. done
  670. spopd # vlc/install-"$OSSTYLE"OS/arm64/lib/vlc/plugins
  671. if [ "$OSSTYLE" != "AppleTV" ]; then
  672. # collect ARMv7/s specific neon modules
  673. VLCNEONMODULES=""
  674. spushd libvlc/vlc/install-"$OSSTYLE"OS/armv7/lib/vlc/plugins
  675. for i in `ls *.a | grep neon`
  676. do
  677. VLCNEONMODULES="$i $VLCNEONMODULES"
  678. done
  679. spopd # vlc/install-"$OSSTYLE"OS/armv7/lib/vlc/plugins
  680. fi
  681. spushd libvlc/vlc
  682. # lipo all the vlc libraries and its plugins
  683. doVLCLipo "" "libvlc.a" "no" $OSSTYLE
  684. doVLCLipo "" "libvlccore.a" "no" $OSSTYLE
  685. doVLCLipo "vlc/" "libcompat.a" "no" $OSSTYLE
  686. for i in $VLCMODULES
  687. do
  688. doVLCLipo "vlc/plugins/" $i "yes" $OSSTYLE
  689. done
  690. # lipo contrib libraries
  691. CONTRIBLIBS=""
  692. spushd contrib/$OSSTYLE-aarch64-apple-darwin14-aarch64/lib
  693. for i in `ls *.a`
  694. do
  695. CONTRIBLIBS="$i $CONTRIBLIBS"
  696. done
  697. spopd # contrib/$OSSTYLE-aarch64-apple-darwin14-aarch64/lib
  698. for i in $CONTRIBLIBS
  699. do
  700. doContribLipo $i $OSSTYLE
  701. done
  702. if [ "$OSSTYLE" != "AppleTV" ]; then
  703. # lipo the remaining NEON plugins
  704. DEVICEARCHS="armv7 armv7s"
  705. SIMULATORARCHS=""
  706. for i in $VLCNEONMODULES
  707. do
  708. doVLCLipo "vlc/plugins/" $i "yes" $OSSTYLE
  709. done
  710. fi
  711. # create module list
  712. info "creating module list"
  713. echo "// This file is autogenerated by $(basename $0)\n\n" > $PROJECT_DIR/Resources/MobileVLCKit/vlc-plugins-$OSSTYLE.h
  714. echo "// This file is autogenerated by $(basename $0)\n\n" > $PROJECT_DIR/Resources/MobileVLCKit/vlc-plugins-$OSSTYLE.xcconfig
  715. # arm64 got the lowest number of modules
  716. BUILTINS="const void *vlc_static_modules[] = {\n"; \
  717. LDFLAGS=""
  718. DEFINITIONS=""
  719. # add contrib libraries to LDFLAGS
  720. for file in $CONTRIBLIBS
  721. do
  722. LDFLAGS+="\$(PROJECT_DIR)/libvlc/vlc/install-"$OSSTYLE"/contrib/$file "
  723. done
  724. for file in $VLCMODULES
  725. do
  726. symbols=$(nm -g -arch arm64 install-$OSSTYLE/plugins/$file)
  727. entryname=$(get_symbol "$symbols" _)
  728. DEFINITIONS+="int $entryname (int (*)(void *, void *, int, ...), void *);\n";
  729. BUILTINS+=" $entryname,\n"
  730. LDFLAGS+="\$(PROJECT_DIR)/libvlc/vlc/install-"$OSSTYLE"/plugins/$file "
  731. info "...$entryname"
  732. done;
  733. if [ "$OSSTYLE" != "AppleTV" ]; then
  734. BUILTINS+="#ifdef __arm__\n"
  735. DEFINITIONS+="#ifdef __arm__\n"
  736. for file in $VLCNEONMODULES
  737. do
  738. symbols=$(nm -g -arch armv7 install-$OSSTYLE/plugins/$file)
  739. entryname=$(get_symbol "$symbols" _)
  740. DEFINITIONS+="int $entryname (int (*)(void *, void *, int, ...), void *);\n";
  741. BUILTINS+=" $entryname,\n"
  742. LDFLAGS+="\$(PROJECT_DIR)/libvlc/vlc/install-"$OSSTYLE"/plugins/$file "
  743. info "...$entryname"
  744. done;
  745. BUILTINS+="#endif\n"
  746. DEFINITIONS+="#endif\n"
  747. fi
  748. BUILTINS="$BUILTINS NULL\n};\n"
  749. echo "$DEFINITIONS\n$BUILTINS" > $PROJECT_DIR/Resources/MobileVLCKit/vlc-plugins-$OSSTYLE.h
  750. echo "VLC_PLUGINS_LDFLAGS=$LDFLAGS" > $PROJECT_DIR/Resources/MobileVLCKit/vlc-plugins-$OSSTYLE.xcconfig
  751. spopd # vlc
  752. }
  753. if [ "$TVOS" != "yes" ]; then
  754. build_universal_static_lib "iPhone"
  755. else
  756. build_universal_static_lib "AppleTV"
  757. fi
  758. info "all done"
  759. if [ "$BUILD_STATIC_FRAMEWORK" != "no" ]; then
  760. if [ "$TVOS" != "yes" ]; then
  761. info "Building static MobileVLCKit.framework"
  762. buildxcodeproj MobileVLCKit "MobileVLCKit" iphoneos
  763. buildxcodeproj MobileVLCKit "MobileVLCKit" iphonesimulator
  764. # Assumes both platforms were built currently
  765. spushd build
  766. rm -rf MobileVLCKit.framework && \
  767. mkdir MobileVLCKit.framework && \
  768. lipo -create ${CONFIGURATION}-iphoneos/libMobileVLCKit.a \
  769. ${CONFIGURATION}-iphonesimulator/libMobileVLCKit.a \
  770. -o MobileVLCKit.framework/MobileVLCKit && \
  771. chmod a+x MobileVLCKit.framework/MobileVLCKit && \
  772. cp -pr ${CONFIGURATION}-iphoneos/MobileVLCKit MobileVLCKit.framework/Headers
  773. spopd # build
  774. info "Build of static MobileVLCKit.framework completed"
  775. else
  776. info "Building static TVVLCKit.framework"
  777. buildxcodeproj MobileVLCKit "TVVLCKit" appletvos
  778. buildxcodeproj MobileVLCKit "TVVLCKit" appletvsimulator
  779. # Assumes both platforms were built currently
  780. spushd build
  781. rm -rf TVVLCKit.framework && \
  782. mkdir TVVLCKit.framework && \
  783. lipo -create ${CONFIGURATION}-appletvos/libTVVLCKit.a \
  784. ${CONFIGURATION}-appletvsimulator/libTVVLCKit.a \
  785. -o TVVLCKit.framework/TVVLCKit && \
  786. chmod a+x TVVLCKit.framework/TVVLCKit && \
  787. cp -pr ${CONFIGURATION}-appletvos/TVVLCKit TVVLCKit.framework/Headers
  788. spopd # build
  789. info "Build of static TVVLCKit.framework completed"
  790. fi
  791. fi