compileAndBuildVLCKit.sh 14 KB

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