compileAndBuildVLCKit.sh 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195
  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=8.0
  11. VERBOSE=no
  12. DEBUG=no
  13. CONFIGURATION="Release"
  14. NONETWORK=no
  15. SKIPLIBVLCCOMPILATION=no
  16. SCARY=yes
  17. TVOS=no
  18. MACOS=no
  19. IOS=yes
  20. BITCODE=no
  21. OSVERSIONMINCFLAG=iphoneos
  22. OSVERSIONMINLDFLAG=ios
  23. ROOT_DIR=empty
  24. FARCH="all"
  25. TESTEDHASH="774a96ae6" # 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 -g"
  153. else
  154. OPTIM="-O3 -g"
  155. fi
  156. if [ "$TVOS" = "yes" ]; then
  157. OSSTYLE=AppleTV
  158. fi
  159. if [ "$MACOS" = "yes" ]; then
  160. OSSTYLE=MacOSX
  161. PLATFORM=
  162. fi
  163. ACTUAL_ARCH=`get_actual_arch $ARCH`
  164. info "Compiling ${ARCH} with SDK version ${SDK_VERSION}, platform ${PLATFORM}"
  165. SDKROOT=`xcode-select -print-path`/Platforms/${OSSTYLE}${PLATFORM}.platform/Developer/SDKs/${OSSTYLE}${PLATFORM}${SDK_VERSION}.sdk
  166. if [ ! -d "${SDKROOT}" ]
  167. then
  168. echo "*** ${SDKROOT} does not exist, please install required SDK, or set SDKROOT manually. ***"
  169. exit 1
  170. fi
  171. BUILDDIR="${VLCROOT}/build-${OSSTYLE}${PLATFORM}/${ACTUAL_ARCH}"
  172. PREFIX="${VLCROOT}/install-${OSSTYLE}${PLATFORM}/${ACTUAL_ARCH}"
  173. TARGET="${ARCH}-apple-darwin14"
  174. # partially clean the environment
  175. export CFLAGS=""
  176. export CPPFLAGS=""
  177. export CXXFLAGS=""
  178. export OBJCFLAGS=""
  179. export LDFLAGS=""
  180. export 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 symbols in 10.13
  251. export ac_cv_func_open_wmemstream=no
  252. export ac_cv_func_fmemopen=no
  253. export ac_cv_func_open_memstream=no
  254. export ac_cv_func_futimens=no
  255. export ac_cv_func_utimensat=no
  256. # Added symbols between 10.11 and 10.12
  257. export ac_cv_func_basename_r=no
  258. export ac_cv_func_clock_getres=no
  259. export ac_cv_func_clock_gettime=no
  260. export ac_cv_func_clock_settime=no
  261. export ac_cv_func_dirname_r=no
  262. export ac_cv_func_getentropy=no
  263. export ac_cv_func_mkostemp=no
  264. export ac_cv_func_mkostemps=no
  265. # Added symbols between 10.7 and 10.11
  266. export ac_cv_func_ffsll=no
  267. export ac_cv_func_flsll=no
  268. export ac_cv_func_fdopendir=no
  269. export ac_cv_func_openat=no
  270. export ac_cv_func_fstatat=no
  271. export ac_cv_func_readlinkat=no
  272. else
  273. # The following symbols do not exist on the minimal iOS version (7.0), so they are disabled
  274. # here. This allows compilation also with newer iOS SDKs
  275. # Added symbols between 7.x and 10.x
  276. export ac_cv_func_basename_r=no
  277. export ac_cv_func_clock_getres=no
  278. export ac_cv_func_clock_gettime=no
  279. export ac_cv_func_clock_settime=no
  280. export ac_cv_func_dirname_r=no
  281. export ac_cv_func_getentropy=no
  282. export ac_cv_func_mkostemp=no
  283. export ac_cv_func_mkostemps=no
  284. export ac_cv_func_open_memstream=no
  285. export ac_cv_func_futimens=no
  286. fi
  287. export USE_FFMPEG=1
  288. ../bootstrap ${BUILD} --host=${TARGET} --prefix=${VLCROOT}/contrib/${OSSTYLE}-${TARGET}-${ARCH} --disable-gpl \
  289. --enable-ad-clauses \
  290. --disable-disc \
  291. --disable-sdl \
  292. --disable-SDL_image \
  293. --disable-iconv \
  294. --enable-zvbi \
  295. --disable-kate \
  296. --disable-caca \
  297. --disable-gettext \
  298. --disable-mpcdec \
  299. --disable-upnp \
  300. --disable-gme \
  301. --disable-srt \
  302. --disable-tremor \
  303. --enable-vorbis \
  304. --disable-sidplay2 \
  305. --disable-samplerate \
  306. --disable-goom \
  307. --disable-vncserver \
  308. --disable-orc \
  309. --disable-schroedinger \
  310. --disable-libmpeg2 \
  311. --disable-chromaprint \
  312. --disable-mad \
  313. --enable-fribidi \
  314. --enable-libxml2 \
  315. --enable-freetype2 \
  316. --enable-ass \
  317. --disable-fontconfig \
  318. --disable-gpg-error \
  319. --disable-vncclient \
  320. --disable-gnutls \
  321. --disable-lua \
  322. --disable-luac \
  323. --disable-aribb24 \
  324. --disable-aribb25 \
  325. --enable-vpx \
  326. --enable-libdsm \
  327. --enable-libplacebo \
  328. --disable-sparkle \
  329. --disable-growl \
  330. --disable-breakpad \
  331. --disable-ncurses \
  332. --disable-asdcplib \
  333. --enable-soxr \
  334. ${CUSTOMOSOPTIONS} \
  335. --enable-taglib > ${out}
  336. echo "EXTRA_CFLAGS += ${EXTRA_CFLAGS}" >> config.mak
  337. echo "EXTRA_LDFLAGS += ${EXTRA_LDFLAGS}" >> config.mak
  338. echo "CC=${CC}" >> config.mak
  339. echo "CXX=${CXX}" >> config.mak
  340. echo "OBJC=${OBJC}" >> config.mak
  341. echo "LD=${LD}" >> config.mak
  342. echo "AR=${AR}" >> config.mak
  343. echo "RANLIB=${RANLIB}" >> config.mak
  344. echo "STRIP=${STRIP}" >> config.mak
  345. make fetch -j$MAKE_JOBS
  346. make -j$MAKE_JOBS > ${out}
  347. spopd # ${VLCROOT}/contrib
  348. if ! [ -e ${VLCROOT}/configure ]; then
  349. info "Bootstraping vlc"
  350. ${VLCROOT}/bootstrap > ${out}
  351. fi
  352. mkdir -p ${BUILDDIR}
  353. spushd ${BUILDDIR}
  354. if [ "$DEBUG" = "yes" ]; then
  355. DEBUGFLAG="--enable-debug"
  356. else
  357. export CFLAGS="${CFLAGS} -DNDEBUG"
  358. fi
  359. if [ "$SCARY" = "yes" ]; then
  360. SCARYFLAG="--enable-dvbpsi --enable-avcodec"
  361. else
  362. SCARYFLAG="--disable-dca --disable-dvbpsi --disable-avcodec --disable-avformat --disable-zvbi --enable-vpx"
  363. fi
  364. if [ "$TVOS" != "yes" -a \( "$ARCH" = "armv7" -o "$ARCH" = "armv7s" \) ];then
  365. export ac_cv_arm_neon=yes
  366. else
  367. export ac_cv_arm_neon=no
  368. fi
  369. # Available but not authorized
  370. export ac_cv_func_daemon=no
  371. export ac_cv_func_fork=no
  372. if [ "${VLCROOT}/configure" -nt config.log -o \
  373. "${THIS_SCRIPT_PATH}" -nt config.log ]; then
  374. info "Configuring vlc"
  375. ${VLCROOT}/configure \
  376. --prefix="${PREFIX}" \
  377. --host="${TARGET}" \
  378. --with-contrib="${VLCROOT}/contrib/${OSSTYLE}-${TARGET}-${ARCH}" \
  379. --enable-static \
  380. ${DEBUGFLAG} \
  381. ${SCARYFLAG} \
  382. --disable-macosx \
  383. --disable-macosx-qtkit \
  384. --disable-macosx-avfoundation \
  385. --disable-shared \
  386. --enable-opus \
  387. --disable-faad \
  388. --disable-lua \
  389. --disable-a52 \
  390. --enable-fribidi \
  391. --disable-qt --disable-skins2 \
  392. --disable-vcd \
  393. --disable-vlc \
  394. --disable-vlm \
  395. --disable-httpd \
  396. --disable-nls \
  397. --disable-sse \
  398. --disable-notify \
  399. --enable-live555 \
  400. --enable-realrtsp \
  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-mad > ${out}
  429. fi
  430. info "Building libvlc"
  431. make -j$MAKE_JOBS > ${out}
  432. info "Installing libvlc"
  433. make install > ${out}
  434. find ${PREFIX}/lib/vlc/plugins -name *.a -type f -exec cp '{}' ${PREFIX}/lib/vlc/plugins \;
  435. rm -rf "${PREFIX}/contribs"
  436. cp -R "${VLCROOT}/contrib/${OSSTYLE}-${TARGET}-${ARCH}" "${PREFIX}/contribs"
  437. info "Removing unneeded modules"
  438. blacklist="
  439. stats
  440. access_bd
  441. shm
  442. access_imem
  443. oldrc
  444. real
  445. hotkeys
  446. gestures
  447. dynamicoverlay
  448. rss
  449. ball
  450. marq
  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. logger
  485. visual
  486. fb
  487. aout_file
  488. invert
  489. sepia
  490. wave
  491. hqdn3d
  492. headphone_channel_mixer
  493. gaussianblur
  494. gradfun
  495. extract
  496. colorthres
  497. antiflicker
  498. anaglyph
  499. remap
  500. oldmovie
  501. vhs
  502. demuxdump
  503. fingerprinter
  504. output_udp
  505. output_livehttp
  506. "
  507. if [ "$SCARY" = "no" ]; then
  508. blacklist="${blacklist}
  509. dts
  510. dvbsub
  511. svcd
  512. hevc
  513. packetizer_mlp
  514. a52
  515. vc1
  516. uleaddvaudio
  517. librar
  518. libvoc
  519. avio
  520. chorus_flanger
  521. smooth
  522. cvdsub
  523. libmod
  524. libdash
  525. libmpgv
  526. dolby_surround
  527. mpegaudio"
  528. fi
  529. echo ${blacklist}
  530. for i in ${blacklist}
  531. do
  532. find ${PREFIX}/lib/vlc/plugins -name *$i* -type f -exec rm '{}' \;
  533. done
  534. spopd
  535. }
  536. buildMobileKit() {
  537. PLATFORM="$1"
  538. cleantheenvironment
  539. if [ "$SKIPLIBVLCCOMPILATION" != "yes" ]; then
  540. if [ "$TVOS" = "yes" ]; then
  541. # this variable is read by libvlc's contrib build script
  542. # to create the required build environment
  543. # for historical raisons, tvOS is a special flavor of iOS
  544. # so we need to export both variables
  545. export BUILDFORIOS="yes"
  546. export BUILDFORTVOS="yes"
  547. info "Building libvlc for tvOS"
  548. fi
  549. if [ "$MACOS" = "yes" ]; then
  550. # macOS is the default build environment for libvlc's contrib
  551. # build scripts, so we don't need to export anything
  552. info "Building libvlc for macOS"
  553. fi
  554. if [ "$IOS" = "yes" ]; then
  555. # this variable is read by libvlc's contrib build script
  556. # to create the required build environment
  557. export BUILDFORIOS="yes"
  558. info "Building libvlc for iOS"
  559. fi
  560. export AR=`xcrun -f ar`
  561. export RANLIB=`xcrun -f ranlib`
  562. export CC=`xcrun -f clang`
  563. export OBJC=`xcrun -f clang`
  564. export CXX=`xcrun -f clang++`
  565. export LD=`xcrun -f ld`
  566. export STRIP=`xcrun -f strip`
  567. export CPPFLAGS=-E
  568. export CXXCPPFLAGS=-E
  569. unset AS
  570. unset CCAS
  571. if [ "$FARCH" = "all" ];then
  572. if [ "$TVOS" = "yes" ]; then
  573. if [ "$PLATFORM" = "iphonesimulator" ]; then
  574. buildLibVLC "x86_64" "Simulator"
  575. else
  576. buildLibVLC "aarch64" "OS"
  577. fi
  578. fi
  579. if [ "$MACOS" = "yes" ]; then
  580. buildLibVLC "x86_64" "OS"
  581. fi
  582. if [ "$IOS" = "yes" ]; then
  583. if [ "$PLATFORM" = "iphonesimulator" ]; then
  584. buildLibVLC "i386" "Simulator"
  585. buildLibVLC "x86_64" "Simulator"
  586. else
  587. buildLibVLC "armv7" "OS"
  588. buildLibVLC "armv7s" "OS"
  589. buildLibVLC "aarch64" "OS"
  590. fi
  591. fi
  592. else
  593. if [ "$FARCH" != "x86_64" -a "$FARCH" != "aarch64" -a "$FARCH" != "i386" \
  594. -a "$FARCH" != "armv7" -a "$FARCH" != "armv7s" ];then
  595. echo "*** Framework ARCH: ${FARCH} is invalid ***"
  596. exit 1
  597. fi
  598. local buildPlatform=""
  599. if [ "$PLATFORM" = "iphonesimulator" ]; then
  600. if [ "$FARCH" == "x86_64" -o "$FARCH" == "i386" ];then
  601. buildPlatform="Simulator"
  602. fi
  603. else
  604. if [ "$FARCH" == "armv7" -o "$FARCH" == "armv7s" -o "$FARCH" == "aarch64" ];then
  605. buildPlatform="OS"
  606. fi
  607. fi
  608. if [ ! -z "$buildPlatform" ];then
  609. buildLibVLC $FARCH $buildPlatform
  610. fi
  611. fi
  612. fi
  613. }
  614. doVLCLipo() {
  615. FILEPATH="$1"
  616. FILE="$2"
  617. PLUGIN="$3"
  618. OSSTYLE="$4"
  619. files=""
  620. info "...$FILEPATH$FILE"
  621. for i in $DEVICEARCHS
  622. do
  623. actual_arch=`get_actual_arch $i`
  624. files="install-"$OSSTYLE"OS/$actual_arch/lib/$FILEPATH$FILE $files"
  625. done
  626. for i in $SIMULATORARCHS
  627. do
  628. actual_arch=`get_actual_arch $i`
  629. files="install-"$OSSTYLE"Simulator/$actual_arch/lib/$FILEPATH$FILE $files"
  630. done
  631. if [ "$PLUGIN" != "no" ]; then
  632. lipo $files -create -output install-$OSSTYLE/plugins/$FILE
  633. else
  634. lipo $files -create -output install-$OSSTYLE/core/$FILE
  635. fi
  636. }
  637. doContribLipo() {
  638. LIBNAME="$1"
  639. OSSTYLE="$2"
  640. files=""
  641. info "...$LIBNAME"
  642. for i in $DEVICEARCHS $SIMULATORARCHS
  643. do
  644. files="contrib/$OSSTYLE-$i-apple-darwin14-$i/lib/$LIBNAME $files"
  645. done
  646. lipo $files -create -output install-$OSSTYLE/contrib/$LIBNAME
  647. }
  648. get_symbol()
  649. {
  650. echo "$1" | grep vlc_entry_$2|cut -d" " -f 3|sed 's/_vlc/vlc/'
  651. }
  652. build_universal_static_lib() {
  653. PROJECT_DIR=`pwd`
  654. OSSTYLE="$1"
  655. info "building universal static libs for OS style $OSSTYLE"
  656. # remove old module list
  657. rm -f $PROJECT_DIR/Resources/MobileVLCKit/vlc-plugins-$OSSTYLE.h
  658. rm -f $PROJECT_DIR/Resources/MobileVLCKit/vlc-plugins-$OSSTYLE.xcconfig
  659. touch $PROJECT_DIR/Resources/MobileVLCKit/vlc-plugins-$OSSTYLE.h
  660. touch $PROJECT_DIR/Resources/MobileVLCKit/vlc-plugins-$OSSTYLE.xcconfig
  661. if [ "$OSSTYLE" != "MacOSX" ]; then
  662. spushd ${VLCROOT}
  663. rm -rf install-$OSSTYLE
  664. mkdir install-$OSSTYLE
  665. mkdir install-$OSSTYLE/core
  666. mkdir install-$OSSTYLE/contrib
  667. mkdir install-$OSSTYLE/plugins
  668. spopd # vlc
  669. else
  670. spushd ${VLCROOT}/install-$OSSTYLE
  671. rm -rf core
  672. rm -rf contrib
  673. rm -rf plugins
  674. ln -s x86_64/lib core
  675. ln -s x86_64/contribs/lib contrib
  676. ln -s x86_64/lib/vlc/plugins plugins
  677. spopd # vlc
  678. fi
  679. VLCMODULES=""
  680. VLCNEONMODULES=""
  681. SIMULATORARCHS=""
  682. CONTRIBLIBS=""
  683. DEVICEARCHS=""
  684. # arm64 got the lowest number of modules
  685. arch="aarch64"
  686. if [ "$FARCH" != "all" ];then
  687. arch="$FARCH"
  688. elif [ "$BUILD_SIMULATOR" = "yes" ]; then
  689. arch="x86_64"
  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. for i in `ls .`
  729. do
  730. local iarch="`get_arch $i`"
  731. if [ "$FARCH" == "all" -o "$FARCH" = "$iarch" ];then
  732. SIMULATORARCHS="$SIMULATORARCHS $iarch"
  733. fi
  734. done
  735. if (is_simulator_arch $arch);then
  736. echo "SIMU OS: $arch"
  737. spushd $arch/lib/vlc/plugins
  738. for i in `ls *.a`
  739. do
  740. VLCMODULES="$i $VLCMODULES"
  741. done
  742. spopd # $iarch/lib/vlc/plugins
  743. fi
  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+="${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+="${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+="${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:e:" 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=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.9
  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/vlc-3.0.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}/Resources/MobileVLCKit/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}/Resources/MobileVLCKit/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. spushd ${VLCROOT}/extras/tools
  973. ./bootstrap
  974. make
  975. make .gas
  976. spopd #${VLCROOT}/extras/tools
  977. fi
  978. if [ "$BUILD_DEVICE" != "no" ]; then
  979. buildMobileKit iphoneos
  980. fi
  981. if [ "$BUILD_SIMULATOR" != "no" ]; then
  982. buildMobileKit iphonesimulator
  983. fi
  984. DEVICEARCHS=""
  985. SIMULATORARCHS=""
  986. if [ "$TVOS" = "yes" ]; then
  987. build_universal_static_lib "AppleTV"
  988. fi
  989. if [ "$MACOS" = "yes" ]; then
  990. build_universal_static_lib "MacOSX"
  991. fi
  992. if [ "$IOS" = "yes" ]; then
  993. build_universal_static_lib "iPhone"
  994. fi
  995. info "all done"
  996. if [ "$BUILD_STATIC_FRAMEWORK" != "no" ]; then
  997. if [ "$TVOS" = "yes" ]; then
  998. info "Building static TVVLCKit.framework"
  999. lipo_libs=""
  1000. platform=""
  1001. if [ "$FARCH" = "all" ] || (! is_simulator_arch $FARCH);then
  1002. platform="appletvos"
  1003. buildxcodeproj MobileVLCKit "TVVLCKit" ${platform}
  1004. lipo_libs="$lipo_libs ${CONFIGURATION}-appletvos/libTVVLCKit.a"
  1005. fi
  1006. if [ "$FARCH" = "all" ] || (is_simulator_arch $arch);then
  1007. platform="appletvsimulator"
  1008. buildxcodeproj MobileVLCKit "TVVLCKit" ${platform}
  1009. lipo_libs="$lipo_libs ${CONFIGURATION}-appletvsimulator/libTVVLCKit.a"
  1010. fi
  1011. # Assumes both platforms were built currently
  1012. spushd build
  1013. rm -rf TVVLCKit.framework && \
  1014. mkdir TVVLCKit.framework && \
  1015. lipo -create ${lipo_libs} -o TVVLCKit.framework/TVVLCKit && \
  1016. chmod a+x TVVLCKit.framework/TVVLCKit && \
  1017. cp -pr ${CONFIGURATION}-${platform}/TVVLCKit TVVLCKit.framework/Headers
  1018. cp -pr ${CONFIGURATION}-${platform}/Modules TVVLCKit.framework/Modules
  1019. spopd # build
  1020. info "Build of static TVVLCKit.framework completed"
  1021. fi
  1022. if [ "$IOS" = "yes" ]; then
  1023. info "Building static MobileVLCKit.framework"
  1024. lipo_libs=""
  1025. platform=""
  1026. if [ "$FARCH" = "all" ] || (! is_simulator_arch $FARCH);then
  1027. platform="iphoneos"
  1028. buildxcodeproj MobileVLCKit "MobileVLCKit" ${platform}
  1029. lipo_libs="$lipo_libs ${CONFIGURATION}-iphoneos/libMobileVLCKit.a"
  1030. fi
  1031. if [ "$FARCH" = "all" ] || (is_simulator_arch $arch);then
  1032. platform="iphonesimulator"
  1033. buildxcodeproj MobileVLCKit "MobileVLCKit" ${platform}
  1034. lipo_libs="$lipo_libs ${CONFIGURATION}-iphonesimulator/libMobileVLCKit.a"
  1035. fi
  1036. # Assumes both platforms were built currently
  1037. spushd build
  1038. rm -rf MobileVLCKit.framework && \
  1039. mkdir MobileVLCKit.framework && \
  1040. lipo -create ${lipo_libs} -o MobileVLCKit.framework/MobileVLCKit && \
  1041. chmod a+x MobileVLCKit.framework/MobileVLCKit && \
  1042. cp -pr ${CONFIGURATION}-${platform}/MobileVLCKit MobileVLCKit.framework/Headers
  1043. cp -pr ${CONFIGURATION}-${platform}/Modules MobileVLCKit.framework/Modules
  1044. spopd # build
  1045. info "Build of static MobileVLCKit.framework completed"
  1046. fi
  1047. fi
  1048. if [ "$BUILD_DYNAMIC_FRAMEWORK" != "no" ]; then
  1049. if [ "$MACOS" = "yes" ]; then
  1050. info "Building VLCKit.framework"
  1051. buildxcodeproj VLCKit "VLCKit" "macosx"
  1052. # remove intermediate build result we don't need to keep
  1053. spushd build
  1054. rm ${CONFIGURATION}/libStaticLibVLC.a
  1055. spopd # build
  1056. info "Build of VLCKit.framework completed"
  1057. fi
  1058. fi