compileAndBuildVLCKit.sh 32 KB

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