blob: 264626bf9f226102597603fd32c45162221f11aa [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
99 TESTED_HASH=f4f162d3e503fad882f332d95386dbc04157d463
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}
107 git checkout contrib
108 else
109 echo "Ring source found"
110 cd sflphone
111 git checkout contrib
112# 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}
210../bootstrap --host=${TARGET_TUPLE}
211
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 Lision43b9aeb2014-07-15 14:21:19 -0400231# We already have zlib available
232[ -e .zlib ] || (mkdir -p zlib; touch .zlib)
233which autopoint >/dev/null || make $MAKEFLAGS .gettext
234export PATH="$PATH:$PWD/../$TARGET_TUPLE/bin"
235make $MAKEFLAGS
236
237############
Tristan Matthews8d02ef62014-07-22 16:03:17 -0400238# Make SFLPHONE #
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400239############
240cd ../.. && mkdir -p build-android-${TARGET_TUPLE} && cd build-android-${TARGET_TUPLE}
241
242if [ $# -eq 1 ] && [ "$1" = "jni" ]; then
243 CLEAN="jniclean"
Tristan Matthews8d02ef62014-07-22 16:03:17 -0400244 TARGET="sflphone-android/obj/local/armeabi-v7a/libsflphone.so"
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400245else
246 CLEAN="distclean"
247 if [ ! -f config.h ]; then
248 echo "Bootstraping"
249 ../bootstrap
250 echo "Configuring"
251 ${ANDROID_PATH}/configure.sh $OPTS
252 fi
253 TARGET=
254fi
255
256echo "Building"
257make $MAKEFLAGS
258
259####################################
260# Ring android UI and specific code
261####################################
262echo "Building Ring for Android"
263cd ../../
264
265export ANDROID_SYS_HEADERS_GINGERBREAD=${PWD}/android-headers-gingerbread
266export ANDROID_SYS_HEADERS_HC=${PWD}/android-headers-hc
267export ANDROID_SYS_HEADERS_ICS=${PWD}/android-headers-ics
268
269export ANDROID_LIBS=${PWD}/android-libs
Tristan Matthews8d02ef62014-07-22 16:03:17 -0400270export SFLPHONE_BUILD_DIR=sflphone/build-android-${TARGET_TUPLE}
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400271
272make $CLEAN
273make -j1 TARGET_TUPLE=$TARGET_TUPLE PLATFORM_SHORT_ARCH=$PLATFORM_SHORT_ARCH CXXSTL=$CXXSTL RELEASE=$RELEASE $TARGET
274
275#
276# Exporting a environment script with all the necessary variables
277#
278echo "Generating environment script."
279cat <<EOF
280This is a script that will export many of the variables used in this
281script. It will allow you to compile parts of the build without having
282to rebuild the entire build (e.g. recompile only the Java part).
283
284To use it, include the script into your shell, like this:
285 source env.sh
286
287Now, you can use this command to build the Java portion:
288 make -e
289
290The file will be automatically regenerated by compile.sh, so if you change
291your NDK/SDK locations or any build configurations, just re-run this
292script (sh compile.sh) and it will automatically update the file.
293
294EOF
295
296echo "# This file was automatically generated by compile.sh" > env.sh
297echo "# Re-run 'sh compile.sh' to update this file." >> env.sh
298
299# The essentials
300cat <<EssentialsA >> env.sh
301export ANDROID_ABI=$ANDROID_ABI
302export ANDROID_SDK=$ANDROID_SDK
303export ANDROID_NDK=$ANDROID_NDK
304export GCCVER=$GCCVER
305export CXXSTL=$CXXSTL
306export ANDROID_SYS_HEADERS_GINGERBREAD=$ANDROID_SYS_HEADERS_GINGERBREAD
307export ANDROID_SYS_HEADERS_HC=$ANDROID_SYS_HEADERS_HC
308export ANDROID_SYS_HEADERS_ICS=$ANDROID_SYS_HEADERS_ICS
309export ANDROID_LIBS=$ANDROID_LIBS
Tristan Matthews8d02ef62014-07-22 16:03:17 -0400310export SFLPHONE_BUILD_DIR=$PWD/sflphone/android
Alexandre Lision43b9aeb2014-07-15 14:21:19 -0400311export TARGET_TUPLE=$TARGET_TUPLE
312export PATH_HOST=$PATH_HOST
313export PLATFORM_SHORT_ARCH=$PLATFORM_SHORT_ARCH
314EssentialsA
315
316# PATH
317echo "export PATH=$NDK_TOOLCHAIN_PATH:\${ANDROID_SDK}/platform-tools:\${PATH}" >> env.sh
318
319# CPU flags
320if [ -n "${HAVE_ARM}" ]; then
321 echo "export HAVE_ARM=1" >> env.sh
322elif [ -n "${HAVE_X86}" ]; then
323 echo "export HAVE_X86=1" >> env.sh
324elif [ -n "${HAVE_MIPS}" ]; then
325 echo "export HAVE_MIPS=1" >> env.sh
326fi
327
328if [ -n "${NO_ARMV6}" ]; then
329 echo "export NO_ARMV6=1" >> env.sh
330fi
331if [ -n "${NO_FPU}" ]; then
332 echo "export NO_FPU=1" >> env.sh
333fi