compileAndBuildVLCKit.sh 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197
  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. marq
  444. magnify
  445. audiobargraph_
  446. clone
  447. mosaic
  448. osdmenu
  449. puzzle
  450. mediadirs
  451. t140
  452. ripple
  453. motion
  454. sharpen
  455. grain
  456. posterize
  457. mirror
  458. wall
  459. scene
  460. blendbench
  461. psychedelic
  462. alphamask
  463. netsync
  464. audioscrobbler
  465. motiondetect
  466. motionblur
  467. export
  468. smf
  469. podcast
  470. bluescreen
  471. erase
  472. stream_filter_record
  473. speex_resampler
  474. remoteosd
  475. magnify
  476. gradient
  477. logger
  478. visual
  479. fb
  480. aout_file
  481. invert
  482. sepia
  483. wave
  484. hqdn3d
  485. headphone_channel_mixer
  486. gaussianblur
  487. gradfun
  488. extract
  489. colorthres
  490. antiflicker
  491. anaglyph
  492. remap
  493. oldmovie
  494. vhs
  495. demuxdump
  496. fingerprinter
  497. output_udp
  498. output_livehttp
  499. "
  500. if [ "$SCARY" = "no" ]; then
  501. blacklist="${blacklist}
  502. dts
  503. dvbsub
  504. svcd
  505. hevc
  506. packetizer_mlp
  507. a52
  508. vc1
  509. uleaddvaudio
  510. librar
  511. libvoc
  512. avio
  513. chorus_flanger
  514. smooth
  515. cvdsub
  516. libmod
  517. libdash
  518. libmpgv
  519. dolby_surround
  520. mpegaudio"
  521. fi
  522. echo ${blacklist}
  523. for i in ${blacklist}
  524. do
  525. find ${PREFIX}/lib/vlc/plugins -name *$i* -type f -exec rm '{}' \;
  526. done
  527. spopd
  528. }
  529. buildMobileKit() {
  530. PLATFORM="$1"
  531. cleantheenvironment
  532. if [ "$SKIPLIBVLCCOMPILATION" != "yes" ]; then
  533. if [ "$TVOS" = "yes" ]; then
  534. # this variable is read by libvlc's contrib build script
  535. # to create the required build environment
  536. # for historical raisons, tvOS is a special flavor of iOS
  537. # so we need to export both variables
  538. export BUILDFORIOS="yes"
  539. export BUILDFORTVOS="yes"
  540. info "Building libvlc for tvOS"
  541. fi
  542. if [ "$MACOS" = "yes" ]; then
  543. # macOS is the default build environment for libvlc's contrib
  544. # build scripts, so we don't need to export anything
  545. info "Building libvlc for macOS"
  546. fi
  547. if [ "$IOS" = "yes" ]; then
  548. # this variable is read by libvlc's contrib build script
  549. # to create the required build environment
  550. export BUILDFORIOS="yes"
  551. info "Building libvlc for iOS"
  552. fi
  553. export AR=`xcrun -f ar`
  554. export RANLIB=`xcrun -f ranlib`
  555. export CC=`xcrun -f clang`
  556. export OBJC=`xcrun -f clang`
  557. export CXX=`xcrun -f clang++`
  558. export LD=`xcrun -f ld`
  559. export STRIP=`xcrun -f strip`
  560. export CPPFLAGS=-E
  561. export CXXCPPFLAGS=-E
  562. unset AS
  563. unset CCAS
  564. if [ "$FARCH" = "all" ];then
  565. if [ "$TVOS" = "yes" ]; then
  566. if [ "$PLATFORM" = "iphonesimulator" ]; then
  567. buildLibVLC "x86_64" "Simulator"
  568. else
  569. buildLibVLC "aarch64" "OS"
  570. fi
  571. fi
  572. if [ "$MACOS" = "yes" ]; then
  573. buildLibVLC "x86_64" "OS"
  574. fi
  575. if [ "$IOS" = "yes" ]; then
  576. if [ "$PLATFORM" = "iphonesimulator" ]; then
  577. buildLibVLC "i386" "Simulator"
  578. buildLibVLC "x86_64" "Simulator"
  579. else
  580. buildLibVLC "armv7" "OS"
  581. buildLibVLC "armv7s" "OS"
  582. buildLibVLC "aarch64" "OS"
  583. fi
  584. fi
  585. else
  586. if [ "$FARCH" != "x86_64" -a "$FARCH" != "aarch64" -a "$FARCH" != "i386" \
  587. -a "$FARCH" != "armv7" -a "$FARCH" != "armv7s" ];then
  588. echo "*** Framework ARCH: ${FARCH} is invalid ***"
  589. exit 1
  590. fi
  591. local buildPlatform=""
  592. if [ "$PLATFORM" = "iphonesimulator" ]; then
  593. if [ "$FARCH" == "x86_64" -o "$FARCH" == "i386" ];then
  594. buildPlatform="Simulator"
  595. fi
  596. else
  597. if [ "$FARCH" == "armv7" -o "$FARCH" == "armv7s" -o "$FARCH" == "aarch64" ];then
  598. buildPlatform="OS"
  599. fi
  600. fi
  601. if [ ! -z "$buildPlatform" ];then
  602. buildLibVLC $FARCH $buildPlatform
  603. fi
  604. fi
  605. fi
  606. }
  607. doVLCLipo() {
  608. FILEPATH="$1"
  609. FILE="$2"
  610. PLUGIN="$3"
  611. OSSTYLE="$4"
  612. files=""
  613. info "...$FILEPATH$FILE"
  614. for i in $DEVICEARCHS
  615. do
  616. actual_arch=`get_actual_arch $i`
  617. files="install-"$OSSTYLE"OS/$actual_arch/lib/$FILEPATH$FILE $files"
  618. done
  619. for i in $SIMULATORARCHS
  620. do
  621. actual_arch=`get_actual_arch $i`
  622. files="install-"$OSSTYLE"Simulator/$actual_arch/lib/$FILEPATH$FILE $files"
  623. done
  624. if [ "$PLUGIN" != "no" ]; then
  625. lipo $files -create -output install-$OSSTYLE/plugins/$FILE
  626. else
  627. lipo $files -create -output install-$OSSTYLE/core/$FILE
  628. fi
  629. }
  630. doContribLipo() {
  631. LIBNAME="$1"
  632. OSSTYLE="$2"
  633. files=""
  634. info "...$LIBNAME"
  635. for i in $DEVICEARCHS $SIMULATORARCHS
  636. do
  637. files="contrib/$OSSTYLE-$i-apple-darwin14-$i/lib/$LIBNAME $files"
  638. done
  639. lipo $files -create -output install-$OSSTYLE/contrib/$LIBNAME
  640. }
  641. get_symbol()
  642. {
  643. echo "$1" | grep vlc_entry_$2|cut -d" " -f 3|sed 's/_vlc/vlc/'
  644. }
  645. build_universal_static_lib() {
  646. PROJECT_DIR=`pwd`
  647. OSSTYLE="$1"
  648. info "building universal static libs for OS style $OSSTYLE"
  649. # remove old module list
  650. rm -f $PROJECT_DIR/Resources/MobileVLCKit/vlc-plugins-$OSSTYLE.h
  651. rm -f $PROJECT_DIR/Resources/MobileVLCKit/vlc-plugins-$OSSTYLE.xcconfig
  652. touch $PROJECT_DIR/Resources/MobileVLCKit/vlc-plugins-$OSSTYLE.h
  653. touch $PROJECT_DIR/Resources/MobileVLCKit/vlc-plugins-$OSSTYLE.xcconfig
  654. if [ "$OSSTYLE" != "MacOSX" ]; then
  655. spushd ${VLCROOT}
  656. rm -rf install-$OSSTYLE
  657. mkdir install-$OSSTYLE
  658. mkdir install-$OSSTYLE/core
  659. mkdir install-$OSSTYLE/contrib
  660. mkdir install-$OSSTYLE/plugins
  661. spopd # vlc
  662. else
  663. spushd ${VLCROOT}/install-$OSSTYLE
  664. rm -rf core
  665. rm -rf contrib
  666. rm -rf plugins
  667. ln -s x86_64/lib core
  668. ln -s x86_64/contribs/lib contrib
  669. ln -s x86_64/lib/vlc/plugins plugins
  670. spopd # vlc
  671. fi
  672. VLCMODULES=""
  673. VLCNEONMODULES=""
  674. SIMULATORARCHS=""
  675. CONTRIBLIBS=""
  676. DEVICEARCHS=""
  677. # arm64 got the lowest number of modules
  678. arch="aarch64"
  679. if [ "$FARCH" != "all" ];then
  680. arch="$FARCH"
  681. elif [ "$BUILD_SIMULATOR" = "yes" ]; then
  682. arch="x86_64"
  683. fi
  684. actual_arch=`get_actual_arch $arch`
  685. if [ -d ${VLCROOT}/install-"$OSSTYLE"OS ];then
  686. spushd ${VLCROOT}/install-"$OSSTYLE"OS
  687. for i in `ls .`
  688. do
  689. local iarch="`get_arch $i`"
  690. if [ "$FARCH" == "all" -o "$FARCH" = "$iarch" ];then
  691. DEVICEARCHS="$DEVICEARCHS $iarch"
  692. fi
  693. done
  694. if (! is_simulator_arch $arch);then
  695. echo "IPHONE OS: $arch"
  696. spushd $actual_arch/lib/vlc/plugins
  697. for i in `ls *.a`
  698. do
  699. VLCMODULES="$i $VLCMODULES"
  700. done
  701. spopd # $actual_arch/lib/vlc/plugins
  702. fi
  703. if [ "$OSSTYLE" != "AppleTV" -a \
  704. \( "$FARCH" = "all" -o "$FARCH" = "armv7" -o "$FARCH" = "armv7s" \) ]; then
  705. # collect ARMv7/s specific neon modules
  706. if [ "$FARCH" = "all" ];then
  707. spushd armv7/lib/vlc/plugins
  708. else
  709. spushd $FARCH/lib/vlc/plugins
  710. fi
  711. for i in `ls *.a | grep neon`
  712. do
  713. VLCNEONMODULES="$i $VLCNEONMODULES"
  714. done
  715. spopd # armv7/lib/vlc/plugins
  716. fi
  717. spopd # vlc-install-"$OSSTYLE"OS
  718. fi
  719. if [ -d ${VLCROOT}/install-"$OSSTYLE"Simulator ];then
  720. spushd ${VLCROOT}/install-"$OSSTYLE"Simulator
  721. for i in `ls .`
  722. do
  723. local iarch="`get_arch $i`"
  724. if [ "$FARCH" == "all" -o "$FARCH" = "$iarch" ];then
  725. SIMULATORARCHS="$SIMULATORARCHS $iarch"
  726. fi
  727. done
  728. if (is_simulator_arch $arch);then
  729. echo "SIMU OS: $arch"
  730. spushd $arch/lib/vlc/plugins
  731. for i in `ls *.a`
  732. do
  733. VLCMODULES="$i $VLCMODULES"
  734. done
  735. spopd # $iarch/lib/vlc/plugins
  736. fi
  737. spopd # vlc-install-"$OSSTYLE"Simulator
  738. fi
  739. if [ "$OSSTYLE" = "MacOSX" ]; then
  740. if [ -d ${VLCROOT}/install-"$OSSTYLE" ];then
  741. spushd ${VLCROOT}/install-"$OSSTYLE"
  742. echo `pwd`
  743. echo "macOS: $arch"
  744. spushd $arch/lib/vlc/plugins
  745. for i in `ls *.a`
  746. do
  747. VLCMODULES="$i $VLCMODULES"
  748. done
  749. spopd # $actual_arch/lib/vlc/plugins
  750. spopd # vlc-install-"$OSSTYLE"
  751. fi
  752. fi
  753. spushd ${VLCROOT}
  754. # collect contrib libraries
  755. spushd contrib/$OSSTYLE-$arch-apple-darwin14-$arch/lib
  756. for i in `ls *.a`
  757. do
  758. CONTRIBLIBS="$i $CONTRIBLIBS"
  759. done
  760. spopd # contrib/$OSSTYLE-$arch-apple-darwin14-$arch/lib
  761. # lipo all the vlc libraries and its plugins
  762. if [ "$OSSTYLE" != "MacOSX" ]; then
  763. doVLCLipo "" "libvlc.a" "no" $OSSTYLE
  764. doVLCLipo "" "libvlccore.a" "no" $OSSTYLE
  765. doVLCLipo "vlc/" "libcompat.a" "no" $OSSTYLE
  766. for i in $VLCMODULES
  767. do
  768. doVLCLipo "vlc/plugins/" $i "yes" $OSSTYLE
  769. done
  770. # lipo contrib libraries
  771. for i in $CONTRIBLIBS
  772. do
  773. doContribLipo $i $OSSTYLE
  774. done
  775. if [ "$OSSTYLE" != "AppleTV" ]; then
  776. # lipo the remaining NEON plugins
  777. DEVICEARCHS=""
  778. for i in armv7 armv7s; do
  779. local iarch="`get_arch $i`"
  780. if [ "$FARCH" == "all" -o "$FARCH" = "$iarch" ];then
  781. DEVICEARCHS="$DEVICEARCHS $iarch"
  782. fi
  783. done
  784. SIMULATORARCHS=""
  785. for i in $VLCNEONMODULES
  786. do
  787. doVLCLipo "vlc/plugins/" $i "yes" $OSSTYLE
  788. done
  789. fi
  790. fi
  791. # create module list
  792. info "creating module list"
  793. echo "// This file is autogenerated by $(basename $0)\n\n" > $PROJECT_DIR/Resources/MobileVLCKit/vlc-plugins-$OSSTYLE.h
  794. echo "// This file is autogenerated by $(basename $0)\n\n" > $PROJECT_DIR/Resources/MobileVLCKit/vlc-plugins-$OSSTYLE.xcconfig
  795. # arm64 got the lowest number of modules
  796. BUILTINS="const void *vlc_static_modules[] = {\n"; \
  797. LDFLAGS=""
  798. DEFINITIONS=""
  799. # add contrib libraries to LDFLAGS
  800. for file in $CONTRIBLIBS
  801. do
  802. LDFLAGS+="${VLCROOT}/install-$OSSTYLE/contrib/$file "
  803. done
  804. for file in $VLCMODULES
  805. do
  806. symbols=$(nm -g -arch $actual_arch install-$OSSTYLE/plugins/$file)
  807. entryname=$(get_symbol "$symbols" _)
  808. DEFINITIONS+="int $entryname (int (*)(void *, void *, int, ...), void *);\n";
  809. BUILTINS+=" $entryname,\n"
  810. LDFLAGS+="${VLCROOT}/install-$OSSTYLE/plugins/$file "
  811. info "...$entryname"
  812. done;
  813. # we only have ARM NEON modules for 32bit so this is limited to iOS
  814. if [ "$OSSTYLE" = "iPhone" ]; then
  815. BUILTINS+="#ifdef __arm__\n"
  816. DEFINITIONS+="#ifdef __arm__\n"
  817. for file in $VLCNEONMODULES
  818. do
  819. symbols=$(nm -g -arch $actual_arch install-$OSSTYLE/plugins/$file)
  820. entryname=$(get_symbol "$symbols" _)
  821. DEFINITIONS+="int $entryname (int (*)(void *, void *, int, ...), void *);\n";
  822. BUILTINS+=" $entryname,\n"
  823. LDFLAGS+="${VLCROOT}/install-$OSSTYLE/plugins/$file "
  824. info "...$entryname"
  825. done;
  826. BUILTINS+="#endif\n"
  827. DEFINITIONS+="#endif\n"
  828. fi
  829. BUILTINS="$BUILTINS NULL\n};\n"
  830. echo "$DEFINITIONS\n$BUILTINS" >> $PROJECT_DIR/Resources/MobileVLCKit/vlc-plugins-$OSSTYLE.h
  831. echo "VLC_PLUGINS_LDFLAGS=$LDFLAGS" >> $PROJECT_DIR/Resources/MobileVLCKit/vlc-plugins-$OSSTYLE.xcconfig
  832. spopd # vlc
  833. }
  834. while getopts "hvwsfbdxntlk:a:e:" OPTION
  835. do
  836. case $OPTION in
  837. h)
  838. usage
  839. exit 1
  840. ;;
  841. v)
  842. VERBOSE=yes
  843. MAKE_JOBS=1
  844. ;;
  845. s)
  846. BUILD_DEVICE=no
  847. BUILD_SIMULATOR=yes
  848. BUILD_STATIC_FRAMEWORK=no
  849. ;;
  850. f)
  851. BUILD_DEVICE=yes
  852. BUILD_SIMULATOR=yes
  853. BUILD_STATIC_FRAMEWORK=yes
  854. ;;
  855. d) CONFIGURATION="Debug"
  856. DEBUG=yes
  857. ;;
  858. w) SCARY="no"
  859. ;;
  860. n)
  861. NONETWORK=yes
  862. ;;
  863. l)
  864. SKIPLIBVLCCOMPILATION=yes
  865. ;;
  866. k)
  867. SDK=$OPTARG
  868. ;;
  869. a)
  870. BUILD_DEVICE=yes
  871. BUILD_SIMULATOR=yes
  872. BUILD_STATIC_FRAMEWORK=yes
  873. FARCH=$OPTARG
  874. ;;
  875. b)
  876. BITCODE=yes
  877. ;;
  878. t)
  879. TVOS=yes
  880. IOS=no
  881. BITCODE=yes
  882. SDK_VERSION=`xcrun --sdk appletvos --show-sdk-version`
  883. SDK_MIN=10.2
  884. OSVERSIONMINCFLAG=tvos
  885. OSVERSIONMINLDFLAG=tvos
  886. ;;
  887. x)
  888. MACOS=yes
  889. IOS=no
  890. BITCODE=no
  891. SDK_VERSION=`xcrun --sdk macosx --show-sdk-version`
  892. SDK_MIN=10.11
  893. OSVERSIONMINCFLAG=macosx
  894. OSVERSIONMINLDFLAG=macosx
  895. BUILD_DEVICE=yes
  896. FARCH=x86_64
  897. BUILD_DYNAMIC_FRAMEWORK=yes
  898. BUILD_STATIC_FRAMEWORK=no
  899. ;;
  900. e)
  901. VLCROOT=$OPTARG
  902. ;;
  903. ?)
  904. usage
  905. exit 1
  906. ;;
  907. esac
  908. done
  909. shift $(($OPTIND - 1))
  910. out="/dev/null"
  911. if [ "$VERBOSE" = "yes" ]; then
  912. out="/dev/stdout"
  913. fi
  914. if [ "x$1" != "x" ]; then
  915. usage
  916. exit 1
  917. fi
  918. # Get root dir
  919. spushd .
  920. ROOT_DIR=`pwd`
  921. spopd
  922. if [ "$VLCROOT" = "" ]; then
  923. VLCROOT=${ROOT_DIR}/libvlc/vlc
  924. info "Preparing build dirs"
  925. mkdir -p libvlc
  926. spushd libvlc
  927. if [ "$NONETWORK" != "yes" ]; then
  928. if ! [ -e vlc ]; then
  929. git clone https://git.videolan.org/git/vlc.git vlc
  930. info "Applying patches to vlc.git"
  931. cd vlc
  932. git checkout -B localBranch ${TESTEDHASH}
  933. git branch --set-upstream-to=origin/master localBranch
  934. git am ${ROOT_DIR}/libvlc/patches/*.patch
  935. if [ $? -ne 0 ]; then
  936. git am --abort
  937. info "Applying the patches failed, aborting git-am"
  938. exit 1
  939. fi
  940. cd ..
  941. else
  942. cd vlc
  943. git fetch --all
  944. git reset --hard ${TESTEDHASH}
  945. git am ${ROOT_DIR}/libvlc/patches/*.patch
  946. cd ..
  947. fi
  948. fi
  949. spopd
  950. fi
  951. fetch_python3_path() {
  952. PYTHON3_PATH=$(echo /Library/Frameworks/Python.framework/Versions/3.*/bin | awk '{print $1;}')
  953. if [ ! -d "${PYTHON3_PATH}" ]; then
  954. PYTHON3_PATH=""
  955. fi
  956. }
  957. #
  958. # Build time
  959. #
  960. out="/dev/null"
  961. if [ "$VERBOSE" = "yes" ]; then
  962. out="/dev/stdout"
  963. fi
  964. if [ "$SKIPLIBVLCCOMPILATION" != "yes" ]; then
  965. info "Building tools"
  966. fetch_python3_path
  967. export PATH="${PYTHON3_PATH}:${VLCROOT}/extras/tools/build/bin:${VLCROOT}/contrib/${TARGET}/bin:/usr/bin:/bin:/usr/sbin:/sbin"
  968. spushd ${VLCROOT}/extras/tools
  969. ./bootstrap
  970. make
  971. make .buildgas
  972. make .buildxz
  973. make .buildtar
  974. make .buildmeson
  975. make .buildninja
  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