blob: 2f62f85eab1c76679632962e526f0cd6b230c9e0 [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 Matthewsc4f17ed2014-10-06 14:18:19 -040099 TESTED_HASH=ffcb8d4154e95601438559dc47c83b8bb968fafe
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 Lision65be7702014-09-29 18:06:33 -0400111 git fetch
112 git checkout ${TESTED_HASH}
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400113# if ! git cat-file -e ${TESTED_HASH}; then
114# cat << EOF
115#***
116#*** Error: Your sflphone checkout does not contain the latest tested commit ***
117#***
118#
119#Please update your source with something like:
120#
121#cd sflphone
122#git reset --hard origin
123#git pull origin master
124#git checkout -B android ${TESTED_HASH}
125#
126#*** : This will delete any changes you made to the current branch ***
127#
128#EOF
129# exit 1
130# fi
131 fi
132else
133 cd sflphone
134fi
135
136if [ -z "$BUILD" ]
137then
138 echo "Not building anything, please run $0 --build"
139 exit 0
140fi
141
142# Setup CFLAGS
143if [ ${ANDROID_ABI} = "armeabi-v7a" ] ; then
144 EXTRA_CFLAGS="-mfpu=vfpv3-d16 -mcpu=cortex-a8"
145 EXTRA_CFLAGS="${EXTRA_CFLAGS} -mthumb -mfloat-abi=softfp"
146elif [ ${ANDROID_ABI} = "armeabi" ] ; then
147 if [ -n "${NO_ARMV6}" ]; then
148 EXTRA_CFLAGS="-march=armv5te -mtune=arm9tdmi -msoft-float"
149 else
150 if [ -n "${NO_FPU}" ]; then
151 EXTRA_CFLAGS="-march=armv6j -mtune=arm1136j-s -msoft-float"
152 else
153 EXTRA_CFLAGS="-mfpu=vfp -mcpu=arm1136jf-s -mfloat-abi=softfp"
154 fi
155 fi
156elif [ ${ANDROID_ABI} = "x86" ] ; then
157 EXTRA_CFLAGS="-march=pentium"
158elif [ ${ANDROID_ABI} = "mips" ] ; then
159 EXTRA_CFLAGS="-march=mips32 -mtune=mips32r2 -mhard-float"
160 # All MIPS Linux kernels since 2.4.4 will trap any unimplemented FPU
161 # instruction and emulate it, so we select -mhard-float.
162 # See http://www.linux-mips.org/wiki/Floating_point#The_Linux_kernel_and_floating_point
163else
164 echo "Unknown ABI. Die, die, die!"
165 exit 2
166fi
167
168EXTRA_CFLAGS="${EXTRA_CFLAGS} -O2"
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400169EXTRA_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"
Alexandre Lision60057782014-10-03 14:06:01 -0400171CXXFLAGS="${CXXFLAGS} -I/home/alision/sflphone-android/sflphone-android/jni"
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400172
Tristan Matthews676fcee2014-10-03 15:57:09 -0400173# Setup LDFLAGS
174EXTRA_LDFLAGS="-l${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++${CXXSTL}/libs/${ANDROID_ABI}/libgnustl_static.a"
175
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400176# Make in //
177UNAMES=$(uname -s)
178MAKEFLAGS=
179if which nproc >/dev/null
180then
181MAKEFLAGS=-j`nproc`
182elif [ "$UNAMES" == "Darwin" ] && which sysctl >/dev/null
183then
184MAKEFLAGS=-j`sysctl -n machdep.cpu.thread_count`
185fi
186
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400187############
188# Contribs #
189############
190echo "Building the contribs"
Alexandre Lision40734322014-09-03 14:26:59 -0400191mkdir -p daemon/contrib/contrib-android-${TARGET_TUPLE}
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400192
193gen_pc_file() {
194 echo "Generating $1 pkg-config file"
195 echo "Name: $1
196Description: $1
197Version: $2
198Libs: -l$1
Alexandre Lision40734322014-09-03 14:26:59 -0400199Cflags:" > daemon/contrib/${TARGET_TUPLE}/lib/pkgconfig/`echo $1|tr 'A-Z' 'a-z'`.pc
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400200}
201
Alexandre Lision40734322014-09-03 14:26:59 -0400202mkdir -p daemon/contrib/${TARGET_TUPLE}/lib/pkgconfig
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400203
Alexandre Lision40734322014-09-03 14:26:59 -0400204cd daemon/contrib/contrib-android-${TARGET_TUPLE}
Alexandre Lisionec1f3ee2014-08-04 19:12:42 -0400205../bootstrap --host=${TARGET_TUPLE}
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400206
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400207# Some libraries have arm assembly which won't build in thumb mode
208# We append -marm to the CFLAGS of these libs to disable thumb mode
209[ ${ANDROID_ABI} = "armeabi-v7a" ] && echo "NOTHUMB := -marm" >> config.mak
210
211# Release or not?
212if [ $# -ne 0 ] && [ "$1" = "release" ]; then
213 OPTS=""
214 EXTRA_CFLAGS="${EXTRA_CFLAGS} -DNDEBUG "
215 RELEASE=1
216else
217 OPTS="--enable-debug"
Tristan Matthews8d02ef62014-07-22 16:03:17 -0400218 EXTRA_CFLAGS="${EXTRA_CFLAGS} -DNDEBUG "
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400219 RELEASE=0
220fi
221
222echo "EXTRA_CFLAGS= -g ${EXTRA_CFLAGS}" >> config.mak
Tristan Matthews676fcee2014-10-03 15:57:09 -0400223echo "EXTRA_LDFLAGS= ${EXTRA_LDFLAGS}" >> config.mak
Tristan Matthews8d02ef62014-07-22 16:03:17 -0400224export SFLPHONE_EXTRA_CFLAGS="${EXTRA_CFLAGS}"
Tristan Matthews676fcee2014-10-03 15:57:09 -0400225export SFLPHONE_EXTRA_LDFLAGS="${EXTRA_LDFLAGS}"
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400226
Alexandre Lision68d8f2e2014-07-30 17:42:40 -0400227make install
Alexandre Lisionec1f3ee2014-08-04 19:12:42 -0400228echo ${PWD}
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400229# We already have zlib available
230[ -e .zlib ] || (mkdir -p zlib; touch .zlib)
231which autopoint >/dev/null || make $MAKEFLAGS .gettext
232export PATH="$PATH:$PWD/../$TARGET_TUPLE/bin"
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400233
Alexandre Lisionec1f3ee2014-08-04 19:12:42 -0400234export SFLPHONE_BUILD_DIR=sflphone/build-android-${TARGET_TUPLE}
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400235############
Tristan Matthews8d02ef62014-07-22 16:03:17 -0400236# Make SFLPHONE #
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400237############
238cd ../.. && mkdir -p build-android-${TARGET_TUPLE} && cd build-android-${TARGET_TUPLE}
239
240if [ $# -eq 1 ] && [ "$1" = "jni" ]; then
241 CLEAN="jniclean"
Tristan Matthews8d02ef62014-07-22 16:03:17 -0400242 TARGET="sflphone-android/obj/local/armeabi-v7a/libsflphone.so"
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400243else
244 CLEAN="distclean"
245 if [ ! -f config.h ]; then
246 echo "Bootstraping"
Tristan Matthews5fcc1462014-09-30 18:19:17 -0400247 cd ../../../
Alexandre Lision40734322014-09-03 14:26:59 -0400248 echo $PWD
Alexandre Lision60057782014-10-03 14:06:01 -0400249 cd sflphone-android
250 ./make-swig.sh
251 cd ..
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
Tristan Matthews5fcc1462014-09-30 18:19:17 -0400256 cd contrib
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