blob: 1c9f8b4717c04a0e8ee1d5c8ede1511c2b58d572 [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
Alexandre Lision43b9aeb2014-07-15 14:21:19 -04009if [ -z "$ANDROID_NDK" -o -z "$ANDROID_SDK" ]; then
10 echo "You must define ANDROID_NDK, ANDROID_SDK and ANDROID_ABI before starting."
11 echo "They must point to your NDK and SDK directories.\n"
12 exit 1
13fi
14
15if [ -z "$ANDROID_ABI" ]; then
Alexandre Lision7d5df5d2014-10-27 13:10:01 -040016 echo "Please set ANDROID_ABI to your architecture: armeabi-v7a, armeabi, arm64-v8a, x86, x86_64 or mips."
Alexandre Lision43b9aeb2014-07-15 14:21:19 -040017 exit 1
18fi
19
Alexandre Lision7d5df5d2014-10-27 13:10:01 -040020if [ -z "$NO_FPU" ];then
21 NO_FPU=0
22fi
23if [ -z "$NO_ARMV6" ];then
24 NO_ARMV6=0
25fi
26
27BUILD=0
28FETCH=0
29RELEASE=0
30JNI=0
31
32for i in ${@}; do
33 case "$i" in
34 --fetch)
35 FETCH=1
36 ;;
37 --build)
38 BUILD=1
39 ;;
40 release|--release)
41 RELEASE=1
42 ;;
43 jni|--jni)
44 JNI=1
45 ;;
46 *)
47 ;;
48 esac
49done
50
51if [ "$BUILD" = 0 -a "$FETCH" = 0 ];then
52 BUILD=1
53 FETCH=1
54fi
55
56if [ `set -- ${ANDROID_ABI}; echo $#` -gt 1 ]; then
57 ANDROID_ABI_LIST="${ANDROID_ABI}"
58 echo "More than one ABI specified: ${ANDROID_ABI_LIST}"
59 for i in ${ANDROID_ABI_LIST}; do
60 echo "$i starts building"
61 ANDROID_NDK=$ANDROID_NDK ANDROID_SDK=$ANDROID_SDK \
62 NO_FPU=$NO_FPU NO_ARMV6=$NO_ARMV6 ANDROID_ABI=$i \
63 ./compile.sh $* --jni || { echo "$i build KO"; exit 1; }
64 mkdir -p obj/
65 cp -r sflphone-android/libs/$i obj
66 echo "$i build OK"
67 done
68 for i in ${ANDROID_ABI_LIST}; do
69 cp -r obj/$i sflphone-android/libs/
70 rm -rf obj/$i
71 done
72 make -b -j1 RELEASE=$RELEASE apk || exit 1
73 exit 0
74fi
75
76HAVE_ARM=0
77HAVE_X86=0
78HAVE_MIPS=0
79HAVE_64=0
80
81
82# Set up ABI variables
83if [ ${ANDROID_ABI} = "x86" ] ; then
84 TARGET_TUPLE="i686-linux-android"
85 PATH_HOST="x86"
86 HAVE_X86=1
87 PLATFORM_SHORT_ARCH="x86"
88elif [ ${ANDROID_ABI} = "x86_64" ] ; then
89 TARGET_TUPLE="x86_64-linux-android"
90 PATH_HOST="x86_64"
91 HAVE_X86=1
92 HAVE_64=1
93 PLATFORM_SHORT_ARCH="x86_64"
94elif [ ${ANDROID_ABI} = "mips" ] ; then
95 TARGET_TUPLE="mipsel-linux-android"
96 PATH_HOST=$TARGET_TUPLE
97 HAVE_MIPS=1
98 PLATFORM_SHORT_ARCH="mips"
99elif [ ${ANDROID_ABI} = "arm64-v8a" ] ; then
100 TARGET_TUPLE="aarch64-linux-android"
101 PATH_HOST=$TARGET_TUPLE
102 HAVE_ARM=1
103 HAVE_64=1
104 PLATFORM_SHORT_ARCH="arm64"
105else
106 TARGET_TUPLE="arm-linux-androideabi"
107 PATH_HOST=$TARGET_TUPLE
108 HAVE_ARM=1
109 PLATFORM_SHORT_ARCH="arm"
110fi
111
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400112# try to detect NDK version
113REL=$(grep -o '^r[0-9]*.*' $ANDROID_NDK/RELEASE.TXT 2>/dev/null|cut -b2-)
114case "$REL" in
Tristan Matthewsd6033b42014-10-09 17:00:07 -0400115 10*)
116 if [ "${HAVE_64}" = 1 ];then
117 GCCVER=4.9
Alexandre Lision7d5df5d2014-10-27 13:10:01 -0400118 ANDROID_API=android-21
Tristan Matthewsd6033b42014-10-09 17:00:07 -0400119 else
120 GCCVER=4.8
121 ANDROID_API=android-9
122 fi
123 CXXSTL="/"${GCCVER}
124 ;;
125 9*)
126 if [ "${HAVE_64}" = 1 ];then
127 echo "You need the NDKv10 or later for 64 bits build"
128 exit 1
129 fi
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400130 GCCVER=4.8
Tristan Matthewsd6033b42014-10-09 17:00:07 -0400131 ANDROID_API=android-9
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400132 CXXSTL="/"${GCCVER}
133 ;;
134 7|8|*)
135 echo "You need the NDKv9 or later"
136 exit 1
137 ;;
138esac
139
140export GCCVER
141export CXXSTL
Tristan Matthewsd6033b42014-10-09 17:00:07 -0400142export ANDROID_API
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400143
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400144# XXX : important!
145[ "$HAVE_ARM" = 1 ] && cat << EOF
146For an ARMv6 device without FPU:
147$ export NO_FPU=1
148For an ARMv5 device:
149$ export NO_ARMV6=1
150
151If you plan to use a release build, run 'compile.sh release'
152EOF
153
154export TARGET_TUPLE
155export PATH_HOST
156export HAVE_ARM
157export HAVE_X86
158export HAVE_MIPS
Alexandre Lision7d5df5d2014-10-27 13:10:01 -0400159export HAVE_64
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400160export PLATFORM_SHORT_ARCH
161
162# Add the NDK toolchain to the PATH, needed both for contribs and for building
163# stub libraries
164NDK_TOOLCHAIN_PATH=`echo ${ANDROID_NDK}/toolchains/${PATH_HOST}-${GCCVER}/prebuilt/\`uname|tr A-Z a-z\`-*/bin`
165export PATH=${NDK_TOOLCHAIN_PATH}:${PATH}
166
167ANDROID_PATH="`pwd`"
168
Tristan Matthewsa2665ff2014-08-12 18:27:23 -0400169# Fetch sflphone daemon source
Alexandre Lision7f46d1c2014-10-27 16:39:25 -0400170if [ "$FETCH" = 1 ]
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400171then
Tristan Matthews8d02ef62014-07-22 16:03:17 -0400172 # 1/ libsflphone
Alexandre Lision65a1d102014-11-07 12:25:57 -0500173 TESTED_HASH=86207dcf4d3c37a2ba0139f10da1bcdbc69269ea
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400174 if [ ! -d "sflphone" ]; then
Tristan Matthewsa2665ff2014-08-12 18:27:23 -0400175 echo "sflphone daemon source not found, cloning"
176 git clone https://gerrit-sflphone.savoirfairelinux.com/sflphone
177 cd sflphone
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400178 echo android/ >> .git/info/exclude
179 echo contrib/android/ >> .git/info/exclude
Alexandre Lision3a206cf2014-10-15 12:18:51 -0400180 git checkout $TESTED_HASH
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400181 else
Tristan Matthewsa2665ff2014-08-12 18:27:23 -0400182 echo "sflphone daemon source found"
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400183 cd sflphone
Alexandre Lision65be7702014-09-29 18:06:33 -0400184 git fetch
185 git checkout ${TESTED_HASH}
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400186# if ! git cat-file -e ${TESTED_HASH}; then
187# cat << EOF
188#***
189#*** Error: Your sflphone checkout does not contain the latest tested commit ***
190#***
191#
192#Please update your source with something like:
193#
194#cd sflphone
195#git reset --hard origin
196#git pull origin master
197#git checkout -B android ${TESTED_HASH}
198#
199#*** : This will delete any changes you made to the current branch ***
200#
201#EOF
202# exit 1
203# fi
204 fi
205else
206 cd sflphone
207fi
208
209if [ -z "$BUILD" ]
210then
211 echo "Not building anything, please run $0 --build"
212 exit 0
213fi
214
215# Setup CFLAGS
216if [ ${ANDROID_ABI} = "armeabi-v7a" ] ; then
217 EXTRA_CFLAGS="-mfpu=vfpv3-d16 -mcpu=cortex-a8"
218 EXTRA_CFLAGS="${EXTRA_CFLAGS} -mthumb -mfloat-abi=softfp"
219elif [ ${ANDROID_ABI} = "armeabi" ] ; then
220 if [ -n "${NO_ARMV6}" ]; then
221 EXTRA_CFLAGS="-march=armv5te -mtune=arm9tdmi -msoft-float"
222 else
223 if [ -n "${NO_FPU}" ]; then
224 EXTRA_CFLAGS="-march=armv6j -mtune=arm1136j-s -msoft-float"
225 else
226 EXTRA_CFLAGS="-mfpu=vfp -mcpu=arm1136jf-s -mfloat-abi=softfp"
227 fi
228 fi
Alexandre Lision7d5df5d2014-10-27 13:10:01 -0400229elif [ ${ANDROID_ABI} = "arm64-v8a" ] ; then
230 EXTRA_CFLAGS=""
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400231elif [ ${ANDROID_ABI} = "x86" ] ; then
Alexandre Lision7d5df5d2014-10-27 13:10:01 -0400232 EXTRA_CFLAGS="-march=pentium -m32"
233elif [ ${ANDROID_ABI} = "x86_64" ] ; then
234 EXTRA_CFLAGS=""
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400235elif [ ${ANDROID_ABI} = "mips" ] ; then
236 EXTRA_CFLAGS="-march=mips32 -mtune=mips32r2 -mhard-float"
237 # All MIPS Linux kernels since 2.4.4 will trap any unimplemented FPU
238 # instruction and emulate it, so we select -mhard-float.
239 # See http://www.linux-mips.org/wiki/Floating_point#The_Linux_kernel_and_floating_point
240else
241 echo "Unknown ABI. Die, die, die!"
242 exit 2
243fi
244
245EXTRA_CFLAGS="${EXTRA_CFLAGS} -O2"
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400246EXTRA_CFLAGS="${EXTRA_CFLAGS} -I${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++${CXXSTL}/include"
247EXTRA_CFLAGS="${EXTRA_CFLAGS} -I${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++${CXXSTL}/libs/${ANDROID_ABI}/include"
248
Tristan Matthews676fcee2014-10-03 15:57:09 -0400249# Setup LDFLAGS
Alexandre Lision7d5df5d2014-10-27 13:10:01 -0400250EXTRA_LDFLAGS="-L${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++${CXXSTL}/libs/${ANDROID_ABI} -lgnustl_static"
Tristan Matthews676fcee2014-10-03 15:57:09 -0400251
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400252# Make in //
253UNAMES=$(uname -s)
254MAKEFLAGS=
255if which nproc >/dev/null
256then
257MAKEFLAGS=-j`nproc`
258elif [ "$UNAMES" == "Darwin" ] && which sysctl >/dev/null
259then
260MAKEFLAGS=-j`sysctl -n machdep.cpu.thread_count`
261fi
262
Tristan Matthewsd6d5d402014-10-09 16:41:06 -0400263# Build buildsystem tools
264export PATH=`pwd`/daemon/extras/tools/build/bin:$PATH
265echo "Building tools"
266cd daemon/extras/tools
267./bootstrap
268make $MAKEFLAGS
Tristan Matthewseb9209c2014-10-09 23:11:44 -0400269#FIXME
270echo "HACK for old Jenkins builder...forcing libtool to be built"
271make .libtool
Tristan Matthewsd6d5d402014-10-09 16:41:06 -0400272cd ../../..
273
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400274############
275# Contribs #
276############
277echo "Building the contribs"
Alexandre Lision40734322014-09-03 14:26:59 -0400278mkdir -p daemon/contrib/contrib-android-${TARGET_TUPLE}
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400279
280gen_pc_file() {
281 echo "Generating $1 pkg-config file"
282 echo "Name: $1
283Description: $1
284Version: $2
285Libs: -l$1
Alexandre Lision40734322014-09-03 14:26:59 -0400286Cflags:" > daemon/contrib/${TARGET_TUPLE}/lib/pkgconfig/`echo $1|tr 'A-Z' 'a-z'`.pc
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400287}
288
Alexandre Lision40734322014-09-03 14:26:59 -0400289mkdir -p daemon/contrib/${TARGET_TUPLE}/lib/pkgconfig
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400290
Alexandre Lision40734322014-09-03 14:26:59 -0400291cd daemon/contrib/contrib-android-${TARGET_TUPLE}
Alexandre Lisionec1f3ee2014-08-04 19:12:42 -0400292../bootstrap --host=${TARGET_TUPLE}
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400293
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400294# Some libraries have arm assembly which won't build in thumb mode
295# We append -marm to the CFLAGS of these libs to disable thumb mode
296[ ${ANDROID_ABI} = "armeabi-v7a" ] && echo "NOTHUMB := -marm" >> config.mak
297
298# Release or not?
299if [ $# -ne 0 ] && [ "$1" = "release" ]; then
300 OPTS=""
301 EXTRA_CFLAGS="${EXTRA_CFLAGS} -DNDEBUG "
302 RELEASE=1
303else
304 OPTS="--enable-debug"
Tristan Matthews8d02ef62014-07-22 16:03:17 -0400305 EXTRA_CFLAGS="${EXTRA_CFLAGS} -DNDEBUG "
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400306 RELEASE=0
307fi
308
309echo "EXTRA_CFLAGS= -g ${EXTRA_CFLAGS}" >> config.mak
Tristan Matthewsfc848072014-10-09 03:43:54 -0400310echo "EXTRA_CXXFLAGS= -g ${EXTRA_CXXFLAGS}" >> config.mak
Tristan Matthews676fcee2014-10-03 15:57:09 -0400311echo "EXTRA_LDFLAGS= ${EXTRA_LDFLAGS}" >> config.mak
Tristan Matthews8d02ef62014-07-22 16:03:17 -0400312export SFLPHONE_EXTRA_CFLAGS="${EXTRA_CFLAGS}"
Tristan Matthewsfc848072014-10-09 03:43:54 -0400313export SFLPHONE_EXTRA_CXXFLAGS="${EXTRA_CXXFLAGS}"
Tristan Matthews676fcee2014-10-03 15:57:09 -0400314export SFLPHONE_EXTRA_LDFLAGS="${EXTRA_LDFLAGS}"
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400315
Alexandre Lision68d8f2e2014-07-30 17:42:40 -0400316make install
Alexandre Lisionec1f3ee2014-08-04 19:12:42 -0400317echo ${PWD}
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400318# We already have zlib available
319[ -e .zlib ] || (mkdir -p zlib; touch .zlib)
320which autopoint >/dev/null || make $MAKEFLAGS .gettext
321export PATH="$PATH:$PWD/../$TARGET_TUPLE/bin"
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400322
Tristan Matthewseaaa5ba2014-10-09 04:23:06 -0400323export SFLPHONE_BUILD_DIR=sflphone/daemon/build-android-${TARGET_TUPLE}
Alexandre Lision7d5df5d2014-10-27 13:10:01 -0400324
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400325############
Tristan Matthews8d02ef62014-07-22 16:03:17 -0400326# Make SFLPHONE #
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400327############
328cd ../.. && mkdir -p build-android-${TARGET_TUPLE} && cd build-android-${TARGET_TUPLE}
329
Alexandre Lision7d5df5d2014-10-27 13:10:01 -0400330if [ "$JNI" = 1 ]; then
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400331 CLEAN="jniclean"
Tristan Matthews33873ca2014-10-09 13:35:39 -0400332 TARGET="sflphone-android/obj/local/${ANDROID_ABI}/libsflphone.so"
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400333else
334 CLEAN="distclean"
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400335 TARGET=
336fi
337
Alexandre Lision7d5df5d2014-10-27 13:10:01 -0400338if [ ! -f config.h ]; then
339 echo "Bootstraping"
340 cd ../
341 ./autogen.sh
342 cd ../../
343 cd sflphone-android
344 ./make-swig.sh
345 cd ../sflphone/daemon/build-android-${TARGET_TUPLE}
346 echo "Configuring"
347 ${ANDROID_PATH}/configure.sh ${OPTS}
348fi
349
350# ANDROID NDK FIXUP (BLAME GOOGLE)
351config_undef ()
352{
353 previous_change=`stat -c "%y" config.h`
354 sed -i 's,#define '$1' 1,/\* #undef '$1' \*/,' config.h
355 # don't change modified date in order to don't trigger a full build
356 touch -d "$previous_change" config.h
357}
358
359# if config dependencies change, ./config.status --recheck
360# is run and overwrite previously hacked config.h. So call make Makefile here
361# and hack config.h after.
362
363make $MAKEFLAGS Makefile
364
365if [ ${ANDROID_ABI} = "x86" -a ${ANDROID_API} != "android-21" ] ; then
366 # NDK x86 libm.so has nanf symbol but no nanf definition, we don't known if
367 # intel devices has nanf. Assume they don't have it.
368 config_undef HAVE_NANF
369fi
370if [ ${ANDROID_API} = "android-21" ] ; then
371 # android-21 has empty sys/shm.h headers that triggers shm detection but it
372 # doesn't have any shm functions and/or symbols. */
373 config_undef HAVE_SYS_SHM_H
374fi
375# END OF ANDROID NDK FIXUP
376
Alexandre Lision3a206cf2014-10-15 12:18:51 -0400377echo "Building libsflphone"
378make $MAKEFLAGS
379
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400380####################################
381# Ring android UI and specific code
382####################################
383echo "Building Ring for Android"
Alexandre Lision40734322014-09-03 14:26:59 -0400384cd ../../../
Tristan Matthewsfc848072014-10-09 03:43:54 -0400385
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400386make $CLEAN
387make -j1 TARGET_TUPLE=$TARGET_TUPLE PLATFORM_SHORT_ARCH=$PLATFORM_SHORT_ARCH CXXSTL=$CXXSTL RELEASE=$RELEASE $TARGET
388
389#
390# Exporting a environment script with all the necessary variables
391#
392echo "Generating environment script."
393cat <<EOF
394This is a script that will export many of the variables used in this
395script. It will allow you to compile parts of the build without having
396to rebuild the entire build (e.g. recompile only the Java part).
397
398To use it, include the script into your shell, like this:
399 source env.sh
400
401Now, you can use this command to build the Java portion:
402 make -e
403
404The file will be automatically regenerated by compile.sh, so if you change
405your NDK/SDK locations or any build configurations, just re-run this
406script (sh compile.sh) and it will automatically update the file.
407
408EOF
409
410echo "# This file was automatically generated by compile.sh" > env.sh
411echo "# Re-run 'sh compile.sh' to update this file." >> env.sh
412
413# The essentials
414cat <<EssentialsA >> env.sh
415export ANDROID_ABI=$ANDROID_ABI
416export ANDROID_SDK=$ANDROID_SDK
417export ANDROID_NDK=$ANDROID_NDK
418export GCCVER=$GCCVER
419export CXXSTL=$CXXSTL
Tristan Matthewsfc848072014-10-09 03:43:54 -0400420export SFLPHONE_BUILD_DIR=$SFLPHONE_BUILD_DIR
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400421export TARGET_TUPLE=$TARGET_TUPLE
422export PATH_HOST=$PATH_HOST
423export PLATFORM_SHORT_ARCH=$PLATFORM_SHORT_ARCH
424EssentialsA
425
426# PATH
427echo "export PATH=$NDK_TOOLCHAIN_PATH:\${ANDROID_SDK}/platform-tools:\${PATH}" >> env.sh
428
429# CPU flags
430if [ -n "${HAVE_ARM}" ]; then
431 echo "export HAVE_ARM=1" >> env.sh
432elif [ -n "${HAVE_X86}" ]; then
433 echo "export HAVE_X86=1" >> env.sh
434elif [ -n "${HAVE_MIPS}" ]; then
435 echo "export HAVE_MIPS=1" >> env.sh
436fi
437
438if [ -n "${NO_ARMV6}" ]; then
439 echo "export NO_ARMV6=1" >> env.sh
440fi
441if [ -n "${NO_FPU}" ]; then
442 echo "export NO_FPU=1" >> env.sh
443fi