compileAndBuildVLCKit.sh 14 KB

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