compileAndBuildVLCKit.sh 14 KB

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