]> sigrok.org Git - sigrok-util.git/blame_incremental - cross-compile/android/sigrok-cross-android
sigrok-cross-android: Use new repos for PV and androidutils
[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 Android NDK is located.
25ANDROID_NDK=/usr/local/android-ndk-r9d
26
27# The path where Android SDK is located.
28ANDROID_SDK=/usr/local/android
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# Build host Python before we start messing with the environment.
88$WGET http://python.org/ftp/python/$VER_PYTHON/Python-$VER_PYTHON.tar.xz
89tar xJf Python-$VER_PYTHON.tar.xz
90cd Python-$VER_PYTHON
91./configure
92make python $PARALLEL
93make Parser/pgen $PARALLEL
94mv python hostpython
95mv Parser/pgen Parser/hostpgen
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# Get the latest versions of config.guess/config.sub that know about Android.
112$GIT_CLONE git://git.savannah.gnu.org/config.git
113
114# Get a toolchain for cmake that knows about Android
115wget https://android-cmake.googlecode.com/hg/toolchain/android.toolchain.cmake
116patch < ../android.toolchain.cmake.patch android.toolchain.cmake
117
118# -----------------------------------------------------------------------------
119
120# Python (needed for libsigrokdecode)
121cd Python-$VER_PYTHON
122make distclean
123autoreconf
124patch -p1 < ../../Python-$VER_PYTHON.patch
125ac_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
126sed -i "s/^#zlib/zlib/g" Modules/Setup
127make HOSTPYTHON=./hostpython HOSTPGEN=./Parser/hostpgen install $PARALLEL
128cd ..
129
130# libiconv (needed for glib)
131$WGET http://ftp.gnu.org/pub/gnu/libiconv/libiconv-$VER_LIBICONV.tar.gz
132tar xfz libiconv-$VER_LIBICONV.tar.gz
133cd libiconv-$VER_LIBICONV
134cp -f ../config/config.guess build-aux
135cp -f ../config/config.sub build-aux
136cp -f ../config/config.guess libcharset/build-aux
137cp -f ../config/config.sub libcharset/build-aux
138./configure $C --enable-shared
139make lib/localcharset.h
140cd libcharset
141make $PARALLEL
142make install
143cd ../lib
144make $PARALLEL
145make install
146cd ..
147test -d $PREFIX/include || mkdir $PREFIX/include
148cp include/iconv.h.inst $PREFIX/include/iconv.h
149cd ..
150
151# gettext (needed for glib)
152$WGET http://ftp.gnu.org/pub/gnu/gettext/gettext-$VER_GETTEXT.tar.gz
153tar xfz gettext-$VER_GETTEXT.tar.gz
154cd gettext-$VER_GETTEXT
155./configure $C --enable-shared --disable-libasprintf
156cd gettext-runtime
157make $PARALLEL
158make install
159cd ../..
160
161# zlib (needed for glib and libzip)
162$WGET http://zlib.net/zlib-$VER_ZLIB.tar.gz
163tar xfvz zlib-$VER_ZLIB.tar.gz
164cd zlib-$VER_ZLIB
165# Note: zlib's configure doesn't understand --host, we need to pass $CC.
166CC=$TOOLCHAIN_TRIPLET-gcc ./configure --prefix=$PREFIX
167make $PARALLEL
168make install
169cd ..
170
171# pcre (needed for glib)
172$WGET ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-$VER_PCRE.tar.gz
173tar xfvz pcre-$VER_PCRE.tar.gz
174cd pcre-$VER_PCRE
175./configure $C --disable-cpp
176make $PARALLEL
177make install
178cd ..
179
180# libffi (needed for glib)
181$WGET ftp://sourceware.org/pub/libffi/libffi-$VER_LIBFFI.tar.gz
182tar xfz libffi-$VER_LIBFFI.tar.gz
183cd libffi-$VER_LIBFFI
184./configure $C
185make $PARALLEL
186make install
187cd ..
188
189# glib
190$WGET http://ftp.gnome.org/pub/gnome/sources/glib/$VER_GLIB_SHORT/glib-$VER_GLIB.tar.xz
191tar xJf glib-$VER_GLIB.tar.xz
192cd glib-$VER_GLIB
193./autogen.sh
194# Note: Manual LDFLAGS/CPPFLAGS needed for libiconv, rest uses pkg-config.
195LDFLAGS=-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
196make $PARALLEL
197make install
198cd ..
199
200# libzip
201$WGET http://www.nih.at/libzip/libzip-$VER_LIBZIP.tar.gz
202tar xfz libzip-$VER_LIBZIP.tar.gz
203cd libzip-$VER_LIBZIP
204cp -f ../config/config.guess .
205cp -f ../config/config.sub .
206./configure $C
207make $PARALLEL
208make install
209cd ..
210
211# libusb-1.0
212$WGET http://$SF_MIRROR/project/libusbx/releases/$VER_LIBUSBX/source/libusbx-$VER_LIBUSBX.tar.bz2
213tar xfj libusbx-$VER_LIBUSBX.tar.bz2
214cd libusbx-$VER_LIBUSBX
215patch -p1 < ../../libusb-1.0.patch
216./configure $C --disable-udev
217make $PARALLEL
218make install
219cd ..
220
221# libftdi1
222$WGET http://www.intra2net.com/en/developer/libftdi/download/libftdi1-$VER_LIBFTDI1.tar.bz2
223tar xfj libftdi1-$VER_LIBFTDI1.tar.bz2
224cd libftdi1-$VER_LIBFTDI1
225cmake $CM .
226make $PARALLEL
227make install
228cd ..
229
230# libserialport
231$GIT_CLONE git://sigrok.org/libserialport
232cd libserialport
233./autogen.sh
234./configure $C
235make $PARALLEL V=1
236make install
237cd ..
238
239# libsigrok
240$GIT_CLONE git://sigrok.org/libsigrok
241cd libsigrok
242./autogen.sh
243./configure $C --datadir=/sdcard
244make $PARALLEL V=1
245make install
246cd ..
247
248# libsigrokdecode
249$GIT_CLONE git://sigrok.org/libsigrokdecode
250cd libsigrokdecode
251./autogen.sh
252./configure $C
253make $PARALLEL V=1
254make install
255cd ..
256
257# sigrok-cli
258$GIT_CLONE git://sigrok.org/sigrok-cli
259cd sigrok-cli
260./autogen.sh
261./configure $C
262make $PARALLEL V=1
263make install
264cd ..
265
266
267# Check if we have kit to build PulseView
268
269if [ -z "$ANDROID_NDK" -o ! -d "$ANDROID_NDK" ]; then
270 echo "Android NDK not available, not building PulseView"
271 exit 0
272fi
273
274if [ -z "$ANDROID_SDK" -o ! -d "$ANDROID_SDK"/platforms/android-8 -o \
275 ! -d "$ANDROID_SDK"/platforms/android-10 -o \
276 ! -d "$ANDROID_SDK"/platforms/android-11 -o \
277 ! -d "$ANDROID_SDK"/platforms/android-14 -o \
278 ! -d "$ANDROID_SDK"/platforms/android-16 ]; then
279 echo "Android SDK with platforms 8 10 11 14 16 not available, not building PulseView"
280 exit 0
281fi
282
283ANDROID_TOOLS=${ANDROID_SDK}/tools
284
285if [ ! -e "$ANDROID_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
294# boost (needed for PulseView)
295$WGET http://$SF_MIRROR/project/boost/boost/$VER_BOOST/boost_${VER_BOOST//./_}.tar.bz2
296tar xfj boost_${VER_BOOST//./_}.tar.bz2
297cd boost_${VER_BOOST//./_}
298patch -p1 < ../../boost.patch
299./bootstrap.sh --with-toolset=gcc --with-libraries=filesystem,system --without-icu
300echo "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
301./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
302cd ..
303
304# qt (needed for PulseView)
305$WGET http://download.qt-project.org/official_releases/qt/${VER_QT%.*}/${VER_QT}/single/qt-everywhere-opensource-src-${VER_QT}.tar.gz
306tar xfz qt-everywhere-opensource-src-${VER_QT}.tar.gz
307cd qt-everywhere-opensource-src-${VER_QT}
308patch -p1 < ../../android-qt.patch
309./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
310make $PARALLEL
311make install
312cd ..
313
314# sigrok-androidutils
315$GIT_CLONE git://github.com/zeldin/sigrok-androidutils
316cd sigrok-androidutils
317./autogen.sh
318./configure $C --with-android-sdk="${ANDROID_SDK}"
319make
320make install
321cd ..
322
323# PulseView
324$GIT_CLONE -b android git://github.com/zeldin/pulseview
325# $GIT_CLONE git://sigrok.org/pulseview
326cd pulseview
327cmake $CM -DANDROID_STL_PATH=${ANDROID_NDK}/sources/cxx-stl .
328make $PARALLEL
329cd android
330"$ANDROID_TOOLS/android" update project -p . -t android-14 -n PulseView
331ant debug
332cd ../..