PageRenderTime 56ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/compile.sh

https://github.com/kashbi/vlc-android
Shell | 352 lines | 273 code | 52 blank | 27 comment | 26 complexity | 008248209b536e570c3b4343f4191e75 MD5 | raw file
Possible License(s): AGPL-1.0, Apache-2.0
  1. #! /bin/sh
  2. # Read the Android Wiki http://wiki.videolan.org/AndroidCompile
  3. # Setup all that stuff correctly.
  4. # Get the latest Android SDK Platform or modify numbers in configure.sh and vlc-android/default.properties.
  5. set -e
  6. BUILD=
  7. FETCH=
  8. case "$1" in
  9. --fetch)
  10. FETCH=1
  11. shift
  12. ;;
  13. --build)
  14. BUILD=1
  15. shift
  16. ;;
  17. *)
  18. FETCH=1
  19. BUILD=1
  20. ;;
  21. esac
  22. if [ -z "$ANDROID_NDK" -o -z "$ANDROID_SDK" ]; then
  23. echo "You must define ANDROID_NDK, ANDROID_SDK and ANDROID_ABI before starting."
  24. echo "They must point to your NDK and SDK directories.\n"
  25. exit 1
  26. fi
  27. if [ -z "$ANDROID_ABI" ]; then
  28. echo "Please set ANDROID_ABI to your architecture: armeabi-v7a, armeabi, x86 or mips."
  29. exit 1
  30. fi
  31. # try to detect NDK version
  32. REL=$(grep -o '^r[0-9]*.*' $ANDROID_NDK/RELEASE.TXT 2>/dev/null|cut -b2-)
  33. case "$REL" in
  34. 9*)
  35. GCCVER=4.8
  36. CXXSTL="/"${GCCVER}
  37. ;;
  38. 8?*)
  39. # we don't use 4.4.3 because it doesn't handle threads correctly.
  40. # TODO : clang?
  41. if test -d ${ANDROID_NDK}/toolchains/arm-linux-androideabi-4.7
  42. # if gcc 4.7 is present, it's there for all the archs (x86, mips, arm)
  43. then
  44. # since r8d
  45. GCCVER=4.7
  46. else
  47. GCCVER=4.6
  48. fi
  49. CXXSTL="/"${GCCVER}
  50. ;;
  51. 7|8|*)
  52. echo "You need the NDKv8b or later"
  53. exit 1
  54. ;;
  55. esac
  56. export GCCVER
  57. export CXXSTL
  58. # Set up ABI variables
  59. if [ ${ANDROID_ABI} = "x86" ] ; then
  60. TARGET_TUPLE="i686-linux-android"
  61. PATH_HOST="x86"
  62. HAVE_X86=1
  63. PLATFORM_SHORT_ARCH="x86"
  64. elif [ ${ANDROID_ABI} = "mips" ] ; then
  65. TARGET_TUPLE="mipsel-linux-android"
  66. PATH_HOST=$TARGET_TUPLE
  67. HAVE_MIPS=1
  68. PLATFORM_SHORT_ARCH="mips"
  69. else
  70. TARGET_TUPLE="arm-linux-androideabi"
  71. PATH_HOST=$TARGET_TUPLE
  72. HAVE_ARM=1
  73. PLATFORM_SHORT_ARCH="arm"
  74. fi
  75. # XXX : important!
  76. [ "$HAVE_ARM" = 1 ] && cat << EOF
  77. For an ARMv6 device without FPU:
  78. $ export NO_FPU=1
  79. For an ARMv5 device:
  80. $ export NO_ARMV6=1
  81. If you plan to use a release build, run 'compile.sh release'
  82. EOF
  83. export TARGET_TUPLE
  84. export PATH_HOST
  85. export HAVE_ARM
  86. export HAVE_X86
  87. export HAVE_MIPS
  88. export PLATFORM_SHORT_ARCH
  89. # Add the NDK toolchain to the PATH, needed both for contribs and for building
  90. # stub libraries
  91. NDK_TOOLCHAIN_PATH=`echo ${ANDROID_NDK}/toolchains/${PATH_HOST}-${GCCVER}/prebuilt/\`uname|tr A-Z a-z\`-*/bin`
  92. export PATH=${NDK_TOOLCHAIN_PATH}:${PATH}
  93. ANDROID_PATH="`pwd`"
  94. if [ ! -z "$FETCH" ]
  95. then
  96. # 1/ libvlc, libvlccore and its plugins
  97. TESTED_HASH=2dbc6647
  98. if [ ! -d "vlc" ]; then
  99. echo "VLC source not found, cloning"
  100. git clone git://git.videolan.org/vlc.git vlc
  101. cd vlc
  102. git checkout -B android ${TESTED_HASH}
  103. else
  104. echo "VLC source found"
  105. cd vlc
  106. if ! git cat-file -e ${TESTED_HASH}; then
  107. cat << EOF
  108. ***
  109. *** Error: Your vlc checkout does not contain the latest tested commit ***
  110. ***
  111. Please update your source with something like:
  112. cd vlc
  113. git reset --hard origin
  114. git pull origin master
  115. git checkout -B android ${TESTED_HASH}
  116. *** : This will delete any changes you made to the current branch ***
  117. EOF
  118. exit 1
  119. fi
  120. fi
  121. else
  122. cd vlc
  123. fi
  124. if [ -z "$BUILD" ]
  125. then
  126. echo "Not building anything, please run $0 --build"
  127. exit 0
  128. fi
  129. if [ ${ANDROID_ABI} = "armeabi-v7a" ] ; then
  130. EXTRA_CFLAGS="-mfpu=vfpv3-d16 -mcpu=cortex-a8"
  131. EXTRA_CFLAGS="${EXTRA_CFLAGS} -mthumb -mfloat-abi=softfp"
  132. elif [ ${ANDROID_ABI} = "armeabi" ] ; then
  133. if [ -n "${NO_ARMV6}" ]; then
  134. EXTRA_CFLAGS="-march=armv5te -mtune=arm9tdmi -msoft-float"
  135. else
  136. if [ -n "${NO_FPU}" ]; then
  137. EXTRA_CFLAGS="-march=armv6j -mtune=arm1136j-s -msoft-float"
  138. else
  139. EXTRA_CFLAGS="-mfpu=vfp -mcpu=arm1136jf-s -mfloat-abi=softfp"
  140. fi
  141. fi
  142. elif [ ${ANDROID_ABI} = "x86" ] ; then
  143. EXTRA_CFLAGS="-march=pentium -ffunction-sections -funwind-tables -frtti -fexceptions"
  144. elif [ ${ANDROID_ABI} = "mips" ] ; then
  145. EXTRA_CFLAGS="-march=mips32 -mtune=mips32r2 -mhard-float"
  146. # All MIPS Linux kernels since 2.4.4 will trap any unimplemented FPU
  147. # instruction and emulate it, so we select -mhard-float.
  148. # See http://www.linux-mips.org/wiki/Floating_point#The_Linux_kernel_and_floating_point
  149. else
  150. echo "Unknown ABI. Die, die, die!"
  151. exit 2
  152. fi
  153. EXTRA_CFLAGS="${EXTRA_CFLAGS} -O2"
  154. EXTRA_CFLAGS="${EXTRA_CFLAGS} -I${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++${CXXSTL}/include"
  155. EXTRA_CFLAGS="${EXTRA_CFLAGS} -I${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++${CXXSTL}/libs/${ANDROID_ABI}/include"
  156. UNAMES=$(uname -s)
  157. MAKEFLAGS=
  158. if which nproc >/dev/null
  159. then
  160. MAKEFLAGS=-j`nproc`
  161. elif [ "$UNAMES" == "Darwin" ] && which sysctl >/dev/null
  162. then
  163. MAKEFLAGS=-j`sysctl -n machdep.cpu.thread_count`
  164. fi
  165. export PATH=`pwd`/extras/tools/build/bin:$PATH
  166. echo "Building tools"
  167. cd extras/tools
  168. ./bootstrap
  169. make $MAKEFLAGS
  170. cd ../..
  171. echo "Building the contribs"
  172. mkdir -p contrib/android
  173. gen_pc_file() {
  174. echo "Generating $1 pkg-config file"
  175. echo "Name: $1
  176. Description: $1
  177. Version: $2
  178. Libs: -l$1
  179. Cflags:" > contrib/${TARGET_TUPLE}/lib/pkgconfig/`echo $1|tr 'A-Z' 'a-z'`.pc
  180. }
  181. mkdir -p contrib/${TARGET_TUPLE}/lib/pkgconfig
  182. gen_pc_file EGL 1.1
  183. gen_pc_file GLESv2 2
  184. cd contrib/android
  185. ../bootstrap --host=${TARGET_TUPLE} --disable-disc --disable-sout \
  186. --disable-dca \
  187. --disable-goom \
  188. --disable-chromaprint \
  189. --disable-lua \
  190. --disable-schroedinger \
  191. --disable-sdl \
  192. --disable-SDL_image \
  193. --disable-fontconfig \
  194. --disable-zvbi \
  195. --disable-kate \
  196. --disable-caca \
  197. --disable-gettext \
  198. --disable-mpcdec \
  199. --disable-upnp \
  200. --disable-gme \
  201. --disable-tremor \
  202. --disable-vorbis \
  203. --disable-sidplay2 \
  204. --disable-samplerate \
  205. --disable-faad2 \
  206. --disable-harfbuzz \
  207. --enable-iconv
  208. # TODO: mpeg2, theora
  209. # Some libraries have arm assembly which won't build in thumb mode
  210. # We append -marm to the CFLAGS of these libs to disable thumb mode
  211. [ ${ANDROID_ABI} = "armeabi-v7a" ] && echo "NOTHUMB := -marm" >> config.mak
  212. # Release or not?
  213. if [ $# -ne 0 ] && [ "$1" = "release" ]; then
  214. OPTS=""
  215. EXTRA_CFLAGS="${EXTRA_CFLAGS} -DNDEBUG "
  216. RELEASE=1
  217. else
  218. OPTS="--enable-debug"
  219. RELEASE=0
  220. fi
  221. echo "EXTRA_CFLAGS= -g ${EXTRA_CFLAGS}" >> config.mak
  222. export VLC_EXTRA_CFLAGS="${EXTRA_CFLAGS}"
  223. make fetch
  224. # We already have zlib available
  225. [ -e .zlib ] || (mkdir -p zlib; touch .zlib)
  226. which autopoint >/dev/null || make $MAKEFLAGS .gettext
  227. export PATH="$PATH:$PWD/../$TARGET_TUPLE/bin"
  228. make $MAKEFLAGS
  229. cd ../.. && mkdir -p android && cd android
  230. if [ $# -eq 1 ] && [ "$1" = "jni" ]; then
  231. CLEAN="jniclean"
  232. TARGET="vlc-android/obj/local/armeabi-v7a/libvlcjni.so"
  233. else
  234. CLEAN="distclean"
  235. echo "Bootstraping"
  236. ../bootstrap
  237. echo "Configuring"
  238. ${ANDROID_PATH}/configure.sh $OPTS
  239. TARGET=
  240. fi
  241. echo "Building"
  242. make $MAKEFLAGS
  243. # 2/ VLC android UI and specific code
  244. echo "Building Android"
  245. cd ../../
  246. export ANDROID_SYS_HEADERS_GINGERBREAD=${PWD}/android-headers-gingerbread
  247. export ANDROID_SYS_HEADERS_HC=${PWD}/android-headers-hc
  248. export ANDROID_SYS_HEADERS_ICS=${PWD}/android-headers-ics
  249. export ANDROID_LIBS=${PWD}/android-libs
  250. export VLC_BUILD_DIR=vlc/android
  251. make $CLEAN
  252. make -j1 TARGET_TUPLE=$TARGET_TUPLE PLATFORM_SHORT_ARCH=$PLATFORM_SHORT_ARCH CXXSTL=$CXXSTL RELEASE=$RELEASE $TARGET
  253. # 3/ Environment script
  254. echo "Generating environment script."
  255. cat <<EOF
  256. This is a script that will export many of the variables used in this
  257. script. It will allow you to compile parts of the build without having
  258. to rebuild the entire build (e.g. recompile only the Java part).
  259. To use it, include the script into your shell, like this:
  260. source env.sh
  261. Now, you can use this command to build the Java portion:
  262. make -e
  263. The file will be automatically regenerated by compile.sh, so if you change
  264. your NDK/SDK locations or any build configurations, just re-run this
  265. script (sh compile.sh) and it will automatically update the file.
  266. EOF
  267. echo "# This file was automatically generated by compile.sh" > env.sh
  268. echo "# Re-run 'sh compile.sh' to update this file." >> env.sh
  269. # The essentials
  270. cat <<EssentialsA >> env.sh
  271. export ANDROID_ABI=$ANDROID_ABI
  272. export ANDROID_SDK=$ANDROID_SDK
  273. export ANDROID_NDK=$ANDROID_NDK
  274. export GCCVER=$GCCVER
  275. export CXXSTL=$CXXSTL
  276. export ANDROID_SYS_HEADERS_GINGERBREAD=$ANDROID_SYS_HEADERS_GINGERBREAD
  277. export ANDROID_SYS_HEADERS_HC=$ANDROID_SYS_HEADERS_HC
  278. export ANDROID_SYS_HEADERS_ICS=$ANDROID_SYS_HEADERS_ICS
  279. export ANDROID_LIBS=$ANDROID_LIBS
  280. export VLC_BUILD_DIR=$PWD/vlc/android
  281. export TARGET_TUPLE=$TARGET_TUPLE
  282. export PATH_HOST=$PATH_HOST
  283. export PLATFORM_SHORT_ARCH=$PLATFORM_SHORT_ARCH
  284. EssentialsA
  285. # PATH
  286. echo "export PATH=$NDK_TOOLCHAIN_PATH:\${ANDROID_SDK}/platform-tools:\${PATH}" >> env.sh
  287. # CPU flags
  288. if [ -n "${HAVE_ARM}" ]; then
  289. echo "export HAVE_ARM=1" >> env.sh
  290. elif [ -n "${HAVE_X86}" ]; then
  291. echo "export HAVE_X86=1" >> env.sh
  292. elif [ -n "${HAVE_MIPS}" ]; then
  293. echo "export HAVE_MIPS=1" >> env.sh
  294. fi
  295. if [ -n "${NO_ARMV6}" ]; then
  296. echo "export NO_ARMV6=1" >> env.sh
  297. fi
  298. if [ -n "${NO_FPU}" ]; then
  299. echo "export NO_FPU=1" >> env.sh
  300. fi