]> sigrok.org Git - sigrok-util.git/blob - cross-compile/android/sigrok-cross-android
sigrok-cross-android: Build libsigrokdecode and sigrok-cli.
[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 your Android toolchain directory is located.
25 TOOLCHAIN=$HOME/android/android-arm-toolchain
26
27 # The path where the cross-compiled packages will be installed.
28 PREFIX=$HOME/sr_android
29
30 # The path where to download files to and where to build packages.
31 BUILDDIR=./sr_android_build
32
33 # You usually don't need to change anything below this line.
34
35 # -----------------------------------------------------------------------------
36
37 VER_LIBICONV=1.14
38 VER_GETTEXT=0.18.3
39 VER_ZLIB=1.2.8
40 VER_PCRE=8.33
41 VER_LIBFFI=3.0.13
42 VER_GLIB=2.34.3
43 VER_LIBZIP=0.11.1
44 VER_LIBUSB=0.1.12
45 VER_LIBFTDI=0.20
46 VER_LIBUSB_1_0=1.0.9
47
48 SF_MIRROR=switch.dl.sourceforge.net
49
50 # -----------------------------------------------------------------------------
51
52 # Remove build directory contents (if any) and create a new build dir.
53 rm -rf $BUILDDIR
54 mkdir $BUILDDIR
55 cd $BUILDDIR
56
57 # Build host Python before we start messing with the environment.
58 wget http://python.org/ftp/python/3.3.3/Python-3.3.3.tar.xz
59 tar xJf Python-3.3.3.tar.xz
60 cd Python-3.3.3
61 ./configure
62 make python
63 make Parser/pgen
64 mv python hostpython
65 mv Parser/pgen Parser/hostpgen
66 cd ..
67
68 # -----------------------------------------------------------------------------
69
70 # We need to find tools in the toolchain.
71 export PATH=$TOOLCHAIN/bin:$PATH
72
73 # Tell pkg-config to only look for our cross-built stuff.
74 export PKG_CONFIG_LIBDIR="$PREFIX/lib/pkgconfig"
75 export -n PKG_CONFIG_PATH
76
77 # Define some helper variables.
78 C="--host=arm-linux-androideabi --prefix=$PREFIX"
79
80 # Remember the directory we're in.
81 case "$0" in
82   /*) TOP=$(dirname "$0");;
83   *) TOP=$(dirname "$(pwd)"/"$0");;
84 esac
85
86 # Get the latest versions of config.guess/config.sub that know about Android.
87 git clone git://git.savannah.gnu.org/config.git
88
89 # -----------------------------------------------------------------------------
90
91 # libiconv (needed for glib)
92 wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-$VER_LIBICONV.tar.gz
93 tar xfz libiconv-$VER_LIBICONV.tar.gz
94 cd libiconv-$VER_LIBICONV
95 cp -f ../config/config.guess build-aux
96 cp -f ../config/config.sub build-aux
97 cp -f ../config/config.guess libcharset/build-aux
98 cp -f ../config/config.sub libcharset/build-aux
99 ./configure $C --enable-shared
100 make lib/localcharset.h
101 cd libcharset
102 make
103 make install
104 cd ../lib
105 make
106 make install
107 cd ..
108 test -d $PREFIX/include || mkdir $PREFIX/include
109 cp include/iconv.h.inst $PREFIX/include/iconv.h
110 cd ..
111
112 # gettext (needed for glib)
113 wget http://ftp.gnu.org/pub/gnu/gettext/gettext-$VER_GETTEXT.tar.gz
114 tar xfz gettext-$VER_GETTEXT.tar.gz
115 cd gettext-$VER_GETTEXT
116 ./configure $C --enable-shared --disable-libasprintf
117 cd gettext-runtime
118 make
119 make install
120 cd ../..
121
122 # zlib (needed for glib and libzip)
123 wget http://zlib.net/zlib-$VER_ZLIB.tar.gz
124 tar xfvz zlib-$VER_ZLIB.tar.gz
125 cd zlib-$VER_ZLIB
126 # Note: zlib's configure doesn't understand --host, we need to pass $CC.
127 CC=arm-linux-androideabi-gcc ./configure --prefix=$PREFIX
128 make
129 make install
130 cd ..
131
132 # pcre (needed for glib)
133 wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-$VER_PCRE.tar.gz
134 tar xfvz pcre-$VER_PCRE.tar.gz
135 cd pcre-$VER_PCRE
136 ./configure $C --disable-cpp
137 make
138 make install
139 cd ..
140
141 # libffi (needed for glib)
142 wget ftp://sourceware.org/pub/libffi/libffi-$VER_LIBFFI.tar.gz
143 tar xfz libffi-$VER_LIBFFI.tar.gz
144 cd libffi-$VER_LIBFFI
145 ./configure $C
146 make
147 make install
148 cd ..
149
150 # glib
151 wget http://ftp.gnome.org/pub/gnome/sources/glib/2.38/glib-2.38.2.tar.xz
152 tar xJf glib-2.38.2.tar.xz
153 cd glib-2.38.2
154 ./autogen.sh
155 # Note: Manual LDFLAGS/CPPFLAGS needed for libiconv, rest uses pkg-config.
156 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 $C
157 make
158 make install
159 cd ..
160
161 # libzip
162 wget http://www.nih.at/libzip/libzip-$VER_LIBZIP.tar.gz
163 tar xfz libzip-$VER_LIBZIP.tar.gz
164 cd libzip-$VER_LIBZIP
165 cp -f ../config/config.guess .
166 cp -f ../config/config.sub .
167 ./configure $C
168 make
169 make install
170 cd ..
171
172 # libusb-0.1 (not used directly, but needed for libftdi)
173 wget http://$SF_MIRROR/project/libusb/libusb-0.1%20%28LEGACY%29/$VER_LIBUSB/libusb-$VER_LIBUSB.tar.gz
174 tar xfz libusb-$VER_LIBUSB.tar.gz
175 cd libusb-$VER_LIBUSB
176 cp -f ../config/config.guess .
177 cp -f ../config/config.sub .
178 ./configure $C
179 # Explicitly exclude libusbpp.la from lib_LTLIBRARIES, and skip subdirs.
180 make lib_LTLIBRARIES=libusb.la SUBDIRS=.
181 make lib_LTLIBRARIES=libusb.la SUBDIRS=. install
182 cd ..
183
184 # libftdi
185 wget http://www.intra2net.com/en/developer/libftdi/download/libftdi-$VER_LIBFTDI.tar.gz
186 tar xfz libftdi-$VER_LIBFTDI.tar.gz
187 cd libftdi-$VER_LIBFTDI
188 cp -f ../config/config.guess .
189 cp -f ../config/config.sub .
190 ./configure $C
191 make
192 make install
193 cd ..
194
195 # libusb-1.0
196 wget http://$SF_MIRROR/project/libusb/libusb-1.0/libusb-$VER_LIBUSB_1_0/libusb-$VER_LIBUSB_1_0.tar.bz2
197 tar xfj libusb-$VER_LIBUSB_1_0.tar.bz2
198 cd libusb-$VER_LIBUSB_1_0
199 patch -p1 < $TOP/libusb-1.0.patch
200 ./configure $C
201 make
202 make install
203 cd ..
204
205 # libsigrok
206 git clone git://sigrok.org/libsigrok
207 cd libsigrok
208 ./autogen.sh
209 ./configure $C
210 make
211 make install
212 cd ..
213
214 # Python
215 cd Python-3.3.3
216 make distclean
217 autoreconf
218 patch -p1 < ../../Python-3.3.3.patch
219 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
220 make HOSTPYTHON=./hostpython HOSTPGEN=./Parser/hostpgen install
221 cd ..
222
223 # libsigrokdecode
224 git clone git://sigrok.org/libsigrokdecode
225 cd libsigrokdecode
226 ./autogen.sh
227 ./configure $C
228 make
229 make install
230 cd ..
231
232 # sigrok-cli
233 git clone git://sigrok.org/sigrok-cli
234 cd sigrok-cli
235 ./autogen.sh
236 ./configure $C
237 make
238 make install
239 cd ..