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