blob: 7f6636eed137afdd799fb301211ffa3798dd33b3 [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
95# Fetch Ring source
96if [ ! -z "$FETCH" ]
97then
Tristan Matthews8d02ef62014-07-22 16:03:17 -040098 # 1/ libsflphone
Tristan Matthewscac21162014-08-11 18:26:40 -040099 TESTED_HASH=f9b3354a49a29f10c466a4d856216c5d82525666
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400100 if [ ! -d "sflphone" ]; then
101 echo "Ring source not found, cloning"
102 git clone git@gitlab.savoirfairelinux.com:sfl-ports/sflphone.git sflphone
103 cd sflphone
104 echo android/ >> .git/info/exclude
105 echo contrib/android/ >> .git/info/exclude
106 #git checkout -B android ${TESTED_HASH}
Alexandre Lisionec1f3ee2014-08-04 19:12:42 -0400107 git checkout contrib
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400108 else
109 echo "Ring source found"
110 cd sflphone
Alexandre Lisionec1f3ee2014-08-04 19:12:42 -0400111 git checkout contrib
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"
196mkdir -p contrib/contrib-android-${TARGET_TUPLE}
197
198gen_pc_file() {
199 echo "Generating $1 pkg-config file"
200 echo "Name: $1
201Description: $1
202Version: $2
203Libs: -l$1
204Cflags:" > contrib/${TARGET_TUPLE}/lib/pkgconfig/`echo $1|tr 'A-Z' 'a-z'`.pc
205}
206
207mkdir -p contrib/${TARGET_TUPLE}/lib/pkgconfig
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400208
209cd 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"
Tristan Matthewscc806e12014-08-01 16:25:03 -0400250 pushd ../../
251 ./configure.sh
Alexandre Lisionec1f3ee2014-08-04 19:12:42 -0400252 cd sflphone/daemon
Tristan Matthewscc806e12014-08-01 16:25:03 -0400253 echo "Building"
254 make $MAKEFLAGS
255 popd
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400256 fi
257 TARGET=
258fi
259
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400260####################################
261# Ring android UI and specific code
262####################################
263echo "Building Ring for Android"
264cd ../../
265
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400266make $CLEAN
267make -j1 TARGET_TUPLE=$TARGET_TUPLE PLATFORM_SHORT_ARCH=$PLATFORM_SHORT_ARCH CXXSTL=$CXXSTL RELEASE=$RELEASE $TARGET
268
269#
270# Exporting a environment script with all the necessary variables
271#
272echo "Generating environment script."
273cat <<EOF
274This is a script that will export many of the variables used in this
275script. It will allow you to compile parts of the build without having
276to rebuild the entire build (e.g. recompile only the Java part).
277
278To use it, include the script into your shell, like this:
279 source env.sh
280
281Now, you can use this command to build the Java portion:
282 make -e
283
284The file will be automatically regenerated by compile.sh, so if you change
285your NDK/SDK locations or any build configurations, just re-run this
286script (sh compile.sh) and it will automatically update the file.
287
288EOF
289
290echo "# This file was automatically generated by compile.sh" > env.sh
291echo "# Re-run 'sh compile.sh' to update this file." >> env.sh
292
293# The essentials
294cat <<EssentialsA >> env.sh
295export ANDROID_ABI=$ANDROID_ABI
296export ANDROID_SDK=$ANDROID_SDK
297export ANDROID_NDK=$ANDROID_NDK
298export GCCVER=$GCCVER
299export CXXSTL=$CXXSTL
300export ANDROID_SYS_HEADERS_GINGERBREAD=$ANDROID_SYS_HEADERS_GINGERBREAD
301export ANDROID_SYS_HEADERS_HC=$ANDROID_SYS_HEADERS_HC
302export ANDROID_SYS_HEADERS_ICS=$ANDROID_SYS_HEADERS_ICS
Tristan Matthews8d02ef62014-07-22 16:03:17 -0400303export SFLPHONE_BUILD_DIR=$PWD/sflphone/android
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400304export TARGET_TUPLE=$TARGET_TUPLE
305export PATH_HOST=$PATH_HOST
306export PLATFORM_SHORT_ARCH=$PLATFORM_SHORT_ARCH
307EssentialsA
308
309# PATH
310echo "export PATH=$NDK_TOOLCHAIN_PATH:\${ANDROID_SDK}/platform-tools:\${PATH}" >> env.sh
311
312# CPU flags
313if [ -n "${HAVE_ARM}" ]; then
314 echo "export HAVE_ARM=1" >> env.sh
315elif [ -n "${HAVE_X86}" ]; then
316 echo "export HAVE_X86=1" >> env.sh
317elif [ -n "${HAVE_MIPS}" ]; then
318 echo "export HAVE_MIPS=1" >> env.sh
319fi
320
321if [ -n "${NO_ARMV6}" ]; then
322 echo "export NO_ARMV6=1" >> env.sh
323fi
324if [ -n "${NO_FPU}" ]; then
325 echo "export NO_FPU=1" >> env.sh
326fi