Alexandre Lision | 43b9aeb | 2014-07-15 14:21:19 -0400 | [diff] [blame] | 1 | #! /bin/sh |
| 2 | |
| 3 | # Read the Android Wiki http://wiki.videolan.org/AndroidCompile |
| 4 | # Setup all that stuff correctly. |
Tristan Matthews | 8d02ef6 | 2014-07-22 16:03:17 -0400 | [diff] [blame] | 5 | # Get the latest Android SDK Platform or modify numbers in configure.sh and sflphone-android/default.properties. |
Alexandre Lision | 43b9aeb | 2014-07-15 14:21:19 -0400 | [diff] [blame] | 6 | |
| 7 | set -e |
| 8 | |
| 9 | BUILD= |
| 10 | FETCH= |
| 11 | case "$1" in |
| 12 | --fetch) |
| 13 | FETCH=1 |
| 14 | shift |
| 15 | ;; |
| 16 | --build) |
| 17 | BUILD=1 |
| 18 | shift |
| 19 | ;; |
| 20 | *) |
| 21 | FETCH=1 |
| 22 | BUILD=1 |
| 23 | ;; |
| 24 | esac |
| 25 | |
| 26 | if [ -z "$ANDROID_NDK" -o -z "$ANDROID_SDK" ]; then |
| 27 | echo "You must define ANDROID_NDK, ANDROID_SDK and ANDROID_ABI before starting." |
| 28 | echo "They must point to your NDK and SDK directories.\n" |
| 29 | exit 1 |
| 30 | fi |
| 31 | |
| 32 | if [ -z "$ANDROID_ABI" ]; then |
| 33 | echo "Please set ANDROID_ABI to your architecture: armeabi-v7a, armeabi, x86 or mips." |
| 34 | exit 1 |
| 35 | fi |
| 36 | |
| 37 | # try to detect NDK version |
| 38 | REL=$(grep -o '^r[0-9]*.*' $ANDROID_NDK/RELEASE.TXT 2>/dev/null|cut -b2-) |
| 39 | case "$REL" in |
Tristan Matthews | d6033b4 | 2014-10-09 17:00:07 -0400 | [diff] [blame] | 40 | 10*) |
| 41 | if [ "${HAVE_64}" = 1 ];then |
| 42 | GCCVER=4.9 |
| 43 | ANDROID_API=android-L |
| 44 | else |
| 45 | GCCVER=4.8 |
| 46 | ANDROID_API=android-9 |
| 47 | fi |
| 48 | CXXSTL="/"${GCCVER} |
| 49 | ;; |
| 50 | 9*) |
| 51 | if [ "${HAVE_64}" = 1 ];then |
| 52 | echo "You need the NDKv10 or later for 64 bits build" |
| 53 | exit 1 |
| 54 | fi |
Alexandre Lision | 43b9aeb | 2014-07-15 14:21:19 -0400 | [diff] [blame] | 55 | GCCVER=4.8 |
Tristan Matthews | d6033b4 | 2014-10-09 17:00:07 -0400 | [diff] [blame] | 56 | ANDROID_API=android-9 |
Alexandre Lision | 43b9aeb | 2014-07-15 14:21:19 -0400 | [diff] [blame] | 57 | CXXSTL="/"${GCCVER} |
| 58 | ;; |
| 59 | 7|8|*) |
| 60 | echo "You need the NDKv9 or later" |
| 61 | exit 1 |
| 62 | ;; |
| 63 | esac |
| 64 | |
| 65 | export GCCVER |
| 66 | export CXXSTL |
Tristan Matthews | d6033b4 | 2014-10-09 17:00:07 -0400 | [diff] [blame] | 67 | export ANDROID_API |
Alexandre Lision | 43b9aeb | 2014-07-15 14:21:19 -0400 | [diff] [blame] | 68 | |
| 69 | # Set up ABI variables |
| 70 | if [ ${ANDROID_ABI} = "x86" ] ; then |
| 71 | TARGET_TUPLE="i686-linux-android" |
| 72 | PATH_HOST="x86" |
| 73 | HAVE_X86=1 |
| 74 | PLATFORM_SHORT_ARCH="x86" |
| 75 | elif [ ${ANDROID_ABI} = "mips" ] ; then |
| 76 | TARGET_TUPLE="mipsel-linux-android" |
| 77 | PATH_HOST=$TARGET_TUPLE |
| 78 | HAVE_MIPS=1 |
| 79 | PLATFORM_SHORT_ARCH="mips" |
| 80 | else |
| 81 | TARGET_TUPLE="arm-linux-androideabi" |
| 82 | PATH_HOST=$TARGET_TUPLE |
| 83 | HAVE_ARM=1 |
| 84 | PLATFORM_SHORT_ARCH="arm" |
| 85 | fi |
| 86 | |
| 87 | # XXX : important! |
| 88 | [ "$HAVE_ARM" = 1 ] && cat << EOF |
| 89 | For an ARMv6 device without FPU: |
| 90 | $ export NO_FPU=1 |
| 91 | For an ARMv5 device: |
| 92 | $ export NO_ARMV6=1 |
| 93 | |
| 94 | If you plan to use a release build, run 'compile.sh release' |
| 95 | EOF |
| 96 | |
| 97 | export TARGET_TUPLE |
| 98 | export PATH_HOST |
| 99 | export HAVE_ARM |
| 100 | export HAVE_X86 |
| 101 | export HAVE_MIPS |
| 102 | export PLATFORM_SHORT_ARCH |
| 103 | |
| 104 | # Add the NDK toolchain to the PATH, needed both for contribs and for building |
| 105 | # stub libraries |
| 106 | NDK_TOOLCHAIN_PATH=`echo ${ANDROID_NDK}/toolchains/${PATH_HOST}-${GCCVER}/prebuilt/\`uname|tr A-Z a-z\`-*/bin` |
| 107 | export PATH=${NDK_TOOLCHAIN_PATH}:${PATH} |
| 108 | |
| 109 | ANDROID_PATH="`pwd`" |
| 110 | |
Tristan Matthews | a2665ff | 2014-08-12 18:27:23 -0400 | [diff] [blame] | 111 | # Fetch sflphone daemon source |
Alexandre Lision | 43b9aeb | 2014-07-15 14:21:19 -0400 | [diff] [blame] | 112 | if [ ! -z "$FETCH" ] |
| 113 | then |
Tristan Matthews | 8d02ef6 | 2014-07-22 16:03:17 -0400 | [diff] [blame] | 114 | # 1/ libsflphone |
Tristan Matthews | fe24952 | 2014-10-09 19:22:41 -0400 | [diff] [blame] | 115 | TESTED_HASH=3426b44e576e4766bd0bd274346d2bfbda562e07 |
Alexandre Lision | 43b9aeb | 2014-07-15 14:21:19 -0400 | [diff] [blame] | 116 | if [ ! -d "sflphone" ]; then |
Tristan Matthews | a2665ff | 2014-08-12 18:27:23 -0400 | [diff] [blame] | 117 | echo "sflphone daemon source not found, cloning" |
| 118 | git clone https://gerrit-sflphone.savoirfairelinux.com/sflphone |
| 119 | cd sflphone |
Alexandre Lision | 43b9aeb | 2014-07-15 14:21:19 -0400 | [diff] [blame] | 120 | echo android/ >> .git/info/exclude |
| 121 | echo contrib/android/ >> .git/info/exclude |
Alexandre Lision | 4073432 | 2014-09-03 14:26:59 -0400 | [diff] [blame] | 122 | git checkout master |
Alexandre Lision | 43b9aeb | 2014-07-15 14:21:19 -0400 | [diff] [blame] | 123 | else |
Tristan Matthews | a2665ff | 2014-08-12 18:27:23 -0400 | [diff] [blame] | 124 | echo "sflphone daemon source found" |
Alexandre Lision | 43b9aeb | 2014-07-15 14:21:19 -0400 | [diff] [blame] | 125 | cd sflphone |
Alexandre Lision | 65be770 | 2014-09-29 18:06:33 -0400 | [diff] [blame] | 126 | git fetch |
| 127 | git checkout ${TESTED_HASH} |
Alexandre Lision | 43b9aeb | 2014-07-15 14:21:19 -0400 | [diff] [blame] | 128 | # if ! git cat-file -e ${TESTED_HASH}; then |
| 129 | # cat << EOF |
| 130 | #*** |
| 131 | #*** Error: Your sflphone checkout does not contain the latest tested commit *** |
| 132 | #*** |
| 133 | # |
| 134 | #Please update your source with something like: |
| 135 | # |
| 136 | #cd sflphone |
| 137 | #git reset --hard origin |
| 138 | #git pull origin master |
| 139 | #git checkout -B android ${TESTED_HASH} |
| 140 | # |
| 141 | #*** : This will delete any changes you made to the current branch *** |
| 142 | # |
| 143 | #EOF |
| 144 | # exit 1 |
| 145 | # fi |
| 146 | fi |
| 147 | else |
| 148 | cd sflphone |
| 149 | fi |
| 150 | |
| 151 | if [ -z "$BUILD" ] |
| 152 | then |
| 153 | echo "Not building anything, please run $0 --build" |
| 154 | exit 0 |
| 155 | fi |
| 156 | |
| 157 | # Setup CFLAGS |
| 158 | if [ ${ANDROID_ABI} = "armeabi-v7a" ] ; then |
| 159 | EXTRA_CFLAGS="-mfpu=vfpv3-d16 -mcpu=cortex-a8" |
| 160 | EXTRA_CFLAGS="${EXTRA_CFLAGS} -mthumb -mfloat-abi=softfp" |
| 161 | elif [ ${ANDROID_ABI} = "armeabi" ] ; then |
| 162 | if [ -n "${NO_ARMV6}" ]; then |
| 163 | EXTRA_CFLAGS="-march=armv5te -mtune=arm9tdmi -msoft-float" |
| 164 | else |
| 165 | if [ -n "${NO_FPU}" ]; then |
| 166 | EXTRA_CFLAGS="-march=armv6j -mtune=arm1136j-s -msoft-float" |
| 167 | else |
| 168 | EXTRA_CFLAGS="-mfpu=vfp -mcpu=arm1136jf-s -mfloat-abi=softfp" |
| 169 | fi |
| 170 | fi |
| 171 | elif [ ${ANDROID_ABI} = "x86" ] ; then |
| 172 | EXTRA_CFLAGS="-march=pentium" |
| 173 | elif [ ${ANDROID_ABI} = "mips" ] ; then |
| 174 | EXTRA_CFLAGS="-march=mips32 -mtune=mips32r2 -mhard-float" |
| 175 | # All MIPS Linux kernels since 2.4.4 will trap any unimplemented FPU |
| 176 | # instruction and emulate it, so we select -mhard-float. |
| 177 | # See http://www.linux-mips.org/wiki/Floating_point#The_Linux_kernel_and_floating_point |
| 178 | else |
| 179 | echo "Unknown ABI. Die, die, die!" |
| 180 | exit 2 |
| 181 | fi |
| 182 | |
| 183 | EXTRA_CFLAGS="${EXTRA_CFLAGS} -O2" |
Alexandre Lision | 43b9aeb | 2014-07-15 14:21:19 -0400 | [diff] [blame] | 184 | EXTRA_CFLAGS="${EXTRA_CFLAGS} -I${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++${CXXSTL}/include" |
| 185 | EXTRA_CFLAGS="${EXTRA_CFLAGS} -I${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++${CXXSTL}/libs/${ANDROID_ABI}/include" |
| 186 | |
Tristan Matthews | 676fcee | 2014-10-03 15:57:09 -0400 | [diff] [blame] | 187 | #Â Setup LDFLAGS |
| 188 | EXTRA_LDFLAGS="-l${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++${CXXSTL}/libs/${ANDROID_ABI}/libgnustl_static.a" |
| 189 | |
Alexandre Lision | 43b9aeb | 2014-07-15 14:21:19 -0400 | [diff] [blame] | 190 | # Make in // |
| 191 | UNAMES=$(uname -s) |
| 192 | MAKEFLAGS= |
| 193 | if which nproc >/dev/null |
| 194 | then |
| 195 | MAKEFLAGS=-j`nproc` |
| 196 | elif [ "$UNAMES" == "Darwin" ] && which sysctl >/dev/null |
| 197 | then |
| 198 | MAKEFLAGS=-j`sysctl -n machdep.cpu.thread_count` |
| 199 | fi |
| 200 | |
Tristan Matthews | d6d5d40 | 2014-10-09 16:41:06 -0400 | [diff] [blame] | 201 | # Build buildsystem tools |
| 202 | export PATH=`pwd`/daemon/extras/tools/build/bin:$PATH |
| 203 | echo "Building tools" |
| 204 | cd daemon/extras/tools |
| 205 | ./bootstrap |
| 206 | make $MAKEFLAGS |
| 207 | cd ../../.. |
| 208 | |
Alexandre Lision | 43b9aeb | 2014-07-15 14:21:19 -0400 | [diff] [blame] | 209 | ############ |
| 210 | # Contribs # |
| 211 | ############ |
| 212 | echo "Building the contribs" |
Alexandre Lision | 4073432 | 2014-09-03 14:26:59 -0400 | [diff] [blame] | 213 | mkdir -p daemon/contrib/contrib-android-${TARGET_TUPLE} |
Alexandre Lision | 43b9aeb | 2014-07-15 14:21:19 -0400 | [diff] [blame] | 214 | |
| 215 | gen_pc_file() { |
| 216 | echo "Generating $1 pkg-config file" |
| 217 | echo "Name: $1 |
| 218 | Description: $1 |
| 219 | Version: $2 |
| 220 | Libs: -l$1 |
Alexandre Lision | 4073432 | 2014-09-03 14:26:59 -0400 | [diff] [blame] | 221 | Cflags:" > daemon/contrib/${TARGET_TUPLE}/lib/pkgconfig/`echo $1|tr 'A-Z' 'a-z'`.pc |
Alexandre Lision | 43b9aeb | 2014-07-15 14:21:19 -0400 | [diff] [blame] | 222 | } |
| 223 | |
Alexandre Lision | 4073432 | 2014-09-03 14:26:59 -0400 | [diff] [blame] | 224 | mkdir -p daemon/contrib/${TARGET_TUPLE}/lib/pkgconfig |
Alexandre Lision | 43b9aeb | 2014-07-15 14:21:19 -0400 | [diff] [blame] | 225 | |
Alexandre Lision | 4073432 | 2014-09-03 14:26:59 -0400 | [diff] [blame] | 226 | cd daemon/contrib/contrib-android-${TARGET_TUPLE} |
Alexandre Lision | ec1f3ee | 2014-08-04 19:12:42 -0400 | [diff] [blame] | 227 | ../bootstrap --host=${TARGET_TUPLE} |
Alexandre Lision | 43b9aeb | 2014-07-15 14:21:19 -0400 | [diff] [blame] | 228 | |
Alexandre Lision | 43b9aeb | 2014-07-15 14:21:19 -0400 | [diff] [blame] | 229 | # Some libraries have arm assembly which won't build in thumb mode |
| 230 | # We append -marm to the CFLAGS of these libs to disable thumb mode |
| 231 | [ ${ANDROID_ABI} = "armeabi-v7a" ] && echo "NOTHUMB := -marm" >> config.mak |
| 232 | |
| 233 | # Release or not? |
| 234 | if [ $# -ne 0 ] && [ "$1" = "release" ]; then |
| 235 | OPTS="" |
| 236 | EXTRA_CFLAGS="${EXTRA_CFLAGS} -DNDEBUG " |
| 237 | RELEASE=1 |
| 238 | else |
| 239 | OPTS="--enable-debug" |
Tristan Matthews | 8d02ef6 | 2014-07-22 16:03:17 -0400 | [diff] [blame] | 240 | EXTRA_CFLAGS="${EXTRA_CFLAGS} -DNDEBUG " |
Alexandre Lision | 43b9aeb | 2014-07-15 14:21:19 -0400 | [diff] [blame] | 241 | RELEASE=0 |
| 242 | fi |
| 243 | |
| 244 | echo "EXTRA_CFLAGS= -g ${EXTRA_CFLAGS}" >> config.mak |
Tristan Matthews | fc84807 | 2014-10-09 03:43:54 -0400 | [diff] [blame] | 245 | echo "EXTRA_CXXFLAGS= -g ${EXTRA_CXXFLAGS}" >> config.mak |
Tristan Matthews | 676fcee | 2014-10-03 15:57:09 -0400 | [diff] [blame] | 246 | echo "EXTRA_LDFLAGS= ${EXTRA_LDFLAGS}" >> config.mak |
Tristan Matthews | 8d02ef6 | 2014-07-22 16:03:17 -0400 | [diff] [blame] | 247 | export SFLPHONE_EXTRA_CFLAGS="${EXTRA_CFLAGS}" |
Tristan Matthews | fc84807 | 2014-10-09 03:43:54 -0400 | [diff] [blame] | 248 | export SFLPHONE_EXTRA_CXXFLAGS="${EXTRA_CXXFLAGS}" |
Tristan Matthews | 676fcee | 2014-10-03 15:57:09 -0400 | [diff] [blame] | 249 | export SFLPHONE_EXTRA_LDFLAGS="${EXTRA_LDFLAGS}" |
Alexandre Lision | 43b9aeb | 2014-07-15 14:21:19 -0400 | [diff] [blame] | 250 | |
Alexandre Lision | 68d8f2e | 2014-07-30 17:42:40 -0400 | [diff] [blame] | 251 | make install |
Alexandre Lision | ec1f3ee | 2014-08-04 19:12:42 -0400 | [diff] [blame] | 252 | echo ${PWD} |
Alexandre Lision | 43b9aeb | 2014-07-15 14:21:19 -0400 | [diff] [blame] | 253 | # We already have zlib available |
| 254 | [ -e .zlib ] || (mkdir -p zlib; touch .zlib) |
| 255 | which autopoint >/dev/null || make $MAKEFLAGS .gettext |
| 256 | export PATH="$PATH:$PWD/../$TARGET_TUPLE/bin" |
Alexandre Lision | 43b9aeb | 2014-07-15 14:21:19 -0400 | [diff] [blame] | 257 | |
Tristan Matthews | eaaa5ba | 2014-10-09 04:23:06 -0400 | [diff] [blame] | 258 | export SFLPHONE_BUILD_DIR=sflphone/daemon/build-android-${TARGET_TUPLE} |
Alexandre Lision | 43b9aeb | 2014-07-15 14:21:19 -0400 | [diff] [blame] | 259 | ############ |
Tristan Matthews | 8d02ef6 | 2014-07-22 16:03:17 -0400 | [diff] [blame] | 260 | # Make SFLPHONE # |
Alexandre Lision | 43b9aeb | 2014-07-15 14:21:19 -0400 | [diff] [blame] | 261 | ############ |
| 262 | cd ../.. && mkdir -p build-android-${TARGET_TUPLE} && cd build-android-${TARGET_TUPLE} |
| 263 | |
| 264 | if [ $# -eq 1 ] && [ "$1" = "jni" ]; then |
| 265 | CLEAN="jniclean" |
Tristan Matthews | 33873ca | 2014-10-09 13:35:39 -0400 | [diff] [blame] | 266 | TARGET="sflphone-android/obj/local/${ANDROID_ABI}/libsflphone.so" |
Alexandre Lision | 43b9aeb | 2014-07-15 14:21:19 -0400 | [diff] [blame] | 267 | else |
| 268 | CLEAN="distclean" |
| 269 | if [ ! -f config.h ]; then |
| 270 | echo "Bootstraping" |
Tristan Matthews | fc84807 | 2014-10-09 03:43:54 -0400 | [diff] [blame] | 271 | cd ../ |
| 272 | ./autogen.sh |
| 273 | cd ../../ |
Alexandre Lision | 6005778 | 2014-10-03 14:06:01 -0400 | [diff] [blame] | 274 | cd sflphone-android |
| 275 | ./make-swig.sh |
Tristan Matthews | fc84807 | 2014-10-09 03:43:54 -0400 | [diff] [blame] | 276 | cd ../sflphone/daemon/build-android-${TARGET_TUPLE} |
| 277 | echo "Configuring" |
| 278 | echo `pwd` |
| 279 | ${ANDROID_PATH}/configure.sh ${OPTS} |
Tristan Matthews | cc806e1 | 2014-08-01 16:25:03 -0400 | [diff] [blame] | 280 | echo "Building" |
| 281 | make $MAKEFLAGS |
Alexandre Lision | 43b9aeb | 2014-07-15 14:21:19 -0400 | [diff] [blame] | 282 | fi |
| 283 | TARGET= |
| 284 | fi |
| 285 | |
Alexandre Lision | 43b9aeb | 2014-07-15 14:21:19 -0400 | [diff] [blame] | 286 | #################################### |
| 287 | # Ring android UI and specific code |
| 288 | #################################### |
| 289 | echo "Building Ring for Android" |
Alexandre Lision | 4073432 | 2014-09-03 14:26:59 -0400 | [diff] [blame] | 290 | cd ../../../ |
Tristan Matthews | fc84807 | 2014-10-09 03:43:54 -0400 | [diff] [blame] | 291 | |
Alexandre Lision | 43b9aeb | 2014-07-15 14:21:19 -0400 | [diff] [blame] | 292 | make $CLEAN |
| 293 | make -j1 TARGET_TUPLE=$TARGET_TUPLE PLATFORM_SHORT_ARCH=$PLATFORM_SHORT_ARCH CXXSTL=$CXXSTL RELEASE=$RELEASE $TARGET |
| 294 | |
| 295 | # |
| 296 | # Exporting a environment script with all the necessary variables |
| 297 | # |
| 298 | echo "Generating environment script." |
| 299 | cat <<EOF |
| 300 | This is a script that will export many of the variables used in this |
| 301 | script. It will allow you to compile parts of the build without having |
| 302 | to rebuild the entire build (e.g. recompile only the Java part). |
| 303 | |
| 304 | To use it, include the script into your shell, like this: |
| 305 | source env.sh |
| 306 | |
| 307 | Now, you can use this command to build the Java portion: |
| 308 | make -e |
| 309 | |
| 310 | The file will be automatically regenerated by compile.sh, so if you change |
| 311 | your NDK/SDK locations or any build configurations, just re-run this |
| 312 | script (sh compile.sh) and it will automatically update the file. |
| 313 | |
| 314 | EOF |
| 315 | |
| 316 | echo "# This file was automatically generated by compile.sh" > env.sh |
| 317 | echo "# Re-run 'sh compile.sh' to update this file." >> env.sh |
| 318 | |
| 319 | # The essentials |
| 320 | cat <<EssentialsA >> env.sh |
| 321 | export ANDROID_ABI=$ANDROID_ABI |
| 322 | export ANDROID_SDK=$ANDROID_SDK |
| 323 | export ANDROID_NDK=$ANDROID_NDK |
| 324 | export GCCVER=$GCCVER |
| 325 | export CXXSTL=$CXXSTL |
Tristan Matthews | fc84807 | 2014-10-09 03:43:54 -0400 | [diff] [blame] | 326 | export SFLPHONE_BUILD_DIR=$SFLPHONE_BUILD_DIR |
Alexandre Lision | 43b9aeb | 2014-07-15 14:21:19 -0400 | [diff] [blame] | 327 | export TARGET_TUPLE=$TARGET_TUPLE |
| 328 | export PATH_HOST=$PATH_HOST |
| 329 | export PLATFORM_SHORT_ARCH=$PLATFORM_SHORT_ARCH |
| 330 | EssentialsA |
| 331 | |
| 332 | # PATH |
| 333 | echo "export PATH=$NDK_TOOLCHAIN_PATH:\${ANDROID_SDK}/platform-tools:\${PATH}" >> env.sh |
| 334 | |
| 335 | # CPU flags |
| 336 | if [ -n "${HAVE_ARM}" ]; then |
| 337 | echo "export HAVE_ARM=1" >> env.sh |
| 338 | elif [ -n "${HAVE_X86}" ]; then |
| 339 | echo "export HAVE_X86=1" >> env.sh |
| 340 | elif [ -n "${HAVE_MIPS}" ]; then |
| 341 | echo "export HAVE_MIPS=1" >> env.sh |
| 342 | fi |
| 343 | |
| 344 | if [ -n "${NO_ARMV6}" ]; then |
| 345 | echo "export NO_ARMV6=1" >> env.sh |
| 346 | fi |
| 347 | if [ -n "${NO_FPU}" ]; then |
| 348 | echo "export NO_FPU=1" >> env.sh |
| 349 | fi |