compileAndBuildVLCKit.sh 31 KB

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