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