compileAndBuildVLCKit.sh 14 KB

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