buildMobileVLCKit.sh 11 KB

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