compileAndBuildVLCKit.sh 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188
  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=7.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="d3c5d18" # 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. }
  103. buildxcodeproj()
  104. {
  105. cleantheenvironment
  106. local target="$2"
  107. local PLATFORM="$3"
  108. info "Building $1 ($target, ${CONFIGURATION}, $PLATFORM)"
  109. local architectures=""
  110. if [ "$FARCH" = "all" ];then
  111. if [ "$TVOS" = "yes" ]; then
  112. if [ "$PLATFORM" = "appletvsimulator" ]; then
  113. architectures="x86_64"
  114. else
  115. architectures="arm64"
  116. fi
  117. fi
  118. if [ "$IOS" = "yes" ]; then
  119. if [ "$PLATFORM" = "iphonesimulator" ]; then
  120. architectures="i386 x86_64"
  121. else
  122. architectures="armv7 armv7s arm64"
  123. fi
  124. fi
  125. else
  126. architectures=`get_actual_arch $FARCH`
  127. fi
  128. local bitcodeflag=""
  129. if [ "$BITCODE" = "yes" ]; then
  130. bitcodeflag="BITCODE_GENERATION_MODE=bitcode"
  131. fi
  132. local defs="$GCC_PREPROCESSOR_DEFINITIONS"
  133. if [ "$SCARY" = "no" ]; then
  134. defs="$defs NOSCARYCODECS"
  135. fi
  136. xcodebuild -project "$1.xcodeproj" \
  137. -target "$target" \
  138. -sdk $PLATFORM$SDK \
  139. -configuration ${CONFIGURATION} \
  140. ARCHS="${architectures}" \
  141. IPHONEOS_DEPLOYMENT_TARGET=${SDK_MIN} \
  142. GCC_PREPROCESSOR_DEFINITIONS="$defs" \
  143. ${bitcodeflag} \
  144. > ${out}
  145. }
  146. buildLibVLC() {
  147. ARCH="$1"
  148. PLATFORM="$2"
  149. OSSTYLE=iPhone
  150. if [ "$DEBUG" = "yes" ]; then
  151. OPTIM="-O0 -g"
  152. else
  153. OPTIM="-O3 -g"
  154. fi
  155. if [ "$TVOS" = "yes" ]; then
  156. OSSTYLE=AppleTV
  157. fi
  158. if [ "$MACOS" = "yes" ]; then
  159. OSSTYLE=MacOSX
  160. PLATFORM=
  161. fi
  162. ACTUAL_ARCH=`get_actual_arch $ARCH`
  163. info "Compiling ${ARCH} with SDK version ${SDK_VERSION}, platform ${PLATFORM}"
  164. SDKROOT=`xcode-select -print-path`/Platforms/${OSSTYLE}${PLATFORM}.platform/Developer/SDKs/${OSSTYLE}${PLATFORM}${SDK_VERSION}.sdk
  165. if [ ! -d "${SDKROOT}" ]
  166. then
  167. echo "*** ${SDKROOT} does not exist, please install required SDK, or set SDKROOT manually. ***"
  168. exit 1
  169. fi
  170. BUILDDIR="${VLCROOT}/build-${OSSTYLE}${PLATFORM}/${ACTUAL_ARCH}"
  171. PREFIX="${VLCROOT}/install-${OSSTYLE}${PLATFORM}/${ACTUAL_ARCH}"
  172. TARGET="${ARCH}-apple-darwin14"
  173. # partially clean the environment
  174. export CFLAGS=""
  175. export CPPFLAGS=""
  176. export CXXFLAGS=""
  177. export OBJCFLAGS=""
  178. export LDFLAGS=""
  179. export PLATFORM=$PLATFORM
  180. export SDK_VERSION=$SDK_VERSION
  181. export VLCSDKROOT=$SDKROOT
  182. CFLAGS="-isysroot ${SDKROOT} -arch ${ACTUAL_ARCH} ${OPTIM}"
  183. OBJCFLAGS="${OPTIM}"
  184. if [ "$PLATFORM" = "OS" ]; then
  185. if [ "$ARCH" != "aarch64" ]; then
  186. CFLAGS+=" -mcpu=cortex-a8 -${OSVERSIONMINCFLAG}=${SDK_MIN}"
  187. else
  188. CFLAGS+=" -${OSVERSIONMINCFLAG}=${SDK_MIN}"
  189. fi
  190. else
  191. CFLAGS+=" -${OSVERSIONMINCFLAG}=${SDK_MIN}"
  192. fi
  193. if [ "$BITCODE" = "yes" ]; then
  194. CFLAGS+=" -fembed-bitcode"
  195. fi
  196. export CFLAGS="${CFLAGS}"
  197. export CXXFLAGS="${CFLAGS}"
  198. export CPPFLAGS="${CFLAGS}"
  199. export OBJCFLAGS="${OBJCFLAGS}"
  200. if [ "$PLATFORM" = "Simulator" ]; then
  201. # Use the new ABI on simulator, else we can't build
  202. export OBJCFLAGS="-fobjc-abi-version=2 -fobjc-legacy-dispatch ${OBJCFLAGS}"
  203. fi
  204. export LDFLAGS="-arch ${ACTUAL_ARCH}"
  205. if [ "$PLATFORM" = "OS" ]; then
  206. EXTRA_CFLAGS="-arch ${ACTUAL_ARCH}"
  207. EXTRA_LDFLAGS="-arch ${ACTUAL_ARCH}"
  208. if [ "$ARCH" != "aarch64" ]; then
  209. EXTRA_CFLAGS+=" -mcpu=cortex-a8"
  210. EXTRA_CFLAGS+=" -${OSVERSIONMINCFLAG}=${SDK_MIN}"
  211. EXTRA_LDFLAGS+=" -Wl,-${OSVERSIONMINLDFLAG},${SDK_MIN}"
  212. export LDFLAGS="${LDFLAGS} -Wl,-${OSVERSIONMINLDFLAG},${SDK_MIN}"
  213. else
  214. EXTRA_CFLAGS+=" -${OSVERSIONMINCFLAG}=${SDK_MIN}"
  215. EXTRA_LDFLAGS+=" -Wl,-${OSVERSIONMINLDFLAG},${SDK_MIN}"
  216. export LDFLAGS="${LDFLAGS} -Wl,-${OSVERSIONMINLDFLAG},${SDK_MIN}"
  217. fi
  218. else
  219. EXTRA_CFLAGS="-arch ${ARCH}"
  220. EXTRA_CFLAGS+=" -${OSVERSIONMINCFLAG}=${SDK_MIN}"
  221. EXTRA_LDFLAGS=" -Wl,-${OSVERSIONMINLDFLAG},${SDK_MIN}"
  222. export LDFLAGS="${LDFLAGS} -v -Wl,-${OSVERSIONMINLDFLAG},${SDK_MIN}"
  223. fi
  224. spushd ${VLCROOT}/contrib
  225. info "Compiling third-party libraries"
  226. mkdir -p "${VLCROOT}/contrib/${OSSTYLE}${PLATFORM}-${ARCH}"
  227. cd "${VLCROOT}/contrib/${OSSTYLE}${PLATFORM}-${ARCH}"
  228. if [ "$PLATFORM" = "OS" ]; then
  229. export AS="gas-preprocessor.pl ${CC}"
  230. export ASCPP="gas-preprocessor.pl ${CC}"
  231. export CCAS="gas-preprocessor.pl ${CC}"
  232. if [ "$ARCH" = "aarch64" ]; then
  233. export GASPP_FIX_XCODE5=1
  234. fi
  235. else
  236. export ASCPP="xcrun as"
  237. fi
  238. if [ "$TVOS" = "yes" ]; then
  239. CUSTOMOSOPTIONS="--disable-libarchive"
  240. fi
  241. if [ "$MACOS" = "yes" ]; then
  242. CUSTOMOSOPTIONS="--disable-fontconfig --disable-bghudappkit --disable-twolame --disable-microdns --disable-SDL --disable-SDL_image --disable-cddb --disable-bluray"
  243. fi
  244. if [ "$IOS" = "yes" ]; then
  245. CUSTOMOSOPTIONS=""
  246. fi
  247. if [ "${TARGET}" = "x86_64-apple-darwin14" ];then
  248. BUILD=""
  249. else
  250. BUILD="--build=x86_64-apple-darwin14"
  251. fi
  252. if [ "$MACOS" = "yes" ]; then
  253. # The following symbols do not exist on the minimal macOS version (10.7), so they are disabled
  254. # here. This allows compilation also with newer macOS SDKs.
  255. # Added symbols in 10.13
  256. export ac_cv_func_open_wmemstream=no
  257. export ac_cv_func_fmemopen=no
  258. export ac_cv_func_open_memstream=no
  259. export ac_cv_func_futimens=no
  260. export ac_cv_func_utimensat=no
  261. # Added symbols between 10.11 and 10.12
  262. export ac_cv_func_basename_r=no
  263. export ac_cv_func_clock_getres=no
  264. export ac_cv_func_clock_gettime=no
  265. export ac_cv_func_clock_settime=no
  266. export ac_cv_func_dirname_r=no
  267. export ac_cv_func_getentropy=no
  268. export ac_cv_func_mkostemp=no
  269. export ac_cv_func_mkostemps=no
  270. # Added symbols between 10.7 and 10.11
  271. export ac_cv_func_ffsll=no
  272. export ac_cv_func_flsll=no
  273. export ac_cv_func_fdopendir=no
  274. export ac_cv_func_openat=no
  275. export ac_cv_func_fstatat=no
  276. export ac_cv_func_readlinkat=no
  277. else
  278. # The following symbols do not exist on the minimal iOS version (7.0), so they are disabled
  279. # here. This allows compilation also with newer iOS SDKs
  280. # Added symbols between 7.x and 10.x
  281. export ac_cv_func_basename_r=no
  282. export ac_cv_func_clock_getres=no
  283. export ac_cv_func_clock_gettime=no
  284. export ac_cv_func_clock_settime=no
  285. export ac_cv_func_dirname_r=no
  286. export ac_cv_func_getentropy=no
  287. export ac_cv_func_mkostemp=no
  288. export ac_cv_func_mkostemps=no
  289. export ac_cv_func_open_memstream=no
  290. export ac_cv_func_futimens=no
  291. fi
  292. export USE_FFMPEG=1
  293. ../bootstrap ${BUILD} --host=${TARGET} --prefix=${VLCROOT}/contrib/${OSSTYLE}-${TARGET}-${ARCH} --disable-gpl \
  294. --enable-ad-clauses \
  295. --disable-disc --disable-sout \
  296. --disable-sdl \
  297. --disable-SDL_image \
  298. --disable-iconv \
  299. --enable-zvbi \
  300. --disable-kate \
  301. --disable-caca \
  302. --disable-gettext \
  303. --disable-mpcdec \
  304. --disable-upnp \
  305. --disable-gme \
  306. --disable-srt \
  307. --disable-tremor \
  308. --enable-vorbis \
  309. --disable-sidplay2 \
  310. --disable-samplerate \
  311. --disable-goom \
  312. --disable-vncserver \
  313. --disable-orc \
  314. --disable-schroedinger \
  315. --disable-libmpeg2 \
  316. --disable-chromaprint \
  317. --disable-mad \
  318. --enable-fribidi \
  319. --enable-libxml2 \
  320. --enable-freetype2 \
  321. --enable-ass \
  322. --disable-fontconfig \
  323. --disable-gpg-error \
  324. --disable-vncclient \
  325. --disable-gnutls \
  326. --disable-lua \
  327. --disable-luac \
  328. --disable-protobuf \
  329. --disable-aribb24 \
  330. --disable-aribb25 \
  331. --enable-vpx \
  332. --enable-libdsm \
  333. --enable-libplacebo \
  334. --disable-sparkle \
  335. --disable-growl \
  336. --disable-breakpad \
  337. --disable-ncurses \
  338. --disable-asdcplib \
  339. --enable-soxr \
  340. ${CUSTOMOSOPTIONS} \
  341. --enable-taglib > ${out}
  342. echo "EXTRA_CFLAGS += ${EXTRA_CFLAGS}" >> config.mak
  343. echo "EXTRA_LDFLAGS += ${EXTRA_LDFLAGS}" >> config.mak
  344. make fetch -j$MAKE_JOBS
  345. make -j$MAKE_JOBS > ${out}
  346. spopd # ${VLCROOT}/contrib
  347. if ! [ -e ${VLCROOT}/configure ]; then
  348. info "Bootstraping vlc"
  349. ${VLCROOT}/bootstrap > ${out}
  350. fi
  351. mkdir -p ${BUILDDIR}
  352. spushd ${BUILDDIR}
  353. if [ "$DEBUG" = "yes" ]; then
  354. DEBUGFLAG="--enable-debug"
  355. else
  356. export CFLAGS="${CFLAGS} -DNDEBUG"
  357. fi
  358. if [ "$SCARY" = "yes" ]; then
  359. SCARYFLAG="--enable-dvbpsi --enable-avcodec --disable-vpx"
  360. else
  361. SCARYFLAG="--disable-dca --disable-dvbpsi --disable-avcodec --disable-avformat --disable-zvbi --enable-vpx"
  362. fi
  363. if [ "$TVOS" != "yes" -a \( "$ARCH" = "armv7" -o "$ARCH" = "armv7s" \) ];then
  364. export ac_cv_arm_neon=yes
  365. else
  366. export ac_cv_arm_neon=no
  367. fi
  368. # Available but not authorized
  369. export ac_cv_func_daemon=no
  370. export ac_cv_func_fork=no
  371. if [ "${VLCROOT}/configure" -nt config.log -o \
  372. "${THIS_SCRIPT_PATH}" -nt config.log ]; then
  373. info "Configuring vlc"
  374. ${VLCROOT}/configure \
  375. --prefix="${PREFIX}" \
  376. --host="${TARGET}" \
  377. --with-contrib="${VLCROOT}/contrib/${OSSTYLE}-${TARGET}-${ARCH}" \
  378. --enable-static \
  379. ${DEBUGFLAG} \
  380. ${SCARYFLAG} \
  381. --disable-macosx \
  382. --disable-macosx-qtkit \
  383. --disable-macosx-avfoundation \
  384. --disable-shared \
  385. --enable-opus \
  386. --disable-faad \
  387. --disable-lua \
  388. --disable-a52 \
  389. --enable-fribidi \
  390. --disable-qt --disable-skins2 \
  391. --disable-vcd \
  392. --disable-vlc \
  393. --disable-vlm \
  394. --disable-httpd \
  395. --disable-nls \
  396. --disable-sse \
  397. --disable-notify \
  398. --enable-live555 \
  399. --enable-realrtsp \
  400. --enable-swscale \
  401. --disable-projectm \
  402. --enable-libass \
  403. --enable-libxml2 \
  404. --disable-goom \
  405. --disable-dvdread \
  406. --disable-dvdnav \
  407. --disable-bluray \
  408. --disable-linsys \
  409. --disable-libva \
  410. --disable-gme \
  411. --disable-tremor \
  412. --enable-vorbis \
  413. --disable-fluidsynth \
  414. --disable-jack \
  415. --disable-pulse \
  416. --disable-mtp \
  417. --enable-ogg \
  418. --enable-speex \
  419. --enable-theora \
  420. --enable-flac \
  421. --disable-screen \
  422. --enable-freetype \
  423. --enable-taglib \
  424. --disable-mmx \
  425. --disable-sparkle \
  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. cleantheenvironment
  542. if [ "$SKIPLIBVLCCOMPILATION" != "yes" ]; then
  543. if [ "$TVOS" = "yes" ]; then
  544. # this variable is read by libvlc's contrib build script
  545. # to create the required build environment
  546. # for historical raisons, tvOS is a special flavor of iOS
  547. # so we need to export both variables
  548. export BUILDFORIOS="yes"
  549. export BUILDFORTVOS="yes"
  550. info "Building libvlc for tvOS"
  551. fi
  552. if [ "$MACOS" = "yes" ]; then
  553. # macOS is the default build environment for libvlc's contrib
  554. # build scripts, so we don't need to export anything
  555. info "Building libvlc for macOS"
  556. fi
  557. if [ "$IOS" = "yes" ]; then
  558. # this variable is read by libvlc's contrib build script
  559. # to create the required build environment
  560. export BUILDFORIOS="yes"
  561. info "Building libvlc for iOS"
  562. fi
  563. export AR=`xcrun -f ar`
  564. export RANLIB=`xcrun -f ranlib`
  565. export CC=`xcrun -f clang`
  566. export OBJC=`xcrun -f clang`
  567. export CXX=`xcrun -f clang++`
  568. export LD=`xcrun -f ld`
  569. export STRIP=`xcrun -f strip`
  570. export CPPFLAGS=-E
  571. export CXXCPPFLAGS=-E
  572. unset AS
  573. unset CCAS
  574. if [ "$FARCH" = "all" ];then
  575. if [ "$TVOS" = "yes" ]; then
  576. if [ "$PLATFORM" = "iphonesimulator" ]; then
  577. buildLibVLC "x86_64" "Simulator"
  578. else
  579. buildLibVLC "aarch64" "OS"
  580. fi
  581. fi
  582. if [ "$MACOS" = "yes" ]; then
  583. buildLibVLC "x86_64" "OS"
  584. fi
  585. if [ "$IOS" = "yes" ]; then
  586. if [ "$PLATFORM" = "iphonesimulator" ]; then
  587. buildLibVLC "i386" "Simulator"
  588. buildLibVLC "x86_64" "Simulator"
  589. else
  590. buildLibVLC "armv7" "OS"
  591. buildLibVLC "armv7s" "OS"
  592. buildLibVLC "aarch64" "OS"
  593. fi
  594. fi
  595. else
  596. if [ "$FARCH" != "x86_64" -a "$FARCH" != "aarch64" -a "$FARCH" != "i386" \
  597. -a "$FARCH" != "armv7" -a "$FARCH" != "armv7s" ];then
  598. echo "*** Framework ARCH: ${FARCH} is invalid ***"
  599. exit 1
  600. fi
  601. local buildPlatform=""
  602. if [ "$PLATFORM" = "iphonesimulator" ]; then
  603. if [ "$FARCH" == "x86_64" -o "$FARCH" == "i386" ];then
  604. buildPlatform="Simulator"
  605. fi
  606. else
  607. if [ "$FARCH" == "armv7" -o "$FARCH" == "armv7s" -o "$FARCH" == "aarch64" ];then
  608. buildPlatform="OS"
  609. fi
  610. fi
  611. if [ ! -z "$buildPlatform" ];then
  612. buildLibVLC $FARCH $buildPlatform
  613. fi
  614. fi
  615. fi
  616. }
  617. doVLCLipo() {
  618. FILEPATH="$1"
  619. FILE="$2"
  620. PLUGIN="$3"
  621. OSSTYLE="$4"
  622. files=""
  623. info "...$FILEPATH$FILE"
  624. for i in $DEVICEARCHS
  625. do
  626. actual_arch=`get_actual_arch $i`
  627. files="install-"$OSSTYLE"OS/$actual_arch/lib/$FILEPATH$FILE $files"
  628. done
  629. for i in $SIMULATORARCHS
  630. do
  631. actual_arch=`get_actual_arch $i`
  632. files="install-"$OSSTYLE"Simulator/$actual_arch/lib/$FILEPATH$FILE $files"
  633. done
  634. if [ "$PLUGIN" != "no" ]; then
  635. lipo $files -create -output install-$OSSTYLE/plugins/$FILE
  636. else
  637. lipo $files -create -output install-$OSSTYLE/core/$FILE
  638. fi
  639. }
  640. doContribLipo() {
  641. LIBNAME="$1"
  642. OSSTYLE="$2"
  643. files=""
  644. info "...$LIBNAME"
  645. for i in $DEVICEARCHS $SIMULATORARCHS
  646. do
  647. files="contrib/$OSSTYLE-$i-apple-darwin14-$i/lib/$LIBNAME $files"
  648. done
  649. lipo $files -create -output install-$OSSTYLE/contrib/$LIBNAME
  650. }
  651. get_symbol()
  652. {
  653. echo "$1" | grep vlc_entry_$2|cut -d" " -f 3|sed 's/_vlc/vlc/'
  654. }
  655. build_universal_static_lib() {
  656. PROJECT_DIR=`pwd`
  657. OSSTYLE="$1"
  658. info "building universal static libs for OS style $OSSTYLE"
  659. # remove old module list
  660. rm -f $PROJECT_DIR/Resources/MobileVLCKit/vlc-plugins-$OSSTYLE.h
  661. rm -f $PROJECT_DIR/Resources/MobileVLCKit/vlc-plugins-$OSSTYLE.xcconfig
  662. touch $PROJECT_DIR/Resources/MobileVLCKit/vlc-plugins-$OSSTYLE.h
  663. touch $PROJECT_DIR/Resources/MobileVLCKit/vlc-plugins-$OSSTYLE.xcconfig
  664. if [ "$OSSTYLE" != "MacOSX" ]; then
  665. spushd ${VLCROOT}
  666. rm -rf install-$OSSTYLE
  667. mkdir install-$OSSTYLE
  668. mkdir install-$OSSTYLE/core
  669. mkdir install-$OSSTYLE/contrib
  670. mkdir install-$OSSTYLE/plugins
  671. spopd # vlc
  672. else
  673. spushd ${VLCROOT}/install-$OSSTYLE
  674. rm -rf core
  675. rm -rf contrib
  676. rm -rf plugins
  677. ln -s x86_64/lib core
  678. ln -s x86_64/contribs/lib contrib
  679. ln -s x86_64/lib/vlc/plugins plugins
  680. spopd # vlc
  681. fi
  682. VLCMODULES=""
  683. VLCNEONMODULES=""
  684. SIMULATORARCHS=""
  685. CONTRIBLIBS=""
  686. DEVICEARCHS=""
  687. # arm64 got the lowest number of modules
  688. arch="aarch64"
  689. if [ "$FARCH" != "all" ];then
  690. arch="$FARCH"
  691. fi
  692. actual_arch=`get_actual_arch $arch`
  693. if [ -d ${VLCROOT}/install-"$OSSTYLE"OS ];then
  694. spushd ${VLCROOT}/install-"$OSSTYLE"OS
  695. for i in `ls .`
  696. do
  697. local iarch="`get_arch $i`"
  698. if [ "$FARCH" == "all" -o "$FARCH" = "$iarch" ];then
  699. DEVICEARCHS="$DEVICEARCHS $iarch"
  700. fi
  701. done
  702. if (! is_simulator_arch $arch);then
  703. echo "IPHONE OS: $arch"
  704. spushd $actual_arch/lib/vlc/plugins
  705. for i in `ls *.a`
  706. do
  707. VLCMODULES="$i $VLCMODULES"
  708. done
  709. spopd # $actual_arch/lib/vlc/plugins
  710. fi
  711. if [ "$OSSTYLE" != "AppleTV" -a \
  712. \( "$FARCH" = "all" -o "$FARCH" = "armv7" -o "$FARCH" = "armv7s" \) ]; then
  713. # collect ARMv7/s specific neon modules
  714. if [ "$FARCH" = "all" ];then
  715. spushd armv7/lib/vlc/plugins
  716. else
  717. spushd $FARCH/lib/vlc/plugins
  718. fi
  719. for i in `ls *.a | grep neon`
  720. do
  721. VLCNEONMODULES="$i $VLCNEONMODULES"
  722. done
  723. spopd # armv7/lib/vlc/plugins
  724. fi
  725. spopd # vlc-install-"$OSSTYLE"OS
  726. fi
  727. if [ -d ${VLCROOT}/install-"$OSSTYLE"Simulator ];then
  728. spushd ${VLCROOT}/install-"$OSSTYLE"Simulator
  729. if (is_simulator_arch $arch);then
  730. echo "SIMU OS: $arch"
  731. spushd $actual_arch/lib/vlc/plugins
  732. for i in `ls *.a`
  733. do
  734. VLCMODULES="$i $VLCMODULES"
  735. done
  736. spopd # $actual_arch/lib/vlc/plugins
  737. fi
  738. for i in `ls .`
  739. do
  740. local iarch="`get_arch $i`"
  741. if [ "$FARCH" == "all" -o "$FARCH" = "$iarch" ];then
  742. SIMULATORARCHS="$SIMULATORARCHS $iarch"
  743. fi
  744. done
  745. spopd # vlc-install-"$OSSTYLE"Simulator
  746. fi
  747. if [ "$OSSTYLE" = "MacOSX" ]; then
  748. if [ -d ${VLCROOT}/install-"$OSSTYLE" ];then
  749. spushd ${VLCROOT}/install-"$OSSTYLE"
  750. echo `pwd`
  751. echo "macOS: $arch"
  752. spushd $arch/lib/vlc/plugins
  753. for i in `ls *.a`
  754. do
  755. VLCMODULES="$i $VLCMODULES"
  756. done
  757. spopd # $actual_arch/lib/vlc/plugins
  758. spopd # vlc-install-"$OSSTYLE"
  759. fi
  760. fi
  761. spushd ${VLCROOT}
  762. # collect contrib libraries
  763. spushd contrib/$OSSTYLE-$arch-apple-darwin14-$arch/lib
  764. for i in `ls *.a`
  765. do
  766. CONTRIBLIBS="$i $CONTRIBLIBS"
  767. done
  768. spopd # contrib/$OSSTYLE-$arch-apple-darwin14-$arch/lib
  769. # lipo all the vlc libraries and its plugins
  770. if [ "$OSSTYLE" != "MacOSX" ]; then
  771. doVLCLipo "" "libvlc.a" "no" $OSSTYLE
  772. doVLCLipo "" "libvlccore.a" "no" $OSSTYLE
  773. doVLCLipo "vlc/" "libcompat.a" "no" $OSSTYLE
  774. for i in $VLCMODULES
  775. do
  776. doVLCLipo "vlc/plugins/" $i "yes" $OSSTYLE
  777. done
  778. # lipo contrib libraries
  779. for i in $CONTRIBLIBS
  780. do
  781. doContribLipo $i $OSSTYLE
  782. done
  783. if [ "$OSSTYLE" != "AppleTV" ]; then
  784. # lipo the remaining NEON plugins
  785. DEVICEARCHS=""
  786. for i in armv7 armv7s; do
  787. local iarch="`get_arch $i`"
  788. if [ "$FARCH" == "all" -o "$FARCH" = "$iarch" ];then
  789. DEVICEARCHS="$DEVICEARCHS $iarch"
  790. fi
  791. done
  792. SIMULATORARCHS=""
  793. for i in $VLCNEONMODULES
  794. do
  795. doVLCLipo "vlc/plugins/" $i "yes" $OSSTYLE
  796. done
  797. fi
  798. fi
  799. # create module list
  800. info "creating module list"
  801. echo "// This file is autogenerated by $(basename $0)\n\n" > $PROJECT_DIR/Resources/MobileVLCKit/vlc-plugins-$OSSTYLE.h
  802. echo "// This file is autogenerated by $(basename $0)\n\n" > $PROJECT_DIR/Resources/MobileVLCKit/vlc-plugins-$OSSTYLE.xcconfig
  803. # arm64 got the lowest number of modules
  804. BUILTINS="const void *vlc_static_modules[] = {\n"; \
  805. LDFLAGS=""
  806. DEFINITIONS=""
  807. # add contrib libraries to LDFLAGS
  808. for file in $CONTRIBLIBS
  809. do
  810. LDFLAGS+="${VLCROOT}/install-$OSSTYLE/contrib/$file "
  811. done
  812. for file in $VLCMODULES
  813. do
  814. symbols=$(nm -g -arch $actual_arch install-$OSSTYLE/plugins/$file)
  815. entryname=$(get_symbol "$symbols" _)
  816. DEFINITIONS+="int $entryname (int (*)(void *, void *, int, ...), void *);\n";
  817. BUILTINS+=" $entryname,\n"
  818. LDFLAGS+="${VLCROOT}/install-$OSSTYLE/plugins/$file "
  819. info "...$entryname"
  820. done;
  821. # we only have ARM NEON modules for 32bit so this is limited to iOS
  822. if [ "$OSSTYLE" = "iPhone" ]; then
  823. BUILTINS+="#ifdef __arm__\n"
  824. DEFINITIONS+="#ifdef __arm__\n"
  825. for file in $VLCNEONMODULES
  826. do
  827. symbols=$(nm -g -arch $actual_arch install-$OSSTYLE/plugins/$file)
  828. entryname=$(get_symbol "$symbols" _)
  829. DEFINITIONS+="int $entryname (int (*)(void *, void *, int, ...), void *);\n";
  830. BUILTINS+=" $entryname,\n"
  831. LDFLAGS+="${VLCROOT}/install-$OSSTYLE/plugins/$file "
  832. info "...$entryname"
  833. done;
  834. BUILTINS+="#endif\n"
  835. DEFINITIONS+="#endif\n"
  836. fi
  837. BUILTINS="$BUILTINS NULL\n};\n"
  838. echo "$DEFINITIONS\n$BUILTINS" > $PROJECT_DIR/Resources/MobileVLCKit/vlc-plugins-$OSSTYLE.h
  839. echo "VLC_PLUGINS_LDFLAGS=$LDFLAGS" > $PROJECT_DIR/Resources/MobileVLCKit/vlc-plugins-$OSSTYLE.xcconfig
  840. spopd # vlc
  841. }
  842. while getopts "hvwsfbdxntlk:a:e:" OPTION
  843. do
  844. case $OPTION in
  845. h)
  846. usage
  847. exit 1
  848. ;;
  849. v)
  850. VERBOSE=yes
  851. ;;
  852. s)
  853. BUILD_DEVICE=no
  854. BUILD_SIMULATOR=yes
  855. BUILD_STATIC_FRAMEWORK=no
  856. ;;
  857. f)
  858. BUILD_DEVICE=yes
  859. BUILD_SIMULATOR=yes
  860. BUILD_STATIC_FRAMEWORK=yes
  861. ;;
  862. d) CONFIGURATION="Debug"
  863. DEBUG=yes
  864. ;;
  865. w) SCARY="no"
  866. ;;
  867. n)
  868. NONETWORK=yes
  869. ;;
  870. l)
  871. SKIPLIBVLCCOMPILATION=yes
  872. ;;
  873. k)
  874. SDK=$OPTARG
  875. ;;
  876. a)
  877. BUILD_DEVICE=yes
  878. BUILD_SIMULATOR=yes
  879. BUILD_STATIC_FRAMEWORK=yes
  880. FARCH=$OPTARG
  881. ;;
  882. b)
  883. BITCODE=yes
  884. ;;
  885. t)
  886. TVOS=yes
  887. IOS=no
  888. BITCODE=yes
  889. SDK_VERSION=`xcrun --sdk appletvos --show-sdk-version`
  890. SDK_MIN=9.0
  891. OSVERSIONMINCFLAG=mtvos-version-min
  892. OSVERSIONMINLDFLAG=tvos_version_min
  893. ;;
  894. x)
  895. MACOS=yes
  896. IOS=no
  897. BITCODE=no
  898. SDK_VERSION=`xcrun --sdk macosx --show-sdk-version`
  899. SDK_MIN=10.9
  900. OSVERSIONMINCFLAG=mmacosx-version-min
  901. OSVERSIONMINLDFLAG=macosx_version_min
  902. BUILD_DEVICE=yes
  903. FARCH=x86_64
  904. BUILD_DYNAMIC_FRAMEWORK=yes
  905. BUILD_STATIC_FRAMEWORK=no
  906. ;;
  907. e)
  908. VLCROOT=$OPTARG
  909. ;;
  910. ?)
  911. usage
  912. exit 1
  913. ;;
  914. esac
  915. done
  916. shift $(($OPTIND - 1))
  917. out="/dev/null"
  918. if [ "$VERBOSE" = "yes" ]; then
  919. out="/dev/stdout"
  920. fi
  921. if [ "x$1" != "x" ]; then
  922. usage
  923. exit 1
  924. fi
  925. # Get root dir
  926. spushd .
  927. ROOT_DIR=`pwd`
  928. spopd
  929. if [ "$VLCROOT" = "" ]; then
  930. VLCROOT=${ROOT_DIR}/libvlc/vlc
  931. info "Preparing build dirs"
  932. mkdir -p libvlc
  933. spushd libvlc
  934. if [ "$NONETWORK" != "yes" ]; then
  935. if ! [ -e vlc ]; then
  936. git clone https://git.videolan.org/git/vlc/vlc-3.0.git vlc
  937. info "Applying patches to vlc.git"
  938. cd vlc
  939. git checkout -B localBranch ${TESTEDHASH}
  940. git branch --set-upstream-to=origin/master localBranch
  941. git am ${ROOT_DIR}/Resources/MobileVLCKit/patches/*.patch
  942. if [ $? -ne 0 ]; then
  943. git am --abort
  944. info "Applying the patches failed, aborting git-am"
  945. exit 1
  946. fi
  947. cd ..
  948. else
  949. cd vlc
  950. git reset --hard ${TESTEDHASH}
  951. git pull --rebase
  952. git am ${ROOT_DIR}/Resources/MobileVLCKit/patches/*.patch
  953. cd ..
  954. fi
  955. fi
  956. spopd
  957. fi
  958. export PATH="${VLCROOT}/extras/tools/build/bin:${VLCROOT}/contrib/${TARGET}/bin:${VLC_PATH}:/usr/bin:/bin:/usr/sbin:/sbin"
  959. echo `pwd`
  960. #
  961. # Build time
  962. #
  963. out="/dev/null"
  964. if [ "$VERBOSE" = "yes" ]; then
  965. out="/dev/stdout"
  966. fi
  967. if [ "$SKIPLIBVLCCOMPILATION" != "yes" ]; then
  968. info "Building tools"
  969. spushd ${VLCROOT}/extras/tools
  970. ./bootstrap
  971. make
  972. make .gas
  973. spopd #${VLCROOT}/extras/tools
  974. fi
  975. if [ "$BUILD_DEVICE" != "no" ]; then
  976. buildMobileKit iphoneos
  977. fi
  978. if [ "$BUILD_SIMULATOR" != "no" ]; then
  979. buildMobileKit iphonesimulator
  980. fi
  981. DEVICEARCHS=""
  982. SIMULATORARCHS=""
  983. if [ "$TVOS" = "yes" ]; then
  984. build_universal_static_lib "AppleTV"
  985. fi
  986. if [ "$MACOS" = "yes" ]; then
  987. build_universal_static_lib "MacOSX"
  988. fi
  989. if [ "$IOS" = "yes" ]; then
  990. build_universal_static_lib "iPhone"
  991. fi
  992. info "all done"
  993. if [ "$BUILD_STATIC_FRAMEWORK" != "no" ]; then
  994. if [ "$TVOS" = "yes" ]; then
  995. info "Building static TVVLCKit.framework"
  996. lipo_libs=""
  997. platform=""
  998. if [ -d ${VLCROOT}/install-AppleTVOS ];then
  999. platform="appletvos"
  1000. buildxcodeproj MobileVLCKit "TVVLCKit" ${platform}
  1001. lipo_libs="$lipo_libs ${CONFIGURATION}-appletvos/libTVVLCKit.a"
  1002. fi
  1003. if [ -d ${VLCROOT}/install-AppleTVSimulator ];then
  1004. platform="appletvsimulator"
  1005. buildxcodeproj MobileVLCKit "TVVLCKit" ${platform}
  1006. lipo_libs="$lipo_libs ${CONFIGURATION}-appletvsimulator/libTVVLCKit.a"
  1007. fi
  1008. # Assumes both platforms were built currently
  1009. spushd build
  1010. rm -rf TVVLCKit.framework && \
  1011. mkdir TVVLCKit.framework && \
  1012. lipo -create ${lipo_libs} -o TVVLCKit.framework/TVVLCKit && \
  1013. chmod a+x TVVLCKit.framework/TVVLCKit && \
  1014. cp -pr ${CONFIGURATION}-${platform}/TVVLCKit TVVLCKit.framework/Headers
  1015. spopd # build
  1016. info "Build of static TVVLCKit.framework completed"
  1017. fi
  1018. if [ "$IOS" = "yes" ]; then
  1019. info "Building static MobileVLCKit.framework"
  1020. lipo_libs=""
  1021. platform=""
  1022. if [ "$FARCH" = "all" ] || (! is_simulator_arch $FARCH);then
  1023. platform="iphoneos"
  1024. buildxcodeproj MobileVLCKit "MobileVLCKit" ${platform}
  1025. lipo_libs="$lipo_libs ${CONFIGURATION}-iphoneos/libMobileVLCKit.a"
  1026. fi
  1027. if [ "$FARCH" = "all" ] || (is_simulator_arch $arch);then
  1028. platform="iphonesimulator"
  1029. buildxcodeproj MobileVLCKit "MobileVLCKit" ${platform}
  1030. lipo_libs="$lipo_libs ${CONFIGURATION}-iphonesimulator/libMobileVLCKit.a"
  1031. fi
  1032. # Assumes both platforms were built currently
  1033. spushd build
  1034. rm -rf MobileVLCKit.framework && \
  1035. mkdir MobileVLCKit.framework && \
  1036. lipo -create ${lipo_libs} -o MobileVLCKit.framework/MobileVLCKit && \
  1037. chmod a+x MobileVLCKit.framework/MobileVLCKit && \
  1038. cp -pr ${CONFIGURATION}-${platform}/MobileVLCKit MobileVLCKit.framework/Headers
  1039. spopd # build
  1040. info "Build of static MobileVLCKit.framework completed"
  1041. fi
  1042. fi
  1043. if [ "$BUILD_DYNAMIC_FRAMEWORK" != "no" ]; then
  1044. if [ "$MACOS" = "yes" ]; then
  1045. info "Building VLCKit.framework"
  1046. buildxcodeproj VLCKit "VLCKit" "macosx"
  1047. # remove intermediate build result we don't need to keep
  1048. spushd build
  1049. rm ${CONFIGURATION}/libStaticLibVLC.a
  1050. spopd # build
  1051. info "Build of VLCKit.framework completed"
  1052. fi
  1053. fi