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=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="fb26e2443" # 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 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-libplacebo \
  327. --disable-sparkle \
  328. --disable-growl \
  329. --disable-breakpad \
  330. --disable-ncurses \
  331. --disable-asdcplib \
  332. --enable-soxr \
  333. --disable-aom \
  334. --enable-dav1d \
  335. --disable-sqlite \
  336. --disable-medialibrary \
  337. --disable-libdsm \
  338. ${CUSTOMOSOPTIONS} \
  339. --enable-taglib > ${out}
  340. make fetch -j$MAKE_JOBS
  341. make -j$MAKE_JOBS > ${out}
  342. spopd # ${VLCROOT}/contrib
  343. if ! [ -e ${VLCROOT}/configure ]; then
  344. info "Bootstraping vlc"
  345. ${VLCROOT}/bootstrap > ${out}
  346. fi
  347. mkdir -p ${BUILDDIR}
  348. spushd ${BUILDDIR}
  349. if [ "$DEBUG" = "yes" ]; then
  350. DEBUGFLAG="--enable-debug"
  351. else
  352. export CFLAGS="${CFLAGS} -DNDEBUG"
  353. fi
  354. if [ "$SCARY" = "yes" ]; then
  355. SCARYFLAG="--enable-dvbpsi --enable-avcodec"
  356. else
  357. SCARYFLAG="--disable-dca --disable-dvbpsi --disable-avcodec --disable-avformat --disable-zvbi --enable-vpx"
  358. fi
  359. if [ "$TVOS" != "yes" -a \( "$ARCH" = "armv7" -o "$ARCH" = "armv7s" \) ];then
  360. export ac_cv_arm_neon=yes
  361. else
  362. export ac_cv_arm_neon=no
  363. fi
  364. # Available but not authorized
  365. export ac_cv_func_daemon=no
  366. export ac_cv_func_fork=no
  367. if [ "${VLCROOT}/configure" -nt config.log -o \
  368. "${THIS_SCRIPT_PATH}" -nt config.log ]; then
  369. info "Configuring vlc"
  370. ${VLCROOT}/configure \
  371. --prefix="${PREFIX}" \
  372. --host="${TARGET}" \
  373. --with-contrib="${VLCROOT}/contrib/${OSSTYLE}-${TARGET}-${ARCH}" \
  374. --enable-static \
  375. ${DEBUGFLAG} \
  376. ${SCARYFLAG} \
  377. --disable-macosx \
  378. --disable-macosx-avfoundation \
  379. --disable-shared \
  380. --enable-opus \
  381. --disable-faad \
  382. --disable-lua \
  383. --disable-a52 \
  384. --enable-fribidi \
  385. --disable-qt --disable-skins2 \
  386. --disable-vcd \
  387. --disable-vlc \
  388. --disable-vlm \
  389. --disable-nls \
  390. --disable-sse \
  391. --disable-notify \
  392. --enable-live555 \
  393. --enable-swscale \
  394. --disable-projectm \
  395. --enable-libass \
  396. --enable-libxml2 \
  397. --disable-goom \
  398. --disable-dvdread \
  399. --disable-dvdnav \
  400. --disable-bluray \
  401. --disable-linsys \
  402. --disable-libva \
  403. --disable-gme \
  404. --disable-tremor \
  405. --enable-vorbis \
  406. --disable-fluidsynth \
  407. --disable-jack \
  408. --disable-pulse \
  409. --disable-mtp \
  410. --enable-ogg \
  411. --enable-speex \
  412. --enable-theora \
  413. --enable-flac \
  414. --disable-screen \
  415. --enable-freetype \
  416. --enable-taglib \
  417. --disable-mmx \
  418. --disable-sparkle \
  419. --disable-addonmanagermodules \
  420. --disable-libplacebo \
  421. --disable-mad > ${out}
  422. fi
  423. info "Building libvlc"
  424. make -j$MAKE_JOBS > ${out}
  425. info "Installing libvlc"
  426. make install > ${out}
  427. find ${PREFIX}/lib/vlc/plugins -name *.a -type f -exec cp '{}' ${PREFIX}/lib/vlc/plugins \;
  428. rm -rf "${PREFIX}/contribs"
  429. cp -R "${VLCROOT}/contrib/${OSSTYLE}-${TARGET}-${ARCH}" "${PREFIX}/contribs"
  430. info "Removing unneeded modules"
  431. blacklist="
  432. stats
  433. access_bd
  434. shm
  435. access_imem
  436. oldrc
  437. real
  438. hotkeys
  439. gestures
  440. dynamicoverlay
  441. rss
  442. ball
  443. magnify
  444. audiobargraph_
  445. clone
  446. mosaic
  447. osdmenu
  448. puzzle
  449. mediadirs
  450. t140
  451. ripple
  452. motion
  453. sharpen
  454. grain
  455. posterize
  456. mirror
  457. wall
  458. scene
  459. blendbench
  460. psychedelic
  461. alphamask
  462. netsync
  463. audioscrobbler
  464. motiondetect
  465. motionblur
  466. export
  467. smf
  468. podcast
  469. bluescreen
  470. erase
  471. stream_filter_record
  472. speex_resampler
  473. remoteosd
  474. magnify
  475. gradient
  476. visual
  477. fb
  478. aout_file
  479. invert
  480. sepia
  481. wave
  482. hqdn3d
  483. headphone_channel_mixer
  484. gaussianblur
  485. gradfun
  486. extract
  487. colorthres
  488. antiflicker
  489. anaglyph
  490. remap
  491. oldmovie
  492. vhs
  493. demuxdump
  494. fingerprinter
  495. output_udp
  496. output_livehttp
  497. "
  498. if [ "$SCARY" = "no" ]; then
  499. blacklist="${blacklist}
  500. dts
  501. dvbsub
  502. svcd
  503. hevc
  504. packetizer_mlp
  505. a52
  506. vc1
  507. uleaddvaudio
  508. librar
  509. libvoc
  510. avio
  511. chorus_flanger
  512. smooth
  513. cvdsub
  514. libmod
  515. libdash
  516. libmpgv
  517. dolby_surround
  518. mpegaudio"
  519. fi
  520. echo ${blacklist}
  521. for i in ${blacklist}
  522. do
  523. find ${PREFIX}/lib/vlc/plugins -name *$i* -type f -exec rm '{}' \;
  524. done
  525. spopd
  526. }
  527. buildMobileKit() {
  528. PLATFORM="$1"
  529. cleantheenvironment
  530. if [ "$SKIPLIBVLCCOMPILATION" != "yes" ]; then
  531. if [ "$TVOS" = "yes" ]; then
  532. # this variable is read by libvlc's contrib build script
  533. # to create the required build environment
  534. # for historical raisons, tvOS is a special flavor of iOS
  535. # so we need to export both variables
  536. export BUILDFORIOS="yes"
  537. export BUILDFORTVOS="yes"
  538. info "Building libvlc for tvOS"
  539. fi
  540. if [ "$MACOS" = "yes" ]; then
  541. # macOS is the default build environment for libvlc's contrib
  542. # build scripts, so we don't need to export anything
  543. info "Building libvlc for macOS"
  544. fi
  545. if [ "$IOS" = "yes" ]; then
  546. # this variable is read by libvlc's contrib build script
  547. # to create the required build environment
  548. export BUILDFORIOS="yes"
  549. info "Building libvlc for iOS"
  550. fi
  551. export AR=`xcrun -f ar`
  552. export RANLIB=`xcrun -f ranlib`
  553. export CC=`xcrun -f clang`
  554. export OBJC=`xcrun -f clang`
  555. export CXX=`xcrun -f clang++`
  556. export LD=`xcrun -f ld`
  557. export STRIP=`xcrun -f strip`
  558. export CPPFLAGS=-E
  559. export CXXCPPFLAGS=-E
  560. unset AS
  561. unset CCAS
  562. if [ "$FARCH" = "all" ];then
  563. if [ "$TVOS" = "yes" ]; then
  564. if [ "$PLATFORM" = "iphonesimulator" ]; then
  565. buildLibVLC "x86_64" "Simulator"
  566. else
  567. buildLibVLC "aarch64" "OS"
  568. fi
  569. fi
  570. if [ "$MACOS" = "yes" ]; then
  571. buildLibVLC "x86_64" "OS"
  572. fi
  573. if [ "$IOS" = "yes" ]; then
  574. if [ "$PLATFORM" = "iphonesimulator" ]; then
  575. buildLibVLC "i386" "Simulator"
  576. buildLibVLC "x86_64" "Simulator"
  577. else
  578. buildLibVLC "armv7" "OS"
  579. buildLibVLC "armv7s" "OS"
  580. buildLibVLC "aarch64" "OS"
  581. fi
  582. fi
  583. else
  584. if [ "$FARCH" != "x86_64" -a "$FARCH" != "aarch64" -a "$FARCH" != "i386" \
  585. -a "$FARCH" != "armv7" -a "$FARCH" != "armv7s" ];then
  586. echo "*** Framework ARCH: ${FARCH} is invalid ***"
  587. exit 1
  588. fi
  589. local buildPlatform=""
  590. if [ "$PLATFORM" = "iphonesimulator" ]; then
  591. if [ "$FARCH" == "x86_64" -o "$FARCH" == "i386" ];then
  592. buildPlatform="Simulator"
  593. fi
  594. else
  595. if [ "$FARCH" == "armv7" -o "$FARCH" == "armv7s" -o "$FARCH" == "aarch64" ];then
  596. buildPlatform="OS"
  597. fi
  598. fi
  599. if [ ! -z "$buildPlatform" ];then
  600. buildLibVLC $FARCH $buildPlatform
  601. fi
  602. fi
  603. fi
  604. }
  605. doVLCLipo() {
  606. FILEPATH="$1"
  607. FILE="$2"
  608. PLUGIN="$3"
  609. OSSTYLE="$4"
  610. files=""
  611. info "...$FILEPATH$FILE"
  612. for i in $DEVICEARCHS
  613. do
  614. actual_arch=`get_actual_arch $i`
  615. files="install-"$OSSTYLE"OS/$actual_arch/lib/$FILEPATH$FILE $files"
  616. done
  617. for i in $SIMULATORARCHS
  618. do
  619. actual_arch=`get_actual_arch $i`
  620. files="install-"$OSSTYLE"Simulator/$actual_arch/lib/$FILEPATH$FILE $files"
  621. done
  622. if [ "$PLUGIN" != "no" ]; then
  623. lipo $files -create -output install-$OSSTYLE/plugins/$FILE
  624. else
  625. lipo $files -create -output install-$OSSTYLE/core/$FILE
  626. fi
  627. }
  628. doContribLipo() {
  629. LIBNAME="$1"
  630. OSSTYLE="$2"
  631. files=""
  632. info "...$LIBNAME"
  633. for i in $DEVICEARCHS $SIMULATORARCHS
  634. do
  635. files="contrib/$OSSTYLE-$i-apple-darwin14-$i/lib/$LIBNAME $files"
  636. done
  637. lipo $files -create -output install-$OSSTYLE/contrib/$LIBNAME
  638. }
  639. get_symbol()
  640. {
  641. echo "$1" | grep vlc_entry_$2|cut -d" " -f 3|sed 's/_vlc/vlc/'
  642. }
  643. build_universal_static_lib() {
  644. PROJECT_DIR=`pwd`
  645. OSSTYLE="$1"
  646. info "building universal static libs for OS style $OSSTYLE"
  647. # remove old module list
  648. rm -f $PROJECT_DIR/Resources/MobileVLCKit/vlc-plugins-$OSSTYLE.h
  649. rm -f $PROJECT_DIR/Resources/MobileVLCKit/vlc-plugins-$OSSTYLE.xcconfig
  650. touch $PROJECT_DIR/Resources/MobileVLCKit/vlc-plugins-$OSSTYLE.h
  651. touch $PROJECT_DIR/Resources/MobileVLCKit/vlc-plugins-$OSSTYLE.xcconfig
  652. if [ "$OSSTYLE" != "MacOSX" ]; then
  653. spushd ${VLCROOT}
  654. rm -rf install-$OSSTYLE
  655. mkdir install-$OSSTYLE
  656. mkdir install-$OSSTYLE/core
  657. mkdir install-$OSSTYLE/contrib
  658. mkdir install-$OSSTYLE/plugins
  659. spopd # vlc
  660. else
  661. spushd ${VLCROOT}/install-$OSSTYLE
  662. rm -rf core
  663. rm -rf contrib
  664. rm -rf plugins
  665. ln -s x86_64/lib core
  666. ln -s x86_64/contribs/lib contrib
  667. ln -s x86_64/lib/vlc/plugins plugins
  668. spopd # vlc
  669. fi
  670. VLCMODULES=""
  671. VLCNEONMODULES=""
  672. SIMULATORARCHS=""
  673. CONTRIBLIBS=""
  674. DEVICEARCHS=""
  675. # arm64 got the lowest number of modules
  676. arch="aarch64"
  677. if [ "$FARCH" != "all" ];then
  678. arch="$FARCH"
  679. elif [ "$BUILD_SIMULATOR" = "yes" ]; then
  680. arch="x86_64"
  681. fi
  682. actual_arch=`get_actual_arch $arch`
  683. if [ -d ${VLCROOT}/install-"$OSSTYLE"OS ];then
  684. spushd ${VLCROOT}/install-"$OSSTYLE"OS
  685. for i in `ls .`
  686. do
  687. local iarch="`get_arch $i`"
  688. if [ "$FARCH" == "all" -o "$FARCH" = "$iarch" ];then
  689. DEVICEARCHS="$DEVICEARCHS $iarch"
  690. fi
  691. done
  692. if (! is_simulator_arch $arch);then
  693. echo "IPHONE OS: $arch"
  694. spushd $actual_arch/lib/vlc/plugins
  695. for i in `ls *.a`
  696. do
  697. VLCMODULES="$i $VLCMODULES"
  698. done
  699. spopd # $actual_arch/lib/vlc/plugins
  700. fi
  701. if [ "$OSSTYLE" != "AppleTV" -a \
  702. \( "$FARCH" = "all" -o "$FARCH" = "armv7" -o "$FARCH" = "armv7s" \) ]; then
  703. # collect ARMv7/s specific neon modules
  704. if [ "$FARCH" = "all" ];then
  705. spushd armv7/lib/vlc/plugins
  706. else
  707. spushd $FARCH/lib/vlc/plugins
  708. fi
  709. for i in `ls *.a | grep neon`
  710. do
  711. VLCNEONMODULES="$i $VLCNEONMODULES"
  712. done
  713. spopd # armv7/lib/vlc/plugins
  714. fi
  715. spopd # vlc-install-"$OSSTYLE"OS
  716. fi
  717. if [ -d ${VLCROOT}/install-"$OSSTYLE"Simulator ];then
  718. spushd ${VLCROOT}/install-"$OSSTYLE"Simulator
  719. for i in `ls .`
  720. do
  721. local iarch="`get_arch $i`"
  722. if [ "$FARCH" == "all" -o "$FARCH" = "$iarch" ];then
  723. SIMULATORARCHS="$SIMULATORARCHS $iarch"
  724. fi
  725. done
  726. if (is_simulator_arch $arch);then
  727. echo "SIMU OS: $arch"
  728. spushd $arch/lib/vlc/plugins
  729. for i in `ls *.a`
  730. do
  731. VLCMODULES="$i $VLCMODULES"
  732. done
  733. spopd # $iarch/lib/vlc/plugins
  734. fi
  735. spopd # vlc-install-"$OSSTYLE"Simulator
  736. fi
  737. if [ "$OSSTYLE" = "MacOSX" ]; then
  738. if [ -d ${VLCROOT}/install-"$OSSTYLE" ];then
  739. spushd ${VLCROOT}/install-"$OSSTYLE"
  740. echo `pwd`
  741. echo "macOS: $arch"
  742. spushd $arch/lib/vlc/plugins
  743. for i in `ls *.a`
  744. do
  745. VLCMODULES="$i $VLCMODULES"
  746. done
  747. spopd # $actual_arch/lib/vlc/plugins
  748. spopd # vlc-install-"$OSSTYLE"
  749. fi
  750. fi
  751. spushd ${VLCROOT}
  752. # collect contrib libraries
  753. spushd contrib/$OSSTYLE-$arch-apple-darwin14-$arch/lib
  754. for i in `ls *.a`
  755. do
  756. CONTRIBLIBS="$i $CONTRIBLIBS"
  757. done
  758. spopd # contrib/$OSSTYLE-$arch-apple-darwin14-$arch/lib
  759. # lipo all the vlc libraries and its plugins
  760. if [ "$OSSTYLE" != "MacOSX" ]; then
  761. doVLCLipo "" "libvlc.a" "no" $OSSTYLE
  762. doVLCLipo "" "libvlccore.a" "no" $OSSTYLE
  763. doVLCLipo "vlc/" "libcompat.a" "no" $OSSTYLE
  764. for i in $VLCMODULES
  765. do
  766. doVLCLipo "vlc/plugins/" $i "yes" $OSSTYLE
  767. done
  768. # lipo contrib libraries
  769. for i in $CONTRIBLIBS
  770. do
  771. doContribLipo $i $OSSTYLE
  772. done
  773. if [ "$OSSTYLE" != "AppleTV" ]; then
  774. # lipo the remaining NEON plugins
  775. DEVICEARCHS=""
  776. for i in armv7 armv7s; do
  777. local iarch="`get_arch $i`"
  778. if [ "$FARCH" == "all" -o "$FARCH" = "$iarch" ];then
  779. DEVICEARCHS="$DEVICEARCHS $iarch"
  780. fi
  781. done
  782. SIMULATORARCHS=""
  783. for i in $VLCNEONMODULES
  784. do
  785. doVLCLipo "vlc/plugins/" $i "yes" $OSSTYLE
  786. done
  787. fi
  788. fi
  789. # create module list
  790. info "creating module list"
  791. echo "// This file is autogenerated by $(basename $0)\n\n" > $PROJECT_DIR/Resources/MobileVLCKit/vlc-plugins-$OSSTYLE.h
  792. echo "// This file is autogenerated by $(basename $0)\n\n" > $PROJECT_DIR/Resources/MobileVLCKit/vlc-plugins-$OSSTYLE.xcconfig
  793. # arm64 got the lowest number of modules
  794. BUILTINS="const void *vlc_static_modules[] = {\n"; \
  795. LDFLAGS=""
  796. DEFINITIONS=""
  797. # add contrib libraries to LDFLAGS
  798. for file in $CONTRIBLIBS
  799. do
  800. LDFLAGS+="${VLCROOT}/install-$OSSTYLE/contrib/$file "
  801. done
  802. for file in $VLCMODULES
  803. do
  804. symbols=$(nm -g -arch $actual_arch install-$OSSTYLE/plugins/$file)
  805. entryname=$(get_symbol "$symbols" _)
  806. DEFINITIONS+="int $entryname (int (*)(void *, void *, int, ...), void *);\n";
  807. BUILTINS+=" $entryname,\n"
  808. LDFLAGS+="${VLCROOT}/install-$OSSTYLE/plugins/$file "
  809. info "...$entryname"
  810. done;
  811. # we only have ARM NEON modules for 32bit so this is limited to iOS
  812. if [ "$OSSTYLE" = "iPhone" ]; then
  813. BUILTINS+="#ifdef __arm__\n"
  814. DEFINITIONS+="#ifdef __arm__\n"
  815. for file in $VLCNEONMODULES
  816. do
  817. symbols=$(nm -g -arch $actual_arch install-$OSSTYLE/plugins/$file)
  818. entryname=$(get_symbol "$symbols" _)
  819. DEFINITIONS+="int $entryname (int (*)(void *, void *, int, ...), void *);\n";
  820. BUILTINS+=" $entryname,\n"
  821. LDFLAGS+="${VLCROOT}/install-$OSSTYLE/plugins/$file "
  822. info "...$entryname"
  823. done;
  824. BUILTINS+="#endif\n"
  825. DEFINITIONS+="#endif\n"
  826. fi
  827. BUILTINS="$BUILTINS NULL\n};\n"
  828. echo "$DEFINITIONS\n$BUILTINS" >> $PROJECT_DIR/Resources/MobileVLCKit/vlc-plugins-$OSSTYLE.h
  829. echo "VLC_PLUGINS_LDFLAGS=$LDFLAGS" >> $PROJECT_DIR/Resources/MobileVLCKit/vlc-plugins-$OSSTYLE.xcconfig
  830. spopd # vlc
  831. }
  832. while getopts "hvwsfbdxntlk:a:e:" OPTION
  833. do
  834. case $OPTION in
  835. h)
  836. usage
  837. exit 1
  838. ;;
  839. v)
  840. VERBOSE=yes
  841. MAKE_JOBS=1
  842. ;;
  843. s)
  844. BUILD_DEVICE=no
  845. BUILD_SIMULATOR=yes
  846. BUILD_STATIC_FRAMEWORK=no
  847. ;;
  848. f)
  849. BUILD_DEVICE=yes
  850. BUILD_SIMULATOR=yes
  851. BUILD_STATIC_FRAMEWORK=yes
  852. ;;
  853. d) CONFIGURATION="Debug"
  854. DEBUG=yes
  855. ;;
  856. w) SCARY="no"
  857. ;;
  858. n)
  859. NONETWORK=yes
  860. ;;
  861. l)
  862. SKIPLIBVLCCOMPILATION=yes
  863. ;;
  864. k)
  865. SDK=$OPTARG
  866. ;;
  867. a)
  868. BUILD_DEVICE=yes
  869. BUILD_SIMULATOR=yes
  870. BUILD_STATIC_FRAMEWORK=yes
  871. FARCH=$OPTARG
  872. ;;
  873. b)
  874. BITCODE=yes
  875. ;;
  876. t)
  877. TVOS=yes
  878. IOS=no
  879. BITCODE=yes
  880. SDK_VERSION=`xcrun --sdk appletvos --show-sdk-version`
  881. SDK_MIN=10.2
  882. OSVERSIONMINCFLAG=tvos
  883. OSVERSIONMINLDFLAG=tvos
  884. ;;
  885. x)
  886. MACOS=yes
  887. IOS=no
  888. BITCODE=no
  889. SDK_VERSION=`xcrun --sdk macosx --show-sdk-version`
  890. SDK_MIN=10.11
  891. OSVERSIONMINCFLAG=macosx
  892. OSVERSIONMINLDFLAG=macosx
  893. BUILD_DEVICE=yes
  894. FARCH=x86_64
  895. BUILD_DYNAMIC_FRAMEWORK=yes
  896. BUILD_STATIC_FRAMEWORK=no
  897. ;;
  898. e)
  899. VLCROOT=$OPTARG
  900. ;;
  901. ?)
  902. usage
  903. exit 1
  904. ;;
  905. esac
  906. done
  907. shift $(($OPTIND - 1))
  908. out="/dev/null"
  909. if [ "$VERBOSE" = "yes" ]; then
  910. out="/dev/stdout"
  911. fi
  912. if [ "x$1" != "x" ]; then
  913. usage
  914. exit 1
  915. fi
  916. # Get root dir
  917. spushd .
  918. ROOT_DIR=`pwd`
  919. spopd
  920. if [ "$VLCROOT" = "" ]; then
  921. VLCROOT=${ROOT_DIR}/libvlc/vlc
  922. info "Preparing build dirs"
  923. mkdir -p libvlc
  924. spushd libvlc
  925. if [ "$NONETWORK" != "yes" ]; then
  926. if ! [ -e vlc ]; then
  927. git clone https://git.videolan.org/git/vlc.git vlc
  928. info "Applying patches to vlc.git"
  929. cd vlc
  930. git checkout -B localBranch ${TESTEDHASH}
  931. git branch --set-upstream-to=origin/master localBranch
  932. git am ${ROOT_DIR}/libvlc/patches/*.patch
  933. if [ $? -ne 0 ]; then
  934. git am --abort
  935. info "Applying the patches failed, aborting git-am"
  936. exit 1
  937. fi
  938. cd ..
  939. else
  940. cd vlc
  941. git fetch --all
  942. git reset --hard ${TESTEDHASH}
  943. git am ${ROOT_DIR}/libvlc/patches/*.patch
  944. cd ..
  945. fi
  946. fi
  947. spopd
  948. fi
  949. fetch_python3_path() {
  950. PYTHON3_PATH=$(echo /Library/Frameworks/Python.framework/Versions/3.*/bin | awk '{print $1;}')
  951. if [ ! -d "${PYTHON3_PATH}" ]; then
  952. PYTHON3_PATH=""
  953. fi
  954. }
  955. #
  956. # Build time
  957. #
  958. out="/dev/null"
  959. if [ "$VERBOSE" = "yes" ]; then
  960. out="/dev/stdout"
  961. fi
  962. if [ "$SKIPLIBVLCCOMPILATION" != "yes" ]; then
  963. info "Building tools"
  964. fetch_python3_path
  965. export PATH="${PYTHON3_PATH}:${VLCROOT}/extras/tools/build/bin:${VLCROOT}/contrib/${TARGET}/bin:/usr/bin:/bin:/usr/sbin:/sbin"
  966. spushd ${VLCROOT}/extras/tools
  967. ./bootstrap
  968. make
  969. make .buildgas
  970. make .buildxz
  971. make .buildtar
  972. make .buildmeson
  973. make .buildninja
  974. spopd #${VLCROOT}/extras/tools
  975. fi
  976. if [ "$BUILD_DEVICE" != "no" ]; then
  977. buildMobileKit iphoneos
  978. fi
  979. if [ "$BUILD_SIMULATOR" != "no" ]; then
  980. buildMobileKit iphonesimulator
  981. fi
  982. DEVICEARCHS=""
  983. SIMULATORARCHS=""
  984. if [ "$TVOS" = "yes" ]; then
  985. build_universal_static_lib "AppleTV"
  986. fi
  987. if [ "$MACOS" = "yes" ]; then
  988. build_universal_static_lib "MacOSX"
  989. fi
  990. if [ "$IOS" = "yes" ]; then
  991. build_universal_static_lib "iPhone"
  992. fi
  993. info "all done"
  994. if [ "$BUILD_STATIC_FRAMEWORK" != "no" ]; then
  995. if [ "$TVOS" = "yes" ]; then
  996. info "Building static TVVLCKit.framework"
  997. lipo_libs=""
  998. platform=""
  999. if [ "$FARCH" = "all" ] || (! is_simulator_arch $FARCH);then
  1000. platform="appletvos"
  1001. buildxcodeproj MobileVLCKit "TVVLCKit" ${platform}
  1002. lipo_libs="$lipo_libs ${CONFIGURATION}-appletvos/libTVVLCKit.a"
  1003. fi
  1004. if [ "$FARCH" = "all" ] || (is_simulator_arch $arch);then
  1005. platform="appletvsimulator"
  1006. buildxcodeproj MobileVLCKit "TVVLCKit" ${platform}
  1007. lipo_libs="$lipo_libs ${CONFIGURATION}-appletvsimulator/libTVVLCKit.a"
  1008. fi
  1009. # Assumes both platforms were built currently
  1010. spushd build
  1011. rm -rf TVVLCKit.framework && \
  1012. mkdir TVVLCKit.framework && \
  1013. lipo -create ${lipo_libs} -o TVVLCKit.framework/TVVLCKit && \
  1014. chmod a+x TVVLCKit.framework/TVVLCKit && \
  1015. cp -pr ${CONFIGURATION}-${platform}/TVVLCKit TVVLCKit.framework/Headers
  1016. cp -pr ${CONFIGURATION}-${platform}/Modules TVVLCKit.framework/Modules
  1017. spopd # build
  1018. info "Build of static TVVLCKit.framework completed"
  1019. fi
  1020. if [ "$IOS" = "yes" ]; then
  1021. info "Building static MobileVLCKit.framework"
  1022. lipo_libs=""
  1023. platform=""
  1024. if [ "$FARCH" = "all" ] || (! is_simulator_arch $FARCH);then
  1025. platform="iphoneos"
  1026. buildxcodeproj MobileVLCKit "MobileVLCKit" ${platform}
  1027. lipo_libs="$lipo_libs ${CONFIGURATION}-iphoneos/libMobileVLCKit.a"
  1028. fi
  1029. if [ "$FARCH" = "all" ] || (is_simulator_arch $arch);then
  1030. platform="iphonesimulator"
  1031. buildxcodeproj MobileVLCKit "MobileVLCKit" ${platform}
  1032. lipo_libs="$lipo_libs ${CONFIGURATION}-iphonesimulator/libMobileVLCKit.a"
  1033. fi
  1034. # Assumes both platforms were built currently
  1035. spushd build
  1036. rm -rf MobileVLCKit.framework && \
  1037. mkdir MobileVLCKit.framework && \
  1038. lipo -create ${lipo_libs} -o MobileVLCKit.framework/MobileVLCKit && \
  1039. chmod a+x MobileVLCKit.framework/MobileVLCKit && \
  1040. cp -pr ${CONFIGURATION}-${platform}/MobileVLCKit MobileVLCKit.framework/Headers
  1041. cp -pr ${CONFIGURATION}-${platform}/Modules MobileVLCKit.framework/Modules
  1042. spopd # build
  1043. info "Build of static MobileVLCKit.framework completed"
  1044. fi
  1045. fi
  1046. if [ "$BUILD_DYNAMIC_FRAMEWORK" != "no" ]; then
  1047. if [ "$MACOS" = "yes" ]; then
  1048. info "Building VLCKit.framework"
  1049. buildxcodeproj VLCKit "VLCKit" "macosx"
  1050. # remove intermediate build result we don't need to keep
  1051. spushd build
  1052. rm ${CONFIGURATION}/libStaticLibVLC.a
  1053. spopd # build
  1054. info "Build of VLCKit.framework completed"
  1055. fi
  1056. fi