buildMobileVLCKit.sh 9.5 KB

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