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