compileAndBuildVLCKit.sh 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528
  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. spopd # builddir
  148. info "Finished compiling libvlc for ${ARCH} with SDK version ${SDK_VERSION}, platform ${PLATFORM}"
  149. }
  150. buildMobileKit() {
  151. PLATFORM="$1"
  152. if [ "$SKIPLIBVLCCOMPILATION" != "yes" ]; then
  153. if [ "$FARCH" = "all" ];then
  154. if [ "$TVOS" = "yes" ]; then
  155. if [ "$PLATFORM" = "iphonesimulator" ]; then
  156. buildLibVLC "x86_64" "appletvsimulator"
  157. else
  158. buildLibVLC "aarch64" "appletvos"
  159. fi
  160. fi
  161. if [ "$MACOS" = "yes" ]; then
  162. buildLibVLC "x86_64" "macosx"
  163. fi
  164. if [ "$IOS" = "yes" ]; then
  165. if [ "$PLATFORM" = "iphonesimulator" ]; then
  166. buildLibVLC "i386" $PLATFORM
  167. buildLibVLC "x86_64" $PLATFORM
  168. else
  169. buildLibVLC "armv7" $PLATFORM
  170. buildLibVLC "aarch64" $PLATFORM
  171. fi
  172. fi
  173. else
  174. if [ "$FARCH" != "x86_64" -a "$FARCH" != "aarch64" -a "$FARCH" != "i386" \
  175. -a "$FARCH" != "armv7" ];then
  176. echo "*** Framework ARCH: ${FARCH} is invalid ***"
  177. exit 1
  178. fi
  179. if (is_simulator_arch $FARCH);then
  180. if [ "$TVOS" = "yes" ]; then
  181. PLATFORM="appletvsimulator"
  182. fi
  183. if [ "$IOS" = "yes" ]; then
  184. PLATFORM="iphonesimulator"
  185. fi
  186. if [ "$MACOS" = "yes" ]; then
  187. PLATFORM="macosx"
  188. fi
  189. else
  190. if [ "$TVOS" = "yes" ]; then
  191. PLATFORM="appletvos"
  192. fi
  193. if [ "$IOS" = "yes" ]; then
  194. PLATFORM="iphoneos"
  195. fi
  196. if [ "$MACOS" = "yes" ]; then
  197. PLATFORM="macosx"
  198. fi
  199. fi
  200. buildLibVLC $FARCH "$PLATFORM"
  201. fi
  202. fi
  203. }
  204. get_symbol()
  205. {
  206. echo "$1" | grep vlc_entry_$2|cut -d" " -f 3|sed 's/_vlc/vlc/'
  207. }
  208. build_universal_static_lib() {
  209. PROJECT_DIR=`pwd`
  210. OSSTYLE="$1"
  211. info "building universal static libs for $OSSTYLE"
  212. # remove old module list
  213. rm -f $PROJECT_DIR/Resources/MobileVLCKit/vlc-plugins-$OSSTYLE.h
  214. touch $PROJECT_DIR/Resources/MobileVLCKit/vlc-plugins-$OSSTYLE.h
  215. spushd ${VLCROOT}
  216. rm -rf install-$OSSTYLE
  217. mkdir install-$OSSTYLE
  218. spopd # vlc
  219. VLCSTATICLIBS=""
  220. VLCSTATICLIBRARYNAME="static-lib/libvlc-full-static.a"
  221. VLCSTATICMODULELIST=""
  222. # brute-force test the available architectures we could lipo
  223. BUILD_KIND_AVAILABLES="os-arm64 os-armv7 simulator-x86_64 simulator-i386 -x86_64"
  224. for flavour in $BUILD_KIND_AVAILABLES; do
  225. staticlibname="${VLCROOT}/build-${OSSTYLE}${flavour}/${VLCSTATICLIBRARYNAME}"
  226. modulelistname="${VLCROOT}/build-${OSSTYLE}${flavour}/static-lib/plugins.manifest.h"
  227. if [ -f "$staticlibname" -a -f "$modulelistname" ]; then
  228. VLCSTATICLIBS+=" $staticlibname"
  229. VLCSTATICMODULELIST="$modulelistname" # TODO: which one should we choose ?
  230. else
  231. echo "${VLCROOT}/build-${OSSTYLE}${flavour}/ not available for lipo"
  232. if ! [ -f "$staticlibname" ]; then
  233. echo " -> $staticlibname not available"
  234. fi
  235. if ! [ -f "$modulelistname" ]; then
  236. echo " -> $modulelistname not available"
  237. fi
  238. fi
  239. done
  240. spushd ${VLCROOT}
  241. lipo $VLCSTATICLIBS -create -output install-$OSSTYLE/libvlc-full-static.a
  242. cp $VLCSTATICMODULELIST $PROJECT_DIR/Resources/MobileVLCKit/vlc-plugins-$OSSTYLE.h
  243. spopd # VLCROOT
  244. }
  245. while getopts "hvsfbrxntlk:a:e:" OPTION
  246. do
  247. case $OPTION in
  248. h)
  249. usage
  250. exit 1
  251. ;;
  252. v)
  253. VERBOSE=yes
  254. ;;
  255. s)
  256. BUILD_DEVICE=no
  257. BUILD_SIMULATOR=yes
  258. BUILD_STATIC_FRAMEWORK=yes
  259. ;;
  260. f)
  261. BUILD_DEVICE=yes
  262. BUILD_SIMULATOR=no
  263. BUILD_STATIC_FRAMEWORK=yes
  264. ;;
  265. r) CONFIGURATION="Release"
  266. DISABLEDEBUG=yes
  267. ;;
  268. n)
  269. NONETWORK=yes
  270. ;;
  271. l)
  272. SKIPLIBVLCCOMPILATION=yes
  273. ;;
  274. k)
  275. SDK=$OPTARG
  276. ;;
  277. a)
  278. FARCH=$OPTARG
  279. ;;
  280. b)
  281. BITCODE=yes
  282. ;;
  283. t)
  284. TVOS=yes
  285. IOS=no
  286. BITCODE=yes
  287. SDK_VERSION=`xcrun --sdk appletvos --show-sdk-version`
  288. SDK_MIN=10.2
  289. OSVERSIONMINCFLAG=tvos
  290. OSVERSIONMINLDFLAG=tvos
  291. ;;
  292. x)
  293. MACOS=yes
  294. IOS=no
  295. BITCODE=no
  296. SDK_VERSION=`xcrun --sdk macosx --show-sdk-version`
  297. SDK_MIN=10.11
  298. OSVERSIONMINCFLAG=macosx
  299. OSVERSIONMINLDFLAG=macosx
  300. BUILD_DEVICE=yes
  301. FARCH=x86_64
  302. BUILD_DYNAMIC_FRAMEWORK=yes
  303. BUILD_STATIC_FRAMEWORK=no
  304. ;;
  305. e)
  306. VLCROOT=$OPTARG
  307. ;;
  308. ?)
  309. usage
  310. exit 1
  311. ;;
  312. esac
  313. done
  314. shift $(($OPTIND - 1))
  315. out="/dev/null"
  316. if [ "$VERBOSE" = "yes" ]; then
  317. out="/dev/stdout"
  318. fi
  319. if [ "x$1" != "x" ]; then
  320. usage
  321. exit 1
  322. fi
  323. # Get root dir
  324. spushd .
  325. ROOT_DIR=`pwd`
  326. spopd
  327. if [ "$VLCROOT" = "" ]; then
  328. VLCROOT=${ROOT_DIR}/libvlc/vlc
  329. info "Preparing build dirs"
  330. mkdir -p libvlc
  331. spushd libvlc
  332. if [ "$NONETWORK" != "yes" ]; then
  333. if ! [ -e vlc ]; then
  334. git clone https://git.videolan.org/git/vlc.git vlc
  335. info "Applying patches to vlc.git"
  336. cd vlc
  337. git checkout -B localBranch ${TESTEDHASH}
  338. git branch --set-upstream-to=origin/master localBranch
  339. git am ${ROOT_DIR}/libvlc/patches/*.patch
  340. if [ $? -ne 0 ]; then
  341. git am --abort
  342. info "Applying the patches failed, aborting git-am"
  343. exit 1
  344. fi
  345. cd ..
  346. else
  347. cd vlc
  348. git fetch --all
  349. git reset --hard ${TESTEDHASH}
  350. git am ${ROOT_DIR}/libvlc/patches/*.patch
  351. cd ..
  352. fi
  353. fi
  354. spopd
  355. fi
  356. fetch_python3_path() {
  357. PYTHON3_PATH=$(echo /Library/Frameworks/Python.framework/Versions/3.*/bin | awk '{print $1;}')
  358. if [ ! -d "${PYTHON3_PATH}" ]; then
  359. PYTHON3_PATH=""
  360. fi
  361. }
  362. #
  363. # Build time
  364. #
  365. out="/dev/null"
  366. if [ "$VERBOSE" = "yes" ]; then
  367. out="/dev/stdout"
  368. fi
  369. if [ "$SKIPLIBVLCCOMPILATION" != "yes" ]; then
  370. info "Building tools"
  371. fetch_python3_path
  372. export PATH="${PYTHON3_PATH}:${VLCROOT}/extras/tools/build/bin:${VLCROOT}/contrib/${TARGET}/bin:/usr/bin:/bin:/usr/sbin:/sbin"
  373. spushd ${VLCROOT}/extras/tools
  374. ./bootstrap
  375. make
  376. make .buildgas
  377. make .buildxz
  378. make .buildtar
  379. make .buildmeson
  380. make .buildninja
  381. spopd #${VLCROOT}/extras/tools
  382. fi
  383. if [ "$BUILD_DEVICE" != "no" ]; then
  384. buildMobileKit iphoneos
  385. fi
  386. if [ "$BUILD_SIMULATOR" != "no" ]; then
  387. buildMobileKit iphonesimulator
  388. fi
  389. if [ "$TVOS" = "yes" ]; then
  390. build_universal_static_lib "AppleTV"
  391. fi
  392. if [ "$MACOS" = "yes" ]; then
  393. build_universal_static_lib "MacOSX"
  394. fi
  395. if [ "$IOS" = "yes" ]; then
  396. echo Not building universal static libs
  397. #build_universal_static_lib "iphone"
  398. fi
  399. info "all done"
  400. if [ "$BUILD_STATIC_FRAMEWORK" != "no" ]; then
  401. if [ "$TVOS" = "yes" ]; then
  402. info "Building static TVVLCKit.framework"
  403. lipo_libs=""
  404. platform=""
  405. if [ "$FARCH" = "all" ] || (! is_simulator_arch $FARCH);then
  406. platform="appletvos"
  407. buildxcodeproj MobileVLCKit "TVVLCKit" ${platform}
  408. lipo_libs="$lipo_libs ${CONFIGURATION}-appletvos/libTVVLCKit.a"
  409. fi
  410. if [ "$FARCH" = "all" ] || (is_simulator_arch $FARCH);then
  411. platform="appletvsimulator"
  412. buildxcodeproj MobileVLCKit "TVVLCKit" ${platform}
  413. lipo_libs="$lipo_libs ${CONFIGURATION}-appletvsimulator/libTVVLCKit.a"
  414. fi
  415. # Assumes both platforms were built currently
  416. spushd build
  417. rm -rf TVVLCKit.framework && \
  418. mkdir TVVLCKit.framework && \
  419. lipo -create ${lipo_libs} -o TVVLCKit.framework/TVVLCKit && \
  420. chmod a+x TVVLCKit.framework/TVVLCKit && \
  421. cp -pr ${CONFIGURATION}-${platform}/TVVLCKit TVVLCKit.framework/Headers
  422. cp -pr ${CONFIGURATION}-${platform}/Modules TVVLCKit.framework/Modules
  423. spopd # build
  424. info "Build of static TVVLCKit.framework completed"
  425. fi
  426. if [ "$IOS" = "yes" ]; then
  427. info "Building static MobileVLCKit.framework"
  428. lipo_libs=""
  429. platform=""
  430. if [ "$FARCH" = "all" ] || (! is_simulator_arch $FARCH);then
  431. platform="iphoneos"
  432. buildxcodeproj MobileVLCKit "MobileVLCKit" ${platform}
  433. lipo_libs="$lipo_libs ${CONFIGURATION}-iphoneos/libMobileVLCKit.a"
  434. fi
  435. if [ "$FARCH" = "all" ] || (is_simulator_arch $FARCH);then
  436. platform="iphonesimulator"
  437. buildxcodeproj MobileVLCKit "MobileVLCKit" ${platform}
  438. lipo_libs="$lipo_libs ${CONFIGURATION}-iphonesimulator/libMobileVLCKit.a"
  439. fi
  440. # Assumes both platforms were built currently
  441. spushd build
  442. rm -rf MobileVLCKit.framework && \
  443. mkdir MobileVLCKit.framework && \
  444. lipo -create ${lipo_libs} -o MobileVLCKit.framework/MobileVLCKit && \
  445. chmod a+x MobileVLCKit.framework/MobileVLCKit && \
  446. cp -pr ${CONFIGURATION}-${platform}/MobileVLCKit MobileVLCKit.framework/Headers
  447. cp -pr ${CONFIGURATION}-${platform}/Modules MobileVLCKit.framework/Modules
  448. spopd # build
  449. info "Build of static MobileVLCKit.framework completed"
  450. fi
  451. fi
  452. if [ "$BUILD_DYNAMIC_FRAMEWORK" != "no" ]; then
  453. if [ "$MACOS" = "yes" ]; then
  454. CURRENT_DIR=`pwd`
  455. info "Building VLCKit.framework in ${CURRENT_DIR}"
  456. buildxcodeproj VLCKit "VLCKit" "macosx"
  457. # remove intermediate build result we don't need to keep
  458. spushd build
  459. rm ${CONFIGURATION}/libStaticLibVLC.a
  460. spopd # build
  461. info "Build of VLCKit.framework completed"
  462. fi
  463. fi