]> sigrok.org Git - sigrok-util.git/blame - cross-compile/android/sigrok-cross-android
sigrok-cross-linux: Extract archives silently.
[sigrok-util.git] / cross-compile / android / sigrok-cross-android
CommitLineData
0832e7d6
UH
1#!/bin/bash
2##
3## This file is part of the sigrok-util project.
4##
25b2b9f5 5## Copyright (C) 2013-2014 Uwe Hermann <uwe@hermann-uwe.de>
0832e7d6
UH
6##
7## This program is free software; you can redistribute it and/or modify
8## it under the terms of the GNU General Public License as published by
9## the Free Software Foundation; either version 2 of the License, or
10## (at your option) any later version.
11##
12## This program is distributed in the hope that it will be useful,
13## but WITHOUT ANY WARRANTY; without even the implied warranty of
14## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15## GNU General Public License for more details.
16##
17## You should have received a copy of the GNU General Public License
18## along with this program; if not, write to the Free Software
19## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20##
21
c28fee03
MC
22set -e
23
e25d7d5a 24# The path where the Android NDK is located.
878f60b0 25ANDROID_NDK=$HOME/android/android-ndk-r10c
11b9792e 26
e25d7d5a 27# The path where the Android SDK is located.
b7f669dd 28ANDROID_SDK=$HOME/android/android-sdk-linux
11b9792e 29
0832e7d6
UH
30# The path where your Android toolchain directory is located.
31TOOLCHAIN=$HOME/android/android-arm-toolchain
e2bb3ab1
UH
32# TOOLCHAIN=$HOME/android/android-mipsel-toolchain
33# TOOLCHAIN=$HOME/android/android-i686-toolchain
34
35# Select which Android toolchain to use.
36# Don't forget to also adapt TOOLCHAIN above if you change TOOLCHAIN_TRIPLET!
37TOOLCHAIN_TRIPLET=arm-linux-androideabi
38# TOOLCHAIN_TRIPLET=mipsel-linux-android
39# TOOLCHAIN_TRIPLET=i686-linux-android
0832e7d6
UH
40
41# The path where the cross-compiled packages will be installed.
42PREFIX=$HOME/sr_android
43
44# The path where to download files to and where to build packages.
07947dda 45BUILDDIR=./build
0832e7d6 46
819eb05b
UH
47# Edit this to enable/disable/modify parallel compiles.
48PARALLEL="-j 2"
49
0832e7d6
UH
50# You usually don't need to change anything below this line.
51
52# -----------------------------------------------------------------------------
53
54VER_LIBICONV=1.14
d4069d6e 55VER_GETTEXT=0.19.2
b118df5f 56VER_ZLIB=1.2.8
d4069d6e
UH
57VER_PCRE=8.35
58VER_LIBFFI=3.1
59VER_GLIB=2.41.3
60VER_GLIB_SHORT=2.41
61VER_LIBSIGCXX=2.3.2
62VER_LIBSIGCXX_SHORT=2.3
63VER_LIBZIP=0.11.2
7966c37c 64VER_LIBFTDI1=1.1
d4069d6e 65VER_LIBUSB=1.0.19
5451bfe2 66VER_PYTHON=3.3.3
11b9792e 67VER_BOOST=1.55.0
2256009e 68VER_QT=5.3.1
0832e7d6
UH
69
70SF_MIRROR=switch.dl.sourceforge.net
71
ec49447e 72WGET="wget --quiet"
a51ca6bd 73GIT_CLONE="git clone --depth=1"
ec49447e 74
7966c37c
MC
75case "$TOOLCHAIN_TRIPLET" in
76 arm*) TARGET_ARCH=armeabi;;
77 mips*) TARGET_ARCH=mips;;
78 i686*) TARGET_ARCH=x86;;
e25d7d5a 79 *) echo >&2 "Unknown prefix for TOOLCHAIN_TRIPLET."; exit 1;;
7966c37c
MC
80esac
81
0832e7d6
UH
82# -----------------------------------------------------------------------------
83
2e353a08
ML
84# Remove build directory contents (if any) and create a new build dir.
85rm -rf $BUILDDIR
86mkdir $BUILDDIR
87cd $BUILDDIR
88
e25d7d5a
UH
89# -----------------------------------------------------------------------------
90
2e353a08 91# Build host Python before we start messing with the environment.
510f5ccb 92# Don't do parallel builds, this doesn't seem to work well.
ec49447e 93$WGET http://python.org/ftp/python/$VER_PYTHON/Python-$VER_PYTHON.tar.xz
25b2b9f5 94tar xfJ Python-$VER_PYTHON.tar.xz
5451bfe2 95cd Python-$VER_PYTHON
2e353a08 96./configure
510f5ccb 97make python
2e353a08 98mv python hostpython
2e353a08
ML
99cd ..
100
101# -----------------------------------------------------------------------------
102
103# We need to find tools in the toolchain.
104export PATH=$TOOLCHAIN/bin:$PATH
0832e7d6 105
02c87af2 106# Tell pkg-config to only look for our cross-built stuff.
226830e4
MC
107export PKG_CONFIG_LIBDIR="$PREFIX/lib/pkgconfig"
108export -n PKG_CONFIG_PATH
109
0832e7d6 110# Define some helper variables.
e2bb3ab1 111C="--host=$TOOLCHAIN_TRIPLET --prefix=$PREFIX"
7966c37c 112CM="-Wno-dev -DCMAKE_TOOLCHAIN_FILE=../android.toolchain.cmake -DANDROID_ABI=${TARGET_ARCH} -DCMAKE_INSTALL_PREFIX=${PREFIX} -DANDROID_STANDALONE_TOOLCHAIN=${TOOLCHAIN}"
0832e7d6 113
2fddc139
MC
114# Look for STL, needed to build bindings
115NDK_TOOLCHAIN_VERSION=`${TOOLCHAIN_TRIPLET}-gcc --version | head -1 | sed -e 's/.* \([0-9]\+\.[0-9.]\+\)\( \|.*\)$/\1/'`
116STL_BASE="${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/${NDK_TOOLCHAIN_VERSION}"
117if [ -d ${STL_BASE}/include ]; then
118 CPPFLAGS_STL="-I${STL_BASE}/include -I${STL_BASE}/libs/${TARGET_ARCH}/include"
119 LDFLAGS_STL="-L${STL_BASE}/libs/${TARGET_ARCH} -Wl,-rpath=${STL_BASE}/libs/${TARGET_ARCH}"
120 BINDINGS_CONFIG="--enable-bindings"
121else
122 echo "Warning: STL unavailable, libsigrok bindings will not be built."
123 CPPFLAGS_STL=
124 LDFLAGS_STL=
125 BINDINGS_CONFIG="--disable-bindings"
126fi
127
e25d7d5a
UH
128# -----------------------------------------------------------------------------
129
0832e7d6 130# Get the latest versions of config.guess/config.sub that know about Android.
a51ca6bd 131$GIT_CLONE git://git.savannah.gnu.org/config.git
0832e7d6 132
e25d7d5a
UH
133# Get a toolchain for cmake that knows about Android.
134$WGET https://android-cmake.googlecode.com/hg/toolchain/android.toolchain.cmake
7966c37c
MC
135patch < ../android.toolchain.cmake.patch android.toolchain.cmake
136
0832e7d6
UH
137# -----------------------------------------------------------------------------
138
f7b8aa73 139# Python (needed for libsigrokdecode)
510f5ccb 140# Don't do parallel Python builds, this doesn't seem to work well.
f7b8aa73
UH
141cd Python-$VER_PYTHON
142make distclean
143autoreconf
144patch -p1 < ../../Python-$VER_PYTHON.patch
145ac_cv_file__dev_ptmx=no ac_cv_file__dev_ptc=no ac_cv_func_pipe2=no ac_cv_func_fdatasync=no ac_cv_func_killpg=no ac_cv_func_waitid=no ac_cv_func_sigaltstack=no ./configure $C --build=x86_64-linux-gnu --disable-ipv6
9a98e0d1 146sed -i "s/^#zlib/zlib/g" Modules/Setup
510f5ccb 147make PYTHON_FOR_BUILD=./hostpython install
f7b8aa73
UH
148cd ..
149
85b46172 150# libiconv (needed for glib)
ec49447e 151$WGET http://ftp.gnu.org/pub/gnu/libiconv/libiconv-$VER_LIBICONV.tar.gz
85b46172
MC
152tar xfz libiconv-$VER_LIBICONV.tar.gz
153cd libiconv-$VER_LIBICONV
154cp -f ../config/config.guess build-aux
155cp -f ../config/config.sub build-aux
156cp -f ../config/config.guess libcharset/build-aux
157cp -f ../config/config.sub libcharset/build-aux
158./configure $C --enable-shared
159make lib/localcharset.h
160cd libcharset
819eb05b 161make $PARALLEL
85b46172
MC
162make install
163cd ../lib
819eb05b 164make $PARALLEL
85b46172
MC
165make install
166cd ..
167test -d $PREFIX/include || mkdir $PREFIX/include
168cp include/iconv.h.inst $PREFIX/include/iconv.h
169cd ..
0832e7d6 170
87ea3974 171# gettext (needed for glib)
ec49447e 172$WGET http://ftp.gnu.org/pub/gnu/gettext/gettext-$VER_GETTEXT.tar.gz
87ea3974
MC
173tar xfz gettext-$VER_GETTEXT.tar.gz
174cd gettext-$VER_GETTEXT
175./configure $C --enable-shared --disable-libasprintf
176cd gettext-runtime
819eb05b 177make $PARALLEL
87ea3974
MC
178make install
179cd ../..
0832e7d6
UH
180
181# zlib (needed for glib and libzip)
ec49447e 182$WGET http://zlib.net/zlib-$VER_ZLIB.tar.gz
25b2b9f5 183tar xfz zlib-$VER_ZLIB.tar.gz
167cb16e
UH
184cd zlib-$VER_ZLIB
185# Note: zlib's configure doesn't understand --host, we need to pass $CC.
e2bb3ab1 186CC=$TOOLCHAIN_TRIPLET-gcc ./configure --prefix=$PREFIX
819eb05b 187make $PARALLEL
c28fee03 188make install
167cb16e 189cd ..
0832e7d6
UH
190
191# pcre (needed for glib)
ec49447e 192$WGET ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-$VER_PCRE.tar.gz
25b2b9f5 193tar xfz pcre-$VER_PCRE.tar.gz
85c9910a 194cd pcre-$VER_PCRE
091ed535 195./configure $C --disable-cpp
819eb05b 196make $PARALLEL
c28fee03 197make install
85c9910a 198cd ..
0832e7d6
UH
199
200# libffi (needed for glib)
ec49447e 201$WGET ftp://sourceware.org/pub/libffi/libffi-$VER_LIBFFI.tar.gz
0832e7d6
UH
202tar xfz libffi-$VER_LIBFFI.tar.gz
203cd libffi-$VER_LIBFFI
c28fee03 204./configure $C
819eb05b 205make $PARALLEL
c28fee03 206make install
0832e7d6
UH
207cd ..
208
e25d7d5a 209# glib (needed for libsigrok)
ec49447e 210$WGET http://ftp.gnome.org/pub/gnome/sources/glib/$VER_GLIB_SHORT/glib-$VER_GLIB.tar.xz
25b2b9f5 211tar xfJ glib-$VER_GLIB.tar.xz
f7b8aa73 212cd glib-$VER_GLIB
f0e760bb 213./autogen.sh
559be0ff 214# Note: Manual LDFLAGS/CPPFLAGS needed for libiconv, rest uses pkg-config.
e2bb3ab1 215LDFLAGS=-L$PREFIX/lib CPPFLAGS=-I$PREFIX/include glib_cv_stack_grows=no glib_cv_uscore=no ac_cv_func_posix_getpwuid_r=no ac_cv_func_posix_getgrgid_r=no ./configure --disable-compile-warnings $C
819eb05b 216make $PARALLEL
f0e760bb
MC
217make install
218cd ..
0832e7d6 219
e25d7d5a 220# libzip (needed for libsigrok)
ec49447e 221$WGET http://www.nih.at/libzip/libzip-$VER_LIBZIP.tar.gz
0832e7d6
UH
222tar xfz libzip-$VER_LIBZIP.tar.gz
223cd libzip-$VER_LIBZIP
224cp -f ../config/config.guess .
225cp -f ../config/config.sub .
c28fee03 226./configure $C
819eb05b 227make $PARALLEL
c28fee03 228make install
0832e7d6
UH
229cd ..
230
e25d7d5a 231# libusb-1.0 (needed for libsigrok)
d4069d6e
UH
232$WGET http://$SF_MIRROR/project/libusb/libusb-1.0/libusb-$VER_LIBUSB/libusb-$VER_LIBUSB.tar.bz2
233tar xfj libusb-$VER_LIBUSB.tar.bz2
234cd libusb-$VER_LIBUSB
c09c85b3 235patch -p1 < ../../libusb-1.0.patch
6907ee7e 236./configure $C --disable-udev
819eb05b 237make $PARALLEL
13b2dfdc
MC
238make install
239cd ..
240
e25d7d5a 241# libftdi1 (needed for libsigrok)
7966c37c
MC
242$WGET http://www.intra2net.com/en/developer/libftdi/download/libftdi1-$VER_LIBFTDI1.tar.bz2
243tar xfj libftdi1-$VER_LIBFTDI1.tar.bz2
244cd libftdi1-$VER_LIBFTDI1
2fddc139 245cmake $CM -DFTDIPP=OFF .
7966c37c
MC
246make $PARALLEL
247make install
248cd ..
249
900a8684 250# libserialport
a51ca6bd 251$GIT_CLONE git://sigrok.org/libserialport
900a8684
ML
252cd libserialport
253./autogen.sh
67b2de8a
UH
254mkdir build
255cd build
256../configure $C
83b801db 257make $PARALLEL V=1
900a8684 258make install
67b2de8a 259cd ../..
900a8684 260
2fddc139
MC
261# Build dependencies for libsigrok bindings if needed
262
263if [ x"$CPPFLAGS_STL" != x ]; then
264
265 # libsigc++ (needed for glibmm)
266 $WGET http://ftp.gnome.org/pub/gnome/sources/libsigc++/$VER_LIBSIGCXX_SHORT/libsigc++-$VER_LIBSIGCXX.tar.xz
25b2b9f5 267 tar xfJ libsigc++-$VER_LIBSIGCXX.tar.xz
2fddc139
MC
268 cd libsigc++-$VER_LIBSIGCXX
269 cp -f ../config/config.guess build
270 cp -f ../config/config.sub build
271 CPPFLAGS="$CPPFLAGS_STL" LDFLAGS="$LDFLAGS_STL -lgnustl_shared" ./configure $C
272 make $PARALLEL
273 make install
274 cd ..
275
276 # glibmm (needed for libsigrok bindings)
277 $WGET http://ftp.gnome.org/pub/gnome/sources/glibmm/$VER_GLIB_SHORT/glibmm-$VER_GLIB.tar.xz
25b2b9f5 278 tar xfJ glibmm-$VER_GLIB.tar.xz
2fddc139
MC
279 cd glibmm-$VER_GLIB
280 CPPFLAGS="$CPPFLAGS_STL" LDFLAGS="$LDFLAGS_STL -lgnustl_shared" ./configure $C
281 make $PARALLEL
282 make install
283 cd ..
284
285fi
286
c062d1dc 287# libsigrok
a51ca6bd 288$GIT_CLONE git://sigrok.org/libsigrok
c062d1dc
MC
289cd libsigrok
290./autogen.sh
67b2de8a
UH
291mkdir build
292cd build
293CPPFLAGS="$CPPFLAGS_STL" LDFLAGS="$LDFLAGS_STL" ../configure $C $BINDINGS_CONFIG --datadir=/sdcard
83b801db 294make $PARALLEL V=1
2fddc139 295make datadir='$(datarootdir)' install
67b2de8a 296cd ../..
02c87af2 297
2fbea156 298# libsigrokdecode
a51ca6bd 299$GIT_CLONE git://sigrok.org/libsigrokdecode
2fbea156
ML
300cd libsigrokdecode
301./autogen.sh
67b2de8a
UH
302mkdir build
303cd build
304../configure $C
83b801db 305make $PARALLEL V=1
2fbea156 306make install
67b2de8a 307cd ../..
2fbea156
ML
308
309# sigrok-cli
a51ca6bd 310$GIT_CLONE git://sigrok.org/sigrok-cli
2fbea156
ML
311cd sigrok-cli
312./autogen.sh
67b2de8a
UH
313mkdir build
314cd build
315../configure $C
83b801db 316make $PARALLEL V=1
2fbea156 317make install
67b2de8a 318cd ../..
819eb05b 319
e25d7d5a 320# Check if we have all requirements to build PulseView:
11b9792e
MC
321
322if [ -z "$ANDROID_NDK" -o ! -d "$ANDROID_NDK" ]; then
e25d7d5a 323 echo "Android NDK not available, not building PulseView."
11b9792e
MC
324 exit 0
325fi
326
e25d7d5a
UH
327if [ -z "$ANDROID_SDK" -o \
328 ! -d "$ANDROID_SDK"/platforms/android-8 -o \
7b888971
MC
329 ! -d "$ANDROID_SDK"/platforms/android-10 -o \
330 ! -d "$ANDROID_SDK"/platforms/android-11 -o \
331 ! -d "$ANDROID_SDK"/platforms/android-14 -o \
332 ! -d "$ANDROID_SDK"/platforms/android-16 ]; then
e25d7d5a 333 echo "Android SDK with platforms 8 10 11 14 16 not available, not building PulseView."
11b9792e
MC
334 exit 0
335fi
336
e25d7d5a
UH
337if [ ! -e "${ANDROID_SDK}/tools/android" ]; then
338 echo "Essential Android build tools not available, not building PulseView."
11b9792e
MC
339 exit 0
340fi
341
11b9792e
MC
342NDK_HOST=`"$ANDROID_NDK/ndk-build" -p 2>/dev/null | awk '$1 == "HOST_TAG" { print $3 }'`
343
e25d7d5a 344# Boost (needed for PulseView)
11b9792e
MC
345$WGET http://$SF_MIRROR/project/boost/boost/$VER_BOOST/boost_${VER_BOOST//./_}.tar.bz2
346tar xfj boost_${VER_BOOST//./_}.tar.bz2
347cd boost_${VER_BOOST//./_}
348patch -p1 < ../../boost.patch
7744cf5c 349./bootstrap.sh --with-toolset=gcc --with-libraries=filesystem,system --without-icu
2fddc139 350echo "using gcc : $NDK_TOOLCHAIN_VERSION : \"${TOOLCHAIN_TRIPLET}-g++\" : <cxxflags>\"-I$PREFIX/include $CPPFLAGS_STL\" <linkflags>\"-L$PREFIX/lib $LDFLAGS_STL -lgnustl_shared\" ;" > user-config.jam
ea9301bf 351./b2 -q -d+2 --user-config=user-config.jam toolset=gcc variant=release link=shared threading=multi runtime-link=shared target-os=android --prefix=$PREFIX --layout=system install $PARALLEL
11b9792e
MC
352cd ..
353
e25d7d5a 354# Qt (needed for PulseView)
7b888971
MC
355$WGET http://download.qt-project.org/official_releases/qt/${VER_QT%.*}/${VER_QT}/single/qt-everywhere-opensource-src-${VER_QT}.tar.gz
356tar xfz qt-everywhere-opensource-src-${VER_QT}.tar.gz
357cd qt-everywhere-opensource-src-${VER_QT}
11b9792e 358patch -p1 < ../../android-qt.patch
2256009e 359./configure --prefix="$PREFIX" -developer-build -xplatform android-g++ -nomake tests -nomake examples -android-sdk "$ANDROID_SDK" -android-ndk "$ANDROID_NDK" -android-ndk-host "$NDK_HOST" -android-arch "$TARGET_ARCH" -android-toolchain-version "$NDK_TOOLCHAIN_VERSION" -skip qttranslations -skip qtwebkit -skip qtserialport -skip qtwebkit-examples -skip qtlocation -skip qtconnectivity -opensource -confirm-license
30adf6b9 360make module-qtbase module-qtandroidextras module-qtsvg module-qtimageformats $PARALLEL
7b888971 361make install
11b9792e 362cd ..
5d1a9a53 363
7d3d2c0c 364# sigrok-androidutils
621e2e6e 365$GIT_CLONE git://sigrok.org/sigrok-androidutils
7d3d2c0c
MC
366cd sigrok-androidutils
367./autogen.sh
368./configure $C --with-android-sdk="${ANDROID_SDK}"
bb260ef2 369make $PARALLEL V=1
7d3d2c0c
MC
370make install
371cd ..
372
5d1a9a53 373# PulseView
621e2e6e 374$GIT_CLONE git://sigrok.org/pulseview
5d1a9a53 375cd pulseview
0c5c3b89 376cmake $CM -DANDROID_STL_PATH=${ANDROID_NDK}/sources/cxx-stl .
bb260ef2 377make $PARALLEL VERBOSE=1
1238f785 378cd android
e25d7d5a 379"${ANDROID_SDK}/tools/android" update project -p . -t android-14 -n PulseView
aef0361e
MC
380ant debug
381cd ../..
e25d7d5a 382