buildMobileVLCKit.sh 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  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=949032db
  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. spushd MobileVLCKit/ImportedSources
  160. if [ "$SKIPLIBVLCCOMPILATION" != "yes" ]; then
  161. spushd vlc/extras/package/ios
  162. info "Building vlc"
  163. args=""
  164. if [ "$VERBOSE" = "yes" ]; then
  165. args="${args} -v"
  166. fi
  167. if [ "$CONFIGURATION" = "Debug" ]; then
  168. args="${args} -d"
  169. fi
  170. if [ "$SCARY" = "no" ]; then
  171. args="${args} -w"
  172. fi
  173. if [ "$TVOS" = "no" ]; then
  174. if [ "$PLATFORM" = "iphonesimulator" ]; then
  175. args="${args} -s"
  176. ./build.sh -a i386 ${args} -k "${SDK}" && ./build.sh -a x86_64 ${args} -k "${SDK}"
  177. else
  178. ./build.sh -a armv7 ${args} -k "${SDK}" && ./build.sh -a armv7s ${args} -k "${SDK}" && ./build.sh -a aarch64 ${args} -k "${SDK}"
  179. fi
  180. else
  181. if [ "$PLATFORM" = "iphonesimulator" ]; then
  182. args="${args} -s"
  183. ./build.sh -a x86_64 -t ${args} -k "${SDK}"
  184. else
  185. ./build.sh -a aarch64 -t ${args} -k "${SDK}"
  186. fi
  187. fi
  188. spopd
  189. fi
  190. spopd # MobileVLCKit/ImportedSources
  191. }
  192. if [ "$BUILD_DEVICE" != "no" ]; then
  193. buildMobileKit iphoneos
  194. fi
  195. if [ "$BUILD_SIMULATOR" != "no" ]; then
  196. buildMobileKit iphonesimulator
  197. fi
  198. DEVICEARCHS=""
  199. SIMULATORARCHS=""
  200. doVLCLipo() {
  201. FILEPATH="$1"
  202. FILE="$2"
  203. PLUGIN="$3"
  204. OSSTYLE="$4"
  205. files=""
  206. info "...$FILEPATH$FILE"
  207. for i in $DEVICEARCHS
  208. do
  209. files="install-ios-"$OSSTYLE"OS/$i/lib/$FILEPATH$FILE $files"
  210. done
  211. for i in $SIMULATORARCHS
  212. do
  213. files="install-ios-"$OSSTYLE"Simulator/$i/lib/$FILEPATH$FILE $files"
  214. done
  215. if [ "$PLUGIN" != "no" ]; then
  216. lipo $files -create -output install-ios-$OSSTYLE/plugins/$FILE
  217. else
  218. lipo $files -create -output install-ios-$OSSTYLE/core/$FILE
  219. fi
  220. }
  221. doContribLipo() {
  222. LIBNAME="$1"
  223. OSSTYLE="$2"
  224. files=""
  225. info "...$LIBNAME"
  226. for i in $DEVICEARCHS
  227. do
  228. if [ "$i" != "arm64" ]; then
  229. files="contrib/$OSSTYLE-$i-apple-darwin11-$i/lib/$LIBNAME $files"
  230. else
  231. files="contrib/$OSSTYLE-aarch64-apple-darwin11-aarch64/lib/$LIBNAME $files"
  232. fi
  233. done
  234. for i in $SIMULATORARCHS
  235. do
  236. files="contrib/$OSSTYLE-$i-apple-darwin11-$i/lib/$LIBNAME $files"
  237. done
  238. lipo $files -create -output install-ios-$OSSTYLE/contrib/$LIBNAME
  239. }
  240. get_symbol()
  241. {
  242. echo "$1" | grep vlc_entry_$2|cut -d" " -f 3|sed 's/_vlc/vlc/'
  243. }
  244. build_universal_static_lib() {
  245. PROJECT_DIR=`pwd`
  246. OSSTYLE="$1"
  247. info "building universal static libs for OS style $OSSTYLE"
  248. # remove old module list
  249. rm -f $PROJECT_DIR/MobileVLCKit/vlc-plugins-$OSSTYLE.h
  250. rm -f $PROJECT_DIR/MobileVLCKit/vlc-plugins-$OSSTYLE.xcconfig
  251. touch $PROJECT_DIR/MobileVLCKit/vlc-plugins-$OSSTYLE.h
  252. touch $PROJECT_DIR/MobileVLCKit/vlc-plugins-$OSSTYLE.xcconfig
  253. spushd MobileVLCKit/ImportedSources/vlc
  254. rm -rf install-ios-$OSSTYLE
  255. mkdir install-ios-$OSSTYLE
  256. mkdir install-ios-$OSSTYLE/core
  257. mkdir install-ios-$OSSTYLE/contrib
  258. mkdir install-ios-$OSSTYLE/plugins
  259. spopd # vlc
  260. spushd MobileVLCKit/ImportedSources/vlc/install-ios-"$OSSTYLE"OS
  261. for i in `ls .`
  262. do
  263. DEVICEARCHS="$DEVICEARCHS $i"
  264. done
  265. spopd # vlc-install-ios-"$OSSTYLE"OS
  266. spushd MobileVLCKit/ImportedSources/vlc/install-ios-"$OSSTYLE"Simulator
  267. for i in `ls .`
  268. do
  269. SIMULATORARCHS="$SIMULATORARCHS $i"
  270. done
  271. spopd # vlc-install-ios-"$OSSTYLE"Simulator
  272. # arm64 got the lowest number of modules
  273. VLCMODULES=""
  274. spushd MobileVLCKit/ImportedSources/vlc/install-ios-"$OSSTYLE"OS/arm64/lib/vlc/plugins
  275. for i in `ls *.a`
  276. do
  277. VLCMODULES="$i $VLCMODULES"
  278. done
  279. spopd # vlc/install-ios-"$OSSTYLE"OS/arm64/lib/vlc/plugins
  280. if [ "$OSSTYLE" != "AppleTV" ]; then
  281. # collect ARMv7/s specific neon modules
  282. VLCNEONMODULES=""
  283. spushd MobileVLCKit/ImportedSources/vlc/install-ios-"$OSSTYLE"OS/armv7/lib/vlc/plugins
  284. for i in `ls *.a | grep neon`
  285. do
  286. VLCNEONMODULES="$i $VLCNEONMODULES"
  287. done
  288. spopd # vlc/install-ios-"$OSSTYLE"OS/armv7/lib/vlc/plugins
  289. fi
  290. spushd MobileVLCKit/ImportedSources/vlc
  291. # lipo all the vlc libraries and its plugins
  292. doVLCLipo "" "libvlc.a" "no" $OSSTYLE
  293. doVLCLipo "" "libvlccore.a" "no" $OSSTYLE
  294. doVLCLipo "vlc/" "libcompat.a" "no" $OSSTYLE
  295. for i in $VLCMODULES
  296. do
  297. doVLCLipo "vlc/plugins/" $i "yes" $OSSTYLE
  298. done
  299. # lipo contrib libraries
  300. CONTRIBLIBS=""
  301. spushd contrib/$OSSTYLE-aarch64-apple-darwin11-aarch64/lib
  302. for i in `ls *.a`
  303. do
  304. CONTRIBLIBS="$i $CONTRIBLIBS"
  305. done
  306. spopd # contrib/$OSSTYLE-aarch64-apple-darwin11-aarch64/lib
  307. for i in $CONTRIBLIBS
  308. do
  309. doContribLipo $i $OSSTYLE
  310. done
  311. if [ "$OSSTYLE" != "AppleTV" ]; then
  312. # lipo the remaining NEON plugins
  313. DEVICEARCHS="armv7 armv7s"
  314. SIMULATORARCHS=""
  315. for i in $VLCNEONMODULES
  316. do
  317. doVLCLipo "vlc/plugins/" $i "yes" $OSSTYLE
  318. done
  319. fi
  320. # create module list
  321. info "creating module list"
  322. echo "// This file is autogenerated by $(basename $0)\n\n" > $PROJECT_DIR/MobileVLCKit/vlc-plugins-$OSSTYLE.h
  323. echo "// This file is autogenerated by $(basename $0)\n\n" > $PROJECT_DIR/MobileVLCKit/vlc-plugins-$OSSTYLE.xcconfig
  324. # arm64 got the lowest number of modules
  325. BUILTINS="const void *vlc_static_modules[] = {\n"; \
  326. LDFLAGS=""
  327. DEFINITIONS=""
  328. # add contrib libraries to LDFLAGS
  329. for file in $CONTRIBLIBS
  330. do
  331. LDFLAGS+="\$(PROJECT_DIR)/MobileVLCKit/ImportedSources/vlc/install-ios-"$OSSTYLE"/contrib/$file "
  332. done
  333. for file in $VLCMODULES
  334. do
  335. symbols=$(nm -g -arch arm64 install-ios-$OSSTYLE/plugins/$file)
  336. entryname=$(get_symbol "$symbols" _)
  337. DEFINITIONS+="int $entryname (int (*)(void *, void *, int, ...), void *);\n";
  338. BUILTINS+=" $entryname,\n"
  339. LDFLAGS+="\$(PROJECT_DIR)/MobileVLCKit/ImportedSources/vlc/install-ios-"$OSSTYLE"/plugins/$file "
  340. info "...$entryname"
  341. done;
  342. if [ "$OSSTYLE" != "AppleTV" ]; then
  343. BUILTINS+="#ifdef __arm__\n"
  344. DEFINITIONS+="#ifdef __arm__\n"
  345. for file in $VLCNEONMODULES
  346. do
  347. symbols=$(nm -g -arch armv7 install-ios-$OSSTYLE/plugins/$file)
  348. entryname=$(get_symbol "$symbols" _)
  349. DEFINITIONS+="int $entryname (int (*)(void *, void *, int, ...), void *);\n";
  350. BUILTINS+=" $entryname,\n"
  351. LDFLAGS+="\$(PROJECT_DIR)/MobileVLCKit/ImportedSources/vlc/install-ios-"$OSSTYLE"/plugins/$file "
  352. info "...$entryname"
  353. done;
  354. BUILTINS+="#endif\n"
  355. DEFINITIONS+="#endif\n"
  356. fi
  357. BUILTINS="$BUILTINS NULL\n};\n"
  358. echo "$DEFINITIONS\n$BUILTINS" > $PROJECT_DIR/MobileVLCKit/vlc-plugins-$OSSTYLE.h
  359. echo "VLC_PLUGINS_LDFLAGS=$LDFLAGS" > $PROJECT_DIR/MobileVLCKit/vlc-plugins-$OSSTYLE.xcconfig
  360. spopd # vlc
  361. }
  362. if [ "$TVOS" != "yes" ]; then
  363. build_universal_static_lib "iPhone"
  364. else
  365. build_universal_static_lib "AppleTV"
  366. fi
  367. info "all done"
  368. if [ "$BUILD_STATIC_FRAMEWORK" != "no" ]; then
  369. info "Building static MobileVLCKit.framework"
  370. buildxcodeproj MobileVLCKit "MobileVLCKit" iphoneos
  371. buildxcodeproj MobileVLCKit "MobileVLCKit" iphonesimulator
  372. # Assumes both platforms were built currently
  373. spushd build
  374. rm -rf MobileVLCKit.framework && \
  375. mkdir MobileVLCKit.framework && \
  376. lipo -create ${CONFIGURATION}-iphoneos/libMobileVLCKit.a \
  377. ${CONFIGURATION}-iphonesimulator/libMobileVLCKit.a \
  378. -o MobileVLCKit.framework/MobileVLCKit && \
  379. chmod a+x MobileVLCKit.framework/MobileVLCKit && \
  380. cp -pr ${CONFIGURATION}-iphoneos/MobileVLCKit MobileVLCKit.framework/Headers
  381. spopd # build
  382. info "Build of static MobileVLCKit.framework completed"
  383. fi