compileAndBuildVLCKit.sh 31 KB

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