3 ## This file is part of the sigrok-util project.
5 ## Copyright (C) 2013-2015 Uwe Hermann <uwe@hermann-uwe.de>
6 ## Copyright (C) 2013-2015 Marcus Comstedt <marcus@mc.pp.se>
8 ## This program is free software; you can redistribute it and/or modify
9 ## it under the terms of the GNU General Public License as published by
10 ## the Free Software Foundation; either version 2 of the License, or
11 ## (at your option) any later version.
13 ## This program is distributed in the hope that it will be useful,
14 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ## GNU General Public License for more details.
18 ## You should have received a copy of the GNU General Public License
19 ## along with this program; if not, write to the Free Software
20 ## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 # The path where the NDK, SDK, and toolchains are located.
26 ANDROID_PATH
=$HOME/android
28 # The path where the Android NDK is located.
29 ANDROID_NDK
=$ANDROID_PATH/android-ndk-r10e
31 # The path where the Android SDK is located.
32 ANDROID_SDK
=$ANDROID_PATH/android-sdk-linux
34 # The path where your Android toolchain directory is located.
35 # TOOLCHAIN=$ANDROID_PATH/android-arm-toolchain
36 # TOOLCHAIN=$ANDROID_PATH/android-mipsel-toolchain
37 # TOOLCHAIN=$ANDROID_PATH/android-i686-toolchain
38 TOOLCHAIN
=$ANDROID_NDK/toolchains
/arm-linux-androideabi-4.9
/prebuilt
/linux-x86
39 # TOOLCHAIN=$ANDROID_NDK/toolchains/x86-4.9/prebuilt/linux-x86
40 # TOOLCHAIN=$ANDROID_NDK/toolchains/mipsel-linux-android-4.9/prebuilt/linux-x86
42 # Select which Android toolchain to use.
43 # Don't forget to also adapt TOOLCHAIN above if you change TOOLCHAIN_TRIPLET!
44 TOOLCHAIN_TRIPLET
=arm-linux-androideabi
45 # TOOLCHAIN_TRIPLET=mipsel-linux-android
46 # TOOLCHAIN_TRIPLET=i686-linux-android
48 # The path where the cross-compiled packages will be installed.
49 PREFIX
=$HOME/sr_android
51 # The path where to download files to and where to build packages.
54 # Edit this to control verbose build output.
57 # Edit this to enable/disable/modify parallel compiles.
60 # You usually don't need to change anything below this line.
62 # -----------------------------------------------------------------------------
74 VER_LIBSIGCXX_SHORT
=2.9
82 VER_SIGROK_FIRMWARE_FX2LAFW
=0.1.3
85 VER_AND_BT
=23.0.2 # Android build tools version
86 VER_AND_API
=16 # Target Android API version
88 SF_MIRROR
=download.sourceforge.net
90 WGET
="wget -c --quiet"
91 GIT_CLONE
="git clone --depth=1"
93 case "$TOOLCHAIN_TRIPLET" in
94 arm
*) TARGET_ARCH
=armeabi
;;
95 mips
*) TARGET_ARCH
=mips
;;
96 i686
*) TARGET_ARCH
=x86
;;
97 *) echo >&2 "Unknown prefix for TOOLCHAIN_TRIPLET."; exit 1;;
100 # -----------------------------------------------------------------------------
102 # Get the Android NDK and SDK, install required packages and toolchains.
103 if [ "x$1" = "xprepare" ]; then
104 mkdir
-p $ANDROID_PATH
108 $WGET http
://dl.google.com
/android
/ndk
/android-ndk-r
$VER_NDK-linux-x86.bin
109 chmod 700 android-ndk-r
$VER_NDK-linux-x86.bin
110 .
/android-ndk-r
$VER_NDK-linux-x86.bin
-y
111 cd android-ndk-r
$VER_NDK
112 .
/build
/tools
/make-standalone-toolchain.sh
--platform=android-
$VER_AND_API \
113 --toolchain=arm-linux-androideabi-4.9 \
114 --install-dir=$ANDROID_PATH/android-arm-toolchain
115 .
/build
/tools
/make-standalone-toolchain.sh
--platform=android-
$VER_AND_API \
116 --toolchain=x86-4.9 \
117 --install-dir=$ANDROID_PATH/android-i686-toolchain
118 .
/build
/tools
/make-standalone-toolchain.sh
--platform=android-
$VER_AND_API \
119 --toolchain=mipsel-linux-android-4.9 \
120 --install-dir=$ANDROID_PATH/android-mipsel-toolchain
124 $WGET http
://dl.google.com
/android
/android-sdk_r
$VER_SDK-linux.tgz
125 tar xfz android-sdk_r
$VER_SDK-linux.tgz
127 echo y | .
/tools
/android update sdk
--no-ui --all --filter platform-tools
,build-tools-
$VER_AND_BT,android-
$VER_AND_API
133 # -----------------------------------------------------------------------------
135 # Remove build directory contents (if any) and create a new build dir.
140 # -----------------------------------------------------------------------------
142 # Build host Python before we start messing with the environment.
143 # Don't do parallel builds, this doesn't seem to work well.
144 $WGET http
://python.org
/ftp
/python
/$VER_PYTHON/Python-
$VER_PYTHON.
tar.xz
145 tar xfJ Python-
$VER_PYTHON.
tar.xz
146 cd Python-
$VER_PYTHON
152 # -----------------------------------------------------------------------------
154 # We need to find tools in the toolchain.
155 export PATH
=$TOOLCHAIN/bin
:$PATH
157 # Tell pkg-config to only look for our cross-built stuff.
158 export PKG_CONFIG_LIBDIR
="$PREFIX/lib/pkgconfig"
159 export -n PKG_CONFIG_PATH
162 if test -d "$TOOLCHAIN"/sysroot
; then
163 echo "Toolchain is standalone"
164 STANDALONE_TOOLCHAIN
=$TOOLCHAIN
167 STANDALONE_TOOLCHAIN
=
168 NATIVE_API_LEVEL
=$VER_AND_API
169 SYSROOT_DIR
=${ANDROID_NDK}/platforms/android-${NATIVE_API_LEVEL}/arch-${TARGET_ARCH%eabi*}
170 if [ ! -d "$SYSROOT_DIR" ]; then
171 echo >&2 "Can't build with NDK toolchain; sysroot $SYSROOT_DIR is missing"
174 SYSROOT
="--sysroot $SYSROOT_DIR"
175 CC
="$TOOLCHAIN_TRIPLET-gcc $SYSROOT"
176 CXX
="$TOOLCHAIN_TRIPLET-g++ $SYSROOT"
179 NDK_TOOLCHAIN_VERSION
=`${TOOLCHAIN_TRIPLET}-gcc --version | head -1 | sed -e 's/.* \([0-9]\+\.[0-9.]\+\)\( \|.*\)$/\1/'`
181 # Define some helper variables.
182 C
="--host=$TOOLCHAIN_TRIPLET --prefix=$PREFIX"
183 CM
="-Wno-dev -DCMAKE_TOOLCHAIN_FILE=../android.toolchain.cmake -DANDROID_ABI=${TARGET_ARCH} -DCMAKE_INSTALL_PREFIX=${PREFIX}"
184 if [ -n "$STANDALONE_TOOLCHAIN" ]; then
185 CM
="$CM -DANDROID_STANDALONE_TOOLCHAIN=${STANDALONE_TOOLCHAIN}"
186 if [ -d "${ANDROID_NDK}/sources/cxx-stl" ]; then
187 CM
="$CM -DANDROID_STL_PATH=${ANDROID_NDK}/sources/cxx-stl"
190 CM
="$CM -DANDROID_NDK=${ANDROID_NDK}"
191 CM
="$CM -DANDROID_NATIVE_API_LEVEL=${NATIVE_API_LEVEL}"
192 CM
="$CM -DANDROID_TOOLCHAIN_NAME=${TOOLCHAIN_TRIPLET}-${NDK_TOOLCHAIN_VERSION}"
195 # Look for STL, needed to build bindings
196 STL_BASE
="${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/${NDK_TOOLCHAIN_VERSION}"
197 if [ -d ${STL_BASE}/include
]; then
198 CPPFLAGS_STL
="-I${STL_BASE}/include -I${STL_BASE}/libs/${TARGET_ARCH}/include"
199 LDFLAGS_STL
="-L${STL_BASE}/libs/${TARGET_ARCH} -Wl,-rpath=${STL_BASE}/libs/${TARGET_ARCH}"
200 BINDINGS_CONFIG
="--enable-bindings"
202 echo "Warning: STL unavailable, libsigrok bindings will not be built."
205 BINDINGS_CONFIG
="--disable-bindings"
208 # -----------------------------------------------------------------------------
210 # Get the latest versions of config.guess/config.sub that know about Android.
211 $GIT_CLONE http
://git.savannah.gnu.org
/r
/config.git
213 # Get a toolchain for cmake that knows about Android.
214 $WGET https
://raw.githubusercontent.com
/arithran
/android-cmake
/master
/toolchain
/android.toolchain.cmake
215 patch < ..
/android.toolchain.cmake.
patch android.toolchain.cmake
217 # -----------------------------------------------------------------------------
219 # Python (needed for libsigrokdecode)
220 # Don't do parallel Python builds, this doesn't seem to work well.
221 cd Python-
$VER_PYTHON
224 patch -p1 < ..
/..
/Python-
$VER_PYTHON.
patch
225 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
226 sed -i "s/^#zlib/zlib/g" Modules
/Setup
227 sed -i "s/^#math/math/g" Modules
/Setup
228 sed -i "s/^#time/time/g" Modules
/Setup
229 make PYTHON_FOR_BUILD
='_PYTHON_HOST_PLATFORM=$(_PYTHON_HOST_PLATFORM) ./hostpython' install $V
232 # libiconv (needed for glib)
233 $WGET http
://ftp.gnu.org
/pub
/gnu
/libiconv
/libiconv-
$VER_LIBICONV.
tar.gz
234 tar xfz libiconv-
$VER_LIBICONV.
tar.gz
235 cd libiconv-
$VER_LIBICONV
236 cp -f ..
/config
/config.guess build-aux
237 cp -f ..
/config
/config.sub build-aux
238 cp -f ..
/config
/config.guess libcharset
/build-aux
239 cp -f ..
/config
/config.sub libcharset
/build-aux
240 .
/configure
$C --enable-shared
241 make lib
/localcharset.h
$V
249 test -d $PREFIX/include || mkdir
$PREFIX/include
250 cp include
/iconv.h.inst
$PREFIX/include
/iconv.h
253 # gettext (needed for glib)
254 $WGET http
://ftp.gnu.org
/pub
/gnu
/gettext
/gettext-
$VER_GETTEXT.
tar.gz
255 tar xfz gettext-
$VER_GETTEXT.
tar.gz
256 cd gettext-
$VER_GETTEXT
257 .
/configure
$C --enable-shared --disable-libasprintf
263 # zlib (needed for glib and libzip)
264 $WGET http
://zlib.net
/zlib-
$VER_ZLIB.
tar.gz
265 tar xfz zlib-
$VER_ZLIB.
tar.gz
267 # Note: zlib's configure doesn't understand --host, we need to pass $CC.
268 CC
="$TOOLCHAIN_TRIPLET-gcc $SYSROOT" .
/configure
--prefix=$PREFIX
273 # pcre (needed for glib)
274 $WGET ftp://ftp.csx.cam.ac.uk
/pub
/software
/programming
/pcre
/pcre-
$VER_PCRE.
tar.gz
275 tar xfz pcre-
$VER_PCRE.
tar.gz
277 .
/configure
$C --disable-cpp --enable-utf --enable-unicode-properties
282 # libffi (needed for glib)
283 $WGET ftp://sourceware.org
/pub
/libffi
/libffi-
$VER_LIBFFI.
tar.gz
284 tar xfz libffi-
$VER_LIBFFI.
tar.gz
285 cd libffi-
$VER_LIBFFI
291 # glib (needed for libsigrok)
292 $WGET http
://ftp.gnome.org
/pub
/gnome
/sources
/glib
/$VER_GLIB_SHORT/glib-
$VER_GLIB.
tar.xz
293 tar xfJ glib-
$VER_GLIB.
tar.xz
295 NOCONFIGURE
=yes .
/autogen.sh
296 # Note: Manual LDFLAGS/CPPFLAGS needed for libiconv, rest uses pkg-config.
297 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
302 # libzip (needed for libsigrok)
303 $WGET http
://www.nih.at
/libzip
/libzip-
$VER_LIBZIP.
tar.gz
304 tar xfz libzip-
$VER_LIBZIP.
tar.gz
305 cd libzip-
$VER_LIBZIP
306 cp -f ..
/config
/config.guess .
307 cp -f ..
/config
/config.sub .
313 # libusb-1.0 (needed for libsigrok)
314 $WGET http
://$SF_MIRROR/project
/libusb
/libusb-1.0
/libusb-
$VER_LIBUSB/libusb-
$VER_LIBUSB.
tar.bz2
315 tar xfj libusb-
$VER_LIBUSB.
tar.bz2
316 cd libusb-
$VER_LIBUSB
317 patch -p1 < ..
/..
/libusb-1.0.
patch
318 .
/configure
$C --disable-udev
323 # libftdi1 (needed for libsigrok)
324 $WGET http
://www.intra2net.com
/en
/developer
/libftdi
/download
/libftdi1-
$VER_LIBFTDI1.
tar.bz2
325 tar xfj libftdi1-
$VER_LIBFTDI1.
tar.bz2
326 cd libftdi1-
$VER_LIBFTDI1
327 cmake
$CM -DFTDIPP=no
-DDOCUMENTATION=no
-DEXAMPLES=no
-DFTDI_EEPROM=no
-DPYTHON_BINDINGS=no
-DBUILD_TESTS=n .
333 $GIT_CLONE git
://sigrok.org
/libserialport
343 # Build dependencies for libsigrok bindings if needed
345 if [ x
"$CPPFLAGS_STL" != x
]; then
347 # libsigc++ (needed for glibmm)
348 $WGET http
://ftp.gnome.org
/pub
/gnome
/sources
/libsigc
++/$VER_LIBSIGCXX_SHORT/libsigc
++-$VER_LIBSIGCXX.
tar.xz
349 tar xfJ libsigc
++-$VER_LIBSIGCXX.
tar.xz
350 cd libsigc
++-$VER_LIBSIGCXX
351 cp -f ..
/config
/config.guess build
352 cp -f ..
/config
/config.sub build
353 CPPFLAGS
="$CPPFLAGS_STL" LDFLAGS
="$LDFLAGS_STL -lgnustl_shared" .
/configure
--disable-documentation $C
358 # glibmm (needed for libsigrok bindings)
359 $WGET http
://ftp.gnome.org
/pub
/gnome
/sources
/glibmm
/$VER_GLIBMM_SHORT/glibmm-
$VER_GLIBMM.
tar.xz
360 tar xfJ glibmm-
$VER_GLIBMM.
tar.xz
361 cd glibmm-
$VER_GLIBMM
362 CPPFLAGS
="$CPPFLAGS_STL" LDFLAGS
="$LDFLAGS_STL -lgnustl_shared" .
/configure
--disable-documentation $C
370 $GIT_CLONE git
://sigrok.org
/libsigrok
375 CPPFLAGS
="$CPPFLAGS_STL" LDFLAGS
="$LDFLAGS_STL" JAVAC
="javac -source 1.6 -target 1.6" ..
/configure
$C $BINDINGS_CONFIG --datadir=/sdcard
377 make datadir
='$(datarootdir)' install $V
381 $GIT_CLONE git
://sigrok.org
/libsigrokdecode
392 $GIT_CLONE git
://sigrok.org
/sigrok-firmware
402 # sigrok-firmware-fx2lafw
403 $WGET http
://sigrok.org
/download
/binary
/sigrok-firmware-fx2lafw
/sigrok-firmware-fx2lafw-bin-
$VER_SIGROK_FIRMWARE_FX2LAFW.
tar.gz
404 tar xfz sigrok-firmware-fx2lafw-bin-
$VER_SIGROK_FIRMWARE_FX2LAFW.
tar.gz
405 cd sigrok-firmware-fx2lafw-bin-
$VER_SIGROK_FIRMWARE_FX2LAFW
406 cp *.fw
$PREFIX/share
/sigrok-firmware
/
410 $GIT_CLONE git
://sigrok.org
/sigrok-cli
420 # Check if we have all requirements to build PulseView:
422 if [ -z "$ANDROID_NDK" -o ! -d "$ANDROID_NDK" ]; then
423 echo "Android NDK not available, not building PulseView."
427 if [ -z "$ANDROID_SDK" -o ! -d "$ANDROID_SDK"/platforms
/android-
$VER_AND_API ]; then
428 echo "Android SDK with platform $VER_AND_API not available, not building PulseView."
432 if [ ! -e "${ANDROID_SDK}/tools/android" ]; then
433 echo "Essential Android build tools not available, not building PulseView."
437 NDK_HOST
=`"$ANDROID_NDK/ndk-build" -p 2>/dev/null | awk '$1 == "HOST_TAG" { print $3 }'`
439 # Boost (needed for PulseView)
440 $WGET http
://$SF_MIRROR/project
/boost
/boost
/$VER_BOOST/boost_
${VER_BOOST//./_}.
tar.bz2
441 tar xfj boost_
${VER_BOOST//./_}.
tar.bz2
442 cd boost_
${VER_BOOST//./_}
443 patch -p0 < ..
/..
/boost_wchar.
patch
444 CC
= .
/bootstrap.sh
--with-toolset=gcc
--with-libraries=filesystem
,system
,thread
,serialization
,test --without-icu
445 echo "using gcc : $NDK_TOOLCHAIN_VERSION : \"${TOOLCHAIN_TRIPLET}-g++\" : <cxxflags>\"$SYSROOT -I$PREFIX/include $CPPFLAGS_STL\" <linkflags>\"$SYSROOT -L$PREFIX/lib $LDFLAGS_STL -lgnustl_shared\" ;" > user-config.jam
446 .
/b2
-q -d+2 --ignore-site-config --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
449 # Qt (needed for PulseView)
450 $WGET http
://download.qt.io
/official_releases
/qt
/${VER_QT_SHORT}/${VER_QT}/single/qt-everywhere-opensource-src-${VER_QT}.
tar.xz
451 tar xfi qt-everywhere-opensource-src-
${VER_QT}.
tar.xz
452 cd qt-everywhere-opensource-src-
${VER_QT}
453 patch -p1 < ..
/..
/android-qt.
patch
454 CC
= CXX
= .
/configure \
457 -xplatform android-g
++ \
460 -android-sdk "$ANDROID_SDK" \
461 -android-ndk "$ANDROID_NDK" \
462 -android-ndk-host "$NDK_HOST" \
463 -android-arch "$TARGET_ARCH" \
464 -android-toolchain-version "$NDK_TOOLCHAIN_VERSION" \
465 -skip qtconnectivity \
466 -skip qtdeclarative \
473 -skip qttranslations \
476 -skip qtxmlpatterns \
477 -opensource -confirm-license -silent
478 export ANDROID_API_VERSION
=android-
$VER_AND_API
479 export ANDROID_BUILD_TOOLS_REVISION
=$VER_AND_BT
480 make module-qtbase module-qtandroidextras module-qtsvg module-qtimageformats
$PARALLEL $V
484 # sigrok-androidutils
485 $GIT_CLONE git
://sigrok.org
/sigrok-androidutils
486 cd sigrok-androidutils
488 .
/configure
$C --with-android-sdk="${ANDROID_SDK}" --with-android-platform=android-
$VER_AND_API
493 # Strip all shared libs to reduce size.
494 find $PREFIX -iname "*.so" -exec ${TOOLCHAIN_TRIPLET}-strip -S {} \
;
497 $GIT_CLONE git
://sigrok.org
/pulseview
499 patch -p1 < ..
/..
/pv_cmake_pkgconfig_fix.
patch
500 cmake
$CM -DENABLE_TESTS=y .
502 ${TOOLCHAIN_TRIPLET}-strip -S libs
/$TARGET_ARCH/libpulseview.so
504 "${ANDROID_SDK}/tools/android" update project
-p .
-t android-
$VER_AND_API -n PulseView