buildMobileVLCKit.sh 11 KB

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