buildMobileVLCKit.sh 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
  1. #!/bin/sh
  2. # Copyright (C) Pierre d'Herbemont, 2010
  3. # Copyright (C) Felix Paul Kühne, 2012-2015
  4. set -e
  5. BUILD_DEVICE=yes
  6. BUILD_SIMULATOR=yes
  7. BUILD_STATIC_FRAMEWORK=no
  8. SDK=`xcrun --sdk iphoneos --show-sdk-version`
  9. SDK_MIN=7.0
  10. VERBOSE=no
  11. CONFIGURATION="Release"
  12. NONETWORK=no
  13. SKIPLIBVLCCOMPILATION=no
  14. SCARY=yes
  15. TVOS=no
  16. BITCODE=no
  17. TESTEDHASH=270dc6a
  18. usage()
  19. {
  20. cat << EOF
  21. usage: $0 [-s] [-v] [-k sdk]
  22. OPTIONS
  23. -k Specify which sdk to use (see 'xcodebuild -showsdks', current: ${SDK})
  24. -v Be more verbose
  25. -s Build for simulator
  26. -f Build framework for device and simulator
  27. -d Enable Debug
  28. -n Skip script steps requiring network interaction
  29. -l Skip libvlc compilation
  30. -t Build for tvOS
  31. -w Build a limited stack of non-scary libraries only
  32. -y Build universal static libraries
  33. -b Enable bitcode
  34. EOF
  35. }
  36. spushd()
  37. {
  38. pushd "$1" 2>&1> /dev/null
  39. }
  40. spopd()
  41. {
  42. popd 2>&1> /dev/null
  43. }
  44. info()
  45. {
  46. local green="\033[1;32m"
  47. local normal="\033[0m"
  48. echo "[${green}info${normal}] $1"
  49. }
  50. buildxcodeproj()
  51. {
  52. local target="$2"
  53. local PLATFORM="$3"
  54. info "Building $1 ($target, ${CONFIGURATION}, $PLATFORM)"
  55. local architectures=""
  56. if [ "$TVOS" != "yes" ]; then
  57. if [ "$PLATFORM" = "iphonesimulator" ]; then
  58. architectures="i386 x86_64"
  59. else
  60. architectures="armv7 armv7s arm64"
  61. fi
  62. else
  63. if [ "$PLATFORM" = "appletvsimulator" ]; then
  64. architectures="x86_64"
  65. else
  66. architectures="arm64"
  67. fi
  68. fi
  69. local defs="$GCC_PREPROCESSOR_DEFINITIONS"
  70. if [ "$SCARY" = "no" ]; then
  71. defs="$defs NOSCARYCODECS"
  72. fi
  73. xcodebuild -project "$1.xcodeproj" \
  74. -target "$target" \
  75. -sdk $PLATFORM$SDK \
  76. -configuration ${CONFIGURATION} \
  77. ARCHS="${architectures}" \
  78. IPHONEOS_DEPLOYMENT_TARGET=${SDK_MIN} \
  79. GCC_PREPROCESSOR_DEFINITIONS="$defs" \
  80. > ${out}
  81. }
  82. while getopts "hvwsfbdntlk:" OPTION
  83. do
  84. case $OPTION in
  85. h)
  86. usage
  87. exit 1
  88. ;;
  89. v)
  90. VERBOSE=yes
  91. ;;
  92. s)
  93. BUILD_DEVICE=no
  94. BUILD_SIMULATOR=yes
  95. BUILD_STATIC_FRAMEWORK=no
  96. ;;
  97. f)
  98. BUILD_DEVICE=yes
  99. BUILD_SIMULATOR=yes
  100. BUILD_STATIC_FRAMEWORK=yes
  101. ;;
  102. d) CONFIGURATION="Debug"
  103. ;;
  104. w) SCARY="no"
  105. ;;
  106. n)
  107. NONETWORK=yes
  108. ;;
  109. l)
  110. SKIPLIBVLCCOMPILATION=yes
  111. ;;
  112. k)
  113. SDK=$OPTARG
  114. ;;
  115. b)
  116. BITCODE=yes
  117. ;;
  118. t)
  119. TVOS=yes
  120. BITCODE=yes
  121. SDK=`xcrun --sdk appletvos --show-sdk-version`
  122. SDK_MIN=9.0
  123. ;;
  124. ?)
  125. usage
  126. exit 1
  127. ;;
  128. esac
  129. done
  130. shift $(($OPTIND - 1))
  131. out="/dev/null"
  132. if [ "$VERBOSE" = "yes" ]; then
  133. out="/dev/stdout"
  134. fi
  135. if [ "x$1" != "x" ]; then
  136. usage
  137. exit 1
  138. fi
  139. # Get root dir
  140. spushd .
  141. aspen_root_dir=`pwd`
  142. spopd
  143. info "Preparing build dirs"
  144. mkdir -p MobileVLCKit/ImportedSources
  145. spushd MobileVLCKit/ImportedSources
  146. if [ "$NONETWORK" != "yes" ]; then
  147. if ! [ -e vlc ]; then
  148. git clone git://git.videolan.org/vlc.git vlc
  149. info "Applying patches to vlc.git"
  150. cd vlc
  151. git checkout -B localBranch ${TESTEDHASH}
  152. git branch --set-upstream-to=origin/master localBranch
  153. git am ../../patches/*.patch
  154. if [ $? -ne 0 ]; then
  155. git am --abort
  156. info "Applying the patches failed, aborting git-am"
  157. exit 1
  158. fi
  159. cd ..
  160. else
  161. cd vlc
  162. git pull --rebase
  163. git reset --hard ${TESTEDHASH}
  164. git am ../../patches/*.patch
  165. cd ..
  166. fi
  167. fi
  168. spopd
  169. #
  170. # Build time
  171. #
  172. buildMobileKit() {
  173. PLATFORM="$1"
  174. spushd MobileVLCKit/ImportedSources
  175. if [ "$SKIPLIBVLCCOMPILATION" != "yes" ]; then
  176. spushd vlc/extras/package/ios
  177. info "Building vlc"
  178. args=""
  179. if [ "$VERBOSE" = "yes" ]; then
  180. args="${args} -v"
  181. fi
  182. if [ "$CONFIGURATION" = "Debug" ]; then
  183. args="${args} -d"
  184. fi
  185. if [ "$SCARY" = "no" ]; then
  186. args="${args} -w"
  187. fi
  188. if [ "$BITCODE" = "yes" ]; then
  189. args="${args} -b"
  190. fi
  191. if [ "$TVOS" = "no" ]; then
  192. if [ "$PLATFORM" = "iphonesimulator" ]; then
  193. args="${args} -s"
  194. ./build.sh -a i386 ${args} -k "${SDK}" && ./build.sh -a x86_64 ${args} -k "${SDK}"
  195. else
  196. ./build.sh -a armv7 ${args} -k "${SDK}" && ./build.sh -a armv7s ${args} -k "${SDK}" && ./build.sh -a aarch64 ${args} -k "${SDK}"
  197. fi
  198. else
  199. if [ "$PLATFORM" = "iphonesimulator" ]; then
  200. args="${args} -s"
  201. ./build.sh -a x86_64 -t ${args} -k "${SDK}"
  202. else
  203. ./build.sh -a aarch64 -t ${args} -k "${SDK}"
  204. fi
  205. fi
  206. spopd
  207. fi
  208. spopd # MobileVLCKit/ImportedSources
  209. }
  210. if [ "$BUILD_DEVICE" != "no" ]; then
  211. buildMobileKit iphoneos
  212. fi
  213. if [ "$BUILD_SIMULATOR" != "no" ]; then
  214. buildMobileKit iphonesimulator
  215. fi
  216. DEVICEARCHS=""
  217. SIMULATORARCHS=""
  218. doVLCLipo() {
  219. FILEPATH="$1"
  220. FILE="$2"
  221. PLUGIN="$3"
  222. OSSTYLE="$4"
  223. files=""
  224. info "...$FILEPATH$FILE"
  225. for i in $DEVICEARCHS
  226. do
  227. files="install-ios-"$OSSTYLE"OS/$i/lib/$FILEPATH$FILE $files"
  228. done
  229. for i in $SIMULATORARCHS
  230. do
  231. files="install-ios-"$OSSTYLE"Simulator/$i/lib/$FILEPATH$FILE $files"
  232. done
  233. if [ "$PLUGIN" != "no" ]; then
  234. lipo $files -create -output install-ios-$OSSTYLE/plugins/$FILE
  235. else
  236. lipo $files -create -output install-ios-$OSSTYLE/core/$FILE
  237. fi
  238. }
  239. doContribLipo() {
  240. LIBNAME="$1"
  241. OSSTYLE="$2"
  242. files=""
  243. info "...$LIBNAME"
  244. for i in $DEVICEARCHS
  245. do
  246. if [ "$i" != "arm64" ]; then
  247. files="contrib/$OSSTYLE-$i-apple-darwin11-$i/lib/$LIBNAME $files"
  248. else
  249. files="contrib/$OSSTYLE-aarch64-apple-darwin11-aarch64/lib/$LIBNAME $files"
  250. fi
  251. done
  252. for i in $SIMULATORARCHS
  253. do
  254. files="contrib/$OSSTYLE-$i-apple-darwin11-$i/lib/$LIBNAME $files"
  255. done
  256. lipo $files -create -output install-ios-$OSSTYLE/contrib/$LIBNAME
  257. }
  258. get_symbol()
  259. {
  260. echo "$1" | grep vlc_entry_$2|cut -d" " -f 3|sed 's/_vlc/vlc/'
  261. }
  262. build_universal_static_lib() {
  263. PROJECT_DIR=`pwd`
  264. OSSTYLE="$1"
  265. info "building universal static libs for OS style $OSSTYLE"
  266. # remove old module list
  267. rm -f $PROJECT_DIR/MobileVLCKit/vlc-plugins-$OSSTYLE.h
  268. rm -f $PROJECT_DIR/MobileVLCKit/vlc-plugins-$OSSTYLE.xcconfig
  269. touch $PROJECT_DIR/MobileVLCKit/vlc-plugins-$OSSTYLE.h
  270. touch $PROJECT_DIR/MobileVLCKit/vlc-plugins-$OSSTYLE.xcconfig
  271. spushd MobileVLCKit/ImportedSources/vlc
  272. rm -rf install-ios-$OSSTYLE
  273. mkdir install-ios-$OSSTYLE
  274. mkdir install-ios-$OSSTYLE/core
  275. mkdir install-ios-$OSSTYLE/contrib
  276. mkdir install-ios-$OSSTYLE/plugins
  277. spopd # vlc
  278. spushd MobileVLCKit/ImportedSources/vlc/install-ios-"$OSSTYLE"OS
  279. for i in `ls .`
  280. do
  281. DEVICEARCHS="$DEVICEARCHS $i"
  282. done
  283. spopd # vlc-install-ios-"$OSSTYLE"OS
  284. spushd MobileVLCKit/ImportedSources/vlc/install-ios-"$OSSTYLE"Simulator
  285. for i in `ls .`
  286. do
  287. SIMULATORARCHS="$SIMULATORARCHS $i"
  288. done
  289. spopd # vlc-install-ios-"$OSSTYLE"Simulator
  290. # arm64 got the lowest number of modules
  291. VLCMODULES=""
  292. spushd MobileVLCKit/ImportedSources/vlc/install-ios-"$OSSTYLE"OS/arm64/lib/vlc/plugins
  293. for i in `ls *.a`
  294. do
  295. VLCMODULES="$i $VLCMODULES"
  296. done
  297. spopd # vlc/install-ios-"$OSSTYLE"OS/arm64/lib/vlc/plugins
  298. if [ "$OSSTYLE" != "AppleTV" ]; then
  299. # collect ARMv7/s specific neon modules
  300. VLCNEONMODULES=""
  301. spushd MobileVLCKit/ImportedSources/vlc/install-ios-"$OSSTYLE"OS/armv7/lib/vlc/plugins
  302. for i in `ls *.a | grep neon`
  303. do
  304. VLCNEONMODULES="$i $VLCNEONMODULES"
  305. done
  306. spopd # vlc/install-ios-"$OSSTYLE"OS/armv7/lib/vlc/plugins
  307. fi
  308. spushd MobileVLCKit/ImportedSources/vlc
  309. # lipo all the vlc libraries and its plugins
  310. doVLCLipo "" "libvlc.a" "no" $OSSTYLE
  311. doVLCLipo "" "libvlccore.a" "no" $OSSTYLE
  312. doVLCLipo "vlc/" "libcompat.a" "no" $OSSTYLE
  313. for i in $VLCMODULES
  314. do
  315. doVLCLipo "vlc/plugins/" $i "yes" $OSSTYLE
  316. done
  317. # lipo contrib libraries
  318. CONTRIBLIBS=""
  319. spushd contrib/$OSSTYLE-aarch64-apple-darwin11-aarch64/lib
  320. for i in `ls *.a`
  321. do
  322. CONTRIBLIBS="$i $CONTRIBLIBS"
  323. done
  324. spopd # contrib/$OSSTYLE-aarch64-apple-darwin11-aarch64/lib
  325. for i in $CONTRIBLIBS
  326. do
  327. doContribLipo $i $OSSTYLE
  328. done
  329. if [ "$OSSTYLE" != "AppleTV" ]; then
  330. # lipo the remaining NEON plugins
  331. DEVICEARCHS="armv7 armv7s"
  332. SIMULATORARCHS=""
  333. for i in $VLCNEONMODULES
  334. do
  335. doVLCLipo "vlc/plugins/" $i "yes" $OSSTYLE
  336. done
  337. fi
  338. # create module list
  339. info "creating module list"
  340. echo "// This file is autogenerated by $(basename $0)\n\n" > $PROJECT_DIR/MobileVLCKit/vlc-plugins-$OSSTYLE.h
  341. echo "// This file is autogenerated by $(basename $0)\n\n" > $PROJECT_DIR/MobileVLCKit/vlc-plugins-$OSSTYLE.xcconfig
  342. # arm64 got the lowest number of modules
  343. BUILTINS="const void *vlc_static_modules[] = {\n"; \
  344. LDFLAGS=""
  345. DEFINITIONS=""
  346. # add contrib libraries to LDFLAGS
  347. for file in $CONTRIBLIBS
  348. do
  349. LDFLAGS+="\$(PROJECT_DIR)/MobileVLCKit/ImportedSources/vlc/install-ios-"$OSSTYLE"/contrib/$file "
  350. done
  351. for file in $VLCMODULES
  352. do
  353. symbols=$(nm -g -arch arm64 install-ios-$OSSTYLE/plugins/$file)
  354. entryname=$(get_symbol "$symbols" _)
  355. DEFINITIONS+="int $entryname (int (*)(void *, void *, int, ...), void *);\n";
  356. BUILTINS+=" $entryname,\n"
  357. LDFLAGS+="\$(PROJECT_DIR)/MobileVLCKit/ImportedSources/vlc/install-ios-"$OSSTYLE"/plugins/$file "
  358. info "...$entryname"
  359. done;
  360. if [ "$OSSTYLE" != "AppleTV" ]; then
  361. BUILTINS+="#ifdef __arm__\n"
  362. DEFINITIONS+="#ifdef __arm__\n"
  363. for file in $VLCNEONMODULES
  364. do
  365. symbols=$(nm -g -arch armv7 install-ios-$OSSTYLE/plugins/$file)
  366. entryname=$(get_symbol "$symbols" _)
  367. DEFINITIONS+="int $entryname (int (*)(void *, void *, int, ...), void *);\n";
  368. BUILTINS+=" $entryname,\n"
  369. LDFLAGS+="\$(PROJECT_DIR)/MobileVLCKit/ImportedSources/vlc/install-ios-"$OSSTYLE"/plugins/$file "
  370. info "...$entryname"
  371. done;
  372. BUILTINS+="#endif\n"
  373. DEFINITIONS+="#endif\n"
  374. fi
  375. BUILTINS="$BUILTINS NULL\n};\n"
  376. echo "$DEFINITIONS\n$BUILTINS" > $PROJECT_DIR/MobileVLCKit/vlc-plugins-$OSSTYLE.h
  377. echo "VLC_PLUGINS_LDFLAGS=$LDFLAGS" > $PROJECT_DIR/MobileVLCKit/vlc-plugins-$OSSTYLE.xcconfig
  378. spopd # vlc
  379. }
  380. if [ "$TVOS" != "yes" ]; then
  381. build_universal_static_lib "iPhone"
  382. else
  383. build_universal_static_lib "AppleTV"
  384. fi
  385. info "all done"
  386. if [ "$BUILD_STATIC_FRAMEWORK" != "no" ]; then
  387. if [ "$TVOS" != "yes" ]; then
  388. info "Building static MobileVLCKit.framework"
  389. buildxcodeproj MobileVLCKit "MobileVLCKit" iphoneos
  390. buildxcodeproj MobileVLCKit "MobileVLCKit" iphonesimulator
  391. # Assumes both platforms were built currently
  392. spushd build
  393. rm -rf MobileVLCKit.framework && \
  394. mkdir MobileVLCKit.framework && \
  395. lipo -create ${CONFIGURATION}-iphoneos/libMobileVLCKit.a \
  396. ${CONFIGURATION}-iphonesimulator/libMobileVLCKit.a \
  397. -o MobileVLCKit.framework/MobileVLCKit && \
  398. chmod a+x MobileVLCKit.framework/MobileVLCKit && \
  399. cp -pr ${CONFIGURATION}-iphoneos/MobileVLCKit MobileVLCKit.framework/Headers
  400. spopd # build
  401. info "Build of static MobileVLCKit.framework completed"
  402. else
  403. info "Building static TVVLCKit.framework"
  404. buildxcodeproj MobileVLCKit "TVVLCKit" appletvos
  405. buildxcodeproj MobileVLCKit "TVVLCKit" appletvsimulator
  406. # Assumes both platforms were built currently
  407. spushd build
  408. rm -rf TVVLCKit.framework && \
  409. mkdir TVVLCKit.framework && \
  410. lipo -create ${CONFIGURATION}-appletvos/libTVVLCKit.a \
  411. ${CONFIGURATION}-appletvsimulator/libTVVLCKit.a \
  412. -o TVVLCKit.framework/TVVLCKit && \
  413. chmod a+x TVVLCKit.framework/TVVLCKit && \
  414. cp -pr ${CONFIGURATION}-appletvos/TVVLCKit TVVLCKit.framework/Headers
  415. spopd # build
  416. info "Build of static TVVLCKit.framework completed"
  417. fi
  418. fi