buildMobileVLCKit.sh 22 KB

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