compileAndBuildVLCKit.sh 31 KB

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