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, see <http://www.gnu.org/licenses/>.
24 # The path where the NDK, SDK, and toolchains are located.
25 ANDROID_PATH
=$HOME/android
27 # The path where the Android NDK is located.
28 ANDROID_NDK
=$ANDROID_PATH/android-ndk-r10e
30 # The path where the Android SDK is located.
31 ANDROID_SDK
=$ANDROID_PATH/android-sdk-linux
33 # The path where your Android toolchain directory is located.
34 # TOOLCHAIN=$ANDROID_PATH/android-arm-toolchain
35 # TOOLCHAIN=$ANDROID_PATH/android-mipsel-toolchain
36 # TOOLCHAIN=$ANDROID_PATH/android-i686-toolchain
37 TOOLCHAIN
=$ANDROID_NDK/toolchains
/arm-linux-androideabi-4.9
/prebuilt
/linux-x86
38 # TOOLCHAIN=$ANDROID_NDK/toolchains/x86-4.9/prebuilt/linux-x86
39 # TOOLCHAIN=$ANDROID_NDK/toolchains/mipsel-linux-android-4.9/prebuilt/linux-x86
41 # Select which Android toolchain to use.
42 # Don't forget to also adapt TOOLCHAIN above if you change TOOLCHAIN_TRIPLET!
43 TOOLCHAIN_TRIPLET
=arm-linux-androideabi
44 # TOOLCHAIN_TRIPLET=mipsel-linux-android
45 # TOOLCHAIN_TRIPLET=i686-linux-android
47 # The path where the cross-compiled packages will be installed.
48 PREFIX
=$HOME/sr_android
50 # The path where to download files to and where to build packages.
53 # Edit this to control verbose build output.
56 # Edit this to enable/disable/modify parallel compiles.
59 # You usually don't need to change anything below this line.
61 # -----------------------------------------------------------------------------
73 VER_LIBSIGCXX_SHORT
=2.9
81 VER_SIGROK_FIRMWARE_FX2LAFW
=0.1.3
84 VER_AND_BT
=23.0.2 # Android build tools version
85 VER_AND_API
=16 # Target Android API version
87 SF_MIRROR
=download.sourceforge.net
89 WGET
="wget -c --quiet"
90 GIT_CLONE
="git clone --depth=1"
92 REPO_BASE
="git://sigrok.org"
94 case "$TOOLCHAIN_TRIPLET" in
95 arm
*) TARGET_ARCH
=armeabi
;;
96 mips
*) TARGET_ARCH
=mips
;;
97 i686
*) TARGET_ARCH
=x86
;;
98 *) echo >&2 "Unknown prefix for TOOLCHAIN_TRIPLET."; exit 1;;
101 # -----------------------------------------------------------------------------
103 # Get the Android NDK and SDK, install required packages and toolchains.
104 if [ "x$1" = "xprepare" ]; then
105 mkdir
-p $ANDROID_PATH
109 $WGET http
://dl.google.com
/android
/ndk
/android-ndk-r
$VER_NDK-linux-x86.bin
110 chmod 700 android-ndk-r
$VER_NDK-linux-x86.bin
111 .
/android-ndk-r
$VER_NDK-linux-x86.bin
-y
112 cd android-ndk-r
$VER_NDK
113 .
/build
/tools
/make-standalone-toolchain.sh
--platform=android-
$VER_AND_API \
114 --toolchain=arm-linux-androideabi-4.9 \
115 --install-dir=$ANDROID_PATH/android-arm-toolchain
116 .
/build
/tools
/make-standalone-toolchain.sh
--platform=android-
$VER_AND_API \
117 --toolchain=x86-4.9 \
118 --install-dir=$ANDROID_PATH/android-i686-toolchain
119 .
/build
/tools
/make-standalone-toolchain.sh
--platform=android-
$VER_AND_API \
120 --toolchain=mipsel-linux-android-4.9 \
121 --install-dir=$ANDROID_PATH/android-mipsel-toolchain
125 $WGET http
://dl.google.com
/android
/android-sdk_r
$VER_SDK-linux.tgz
126 tar xfz android-sdk_r
$VER_SDK-linux.tgz
128 echo y | .
/tools
/android update sdk
--no-ui --all --filter platform-tools
,build-tools-
$VER_AND_BT,android-
$VER_AND_API
134 # -----------------------------------------------------------------------------
136 # Remove build directory contents (if any) and create a new build dir.
141 # -----------------------------------------------------------------------------
143 # Build host Python before we start messing with the environment.
144 # Don't do parallel builds, this doesn't seem to work well.
145 $WGET http
://python.org
/ftp
/python
/$VER_PYTHON/Python-
$VER_PYTHON.
tar.xz
146 tar xfJ Python-
$VER_PYTHON.
tar.xz
147 cd Python-
$VER_PYTHON
153 # -----------------------------------------------------------------------------
155 # We need to find tools in the toolchain.
156 export PATH
=$TOOLCHAIN/bin
:$PATH
158 # Tell pkg-config to only look for our cross-built stuff.
159 export PKG_CONFIG_LIBDIR
="$PREFIX/lib/pkgconfig"
160 export -n PKG_CONFIG_PATH
163 if test -d "$TOOLCHAIN"/sysroot
; then
164 echo "Toolchain is standalone"
165 STANDALONE_TOOLCHAIN
=$TOOLCHAIN
168 STANDALONE_TOOLCHAIN
=
169 NATIVE_API_LEVEL
=$VER_AND_API
170 SYSROOT_DIR
=${ANDROID_NDK}/platforms/android-${NATIVE_API_LEVEL}/arch-${TARGET_ARCH%eabi*}
171 if [ ! -d "$SYSROOT_DIR" ]; then
172 echo >&2 "Can't build with NDK toolchain; sysroot $SYSROOT_DIR is missing"
175 SYSROOT
="--sysroot $SYSROOT_DIR"
176 CC
="$TOOLCHAIN_TRIPLET-gcc $SYSROOT"
177 CXX
="$TOOLCHAIN_TRIPLET-g++ $SYSROOT"
180 NDK_TOOLCHAIN_VERSION
=`${TOOLCHAIN_TRIPLET}-gcc --version | head -1 | sed -e 's/.* \([0-9]\+\.[0-9.]\+\)\( \|.*\)$/\1/'`
182 # Define some helper variables.
183 C
="--host=$TOOLCHAIN_TRIPLET --prefix=$PREFIX"
184 CM
="-Wno-dev -DCMAKE_TOOLCHAIN_FILE=../android.toolchain.cmake -DANDROID_ABI=${TARGET_ARCH} -DCMAKE_INSTALL_PREFIX=${PREFIX}"
185 if [ -n "$STANDALONE_TOOLCHAIN" ]; then
186 CM
="$CM -DANDROID_STANDALONE_TOOLCHAIN=${STANDALONE_TOOLCHAIN}"
187 if [ -d "${ANDROID_NDK}/sources/cxx-stl" ]; then
188 CM
="$CM -DANDROID_STL_PATH=${ANDROID_NDK}/sources/cxx-stl"
191 CM
="$CM -DANDROID_NDK=${ANDROID_NDK}"
192 CM
="$CM -DANDROID_NATIVE_API_LEVEL=${NATIVE_API_LEVEL}"
193 CM
="$CM -DANDROID_TOOLCHAIN_NAME=${TOOLCHAIN_TRIPLET}-${NDK_TOOLCHAIN_VERSION}"
196 # Look for STL, needed to build bindings
197 STL_BASE
="${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/${NDK_TOOLCHAIN_VERSION}"
198 if [ -d ${STL_BASE}/include
]; then
199 CPPFLAGS_STL
="-I${STL_BASE}/include -I${STL_BASE}/libs/${TARGET_ARCH}/include"
200 LDFLAGS_STL
="-L${STL_BASE}/libs/${TARGET_ARCH} -Wl,-rpath=${STL_BASE}/libs/${TARGET_ARCH}"
201 BINDINGS_CONFIG
="--enable-bindings"
203 echo "Warning: STL unavailable, libsigrok bindings will not be built."
206 BINDINGS_CONFIG
="--disable-bindings"
209 # -----------------------------------------------------------------------------
211 # Get the latest versions of config.guess/config.sub that know about Android.
212 $GIT_CLONE http
://git.savannah.gnu.org
/r
/config.git
214 # Get a toolchain for cmake that knows about Android.
215 $WGET https
://raw.githubusercontent.com
/arithran
/android-cmake
/master
/toolchain
/android.toolchain.cmake
216 patch < ..
/android.toolchain.cmake.
patch android.toolchain.cmake
218 # -----------------------------------------------------------------------------
220 # Python (needed for libsigrokdecode)
221 # Don't do parallel Python builds, this doesn't seem to work well.
222 cd Python-
$VER_PYTHON
225 patch -p1 < ..
/..
/Python-
$VER_PYTHON.
patch
226 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
227 sed -i "s/^#zlib/zlib/g" Modules
/Setup
228 sed -i "s/^#math/math/g" Modules
/Setup
229 sed -i "s/^#time/time/g" Modules
/Setup
230 make PYTHON_FOR_BUILD
='_PYTHON_HOST_PLATFORM=$(_PYTHON_HOST_PLATFORM) ./hostpython' install $V
233 # libiconv (needed for glib)
234 $WGET http
://ftp.gnu.org
/pub
/gnu
/libiconv
/libiconv-
$VER_LIBICONV.
tar.gz
235 tar xfz libiconv-
$VER_LIBICONV.
tar.gz
236 cd libiconv-
$VER_LIBICONV
237 cp -f ..
/config
/config.guess build-aux
238 cp -f ..
/config
/config.sub build-aux
239 cp -f ..
/config
/config.guess libcharset
/build-aux
240 cp -f ..
/config
/config.sub libcharset
/build-aux
241 .
/configure
$C --enable-shared
242 make lib
/localcharset.h
$V
250 test -d $PREFIX/include || mkdir
$PREFIX/include
251 cp include
/iconv.h.inst
$PREFIX/include
/iconv.h
254 # gettext (needed for glib)
255 $WGET http
://ftp.gnu.org
/pub
/gnu
/gettext
/gettext-
$VER_GETTEXT.
tar.gz
256 tar xfz gettext-
$VER_GETTEXT.
tar.gz
257 cd gettext-
$VER_GETTEXT
258 .
/configure
$C --enable-shared --disable-libasprintf
264 # zlib (needed for glib and libzip)
265 $WGET http
://zlib.net
/zlib-
$VER_ZLIB.
tar.gz
266 tar xfz zlib-
$VER_ZLIB.
tar.gz
268 # Note: zlib's configure doesn't understand --host, we need to pass $CC.
269 CC
="$TOOLCHAIN_TRIPLET-gcc $SYSROOT" .
/configure
--prefix=$PREFIX
274 # pcre (needed for glib)
275 $WGET https
://ftp.pcre.org
/pub
/pcre
/pcre-
$VER_PCRE.
tar.gz
276 tar xfz pcre-
$VER_PCRE.
tar.gz
278 .
/configure
$C --disable-cpp --enable-utf --enable-unicode-properties
283 # libffi (needed for glib)
284 $WGET ftp://sourceware.org
/pub
/libffi
/libffi-
$VER_LIBFFI.
tar.gz
285 tar xfz libffi-
$VER_LIBFFI.
tar.gz
286 cd libffi-
$VER_LIBFFI
292 # glib (needed for libsigrok)
293 $WGET http
://ftp.gnome.org
/pub
/gnome
/sources
/glib
/$VER_GLIB_SHORT/glib-
$VER_GLIB.
tar.xz
294 tar xfJ glib-
$VER_GLIB.
tar.xz
296 NOCONFIGURE
=yes .
/autogen.sh
297 # Note: Manual LDFLAGS/CPPFLAGS needed for libiconv, rest uses pkg-config.
298 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
303 # libzip (needed for libsigrok)
304 $WGET http
://www.nih.at
/libzip
/libzip-
$VER_LIBZIP.
tar.gz
305 tar xfz libzip-
$VER_LIBZIP.
tar.gz
306 cd libzip-
$VER_LIBZIP
307 cp -f ..
/config
/config.guess .
308 cp -f ..
/config
/config.sub .
314 # libusb-1.0 (needed for libsigrok)
315 $WGET http
://$SF_MIRROR/project
/libusb
/libusb-1.0
/libusb-
$VER_LIBUSB/libusb-
$VER_LIBUSB.
tar.bz2
316 tar xfj libusb-
$VER_LIBUSB.
tar.bz2
317 cd libusb-
$VER_LIBUSB
318 patch -p1 < ..
/..
/libusb-1.0.
patch
319 .
/configure
$C --disable-udev
324 # libftdi1 (needed for libsigrok)
325 $WGET http
://www.intra2net.com
/en
/developer
/libftdi
/download
/libftdi1-
$VER_LIBFTDI1.
tar.bz2
326 tar xfj libftdi1-
$VER_LIBFTDI1.
tar.bz2
327 cd libftdi1-
$VER_LIBFTDI1
328 cmake
$CM -DFTDIPP=no
-DDOCUMENTATION=no
-DEXAMPLES=no
-DFTDI_EEPROM=no
-DPYTHON_BINDINGS=no
-DBUILD_TESTS=n .
334 $GIT_CLONE $REPO_BASE/libserialport
344 # Build dependencies for libsigrok bindings if needed
346 if [ x
"$CPPFLAGS_STL" != x
]; then
348 # libsigc++ (needed for glibmm)
349 $WGET http
://ftp.gnome.org
/pub
/gnome
/sources
/libsigc
++/$VER_LIBSIGCXX_SHORT/libsigc
++-$VER_LIBSIGCXX.
tar.xz
350 tar xfJ libsigc
++-$VER_LIBSIGCXX.
tar.xz
351 cd libsigc
++-$VER_LIBSIGCXX
352 cp -f ..
/config
/config.guess build
353 cp -f ..
/config
/config.sub build
354 CPPFLAGS
="$CPPFLAGS_STL" LDFLAGS
="$LDFLAGS_STL -lgnustl_shared" .
/configure
--disable-documentation $C
359 # glibmm (needed for libsigrok bindings)
360 $WGET http
://ftp.gnome.org
/pub
/gnome
/sources
/glibmm
/$VER_GLIBMM_SHORT/glibmm-
$VER_GLIBMM.
tar.xz
361 tar xfJ glibmm-
$VER_GLIBMM.
tar.xz
362 cd glibmm-
$VER_GLIBMM
363 CPPFLAGS
="$CPPFLAGS_STL" LDFLAGS
="$LDFLAGS_STL -lgnustl_shared" .
/configure
--disable-documentation $C
371 $GIT_CLONE $REPO_BASE/libsigrok
376 CPPFLAGS
="$CPPFLAGS_STL" LDFLAGS
="$LDFLAGS_STL" JAVAC
="javac -source 1.6 -target 1.6" ..
/configure
$C $BINDINGS_CONFIG --datadir=/sdcard
378 make datadir
='$(datarootdir)' install $V
382 $GIT_CLONE $REPO_BASE/libsigrokdecode
393 $GIT_CLONE $REPO_BASE/sigrok-firmware
403 # sigrok-firmware-fx2lafw
404 $WGET http
://sigrok.org
/download
/binary
/sigrok-firmware-fx2lafw
/sigrok-firmware-fx2lafw-bin-
$VER_SIGROK_FIRMWARE_FX2LAFW.
tar.gz
405 tar xfz sigrok-firmware-fx2lafw-bin-
$VER_SIGROK_FIRMWARE_FX2LAFW.
tar.gz
406 cd sigrok-firmware-fx2lafw-bin-
$VER_SIGROK_FIRMWARE_FX2LAFW
407 cp *.fw
$PREFIX/share
/sigrok-firmware
/
411 $GIT_CLONE $REPO_BASE/sigrok-cli
421 # Check if we have all requirements to build PulseView:
423 if [ -z "$ANDROID_NDK" -o ! -d "$ANDROID_NDK" ]; then
424 echo "Android NDK not available, not building PulseView."
428 if [ -z "$ANDROID_SDK" -o ! -d "$ANDROID_SDK"/platforms
/android-
$VER_AND_API ]; then
429 echo "Android SDK with platform $VER_AND_API not available, not building PulseView."
433 if [ ! -e "${ANDROID_SDK}/tools/android" ]; then
434 echo "Essential Android build tools not available, not building PulseView."
438 NDK_HOST
=`"$ANDROID_NDK/ndk-build" -p 2>/dev/null | awk '$1 == "HOST_TAG" { print $3 }'`
440 # Boost (needed for PulseView)
441 $WGET http
://$SF_MIRROR/project
/boost
/boost
/$VER_BOOST/boost_
${VER_BOOST//./_}.
tar.bz2
442 tar xfj boost_
${VER_BOOST//./_}.
tar.bz2
443 cd boost_
${VER_BOOST//./_}
444 patch -p0 < ..
/..
/boost_wchar.
patch
445 CC
= .
/bootstrap.sh
--with-toolset=gcc
--with-libraries=filesystem
,system
,serialization
,test --without-icu
446 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
447 .
/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
450 # Qt (needed for PulseView)
451 $WGET http
://download.qt.io
/official_releases
/qt
/${VER_QT_SHORT}/${VER_QT}/single/qt-everywhere-opensource-src-${VER_QT}.
tar.xz
452 tar xfi qt-everywhere-opensource-src-
${VER_QT}.
tar.xz
453 cd qt-everywhere-opensource-src-
${VER_QT}
454 patch -p1 < ..
/..
/android-qt.
patch
455 CC
= CXX
= .
/configure \
458 -xplatform android-g
++ \
461 -android-sdk "$ANDROID_SDK" \
462 -android-ndk "$ANDROID_NDK" \
463 -android-ndk-host "$NDK_HOST" \
464 -android-arch "$TARGET_ARCH" \
465 -android-toolchain-version "$NDK_TOOLCHAIN_VERSION" \
466 -skip qtconnectivity \
467 -skip qtdeclarative \
474 -skip qttranslations \
477 -skip qtxmlpatterns \
478 -opensource -confirm-license -silent
479 export ANDROID_API_VERSION
=android-
$VER_AND_API
480 export ANDROID_BUILD_TOOLS_REVISION
=$VER_AND_BT
481 make module-qtbase module-qtandroidextras module-qtsvg module-qtimageformats
$PARALLEL $V
485 # sigrok-androidutils
486 $GIT_CLONE $REPO_BASE/sigrok-androidutils
487 cd sigrok-androidutils
489 .
/configure
$C --with-android-sdk="${ANDROID_SDK}" --with-android-platform=android-
$VER_AND_API
494 # Strip all shared libs to reduce size.
495 find $PREFIX -iname "*.so" -exec ${TOOLCHAIN_TRIPLET}-strip -S {} \
;
498 $GIT_CLONE $REPO_BASE/pulseview
500 patch -p1 < ..
/..
/pv_cmake_pkgconfig_fix.
patch
501 sed -i -e "s,\t\tandroid:versionName=.*$,\t\tandroid:versionName=\"`date -Iseconds`\"," android
/AndroidManifest.xml
502 cmake
$CM -DENABLE_TESTS=y .
504 ${TOOLCHAIN_TRIPLET}-strip -S libs
/$TARGET_ARCH/libpulseview.so
506 "${ANDROID_SDK}/tools/android" update project
-p .
-t android-
$VER_AND_API -n PulseView