blob: 7fb37503ca7616bc671788ffabfd4b7d40b1a34d [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
Alexandre Lision68d8f2e2014-07-30 17:42:40 -040040 9|10|*)
Alexandre Lision43b9aeb2014-07-15 14:21:19 -040041 GCCVER=4.8
42 CXXSTL="/"${GCCVER}
43 ;;
44 7|8|*)
45 echo "You need the NDKv9 or later"
46 exit 1
47 ;;
48esac
49
50export GCCVER
51export CXXSTL
52
53# Set up ABI variables
54if [ ${ANDROID_ABI} = "x86" ] ; then
55 TARGET_TUPLE="i686-linux-android"
56 PATH_HOST="x86"
57 HAVE_X86=1
58 PLATFORM_SHORT_ARCH="x86"
59elif [ ${ANDROID_ABI} = "mips" ] ; then
60 TARGET_TUPLE="mipsel-linux-android"
61 PATH_HOST=$TARGET_TUPLE
62 HAVE_MIPS=1
63 PLATFORM_SHORT_ARCH="mips"
64else
65 TARGET_TUPLE="arm-linux-androideabi"
66 PATH_HOST=$TARGET_TUPLE
67 HAVE_ARM=1
68 PLATFORM_SHORT_ARCH="arm"
69fi
70
71# XXX : important!
72[ "$HAVE_ARM" = 1 ] && cat << EOF
73For an ARMv6 device without FPU:
74$ export NO_FPU=1
75For an ARMv5 device:
76$ export NO_ARMV6=1
77
78If you plan to use a release build, run 'compile.sh release'
79EOF
80
81export TARGET_TUPLE
82export PATH_HOST
83export HAVE_ARM
84export HAVE_X86
85export HAVE_MIPS
86export PLATFORM_SHORT_ARCH
87
88# Add the NDK toolchain to the PATH, needed both for contribs and for building
89# stub libraries
90NDK_TOOLCHAIN_PATH=`echo ${ANDROID_NDK}/toolchains/${PATH_HOST}-${GCCVER}/prebuilt/\`uname|tr A-Z a-z\`-*/bin`
91export PATH=${NDK_TOOLCHAIN_PATH}:${PATH}
92
93ANDROID_PATH="`pwd`"
94
Tristan Matthewsa2665ff2014-08-12 18:27:23 -040095# Fetch sflphone daemon source
Alexandre Lision43b9aeb2014-07-15 14:21:19 -040096if [ ! -z "$FETCH" ]
97then
Tristan Matthews8d02ef62014-07-22 16:03:17 -040098 # 1/ libsflphone
Tristan Matthews1b5d1322014-09-29 17:29:16 -040099 TESTED_HASH=7104605dd2e7739a1973cee3bbb0fffcfd360bbd
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400100 if [ ! -d "sflphone" ]; then
Tristan Matthewsa2665ff2014-08-12 18:27:23 -0400101 echo "sflphone daemon source not found, cloning"
102 git clone https://gerrit-sflphone.savoirfairelinux.com/sflphone
103 cd sflphone
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400104 echo android/ >> .git/info/exclude
105 echo contrib/android/ >> .git/info/exclude
106 #git checkout -B android ${TESTED_HASH}
Alexandre Lision40734322014-09-03 14:26:59 -0400107 git checkout master
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400108 else
Tristan Matthewsa2665ff2014-08-12 18:27:23 -0400109 echo "sflphone daemon source found"
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400110 cd sflphone
Alexandre Lision40734322014-09-03 14:26:59 -0400111 git checkout master
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400112# 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
131else
132 cd sflphone
133fi
134
135if [ -z "$BUILD" ]
136then
137 echo "Not building anything, please run $0 --build"
138 exit 0
139fi
140
141# Setup CFLAGS
142if [ ${ANDROID_ABI} = "armeabi-v7a" ] ; then
143 EXTRA_CFLAGS="-mfpu=vfpv3-d16 -mcpu=cortex-a8"
144 EXTRA_CFLAGS="${EXTRA_CFLAGS} -mthumb -mfloat-abi=softfp"
145elif [ ${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
155elif [ ${ANDROID_ABI} = "x86" ] ; then
156 EXTRA_CFLAGS="-march=pentium"
157elif [ ${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
162else
163 echo "Unknown ABI. Die, die, die!"
164 exit 2
165fi
166
167EXTRA_CFLAGS="${EXTRA_CFLAGS} -O2"
168
169EXTRA_CFLAGS="${EXTRA_CFLAGS} -I${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++${CXXSTL}/include"
170EXTRA_CFLAGS="${EXTRA_CFLAGS} -I${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++${CXXSTL}/libs/${ANDROID_ABI}/include"
171
172# Make in //
173UNAMES=$(uname -s)
174MAKEFLAGS=
175if which nproc >/dev/null
176then
177MAKEFLAGS=-j`nproc`
178elif [ "$UNAMES" == "Darwin" ] && which sysctl >/dev/null
179then
180MAKEFLAGS=-j`sysctl -n machdep.cpu.thread_count`
181fi
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############
195echo "Building the contribs"
Alexandre Lision40734322014-09-03 14:26:59 -0400196mkdir -p daemon/contrib/contrib-android-${TARGET_TUPLE}
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400197
198gen_pc_file() {
199 echo "Generating $1 pkg-config file"
200 echo "Name: $1
201Description: $1
202Version: $2
203Libs: -l$1
Alexandre Lision40734322014-09-03 14:26:59 -0400204Cflags:" > daemon/contrib/${TARGET_TUPLE}/lib/pkgconfig/`echo $1|tr 'A-Z' 'a-z'`.pc
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400205}
206
Alexandre Lision40734322014-09-03 14:26:59 -0400207mkdir -p daemon/contrib/${TARGET_TUPLE}/lib/pkgconfig
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400208
Alexandre Lision40734322014-09-03 14:26:59 -0400209cd daemon/contrib/contrib-android-${TARGET_TUPLE}
Alexandre Lisionec1f3ee2014-08-04 19:12:42 -0400210../bootstrap --host=${TARGET_TUPLE}
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400211
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400212# 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?
217if [ $# -ne 0 ] && [ "$1" = "release" ]; then
218 OPTS=""
219 EXTRA_CFLAGS="${EXTRA_CFLAGS} -DNDEBUG "
220 RELEASE=1
221else
222 OPTS="--enable-debug"
Tristan Matthews8d02ef62014-07-22 16:03:17 -0400223 EXTRA_CFLAGS="${EXTRA_CFLAGS} -DNDEBUG "
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400224 RELEASE=0
225fi
226
227echo "EXTRA_CFLAGS= -g ${EXTRA_CFLAGS}" >> config.mak
Tristan Matthews8d02ef62014-07-22 16:03:17 -0400228export SFLPHONE_EXTRA_CFLAGS="${EXTRA_CFLAGS}"
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400229
Alexandre Lision68d8f2e2014-07-30 17:42:40 -0400230make install
Alexandre Lisionec1f3ee2014-08-04 19:12:42 -0400231echo ${PWD}
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400232# We already have zlib available
233[ -e .zlib ] || (mkdir -p zlib; touch .zlib)
234which autopoint >/dev/null || make $MAKEFLAGS .gettext
235export PATH="$PATH:$PWD/../$TARGET_TUPLE/bin"
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400236
Alexandre Lisionec1f3ee2014-08-04 19:12:42 -0400237export SFLPHONE_BUILD_DIR=sflphone/build-android-${TARGET_TUPLE}
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400238############
Tristan Matthews8d02ef62014-07-22 16:03:17 -0400239# Make SFLPHONE #
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400240############
241cd ../.. && mkdir -p build-android-${TARGET_TUPLE} && cd build-android-${TARGET_TUPLE}
242
243if [ $# -eq 1 ] && [ "$1" = "jni" ]; then
244 CLEAN="jniclean"
Tristan Matthews8d02ef62014-07-22 16:03:17 -0400245 TARGET="sflphone-android/obj/local/armeabi-v7a/libsflphone.so"
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400246else
247 CLEAN="distclean"
248 if [ ! -f config.h ]; then
249 echo "Bootstraping"
Alexandre Lision40734322014-09-03 14:26:59 -0400250 pushd ../../../
251 echo $PWD
Alexandre Lision7b151702014-09-04 10:07:34 -0400252 ./configure.sh --with-opensl --without-dbus
Alexandre Lisionec1f3ee2014-08-04 19:12:42 -0400253 cd sflphone/daemon
Tristan Matthewscc806e12014-08-01 16:25:03 -0400254 echo "Building"
255 make $MAKEFLAGS
256 popd
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400257 fi
258 TARGET=
259fi
260
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400261####################################
262# Ring android UI and specific code
263####################################
264echo "Building Ring for Android"
Alexandre Lision40734322014-09-03 14:26:59 -0400265cd ../../../
266echo $PWD
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400267make $CLEAN
268make -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#
273echo "Generating environment script."
274cat <<EOF
275This is a script that will export many of the variables used in this
276script. It will allow you to compile parts of the build without having
277to rebuild the entire build (e.g. recompile only the Java part).
278
279To use it, include the script into your shell, like this:
280 source env.sh
281
282Now, you can use this command to build the Java portion:
283 make -e
284
285The file will be automatically regenerated by compile.sh, so if you change
286your NDK/SDK locations or any build configurations, just re-run this
287script (sh compile.sh) and it will automatically update the file.
288
289EOF
290
291echo "# This file was automatically generated by compile.sh" > env.sh
292echo "# Re-run 'sh compile.sh' to update this file." >> env.sh
293
294# The essentials
295cat <<EssentialsA >> env.sh
296export ANDROID_ABI=$ANDROID_ABI
297export ANDROID_SDK=$ANDROID_SDK
298export ANDROID_NDK=$ANDROID_NDK
299export GCCVER=$GCCVER
300export CXXSTL=$CXXSTL
Tristan Matthews8d02ef62014-07-22 16:03:17 -0400301export SFLPHONE_BUILD_DIR=$PWD/sflphone/android
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400302export TARGET_TUPLE=$TARGET_TUPLE
303export PATH_HOST=$PATH_HOST
304export PLATFORM_SHORT_ARCH=$PLATFORM_SHORT_ARCH
305EssentialsA
306
307# PATH
308echo "export PATH=$NDK_TOOLCHAIN_PATH:\${ANDROID_SDK}/platform-tools:\${PATH}" >> env.sh
309
310# CPU flags
311if [ -n "${HAVE_ARM}" ]; then
312 echo "export HAVE_ARM=1" >> env.sh
313elif [ -n "${HAVE_X86}" ]; then
314 echo "export HAVE_X86=1" >> env.sh
315elif [ -n "${HAVE_MIPS}" ]; then
316 echo "export HAVE_MIPS=1" >> env.sh
317fi
318
319if [ -n "${NO_ARMV6}" ]; then
320 echo "export NO_ARMV6=1" >> env.sh
321fi
322if [ -n "${NO_FPU}" ]; then
323 echo "export NO_FPU=1" >> env.sh
324fi