compileAndBuildVLCKit.sh 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574
  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. DISABLEDEBUG=no
  13. CONFIGURATION="Debug"
  14. NONETWORK=no
  15. SKIPLIBVLCCOMPILATION=no
  16. TVOS=no
  17. MACOS=no
  18. IOS=yes
  19. BITCODE=no
  20. OSVERSIONMINCFLAG=iphoneos
  21. OSVERSIONMINLDFLAG=ios
  22. ROOT_DIR=empty
  23. FARCH="all"
  24. TESTEDHASH="361ad729d" # libvlc hash that this version of VLCKit is build on
  25. usage()
  26. {
  27. cat << EOF
  28. usage: $0 [-s] [-v] [-k sdk]
  29. OPTIONS
  30. -k Specify which sdk to use (see 'xcodebuild -showsdks', current: ${SDK})
  31. -v Be more verbose
  32. -s Build framework only for simulator (default both)
  33. -f Build framework only for device (default both)
  34. -r Disable Debug for Release
  35. -n Skip script steps requiring network interaction
  36. -l Skip libvlc compilation
  37. -t Build for tvOS
  38. -x Build for macOS / Mac OS X
  39. -b Enable bitcode
  40. -a Build framework for specific arch (all|i386|x86_64|armv7|aarch64)
  41. -e External VLC source path
  42. EOF
  43. }
  44. get_actual_arch() {
  45. if [ "$1" = "aarch64" ]; then
  46. echo "arm64"
  47. else
  48. echo "$1"
  49. fi
  50. }
  51. get_arch() {
  52. if [ "$1" = "arm64" ]; then
  53. echo "aarch64"
  54. else
  55. echo "$1"
  56. fi
  57. }
  58. is_simulator_arch() {
  59. if [ "$1" = "i386" -o "$1" = "x86_64" ];then
  60. return 0
  61. else
  62. return 1
  63. fi
  64. }
  65. spushd()
  66. {
  67. pushd "$1" 2>&1> /dev/null
  68. }
  69. spopd()
  70. {
  71. popd 2>&1> /dev/null
  72. }
  73. info()
  74. {
  75. local green="\033[1;32m"
  76. local normal="\033[0m"
  77. echo "[${green}info${normal}] $1"
  78. }
  79. buildxcodeproj()
  80. {
  81. local target="$2"
  82. local PLATFORM="$3"
  83. info "Building $1 ($target, ${CONFIGURATION}, $PLATFORM)"
  84. local architectures=""
  85. if [ "$FARCH" = "all" ];then
  86. if [ "$TVOS" = "yes" ]; then
  87. if [ "$PLATFORM" = "appletvsimulator" ]; then
  88. architectures="x86_64"
  89. else
  90. architectures="arm64"
  91. fi
  92. fi
  93. if [ "$IOS" = "yes" ]; then
  94. if [ "$PLATFORM" = "iphonesimulator" ]; then
  95. architectures="i386 x86_64"
  96. else
  97. architectures="armv7 arm64"
  98. fi
  99. fi
  100. else
  101. architectures=`get_actual_arch $FARCH`
  102. fi
  103. local bitcodeflag=""
  104. if [ "$BITCODE" = "yes" ]; then
  105. bitcodeflag="BITCODE_GENERATION_MODE=bitcode"
  106. fi
  107. local defs="$GCC_PREPROCESSOR_DEFINITIONS"
  108. xcodebuild -project "$1.xcodeproj" \
  109. -target "$target" \
  110. -sdk $PLATFORM$SDK \
  111. -configuration ${CONFIGURATION} \
  112. ARCHS="${architectures}" \
  113. IPHONEOS_DEPLOYMENT_TARGET=${SDK_MIN} \
  114. GCC_PREPROCESSOR_DEFINITIONS="$defs" \
  115. ${bitcodeflag} \
  116. > ${out}
  117. }
  118. buildLibVLC() {
  119. ARCH="$1"
  120. PLATFORM="$2"
  121. if [ "$DISABLEDEBUG" = "yes" ]; then
  122. DEBUGFLAG="--disable-debug"
  123. else
  124. DEBUGFLAG=""
  125. fi
  126. if [ "$VERBOSE" = "yes" ]; then
  127. VERBOSEFLAG="--verbose"
  128. else
  129. VERBOSEFLAG=""
  130. fi
  131. if [ "$BITCODE" = "yes" ]; then
  132. BITCODEFLAG="--enable-bitcode"
  133. else
  134. BITCODEFLAG=""
  135. fi
  136. info "Compiling ${ARCH} with SDK version ${SDK_VERSION}, platform ${PLATFORM}"
  137. ACTUAL_ARCH=`get_actual_arch $ARCH`
  138. BUILDDIR="${VLCROOT}/build-${PLATFORM}-${ACTUAL_ARCH}"
  139. mkdir -p ${BUILDDIR}
  140. spushd ${BUILDDIR}
  141. ../extras/package/apple/build.sh \
  142. --arch=$ARCH \
  143. --sdk=${PLATFORM}${SDK_VERSION} \
  144. --build-libvlc=dynamic \
  145. --build-modules=static \
  146. ${DEBUGFLAG} ${VERBOSEFLAG} ${BITCODEFLAG}
  147. # COPY to the framework:
  148. # - ${VLC_INSTALL_DIR}/lib/libvlc.dylib
  149. # - ${VLC_INSTALL_DIR}/lib/libvlccore.dylib
  150. # - ${VLC_INSTALL_DIR}/lib/libvlcmodules_plugin.dylib
  151. # - ${VLC_INSTALL_DIR}/include/vlc/plugins.manifest.h
  152. spopd # builddir
  153. info "Finished compiling libvlc for ${ARCH} with SDK version ${SDK_VERSION}, platform ${PLATFORM}"
  154. }
  155. buildMobileKit() {
  156. PLATFORM="$1"
  157. if [ "$SKIPLIBVLCCOMPILATION" != "yes" ]; then
  158. if [ "$FARCH" = "all" ];then
  159. if [ "$TVOS" = "yes" ]; then
  160. if [ "$PLATFORM" = "iphonesimulator" ]; then
  161. buildLibVLC "x86_64" "appletvsimulator"
  162. else
  163. buildLibVLC "aarch64" "appletvos"
  164. fi
  165. fi
  166. if [ "$MACOS" = "yes" ]; then
  167. buildLibVLC "x86_64" "macosx"
  168. fi
  169. if [ "$IOS" = "yes" ]; then
  170. if [ "$PLATFORM" = "iphonesimulator" ]; then
  171. buildLibVLC "i386" $PLATFORM
  172. buildLibVLC "x86_64" $PLATFORM
  173. else
  174. buildLibVLC "armv7" $PLATFORM
  175. buildLibVLC "aarch64" $PLATFORM
  176. fi
  177. fi
  178. else
  179. if [ "$FARCH" != "x86_64" -a "$FARCH" != "aarch64" -a "$FARCH" != "i386" \
  180. -a "$FARCH" != "armv7" ];then
  181. echo "*** Framework ARCH: ${FARCH} is invalid ***"
  182. exit 1
  183. fi
  184. if (is_simulator_arch $FARCH);then
  185. if [ "$TVOS" = "yes" ]; then
  186. PLATFORM="appletvsimulator"
  187. fi
  188. if [ "$IOS" = "yes" ]; then
  189. PLATFORM="iphonesimulator"
  190. fi
  191. if [ "$MACOS" = "yes" ]; then
  192. PLATFORM="macosx"
  193. fi
  194. else
  195. if [ "$TVOS" = "yes" ]; then
  196. PLATFORM="appletvos"
  197. fi
  198. if [ "$IOS" = "yes" ]; then
  199. PLATFORM="iphoneos"
  200. fi
  201. if [ "$MACOS" = "yes" ]; then
  202. PLATFORM="macosx"
  203. fi
  204. fi
  205. buildLibVLC $FARCH "$PLATFORM"
  206. fi
  207. fi
  208. }
  209. get_symbol()
  210. {
  211. echo "$1" | grep vlc_entry_$2|cut -d" " -f 3|sed 's/_vlc/vlc/'
  212. }
  213. build_universal_static_lib() {
  214. PROJECT_DIR=`pwd`
  215. OSSTYLE="$1"
  216. info "building universal static libs for $OSSTYLE"
  217. # remove old module list
  218. rm -f $PROJECT_DIR/Resources/MobileVLCKit/vlc-plugins-$OSSTYLE.h
  219. touch $PROJECT_DIR/Resources/MobileVLCKit/vlc-plugins-$OSSTYLE.h
  220. spushd ${VLCROOT}
  221. rm -rf install-$OSSTYLE
  222. mkdir install-$OSSTYLE
  223. spopd # vlc
  224. VLCSTATICLIBS=""
  225. VLCSTATICLIBRARYNAME="static-lib/libvlc-full-static.a"
  226. VLCSTATICMODULELIST=""
  227. # brute-force test the available architectures we could lipo
  228. BUILD_KIND_AVAILABLES="os-arm64 os-armv7 simulator-x86_64 simulator-i386 -x86_64"
  229. for flavour in $BUILD_KIND_AVAILABLES; do
  230. staticlibname="${VLCROOT}/build-${OSSTYLE}${flavour}/${VLCSTATICLIBRARYNAME}"
  231. modulelistname="${VLCROOT}/build-${OSSTYLE}${flavour}/static-lib/plugins.manifest.h"
  232. if [ -f "$staticlibname" -a -f "$modulelistname" ]; then
  233. VLCSTATICLIBS+=" $staticlibname"
  234. VLCSTATICMODULELIST="$modulelistname" # TODO: which one should we choose ?
  235. else
  236. echo "${VLCROOT}/build-${OSSTYLE}${flavour}/ not available for lipo"
  237. if ! [ -f "$staticlibname" ]; then
  238. echo " -> $staticlibname not available"
  239. fi
  240. if ! [ -f "$modulelistname" ]; then
  241. echo " -> $modulelistname not available"
  242. fi
  243. fi
  244. done
  245. spushd ${VLCROOT}
  246. lipo $VLCSTATICLIBS -create -output install-$OSSTYLE/libvlc-full-static.a
  247. cp $VLCSTATICMODULELIST $PROJECT_DIR/Resources/MobileVLCKit/vlc-plugins-$OSSTYLE.h
  248. spopd # VLCROOT
  249. }
  250. while getopts "hvsfbrxntlk:a:e:" OPTION
  251. do
  252. case $OPTION in
  253. h)
  254. usage
  255. exit 1
  256. ;;
  257. v)
  258. VERBOSE=yes
  259. ;;
  260. s)
  261. BUILD_DEVICE=no
  262. BUILD_SIMULATOR=yes
  263. BUILD_STATIC_FRAMEWORK=yes
  264. ;;
  265. f)
  266. BUILD_DEVICE=yes
  267. BUILD_SIMULATOR=no
  268. BUILD_STATIC_FRAMEWORK=yes
  269. ;;
  270. r) CONFIGURATION="Release"
  271. DISABLEDEBUG=yes
  272. ;;
  273. n)
  274. NONETWORK=yes
  275. ;;
  276. l)
  277. SKIPLIBVLCCOMPILATION=yes
  278. ;;
  279. k)
  280. SDK=$OPTARG
  281. ;;
  282. a)
  283. FARCH=$OPTARG
  284. ;;
  285. b)
  286. BITCODE=yes
  287. ;;
  288. t)
  289. TVOS=yes
  290. IOS=no
  291. BITCODE=yes
  292. SDK_VERSION=`xcrun --sdk appletvos --show-sdk-version`
  293. SDK_MIN=10.2
  294. OSVERSIONMINCFLAG=tvos
  295. OSVERSIONMINLDFLAG=tvos
  296. ;;
  297. x)
  298. MACOS=yes
  299. IOS=no
  300. BITCODE=no
  301. SDK_VERSION=`xcrun --sdk macosx --show-sdk-version`
  302. SDK_MIN=10.11
  303. OSVERSIONMINCFLAG=macosx
  304. OSVERSIONMINLDFLAG=macosx
  305. BUILD_DEVICE=yes
  306. FARCH=x86_64
  307. BUILD_DYNAMIC_FRAMEWORK=yes
  308. BUILD_STATIC_FRAMEWORK=no
  309. ;;
  310. e)
  311. VLCROOT=$OPTARG
  312. ;;
  313. ?)
  314. usage
  315. exit 1
  316. ;;
  317. esac
  318. done
  319. shift $(($OPTIND - 1))
  320. out="/dev/null"
  321. if [ "$VERBOSE" = "yes" ]; then
  322. out="/dev/stdout"
  323. fi
  324. if [ "x$1" != "x" ]; then
  325. usage
  326. exit 1
  327. fi
  328. # Get root dir
  329. spushd .
  330. ROOT_DIR=`pwd`
  331. spopd
  332. if [ "$VLCROOT" = "" ]; then
  333. VLCROOT=${ROOT_DIR}/libvlc/vlc
  334. info "Preparing build dirs"
  335. mkdir -p libvlc
  336. spushd libvlc
  337. if [ "$NONETWORK" != "yes" ]; then
  338. if ! [ -e vlc ]; then
  339. git clone https://git.videolan.org/git/vlc.git vlc
  340. info "Applying patches to vlc.git"
  341. cd vlc
  342. git checkout -B localBranch ${TESTEDHASH}
  343. git branch --set-upstream-to=origin/master localBranch
  344. git am ${ROOT_DIR}/libvlc/patches/*.patch
  345. if [ $? -ne 0 ]; then
  346. git am --abort
  347. info "Applying the patches failed, aborting git-am"
  348. exit 1
  349. fi
  350. cd ..
  351. else
  352. cd vlc
  353. git fetch --all
  354. git reset --hard ${TESTEDHASH}
  355. git am ${ROOT_DIR}/libvlc/patches/*.patch
  356. cd ..
  357. fi
  358. fi
  359. spopd
  360. fi
  361. fetch_python3_path() {
  362. PYTHON3_PATH=$(echo /Library/Frameworks/Python.framework/Versions/3.*/bin | awk '{print $1;}')
  363. if [ ! -d "${PYTHON3_PATH}" ]; then
  364. PYTHON3_PATH=""
  365. fi
  366. }
  367. #
  368. # Build time
  369. #
  370. out="/dev/null"
  371. if [ "$VERBOSE" = "yes" ]; then
  372. out="/dev/stdout"
  373. fi
  374. if [ "$SKIPLIBVLCCOMPILATION" != "yes" ]; then
  375. info "Building tools"
  376. fetch_python3_path
  377. export PATH="${PYTHON3_PATH}:${VLCROOT}/extras/tools/build/bin:${VLCROOT}/contrib/${TARGET}/bin:/usr/bin:/bin:/usr/sbin:/sbin"
  378. spushd ${VLCROOT}/extras/tools
  379. ./bootstrap
  380. make
  381. make .buildgas
  382. make .buildxz
  383. make .buildtar
  384. make .buildmeson
  385. make .buildninja
  386. spopd #${VLCROOT}/extras/tools
  387. fi
  388. if [ "$BUILD_DEVICE" != "no" ]; then
  389. buildMobileKit iphoneos
  390. fi
  391. if [ "$BUILD_SIMULATOR" != "no" ]; then
  392. buildMobileKit iphonesimulator
  393. fi
  394. if [ "$TVOS" = "yes" ]; then
  395. build_universal_static_lib "AppleTV"
  396. fi
  397. if [ "$MACOS" = "yes" ]; then
  398. build_universal_static_lib "MacOSX"
  399. fi
  400. if [ "$IOS" = "yes" ]; then
  401. echo Not building universal static libs
  402. #build_universal_static_lib "iphone"
  403. fi
  404. info "all done"
  405. copy_libvlc_files() {
  406. OUTPUT="$1"
  407. ARCH="$2"
  408. PLATFORM="$3"
  409. info "Copy plugin manifest for $PLATFORM-$ARCH to $OUTPUT"
  410. ACTUAL_ARCH=`get_actual_arch $ARCH`
  411. BUILDDIR="${VLCROOT}/build-${PLATFORM}-${ACTUAL_ARCH}"
  412. # HACK: find the path to VLC install directory ourselves, althoug we should
  413. # be able to explicit it ourselves instead of relying on the script to
  414. # decide for us.
  415. VLC_INSTALL_DIR="${BUILDDIR}/vlc-${PLATFORM}${SDK_VERSION}-${ACTUAL_ARCH}/"
  416. mkdir -p "${OUTPUT}/Headers"
  417. mkdir -p "${OUTPUT}/Libraries"
  418. cp -p "${VLC_INSTALL_DIR}/include/vlc/plugins.manifest.h" "$OUTPUT/Headers/"
  419. cp -p "${VLC_INSTALL_DIR}/lib/libvlc.dylib" "$OUTPUT/Libraries/"
  420. cp -p "${VLC_INSTALL_DIR}/lib/libvlccore.dylib" "$OUTPUT/Libraries/"
  421. cp -p "${VLC_INSTALL_DIR}/lib/libvlcmodules_plugin.dylib" "$OUTPUT/Libraries/"
  422. # The application has to set the run-search path to the MobileVLCKit Library folder
  423. install_name_tool \
  424. "$OUTPUT/Libraries/libvlc.dylib" \
  425. -id "@rpath/libvlc.dylib"
  426. install_name_tool \
  427. "$OUTPUT/Libraries/libvlccore.dylib" \
  428. -id "@rpath/libvlccore.dylib"
  429. install_name_tool \
  430. "$OUTPUT/Libraries/libvlcmodules_plugin.dylib" \
  431. \-id "@rpath/libvlcmodules_plugin.dylib"
  432. }
  433. if [ "$BUILD_STATIC_FRAMEWORK" != "no" ]; then
  434. if [ "$TVOS" = "yes" ]; then
  435. info "Building static TVVLCKit.framework"
  436. lipo_libs=""
  437. platform=""
  438. if [ "$FARCH" = "all" ] || (! is_simulator_arch $FARCH);then
  439. platform="appletvos"
  440. buildxcodeproj MobileVLCKit "TVVLCKit" ${platform}
  441. lipo_libs="$lipo_libs ${CONFIGURATION}-appletvos/libTVVLCKit.a"
  442. fi
  443. if [ "$FARCH" = "all" ] || (is_simulator_arch $FARCH);then
  444. platform="appletvsimulator"
  445. buildxcodeproj MobileVLCKit "TVVLCKit" ${platform}
  446. lipo_libs="$lipo_libs ${CONFIGURATION}-appletvsimulator/libTVVLCKit.a"
  447. fi
  448. # Assumes both platforms were built currently
  449. spushd build
  450. rm -rf TVVLCKit.framework && \
  451. mkdir TVVLCKit.framework && \
  452. lipo -create ${lipo_libs} -o TVVLCKit.framework/TVVLCKit && \
  453. chmod a+x TVVLCKit.framework/TVVLCKit && \
  454. cp -pr ${CONFIGURATION}-${platform}/TVVLCKit TVVLCKit.framework/Headers
  455. cp -pr ${CONFIGURATION}-${platform}/Modules TVVLCKit.framework/Modules
  456. spopd # build
  457. info "Build of static TVVLCKit.framework completed"
  458. fi
  459. if [ "$IOS" = "yes" ]; then
  460. info "Building static MobileVLCKit.framework"
  461. lipo_libs=""
  462. platform=""
  463. if [ "$FARCH" = "all" ] || (! is_simulator_arch $FARCH);then
  464. platform="iphoneos"
  465. buildxcodeproj MobileVLCKit "MobileVLCKit" ${platform}
  466. lipo_libs="$lipo_libs ${CONFIGURATION}-iphoneos/libMobileVLCKit.a"
  467. fi
  468. if [ "$FARCH" = "all" ] || (is_simulator_arch $FARCH);then
  469. platform="iphonesimulator"
  470. buildxcodeproj MobileVLCKit "MobileVLCKit" ${platform}
  471. lipo_libs="$lipo_libs ${CONFIGURATION}-iphonesimulator/libMobileVLCKit.a"
  472. fi
  473. # Assumes both platforms were built currently
  474. spushd build
  475. rm -rf MobileVLCKit.framework && \
  476. mkdir MobileVLCKit.framework && \
  477. lipo -create ${lipo_libs} -o MobileVLCKit.framework/MobileVLCKit && \
  478. chmod a+x MobileVLCKit.framework/MobileVLCKit && \
  479. cp -pr ${CONFIGURATION}-${platform}/MobileVLCKit MobileVLCKit.framework/Headers
  480. cp -pr ${CONFIGURATION}-${platform}/Modules MobileVLCKit.framework/Modules
  481. # Only support the non-ALL case for now
  482. if [ "$FARCH" != "all" ]; then
  483. copy_libvlc_files MobileVLCKit.framework/ ${FARCH} ${platform}
  484. fi
  485. spopd # build
  486. info "Build of static MobileVLCKit.framework completed"
  487. fi
  488. fi
  489. if [ "$BUILD_DYNAMIC_FRAMEWORK" != "no" ]; then
  490. if [ "$MACOS" = "yes" ]; then
  491. CURRENT_DIR=`pwd`
  492. info "Building VLCKit.framework in ${CURRENT_DIR}"
  493. buildxcodeproj VLCKit "VLCKit" "macosx"
  494. # remove intermediate build result we don't need to keep
  495. spushd build
  496. rm ${CONFIGURATION}/libStaticLibVLC.a
  497. spopd # build
  498. info "Build of VLCKit.framework completed"
  499. fi
  500. fi