compileAndBuildVLCKit.sh 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172
  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. OBJCFLAGS="${OPTIM}"
  183. CFLAGS="-isysroot ${SDKROOT} -arch ${ACTUAL_ARCH} ${OPTIM}"
  184. EXTRA_CFLAGS="-arch ${ACTUAL_ARCH}"
  185. LDFLAGS="-arch ${ACTUAL_ARCH}"
  186. EXTRA_LDFLAGS="-arch ${ACTUAL_ARCH}"
  187. CFLAGS+=" -${OSVERSIONMINCFLAG}=${SDK_MIN}"
  188. EXTRA_CFLAGS+=" -${OSVERSIONMINCFLAG}=${SDK_MIN}"
  189. LDFLAGS+=" -Wl,-${OSVERSIONMINLDFLAG},${SDK_MIN}"
  190. EXTRA_LDFLAGS+=" -Wl,-${OSVERSIONMINLDFLAG},${SDK_MIN}"
  191. if [ "$PLATFORM" = "OS" ]; then
  192. if [ "$ARCH" != "aarch64" ]; then
  193. CFLAGS+=" -mcpu=cortex-a8"
  194. EXTRA_CFLAGS+=" -mcpu=cortex-a8"
  195. fi
  196. else # Simulator platform
  197. LDFLAGS+=" -v"
  198. # Use the new ABI on simulator, else we can't build
  199. OBJCFLAGS+=" -fobjc-abi-version=2 -fobjc-legacy-dispatch"
  200. fi
  201. if [ "$BITCODE" = "yes" ]; then
  202. CFLAGS+=" -fembed-bitcode"
  203. fi
  204. export CFLAGS="${CFLAGS}"
  205. export CXXFLAGS="${CFLAGS}"
  206. export CPPFLAGS="${CFLAGS}"
  207. export OBJCFLAGS="${OBJCFLAGS}"
  208. export LDFLAGS="${LDFLAGS}"
  209. spushd ${VLCROOT}/contrib
  210. info "Compiling third-party libraries"
  211. mkdir -p "${VLCROOT}/contrib/${OSSTYLE}${PLATFORM}-${ARCH}"
  212. cd "${VLCROOT}/contrib/${OSSTYLE}${PLATFORM}-${ARCH}"
  213. if [ "$PLATFORM" = "OS" ]; then
  214. export AS="gas-preprocessor.pl ${CC}"
  215. export ASCPP="gas-preprocessor.pl ${CC}"
  216. export CCAS="gas-preprocessor.pl ${CC}"
  217. if [ "$ARCH" = "aarch64" ]; then
  218. export GASPP_FIX_XCODE5=1
  219. fi
  220. else
  221. export ASCPP="xcrun as"
  222. fi
  223. if [ "$TVOS" = "yes" ]; then
  224. CUSTOMOSOPTIONS="--disable-libarchive"
  225. fi
  226. if [ "$MACOS" = "yes" ]; then
  227. CUSTOMOSOPTIONS="--disable-fontconfig --disable-bghudappkit --disable-twolame --disable-microdns --disable-SDL --disable-SDL_image --disable-cddb --disable-bluray"
  228. fi
  229. if [ "$IOS" = "yes" ]; then
  230. CUSTOMOSOPTIONS=""
  231. fi
  232. if [ "${TARGET}" = "x86_64-apple-darwin14" ];then
  233. BUILD=""
  234. else
  235. BUILD="--build=x86_64-apple-darwin14"
  236. fi
  237. if [ "$MACOS" = "yes" ]; then
  238. # The following symbols do not exist on the minimal macOS version (10.7), so they are disabled
  239. # here. This allows compilation also with newer macOS SDKs.
  240. # Added symbols in 10.13
  241. export ac_cv_func_open_wmemstream=no
  242. export ac_cv_func_fmemopen=no
  243. export ac_cv_func_open_memstream=no
  244. export ac_cv_func_futimens=no
  245. export ac_cv_func_utimensat=no
  246. # Added symbols between 10.11 and 10.12
  247. export ac_cv_func_basename_r=no
  248. export ac_cv_func_clock_getres=no
  249. export ac_cv_func_clock_gettime=no
  250. export ac_cv_func_clock_settime=no
  251. export ac_cv_func_dirname_r=no
  252. export ac_cv_func_getentropy=no
  253. export ac_cv_func_mkostemp=no
  254. export ac_cv_func_mkostemps=no
  255. # Added symbols between 10.7 and 10.11
  256. export ac_cv_func_ffsll=no
  257. export ac_cv_func_flsll=no
  258. export ac_cv_func_fdopendir=no
  259. export ac_cv_func_openat=no
  260. export ac_cv_func_fstatat=no
  261. export ac_cv_func_readlinkat=no
  262. else
  263. # The following symbols do not exist on the minimal iOS version (7.0), so they are disabled
  264. # here. This allows compilation also with newer iOS SDKs
  265. # Added symbols between 7.x and 10.x
  266. export ac_cv_func_basename_r=no
  267. export ac_cv_func_clock_getres=no
  268. export ac_cv_func_clock_gettime=no
  269. export ac_cv_func_clock_settime=no
  270. export ac_cv_func_dirname_r=no
  271. export ac_cv_func_getentropy=no
  272. export ac_cv_func_mkostemp=no
  273. export ac_cv_func_mkostemps=no
  274. export ac_cv_func_open_memstream=no
  275. export ac_cv_func_futimens=no
  276. fi
  277. export USE_FFMPEG=1
  278. ../bootstrap ${BUILD} --host=${TARGET} --prefix=${VLCROOT}/contrib/${OSSTYLE}-${TARGET}-${ARCH} --disable-gpl \
  279. --enable-ad-clauses \
  280. --disable-disc --disable-sout \
  281. --disable-sdl \
  282. --disable-SDL_image \
  283. --disable-iconv \
  284. --enable-zvbi \
  285. --disable-kate \
  286. --disable-caca \
  287. --disable-gettext \
  288. --disable-mpcdec \
  289. --disable-upnp \
  290. --disable-gme \
  291. --disable-srt \
  292. --disable-tremor \
  293. --enable-vorbis \
  294. --disable-sidplay2 \
  295. --disable-samplerate \
  296. --disable-goom \
  297. --disable-vncserver \
  298. --disable-orc \
  299. --disable-schroedinger \
  300. --disable-libmpeg2 \
  301. --disable-chromaprint \
  302. --disable-mad \
  303. --enable-fribidi \
  304. --enable-libxml2 \
  305. --enable-freetype2 \
  306. --enable-ass \
  307. --disable-fontconfig \
  308. --disable-gpg-error \
  309. --disable-vncclient \
  310. --disable-gnutls \
  311. --disable-lua \
  312. --disable-luac \
  313. --disable-protobuf \
  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 --disable-vpx"
  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. dummy
  473. invert
  474. sepia
  475. wave
  476. hqdn3d
  477. headphone_channel_mixer
  478. gaussianblur
  479. gradfun
  480. extract
  481. colorthres
  482. antiflicker
  483. anaglyph
  484. remap
  485. oldmovie
  486. vhs
  487. demuxdump
  488. fingerprinter
  489. output_udp
  490. output_http
  491. output_livehttp
  492. libmux
  493. stream_out
  494. "
  495. if [ "$SCARY" = "no" ]; then
  496. blacklist="${blacklist}
  497. dts
  498. dvbsub
  499. svcd
  500. hevc
  501. packetizer_mlp
  502. a52
  503. vc1
  504. uleaddvaudio
  505. librar
  506. libvoc
  507. avio
  508. chorus_flanger
  509. smooth
  510. cvdsub
  511. libmod
  512. libdash
  513. libmpgv
  514. dolby_surround
  515. mpegaudio"
  516. fi
  517. echo ${blacklist}
  518. for i in ${blacklist}
  519. do
  520. find ${PREFIX}/lib/vlc/plugins -name *$i* -type f -exec rm '{}' \;
  521. done
  522. spopd
  523. }
  524. buildMobileKit() {
  525. PLATFORM="$1"
  526. cleantheenvironment
  527. if [ "$SKIPLIBVLCCOMPILATION" != "yes" ]; then
  528. if [ "$TVOS" = "yes" ]; then
  529. # this variable is read by libvlc's contrib build script
  530. # to create the required build environment
  531. # for historical raisons, tvOS is a special flavor of iOS
  532. # so we need to export both variables
  533. export BUILDFORIOS="yes"
  534. export BUILDFORTVOS="yes"
  535. info "Building libvlc for tvOS"
  536. fi
  537. if [ "$MACOS" = "yes" ]; then
  538. # macOS is the default build environment for libvlc's contrib
  539. # build scripts, so we don't need to export anything
  540. info "Building libvlc for macOS"
  541. fi
  542. if [ "$IOS" = "yes" ]; then
  543. # this variable is read by libvlc's contrib build script
  544. # to create the required build environment
  545. export BUILDFORIOS="yes"
  546. info "Building libvlc for iOS"
  547. fi
  548. export AR=`xcrun -f ar`
  549. export RANLIB=`xcrun -f ranlib`
  550. export CC=`xcrun -f clang`
  551. export OBJC=`xcrun -f clang`
  552. export CXX=`xcrun -f clang++`
  553. export LD=`xcrun -f ld`
  554. export STRIP=`xcrun -f strip`
  555. export CPPFLAGS=-E
  556. export CXXCPPFLAGS=-E
  557. unset AS
  558. unset CCAS
  559. if [ "$FARCH" = "all" ];then
  560. if [ "$TVOS" = "yes" ]; then
  561. if [ "$PLATFORM" = "iphonesimulator" ]; then
  562. buildLibVLC "x86_64" "Simulator"
  563. else
  564. buildLibVLC "aarch64" "OS"
  565. fi
  566. fi
  567. if [ "$MACOS" = "yes" ]; then
  568. buildLibVLC "x86_64" "OS"
  569. fi
  570. if [ "$IOS" = "yes" ]; then
  571. if [ "$PLATFORM" = "iphonesimulator" ]; then
  572. buildLibVLC "i386" "Simulator"
  573. buildLibVLC "x86_64" "Simulator"
  574. else
  575. buildLibVLC "armv7" "OS"
  576. buildLibVLC "armv7s" "OS"
  577. buildLibVLC "aarch64" "OS"
  578. fi
  579. fi
  580. else
  581. if [ "$FARCH" != "x86_64" -a "$FARCH" != "aarch64" -a "$FARCH" != "i386" \
  582. -a "$FARCH" != "armv7" -a "$FARCH" != "armv7s" ];then
  583. echo "*** Framework ARCH: ${FARCH} is invalid ***"
  584. exit 1
  585. fi
  586. local buildPlatform=""
  587. if [ "$PLATFORM" = "iphonesimulator" ]; then
  588. if [ "$FARCH" == "x86_64" -o "$FARCH" == "i386" ];then
  589. buildPlatform="Simulator"
  590. fi
  591. else
  592. if [ "$FARCH" == "armv7" -o "$FARCH" == "armv7s" -o "$FARCH" == "aarch64" ];then
  593. buildPlatform="OS"
  594. fi
  595. fi
  596. if [ ! -z "$buildPlatform" ];then
  597. buildLibVLC $FARCH $buildPlatform
  598. fi
  599. fi
  600. fi
  601. }
  602. doVLCLipo() {
  603. FILEPATH="$1"
  604. FILE="$2"
  605. PLUGIN="$3"
  606. OSSTYLE="$4"
  607. files=""
  608. info "...$FILEPATH$FILE"
  609. for i in $DEVICEARCHS
  610. do
  611. actual_arch=`get_actual_arch $i`
  612. files="install-"$OSSTYLE"OS/$actual_arch/lib/$FILEPATH$FILE $files"
  613. done
  614. for i in $SIMULATORARCHS
  615. do
  616. actual_arch=`get_actual_arch $i`
  617. files="install-"$OSSTYLE"Simulator/$actual_arch/lib/$FILEPATH$FILE $files"
  618. done
  619. if [ "$PLUGIN" != "no" ]; then
  620. lipo $files -create -output install-$OSSTYLE/plugins/$FILE
  621. else
  622. lipo $files -create -output install-$OSSTYLE/core/$FILE
  623. fi
  624. }
  625. doContribLipo() {
  626. LIBNAME="$1"
  627. OSSTYLE="$2"
  628. files=""
  629. info "...$LIBNAME"
  630. for i in $DEVICEARCHS $SIMULATORARCHS
  631. do
  632. files="contrib/$OSSTYLE-$i-apple-darwin14-$i/lib/$LIBNAME $files"
  633. done
  634. lipo $files -create -output install-$OSSTYLE/contrib/$LIBNAME
  635. }
  636. get_symbol()
  637. {
  638. echo "$1" | grep vlc_entry_$2|cut -d" " -f 3|sed 's/_vlc/vlc/'
  639. }
  640. build_universal_static_lib() {
  641. PROJECT_DIR=`pwd`
  642. OSSTYLE="$1"
  643. info "building universal static libs for OS style $OSSTYLE"
  644. # remove old module list
  645. rm -f $PROJECT_DIR/Resources/MobileVLCKit/vlc-plugins-$OSSTYLE.h
  646. rm -f $PROJECT_DIR/Resources/MobileVLCKit/vlc-plugins-$OSSTYLE.xcconfig
  647. touch $PROJECT_DIR/Resources/MobileVLCKit/vlc-plugins-$OSSTYLE.h
  648. touch $PROJECT_DIR/Resources/MobileVLCKit/vlc-plugins-$OSSTYLE.xcconfig
  649. if [ "$OSSTYLE" != "MacOSX" ]; then
  650. spushd ${VLCROOT}
  651. rm -rf install-$OSSTYLE
  652. mkdir install-$OSSTYLE
  653. mkdir install-$OSSTYLE/core
  654. mkdir install-$OSSTYLE/contrib
  655. mkdir install-$OSSTYLE/plugins
  656. spopd # vlc
  657. else
  658. spushd ${VLCROOT}/install-$OSSTYLE
  659. rm -rf core
  660. rm -rf contrib
  661. rm -rf plugins
  662. ln -s x86_64/lib core
  663. ln -s x86_64/contribs/lib contrib
  664. ln -s x86_64/lib/vlc/plugins plugins
  665. spopd # vlc
  666. fi
  667. VLCMODULES=""
  668. VLCNEONMODULES=""
  669. SIMULATORARCHS=""
  670. CONTRIBLIBS=""
  671. DEVICEARCHS=""
  672. # arm64 got the lowest number of modules
  673. arch="aarch64"
  674. if [ "$FARCH" != "all" ];then
  675. arch="$FARCH"
  676. fi
  677. actual_arch=`get_actual_arch $arch`
  678. if [ -d ${VLCROOT}/install-"$OSSTYLE"OS ];then
  679. spushd ${VLCROOT}/install-"$OSSTYLE"OS
  680. for i in `ls .`
  681. do
  682. local iarch="`get_arch $i`"
  683. if [ "$FARCH" == "all" -o "$FARCH" = "$iarch" ];then
  684. DEVICEARCHS="$DEVICEARCHS $iarch"
  685. fi
  686. done
  687. if (! is_simulator_arch $arch);then
  688. echo "IPHONE OS: $arch"
  689. spushd $actual_arch/lib/vlc/plugins
  690. for i in `ls *.a`
  691. do
  692. VLCMODULES="$i $VLCMODULES"
  693. done
  694. spopd # $actual_arch/lib/vlc/plugins
  695. fi
  696. if [ "$OSSTYLE" != "AppleTV" -a \
  697. \( "$FARCH" = "all" -o "$FARCH" = "armv7" -o "$FARCH" = "armv7s" \) ]; then
  698. # collect ARMv7/s specific neon modules
  699. if [ "$FARCH" = "all" ];then
  700. spushd armv7/lib/vlc/plugins
  701. else
  702. spushd $FARCH/lib/vlc/plugins
  703. fi
  704. for i in `ls *.a | grep neon`
  705. do
  706. VLCNEONMODULES="$i $VLCNEONMODULES"
  707. done
  708. spopd # armv7/lib/vlc/plugins
  709. fi
  710. spopd # vlc-install-"$OSSTYLE"OS
  711. fi
  712. if [ -d ${VLCROOT}/install-"$OSSTYLE"Simulator ];then
  713. spushd ${VLCROOT}/install-"$OSSTYLE"Simulator
  714. if (is_simulator_arch $arch);then
  715. echo "SIMU OS: $arch"
  716. spushd $actual_arch/lib/vlc/plugins
  717. for i in `ls *.a`
  718. do
  719. VLCMODULES="$i $VLCMODULES"
  720. done
  721. spopd # $actual_arch/lib/vlc/plugins
  722. fi
  723. for i in `ls .`
  724. do
  725. local iarch="`get_arch $i`"
  726. if [ "$FARCH" == "all" -o "$FARCH" = "$iarch" ];then
  727. SIMULATORARCHS="$SIMULATORARCHS $iarch"
  728. fi
  729. done
  730. spopd # vlc-install-"$OSSTYLE"Simulator
  731. fi
  732. if [ "$OSSTYLE" = "MacOSX" ]; then
  733. if [ -d ${VLCROOT}/install-"$OSSTYLE" ];then
  734. spushd ${VLCROOT}/install-"$OSSTYLE"
  735. echo `pwd`
  736. echo "macOS: $arch"
  737. spushd $arch/lib/vlc/plugins
  738. for i in `ls *.a`
  739. do
  740. VLCMODULES="$i $VLCMODULES"
  741. done
  742. spopd # $actual_arch/lib/vlc/plugins
  743. spopd # vlc-install-"$OSSTYLE"
  744. fi
  745. fi
  746. spushd ${VLCROOT}
  747. # collect contrib libraries
  748. spushd contrib/$OSSTYLE-$arch-apple-darwin14-$arch/lib
  749. for i in `ls *.a`
  750. do
  751. CONTRIBLIBS="$i $CONTRIBLIBS"
  752. done
  753. spopd # contrib/$OSSTYLE-$arch-apple-darwin14-$arch/lib
  754. # lipo all the vlc libraries and its plugins
  755. if [ "$OSSTYLE" != "MacOSX" ]; then
  756. doVLCLipo "" "libvlc.a" "no" $OSSTYLE
  757. doVLCLipo "" "libvlccore.a" "no" $OSSTYLE
  758. doVLCLipo "vlc/" "libcompat.a" "no" $OSSTYLE
  759. for i in $VLCMODULES
  760. do
  761. doVLCLipo "vlc/plugins/" $i "yes" $OSSTYLE
  762. done
  763. # lipo contrib libraries
  764. for i in $CONTRIBLIBS
  765. do
  766. doContribLipo $i $OSSTYLE
  767. done
  768. if [ "$OSSTYLE" != "AppleTV" ]; then
  769. # lipo the remaining NEON plugins
  770. DEVICEARCHS=""
  771. for i in armv7 armv7s; do
  772. local iarch="`get_arch $i`"
  773. if [ "$FARCH" == "all" -o "$FARCH" = "$iarch" ];then
  774. DEVICEARCHS="$DEVICEARCHS $iarch"
  775. fi
  776. done
  777. SIMULATORARCHS=""
  778. for i in $VLCNEONMODULES
  779. do
  780. doVLCLipo "vlc/plugins/" $i "yes" $OSSTYLE
  781. done
  782. fi
  783. fi
  784. # create module list
  785. info "creating module list"
  786. echo "// This file is autogenerated by $(basename $0)\n\n" > $PROJECT_DIR/Resources/MobileVLCKit/vlc-plugins-$OSSTYLE.h
  787. echo "// This file is autogenerated by $(basename $0)\n\n" > $PROJECT_DIR/Resources/MobileVLCKit/vlc-plugins-$OSSTYLE.xcconfig
  788. # arm64 got the lowest number of modules
  789. BUILTINS="const void *vlc_static_modules[] = {\n"; \
  790. LDFLAGS=""
  791. DEFINITIONS=""
  792. # add contrib libraries to LDFLAGS
  793. for file in $CONTRIBLIBS
  794. do
  795. LDFLAGS+="${VLCROOT}/install-$OSSTYLE/contrib/$file "
  796. done
  797. for file in $VLCMODULES
  798. do
  799. symbols=$(nm -g -arch $actual_arch install-$OSSTYLE/plugins/$file)
  800. entryname=$(get_symbol "$symbols" _)
  801. DEFINITIONS+="int $entryname (int (*)(void *, void *, int, ...), void *);\n";
  802. BUILTINS+=" $entryname,\n"
  803. LDFLAGS+="${VLCROOT}/install-$OSSTYLE/plugins/$file "
  804. info "...$entryname"
  805. done;
  806. # we only have ARM NEON modules for 32bit so this is limited to iOS
  807. if [ "$OSSTYLE" = "iPhone" ]; then
  808. BUILTINS+="#ifdef __arm__\n"
  809. DEFINITIONS+="#ifdef __arm__\n"
  810. for file in $VLCNEONMODULES
  811. do
  812. symbols=$(nm -g -arch $actual_arch install-$OSSTYLE/plugins/$file)
  813. entryname=$(get_symbol "$symbols" _)
  814. DEFINITIONS+="int $entryname (int (*)(void *, void *, int, ...), void *);\n";
  815. BUILTINS+=" $entryname,\n"
  816. LDFLAGS+="${VLCROOT}/install-$OSSTYLE/plugins/$file "
  817. info "...$entryname"
  818. done;
  819. BUILTINS+="#endif\n"
  820. DEFINITIONS+="#endif\n"
  821. fi
  822. BUILTINS="$BUILTINS NULL\n};\n"
  823. echo "$DEFINITIONS\n$BUILTINS" >> $PROJECT_DIR/Resources/MobileVLCKit/vlc-plugins-$OSSTYLE.h
  824. echo "VLC_PLUGINS_LDFLAGS=$LDFLAGS" >> $PROJECT_DIR/Resources/MobileVLCKit/vlc-plugins-$OSSTYLE.xcconfig
  825. spopd # vlc
  826. }
  827. while getopts "hvwsfbdxntlk:a:e:" OPTION
  828. do
  829. case $OPTION in
  830. h)
  831. usage
  832. exit 1
  833. ;;
  834. v)
  835. VERBOSE=yes
  836. ;;
  837. s)
  838. BUILD_DEVICE=no
  839. BUILD_SIMULATOR=yes
  840. BUILD_STATIC_FRAMEWORK=no
  841. ;;
  842. f)
  843. BUILD_DEVICE=yes
  844. BUILD_SIMULATOR=yes
  845. BUILD_STATIC_FRAMEWORK=yes
  846. ;;
  847. d) CONFIGURATION="Debug"
  848. DEBUG=yes
  849. ;;
  850. w) SCARY="no"
  851. ;;
  852. n)
  853. NONETWORK=yes
  854. ;;
  855. l)
  856. SKIPLIBVLCCOMPILATION=yes
  857. ;;
  858. k)
  859. SDK=$OPTARG
  860. ;;
  861. a)
  862. BUILD_DEVICE=yes
  863. BUILD_SIMULATOR=yes
  864. BUILD_STATIC_FRAMEWORK=yes
  865. FARCH=$OPTARG
  866. ;;
  867. b)
  868. BITCODE=yes
  869. ;;
  870. t)
  871. TVOS=yes
  872. IOS=no
  873. BITCODE=yes
  874. SDK_VERSION=`xcrun --sdk appletvos --show-sdk-version`
  875. SDK_MIN=9.0
  876. OSVERSIONMINCFLAG=mtvos-version-min
  877. OSVERSIONMINLDFLAG=tvos_version_min
  878. ;;
  879. x)
  880. MACOS=yes
  881. IOS=no
  882. BITCODE=no
  883. SDK_VERSION=`xcrun --sdk macosx --show-sdk-version`
  884. SDK_MIN=10.9
  885. OSVERSIONMINCFLAG=mmacosx-version-min
  886. OSVERSIONMINLDFLAG=macosx_version_min
  887. BUILD_DEVICE=yes
  888. FARCH=x86_64
  889. BUILD_DYNAMIC_FRAMEWORK=yes
  890. BUILD_STATIC_FRAMEWORK=no
  891. ;;
  892. e)
  893. VLCROOT=$OPTARG
  894. ;;
  895. ?)
  896. usage
  897. exit 1
  898. ;;
  899. esac
  900. done
  901. shift $(($OPTIND - 1))
  902. out="/dev/null"
  903. if [ "$VERBOSE" = "yes" ]; then
  904. out="/dev/stdout"
  905. fi
  906. if [ "x$1" != "x" ]; then
  907. usage
  908. exit 1
  909. fi
  910. # Get root dir
  911. spushd .
  912. ROOT_DIR=`pwd`
  913. spopd
  914. if [ "$VLCROOT" = "" ]; then
  915. VLCROOT=${ROOT_DIR}/libvlc/vlc
  916. info "Preparing build dirs"
  917. mkdir -p libvlc
  918. spushd libvlc
  919. if [ "$NONETWORK" != "yes" ]; then
  920. if ! [ -e vlc ]; then
  921. git clone https://git.videolan.org/git/vlc/vlc-3.0.git vlc
  922. info "Applying patches to vlc.git"
  923. cd vlc
  924. git checkout -B localBranch ${TESTEDHASH}
  925. git branch --set-upstream-to=origin/master localBranch
  926. git am ${ROOT_DIR}/Resources/MobileVLCKit/patches/*.patch
  927. if [ $? -ne 0 ]; then
  928. git am --abort
  929. info "Applying the patches failed, aborting git-am"
  930. exit 1
  931. fi
  932. cd ..
  933. else
  934. cd vlc
  935. git reset --hard ${TESTEDHASH}
  936. git pull --rebase
  937. git am ${ROOT_DIR}/Resources/MobileVLCKit/patches/*.patch
  938. cd ..
  939. fi
  940. fi
  941. spopd
  942. fi
  943. export PATH="${VLCROOT}/extras/tools/build/bin:${VLCROOT}/contrib/${TARGET}/bin:${VLC_PATH}:/usr/bin:/bin:/usr/sbin:/sbin"
  944. echo `pwd`
  945. #
  946. # Build time
  947. #
  948. out="/dev/null"
  949. if [ "$VERBOSE" = "yes" ]; then
  950. out="/dev/stdout"
  951. fi
  952. if [ "$SKIPLIBVLCCOMPILATION" != "yes" ]; then
  953. info "Building tools"
  954. spushd ${VLCROOT}/extras/tools
  955. ./bootstrap
  956. make
  957. make .gas
  958. spopd #${VLCROOT}/extras/tools
  959. fi
  960. if [ "$BUILD_DEVICE" != "no" ]; then
  961. buildMobileKit iphoneos
  962. fi
  963. if [ "$BUILD_SIMULATOR" != "no" ]; then
  964. buildMobileKit iphonesimulator
  965. fi
  966. DEVICEARCHS=""
  967. SIMULATORARCHS=""
  968. if [ "$TVOS" = "yes" ]; then
  969. build_universal_static_lib "AppleTV"
  970. fi
  971. if [ "$MACOS" = "yes" ]; then
  972. build_universal_static_lib "MacOSX"
  973. fi
  974. if [ "$IOS" = "yes" ]; then
  975. build_universal_static_lib "iPhone"
  976. fi
  977. info "all done"
  978. if [ "$BUILD_STATIC_FRAMEWORK" != "no" ]; then
  979. if [ "$TVOS" = "yes" ]; then
  980. info "Building static TVVLCKit.framework"
  981. lipo_libs=""
  982. platform=""
  983. if [ -d ${VLCROOT}/install-AppleTVOS ];then
  984. platform="appletvos"
  985. buildxcodeproj MobileVLCKit "TVVLCKit" ${platform}
  986. lipo_libs="$lipo_libs ${CONFIGURATION}-appletvos/libTVVLCKit.a"
  987. fi
  988. if [ -d ${VLCROOT}/install-AppleTVSimulator ];then
  989. platform="appletvsimulator"
  990. buildxcodeproj MobileVLCKit "TVVLCKit" ${platform}
  991. lipo_libs="$lipo_libs ${CONFIGURATION}-appletvsimulator/libTVVLCKit.a"
  992. fi
  993. # Assumes both platforms were built currently
  994. spushd build
  995. rm -rf TVVLCKit.framework && \
  996. mkdir TVVLCKit.framework && \
  997. lipo -create ${lipo_libs} -o TVVLCKit.framework/TVVLCKit && \
  998. chmod a+x TVVLCKit.framework/TVVLCKit && \
  999. cp -pr ${CONFIGURATION}-${platform}/TVVLCKit TVVLCKit.framework/Headers
  1000. spopd # build
  1001. info "Build of static TVVLCKit.framework completed"
  1002. fi
  1003. if [ "$IOS" = "yes" ]; then
  1004. info "Building static MobileVLCKit.framework"
  1005. lipo_libs=""
  1006. platform=""
  1007. if [ "$FARCH" = "all" ] || (! is_simulator_arch $FARCH);then
  1008. platform="iphoneos"
  1009. buildxcodeproj MobileVLCKit "MobileVLCKit" ${platform}
  1010. lipo_libs="$lipo_libs ${CONFIGURATION}-iphoneos/libMobileVLCKit.a"
  1011. fi
  1012. if [ "$FARCH" = "all" ] || (is_simulator_arch $arch);then
  1013. platform="iphonesimulator"
  1014. buildxcodeproj MobileVLCKit "MobileVLCKit" ${platform}
  1015. lipo_libs="$lipo_libs ${CONFIGURATION}-iphonesimulator/libMobileVLCKit.a"
  1016. fi
  1017. # Assumes both platforms were built currently
  1018. spushd build
  1019. rm -rf MobileVLCKit.framework && \
  1020. mkdir MobileVLCKit.framework && \
  1021. lipo -create ${lipo_libs} -o MobileVLCKit.framework/MobileVLCKit && \
  1022. chmod a+x MobileVLCKit.framework/MobileVLCKit && \
  1023. cp -pr ${CONFIGURATION}-${platform}/MobileVLCKit MobileVLCKit.framework/Headers
  1024. spopd # build
  1025. info "Build of static MobileVLCKit.framework completed"
  1026. fi
  1027. fi
  1028. if [ "$BUILD_DYNAMIC_FRAMEWORK" != "no" ]; then
  1029. if [ "$MACOS" = "yes" ]; then
  1030. info "Building VLCKit.framework"
  1031. buildxcodeproj VLCKit "VLCKit" "macosx"
  1032. # remove intermediate build result we don't need to keep
  1033. spushd build
  1034. rm ${CONFIGURATION}/libStaticLibVLC.a
  1035. spopd # build
  1036. info "Build of VLCKit.framework completed"
  1037. fi
  1038. fi