blob: 6cdfa308117e9a6e117e7f7f973cf1c9e7c8f9cb [file] [log] [blame]
Alexandre Lision43b9aeb2014-07-15 14:21:19 -04001#! /bin/sh
2
3# Read the Android Wiki http://wiki.videolan.org/AndroidCompile
4# Setup all that stuff correctly.
Tristan Matthews8d02ef62014-07-22 16:03:17 -04005# Get the latest Android SDK Platform or modify numbers in configure.sh and sflphone-android/default.properties.
Alexandre Lision43b9aeb2014-07-15 14:21:19 -04006
7set -e
8
9BUILD=
10FETCH=
11case "$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 ;;
24esac
25
26if [ -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
30fi
31
32if [ -z "$ANDROID_ABI" ]; then
33 echo "Please set ANDROID_ABI to your architecture: armeabi-v7a, armeabi, x86 or mips."
34 exit 1
35fi
36
37# try to detect NDK version
38REL=$(grep -o '^r[0-9]*.*' $ANDROID_NDK/RELEASE.TXT 2>/dev/null|cut -b2-)
39case "$REL" in
Tristan Matthewsd6033b42014-10-09 17:00:07 -040040 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 Lision43b9aeb2014-07-15 14:21:19 -040055 GCCVER=4.8
Tristan Matthewsd6033b42014-10-09 17:00:07 -040056 ANDROID_API=android-9
Alexandre Lision43b9aeb2014-07-15 14:21:19 -040057 CXXSTL="/"${GCCVER}
58 ;;
59 7|8|*)
60 echo "You need the NDKv9 or later"
61 exit 1
62 ;;
63esac
64
65export GCCVER
66export CXXSTL
Tristan Matthewsd6033b42014-10-09 17:00:07 -040067export ANDROID_API
Alexandre Lision43b9aeb2014-07-15 14:21:19 -040068
69# Set up ABI variables
70if [ ${ANDROID_ABI} = "x86" ] ; then
71 TARGET_TUPLE="i686-linux-android"
72 PATH_HOST="x86"
73 HAVE_X86=1
74 PLATFORM_SHORT_ARCH="x86"
75elif [ ${ANDROID_ABI} = "mips" ] ; then
76 TARGET_TUPLE="mipsel-linux-android"
77 PATH_HOST=$TARGET_TUPLE
78 HAVE_MIPS=1
79 PLATFORM_SHORT_ARCH="mips"
80else
81 TARGET_TUPLE="arm-linux-androideabi"
82 PATH_HOST=$TARGET_TUPLE
83 HAVE_ARM=1
84 PLATFORM_SHORT_ARCH="arm"
85fi
86
87# XXX : important!
88[ "$HAVE_ARM" = 1 ] && cat << EOF
89For an ARMv6 device without FPU:
90$ export NO_FPU=1
91For an ARMv5 device:
92$ export NO_ARMV6=1
93
94If you plan to use a release build, run 'compile.sh release'
95EOF
96
97export TARGET_TUPLE
98export PATH_HOST
99export HAVE_ARM
100export HAVE_X86
101export HAVE_MIPS
102export PLATFORM_SHORT_ARCH
103
104# Add the NDK toolchain to the PATH, needed both for contribs and for building
105# stub libraries
106NDK_TOOLCHAIN_PATH=`echo ${ANDROID_NDK}/toolchains/${PATH_HOST}-${GCCVER}/prebuilt/\`uname|tr A-Z a-z\`-*/bin`
107export PATH=${NDK_TOOLCHAIN_PATH}:${PATH}
108
109ANDROID_PATH="`pwd`"
110
Tristan Matthewsa2665ff2014-08-12 18:27:23 -0400111# Fetch sflphone daemon source
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400112if [ ! -z "$FETCH" ]
113then
Tristan Matthews8d02ef62014-07-22 16:03:17 -0400114 # 1/ libsflphone
Tristan Matthewsfe249522014-10-09 19:22:41 -0400115 TESTED_HASH=3426b44e576e4766bd0bd274346d2bfbda562e07
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400116 if [ ! -d "sflphone" ]; then
Tristan Matthewsa2665ff2014-08-12 18:27:23 -0400117 echo "sflphone daemon source not found, cloning"
118 git clone https://gerrit-sflphone.savoirfairelinux.com/sflphone
119 cd sflphone
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400120 echo android/ >> .git/info/exclude
121 echo contrib/android/ >> .git/info/exclude
Alexandre Lision3a206cf2014-10-15 12:18:51 -0400122 git checkout $TESTED_HASH
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400123 else
Tristan Matthewsa2665ff2014-08-12 18:27:23 -0400124 echo "sflphone daemon source found"
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400125 cd sflphone
Alexandre Lision65be7702014-09-29 18:06:33 -0400126 git fetch
127 git checkout ${TESTED_HASH}
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400128# 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
147else
148 cd sflphone
149fi
150
151if [ -z "$BUILD" ]
152then
153 echo "Not building anything, please run $0 --build"
154 exit 0
155fi
156
157# Setup CFLAGS
158if [ ${ANDROID_ABI} = "armeabi-v7a" ] ; then
159 EXTRA_CFLAGS="-mfpu=vfpv3-d16 -mcpu=cortex-a8"
160 EXTRA_CFLAGS="${EXTRA_CFLAGS} -mthumb -mfloat-abi=softfp"
161elif [ ${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
171elif [ ${ANDROID_ABI} = "x86" ] ; then
172 EXTRA_CFLAGS="-march=pentium"
173elif [ ${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
178else
179 echo "Unknown ABI. Die, die, die!"
180 exit 2
181fi
182
183EXTRA_CFLAGS="${EXTRA_CFLAGS} -O2"
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400184EXTRA_CFLAGS="${EXTRA_CFLAGS} -I${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++${CXXSTL}/include"
185EXTRA_CFLAGS="${EXTRA_CFLAGS} -I${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++${CXXSTL}/libs/${ANDROID_ABI}/include"
186
Tristan Matthews676fcee2014-10-03 15:57:09 -0400187# Setup LDFLAGS
188EXTRA_LDFLAGS="-l${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++${CXXSTL}/libs/${ANDROID_ABI}/libgnustl_static.a"
189
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400190# Make in //
191UNAMES=$(uname -s)
192MAKEFLAGS=
193if which nproc >/dev/null
194then
195MAKEFLAGS=-j`nproc`
196elif [ "$UNAMES" == "Darwin" ] && which sysctl >/dev/null
197then
198MAKEFLAGS=-j`sysctl -n machdep.cpu.thread_count`
199fi
200
Tristan Matthewsd6d5d402014-10-09 16:41:06 -0400201# Build buildsystem tools
202export PATH=`pwd`/daemon/extras/tools/build/bin:$PATH
203echo "Building tools"
204cd daemon/extras/tools
205./bootstrap
206make $MAKEFLAGS
Tristan Matthewseb9209c2014-10-09 23:11:44 -0400207#FIXME
208echo "HACK for old Jenkins builder...forcing libtool to be built"
209make .libtool
Tristan Matthewsd6d5d402014-10-09 16:41:06 -0400210cd ../../..
211
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400212############
213# Contribs #
214############
215echo "Building the contribs"
Alexandre Lision40734322014-09-03 14:26:59 -0400216mkdir -p daemon/contrib/contrib-android-${TARGET_TUPLE}
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400217
218gen_pc_file() {
219 echo "Generating $1 pkg-config file"
220 echo "Name: $1
221Description: $1
222Version: $2
223Libs: -l$1
Alexandre Lision40734322014-09-03 14:26:59 -0400224Cflags:" > daemon/contrib/${TARGET_TUPLE}/lib/pkgconfig/`echo $1|tr 'A-Z' 'a-z'`.pc
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400225}
226
Alexandre Lision40734322014-09-03 14:26:59 -0400227mkdir -p daemon/contrib/${TARGET_TUPLE}/lib/pkgconfig
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400228
Alexandre Lision40734322014-09-03 14:26:59 -0400229cd daemon/contrib/contrib-android-${TARGET_TUPLE}
Alexandre Lisionec1f3ee2014-08-04 19:12:42 -0400230../bootstrap --host=${TARGET_TUPLE}
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400231
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400232# Some libraries have arm assembly which won't build in thumb mode
233# We append -marm to the CFLAGS of these libs to disable thumb mode
234[ ${ANDROID_ABI} = "armeabi-v7a" ] && echo "NOTHUMB := -marm" >> config.mak
235
236# Release or not?
237if [ $# -ne 0 ] && [ "$1" = "release" ]; then
238 OPTS=""
239 EXTRA_CFLAGS="${EXTRA_CFLAGS} -DNDEBUG "
240 RELEASE=1
241else
242 OPTS="--enable-debug"
Tristan Matthews8d02ef62014-07-22 16:03:17 -0400243 EXTRA_CFLAGS="${EXTRA_CFLAGS} -DNDEBUG "
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400244 RELEASE=0
245fi
246
247echo "EXTRA_CFLAGS= -g ${EXTRA_CFLAGS}" >> config.mak
Tristan Matthewsfc848072014-10-09 03:43:54 -0400248echo "EXTRA_CXXFLAGS= -g ${EXTRA_CXXFLAGS}" >> config.mak
Tristan Matthews676fcee2014-10-03 15:57:09 -0400249echo "EXTRA_LDFLAGS= ${EXTRA_LDFLAGS}" >> config.mak
Tristan Matthews8d02ef62014-07-22 16:03:17 -0400250export SFLPHONE_EXTRA_CFLAGS="${EXTRA_CFLAGS}"
Tristan Matthewsfc848072014-10-09 03:43:54 -0400251export SFLPHONE_EXTRA_CXXFLAGS="${EXTRA_CXXFLAGS}"
Tristan Matthews676fcee2014-10-03 15:57:09 -0400252export SFLPHONE_EXTRA_LDFLAGS="${EXTRA_LDFLAGS}"
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400253
Alexandre Lision68d8f2e2014-07-30 17:42:40 -0400254make install
Alexandre Lisionec1f3ee2014-08-04 19:12:42 -0400255echo ${PWD}
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400256# We already have zlib available
257[ -e .zlib ] || (mkdir -p zlib; touch .zlib)
258which autopoint >/dev/null || make $MAKEFLAGS .gettext
259export PATH="$PATH:$PWD/../$TARGET_TUPLE/bin"
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400260
Tristan Matthewseaaa5ba2014-10-09 04:23:06 -0400261export SFLPHONE_BUILD_DIR=sflphone/daemon/build-android-${TARGET_TUPLE}
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400262############
Tristan Matthews8d02ef62014-07-22 16:03:17 -0400263# Make SFLPHONE #
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400264############
265cd ../.. && mkdir -p build-android-${TARGET_TUPLE} && cd build-android-${TARGET_TUPLE}
266
267if [ $# -eq 1 ] && [ "$1" = "jni" ]; then
268 CLEAN="jniclean"
Tristan Matthews33873ca2014-10-09 13:35:39 -0400269 TARGET="sflphone-android/obj/local/${ANDROID_ABI}/libsflphone.so"
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400270else
271 CLEAN="distclean"
272 if [ ! -f config.h ]; then
273 echo "Bootstraping"
Tristan Matthewsfc848072014-10-09 03:43:54 -0400274 cd ../
275 ./autogen.sh
276 cd ../../
Alexandre Lision60057782014-10-03 14:06:01 -0400277 cd sflphone-android
278 ./make-swig.sh
Tristan Matthewsfc848072014-10-09 03:43:54 -0400279 cd ../sflphone/daemon/build-android-${TARGET_TUPLE}
280 echo "Configuring"
281 echo `pwd`
282 ${ANDROID_PATH}/configure.sh ${OPTS}
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400283 fi
284 TARGET=
285fi
286
Alexandre Lision3a206cf2014-10-15 12:18:51 -0400287echo "Building libsflphone"
288make $MAKEFLAGS
289
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400290####################################
291# Ring android UI and specific code
292####################################
293echo "Building Ring for Android"
Alexandre Lision40734322014-09-03 14:26:59 -0400294cd ../../../
Tristan Matthewsfc848072014-10-09 03:43:54 -0400295
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400296make $CLEAN
297make -j1 TARGET_TUPLE=$TARGET_TUPLE PLATFORM_SHORT_ARCH=$PLATFORM_SHORT_ARCH CXXSTL=$CXXSTL RELEASE=$RELEASE $TARGET
298
299#
300# Exporting a environment script with all the necessary variables
301#
302echo "Generating environment script."
303cat <<EOF
304This is a script that will export many of the variables used in this
305script. It will allow you to compile parts of the build without having
306to rebuild the entire build (e.g. recompile only the Java part).
307
308To use it, include the script into your shell, like this:
309 source env.sh
310
311Now, you can use this command to build the Java portion:
312 make -e
313
314The file will be automatically regenerated by compile.sh, so if you change
315your NDK/SDK locations or any build configurations, just re-run this
316script (sh compile.sh) and it will automatically update the file.
317
318EOF
319
320echo "# This file was automatically generated by compile.sh" > env.sh
321echo "# Re-run 'sh compile.sh' to update this file." >> env.sh
322
323# The essentials
324cat <<EssentialsA >> env.sh
325export ANDROID_ABI=$ANDROID_ABI
326export ANDROID_SDK=$ANDROID_SDK
327export ANDROID_NDK=$ANDROID_NDK
328export GCCVER=$GCCVER
329export CXXSTL=$CXXSTL
Tristan Matthewsfc848072014-10-09 03:43:54 -0400330export SFLPHONE_BUILD_DIR=$SFLPHONE_BUILD_DIR
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400331export TARGET_TUPLE=$TARGET_TUPLE
332export PATH_HOST=$PATH_HOST
333export PLATFORM_SHORT_ARCH=$PLATFORM_SHORT_ARCH
334EssentialsA
335
336# PATH
337echo "export PATH=$NDK_TOOLCHAIN_PATH:\${ANDROID_SDK}/platform-tools:\${PATH}" >> env.sh
338
339# CPU flags
340if [ -n "${HAVE_ARM}" ]; then
341 echo "export HAVE_ARM=1" >> env.sh
342elif [ -n "${HAVE_X86}" ]; then
343 echo "export HAVE_X86=1" >> env.sh
344elif [ -n "${HAVE_MIPS}" ]; then
345 echo "export HAVE_MIPS=1" >> env.sh
346fi
347
348if [ -n "${NO_ARMV6}" ]; then
349 echo "export NO_ARMV6=1" >> env.sh
350fi
351if [ -n "${NO_FPU}" ]; then
352 echo "export NO_FPU=1" >> env.sh
353fi