]> sigrok.org Git - sigrok-util.git/blame_incremental - cross-compile/android/sigrok-cross-android
sigrok-cross-android: Enable parallel and verbose builds.
[sigrok-util.git] / cross-compile / android / sigrok-cross-android
... / ...
CommitLineData
1#!/bin/bash
2##
3## This file is part of the sigrok-util project.
4##
5## Copyright (C) 2013 Uwe Hermann <uwe@hermann-uwe.de>
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
22set -e
23
24# The path where the Android NDK is located.
25ANDROID_NDK=$HOME/android/android-ndk-r9d
26
27# The path where the Android SDK is located.
28ANDROID_SDK=$HOME/android/android-sdk-linux
29
30# The path where your Android toolchain directory is located.
31TOOLCHAIN=$HOME/android/android-arm-toolchain
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
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.
45BUILDDIR=./build
46
47# Edit this to enable/disable/modify parallel compiles.
48PARALLEL="-j 2"
49
50# You usually don't need to change anything below this line.
51
52# -----------------------------------------------------------------------------
53
54VER_LIBICONV=1.14
55VER_GETTEXT=0.18.3
56VER_ZLIB=1.2.8
57VER_PCRE=8.33
58VER_LIBFFI=3.0.13
59VER_GLIB=2.38.2
60VER_GLIB_SHORT=2.38
61VER_LIBZIP=0.11.1
62VER_LIBFTDI1=1.1
63VER_LIBUSBX=1.0.17
64VER_PYTHON=3.3.3
65VER_BOOST=1.55.0
66VER_QT=5.3.1
67
68SF_MIRROR=switch.dl.sourceforge.net
69
70WGET="wget --quiet"
71GIT_CLONE="git clone --depth=1"
72
73case "$TOOLCHAIN_TRIPLET" in
74 arm*) TARGET_ARCH=armeabi;;
75 mips*) TARGET_ARCH=mips;;
76 i686*) TARGET_ARCH=x86;;
77 *) echo >&2 "Unknown prefix for TOOLCHAIN_TRIPLET."; exit 1;;
78esac
79
80# -----------------------------------------------------------------------------
81
82# Remove build directory contents (if any) and create a new build dir.
83rm -rf $BUILDDIR
84mkdir $BUILDDIR
85cd $BUILDDIR
86
87# -----------------------------------------------------------------------------
88
89# Build host Python before we start messing with the environment.
90$WGET http://python.org/ftp/python/$VER_PYTHON/Python-$VER_PYTHON.tar.xz
91tar xJf Python-$VER_PYTHON.tar.xz
92cd Python-$VER_PYTHON
93./configure
94make python $PARALLEL
95mv python hostpython
96cd ..
97
98# -----------------------------------------------------------------------------
99
100# We need to find tools in the toolchain.
101export PATH=$TOOLCHAIN/bin:$PATH
102
103# Tell pkg-config to only look for our cross-built stuff.
104export PKG_CONFIG_LIBDIR="$PREFIX/lib/pkgconfig"
105export -n PKG_CONFIG_PATH
106
107# Define some helper variables.
108C="--host=$TOOLCHAIN_TRIPLET --prefix=$PREFIX"
109CM="-Wno-dev -DCMAKE_TOOLCHAIN_FILE=../android.toolchain.cmake -DANDROID_ABI=${TARGET_ARCH} -DCMAKE_INSTALL_PREFIX=${PREFIX} -DANDROID_STANDALONE_TOOLCHAIN=${TOOLCHAIN}"
110
111# -----------------------------------------------------------------------------
112
113# Get the latest versions of config.guess/config.sub that know about Android.
114$GIT_CLONE git://git.savannah.gnu.org/config.git
115
116# Get a toolchain for cmake that knows about Android.
117$WGET https://android-cmake.googlecode.com/hg/toolchain/android.toolchain.cmake
118patch < ../android.toolchain.cmake.patch android.toolchain.cmake
119
120# -----------------------------------------------------------------------------
121
122# Python (needed for libsigrokdecode)
123cd Python-$VER_PYTHON
124make distclean
125autoreconf
126patch -p1 < ../../Python-$VER_PYTHON.patch
127ac_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
128sed -i "s/^#zlib/zlib/g" Modules/Setup
129make PYTHON_FOR_BUILD=./hostpython install $PARALLEL
130cd ..
131
132# libiconv (needed for glib)
133$WGET http://ftp.gnu.org/pub/gnu/libiconv/libiconv-$VER_LIBICONV.tar.gz
134tar xfz libiconv-$VER_LIBICONV.tar.gz
135cd libiconv-$VER_LIBICONV
136cp -f ../config/config.guess build-aux
137cp -f ../config/config.sub build-aux
138cp -f ../config/config.guess libcharset/build-aux
139cp -f ../config/config.sub libcharset/build-aux
140./configure $C --enable-shared
141make lib/localcharset.h
142cd libcharset
143make $PARALLEL
144make install
145cd ../lib
146make $PARALLEL
147make install
148cd ..
149test -d $PREFIX/include || mkdir $PREFIX/include
150cp include/iconv.h.inst $PREFIX/include/iconv.h
151cd ..
152
153# gettext (needed for glib)
154$WGET http://ftp.gnu.org/pub/gnu/gettext/gettext-$VER_GETTEXT.tar.gz
155tar xfz gettext-$VER_GETTEXT.tar.gz
156cd gettext-$VER_GETTEXT
157./configure $C --enable-shared --disable-libasprintf
158cd gettext-runtime
159make $PARALLEL
160make install
161cd ../..
162
163# zlib (needed for glib and libzip)
164$WGET http://zlib.net/zlib-$VER_ZLIB.tar.gz
165tar xfvz zlib-$VER_ZLIB.tar.gz
166cd zlib-$VER_ZLIB
167# Note: zlib's configure doesn't understand --host, we need to pass $CC.
168CC=$TOOLCHAIN_TRIPLET-gcc ./configure --prefix=$PREFIX
169make $PARALLEL
170make install
171cd ..
172
173# pcre (needed for glib)
174$WGET ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-$VER_PCRE.tar.gz
175tar xfvz pcre-$VER_PCRE.tar.gz
176cd pcre-$VER_PCRE
177./configure $C --disable-cpp
178make $PARALLEL
179make install
180cd ..
181
182# libffi (needed for glib)
183$WGET ftp://sourceware.org/pub/libffi/libffi-$VER_LIBFFI.tar.gz
184tar xfz libffi-$VER_LIBFFI.tar.gz
185cd libffi-$VER_LIBFFI
186./configure $C
187make $PARALLEL
188make install
189cd ..
190
191# glib (needed for libsigrok)
192$WGET http://ftp.gnome.org/pub/gnome/sources/glib/$VER_GLIB_SHORT/glib-$VER_GLIB.tar.xz
193tar xJf glib-$VER_GLIB.tar.xz
194cd glib-$VER_GLIB
195./autogen.sh
196# Note: Manual LDFLAGS/CPPFLAGS needed for libiconv, rest uses pkg-config.
197LDFLAGS=-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
198make $PARALLEL
199make install
200cd ..
201
202# libzip (needed for libsigrok)
203$WGET http://www.nih.at/libzip/libzip-$VER_LIBZIP.tar.gz
204tar xfz libzip-$VER_LIBZIP.tar.gz
205cd libzip-$VER_LIBZIP
206cp -f ../config/config.guess .
207cp -f ../config/config.sub .
208./configure $C
209make $PARALLEL
210make install
211cd ..
212
213# libusb-1.0 (needed for libsigrok)
214$WGET http://$SF_MIRROR/project/libusbx/releases/$VER_LIBUSBX/source/libusbx-$VER_LIBUSBX.tar.bz2
215tar xfj libusbx-$VER_LIBUSBX.tar.bz2
216cd libusbx-$VER_LIBUSBX
217patch -p1 < ../../libusb-1.0.patch
218./configure $C --disable-udev
219make $PARALLEL
220make install
221cd ..
222
223# libftdi1 (needed for libsigrok)
224$WGET http://www.intra2net.com/en/developer/libftdi/download/libftdi1-$VER_LIBFTDI1.tar.bz2
225tar xfj libftdi1-$VER_LIBFTDI1.tar.bz2
226cd libftdi1-$VER_LIBFTDI1
227cmake $CM .
228make $PARALLEL
229make install
230cd ..
231
232# libserialport
233$GIT_CLONE git://sigrok.org/libserialport
234cd libserialport
235./autogen.sh
236./configure $C
237make $PARALLEL V=1
238make install
239cd ..
240
241# libsigrok
242$GIT_CLONE git://sigrok.org/libsigrok
243cd libsigrok
244./autogen.sh
245./configure $C --datadir=/sdcard
246make $PARALLEL V=1
247make install
248cd ..
249
250# libsigrokdecode
251$GIT_CLONE git://sigrok.org/libsigrokdecode
252cd libsigrokdecode
253./autogen.sh
254./configure $C
255make $PARALLEL V=1
256make install
257cd ..
258
259# sigrok-cli
260$GIT_CLONE git://sigrok.org/sigrok-cli
261cd sigrok-cli
262./autogen.sh
263./configure $C
264make $PARALLEL V=1
265make install
266cd ..
267
268# Check if we have all requirements to build PulseView:
269
270if [ -z "$ANDROID_NDK" -o ! -d "$ANDROID_NDK" ]; then
271 echo "Android NDK not available, not building PulseView."
272 exit 0
273fi
274
275if [ -z "$ANDROID_SDK" -o \
276 ! -d "$ANDROID_SDK"/platforms/android-8 -o \
277 ! -d "$ANDROID_SDK"/platforms/android-10 -o \
278 ! -d "$ANDROID_SDK"/platforms/android-11 -o \
279 ! -d "$ANDROID_SDK"/platforms/android-14 -o \
280 ! -d "$ANDROID_SDK"/platforms/android-16 ]; then
281 echo "Android SDK with platforms 8 10 11 14 16 not available, not building PulseView."
282 exit 0
283fi
284
285if [ ! -e "${ANDROID_SDK}/tools/android" ]; then
286 echo "Essential Android build tools not available, not building PulseView."
287 exit 0
288fi
289
290NDK_TOOLCHAIN_VERSION=`${TOOLCHAIN_TRIPLET}-gcc --version | head -1 | sed -e 's/.* \([0-9]\+\.[0-9.]\+\)\( \|.*\)$/\1/'`
291NDK_HOST=`"$ANDROID_NDK/ndk-build" -p 2>/dev/null | awk '$1 == "HOST_TAG" { print $3 }'`
292
293# Boost (needed for PulseView)
294$WGET http://$SF_MIRROR/project/boost/boost/$VER_BOOST/boost_${VER_BOOST//./_}.tar.bz2
295tar xfj boost_${VER_BOOST//./_}.tar.bz2
296cd boost_${VER_BOOST//./_}
297patch -p1 < ../../boost.patch
298./bootstrap.sh --with-toolset=gcc --with-libraries=filesystem,system --without-icu
299echo "using gcc : $NDK_TOOLCHAIN_VERSION : \"${TOOLCHAIN_TRIPLET}-g++\" : <cxxflags>\"-I$PREFIX/include -I${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/${NDK_TOOLCHAIN_VERSION}/include -I${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/${NDK_TOOLCHAIN_VERSION}/libs/${TARGET_ARCH}/include\" <linkflags>\"-L$PREFIX/lib -L${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/${NDK_TOOLCHAIN_VERSION}/libs/${TARGET_ARCH} -Wl,-rpath=${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/${NDK_TOOLCHAIN_VERSION}/libs/${TARGET_ARCH} -lgnustl_shared\" ;" > user-config.jam
300./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
301cd ..
302
303# Qt (needed for PulseView)
304$WGET http://download.qt-project.org/official_releases/qt/${VER_QT%.*}/${VER_QT}/single/qt-everywhere-opensource-src-${VER_QT}.tar.gz
305tar xfz qt-everywhere-opensource-src-${VER_QT}.tar.gz
306cd qt-everywhere-opensource-src-${VER_QT}
307patch -p1 < ../../android-qt.patch
308./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
309make $PARALLEL
310make install
311cd ..
312
313# sigrok-androidutils
314$GIT_CLONE git://sigrok.org/sigrok-androidutils
315cd sigrok-androidutils
316./autogen.sh
317./configure $C --with-android-sdk="${ANDROID_SDK}"
318make $PARALLEL V=1
319make install
320cd ..
321
322# PulseView
323$GIT_CLONE git://sigrok.org/pulseview
324cd pulseview
325cmake $CM -DANDROID_STL_PATH=${ANDROID_NDK}/sources/cxx-stl .
326make $PARALLEL VERBOSE=1
327cd android
328"${ANDROID_SDK}/tools/android" update project -p . -t android-14 -n PulseView
329ant debug
330cd ../..
331