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_NDK/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86
35 # TOOLCHAIN=$ANDROID_NDK/toolchains/x86-4.9/prebuilt/linux-x86
37 # Select which Android toolchain to use.
38 # Don't forget to also adapt TOOLCHAIN above if you change TOOLCHAIN_TRIPLET!
39 TOOLCHAIN_TRIPLET=arm-linux-androideabi
40 # TOOLCHAIN_TRIPLET=i686-linux-android
42 # The path where the cross-compiled packages will be installed.
43 PREFIX=$HOME/sr_android
45 # The path where to download files to and where to build packages.
48 # Edit this to control verbose build output.
51 # Edit this to enable/disable/modify parallel compiles.
54 # You usually don't need to change anything below this line.
56 # -----------------------------------------------------------------------------
68 VER_LIBSIGCXX_SHORT=2.9
76 VER_SIGROK_FIRMWARE_FX2LAFW=0.1.6
79 VER_AND_BT=23.0.2 # Android build tools version
80 VER_AND_API=16 # Target Android API version
82 SF_MIRROR=download.sourceforge.net
84 WGET="wget -c --quiet"
85 GIT_CLONE="git clone --depth=1"
87 REPO_BASE="git://sigrok.org"
89 case "$TOOLCHAIN_TRIPLET" in
90 arm*) TARGET_ARCH=armeabi;;
91 i686*) TARGET_ARCH=x86;;
92 *) echo >&2 "Unknown prefix for TOOLCHAIN_TRIPLET."; exit 1;;
95 # -----------------------------------------------------------------------------
97 # Get the Android NDK and SDK, install required packages and toolchains.
98 if [ "x$1" = "xprepare" ]; then
99 mkdir -p $ANDROID_PATH
103 $WGET http://dl.google.com/android/ndk/android-ndk-r$VER_NDK-linux-x86.bin
104 chmod 700 android-ndk-r$VER_NDK-linux-x86.bin
105 ./android-ndk-r$VER_NDK-linux-x86.bin -y
106 cd android-ndk-r$VER_NDK
107 ./build/tools/make-standalone-toolchain.sh --platform=android-$VER_AND_API \
108 --toolchain=arm-linux-androideabi-4.9 \
109 --install-dir=$ANDROID_PATH/android-arm-toolchain
110 ./build/tools/make-standalone-toolchain.sh --platform=android-$VER_AND_API \
111 --toolchain=x86-4.9 \
112 --install-dir=$ANDROID_PATH/android-i686-toolchain
116 $WGET http://dl.google.com/android/android-sdk_r$VER_SDK-linux.tgz
117 tar xfz android-sdk_r$VER_SDK-linux.tgz
119 echo y | ./tools/android update sdk --no-ui --all --filter platform-tools,build-tools-$VER_AND_BT,android-$VER_AND_API
125 # -----------------------------------------------------------------------------
127 # Remove build directory contents (if any) and create a new build dir.
132 # -----------------------------------------------------------------------------
134 # Build host Python before we start messing with the environment.
135 # Don't do parallel builds, this doesn't seem to work well.
136 $WGET http://python.org/ftp/python/$VER_PYTHON/Python-$VER_PYTHON.tar.xz
137 tar xfJ Python-$VER_PYTHON.tar.xz
138 cd Python-$VER_PYTHON
144 # -----------------------------------------------------------------------------
146 # We need to find tools in the toolchain.
147 export PATH=$TOOLCHAIN/bin:$PATH
149 # Tell pkg-config to only look for our cross-built stuff.
150 export PKG_CONFIG_LIBDIR="$PREFIX/lib/pkgconfig"
151 export -n PKG_CONFIG_PATH
154 if test -d "$TOOLCHAIN"/sysroot; then
155 echo "Toolchain is standalone"
156 STANDALONE_TOOLCHAIN=$TOOLCHAIN
159 STANDALONE_TOOLCHAIN=
160 NATIVE_API_LEVEL=$VER_AND_API
161 SYSROOT_DIR=${ANDROID_NDK}/platforms/android-${NATIVE_API_LEVEL}/arch-${TARGET_ARCH%eabi*}
162 if [ ! -d "$SYSROOT_DIR" ]; then
163 echo >&2 "Can't build with NDK toolchain; sysroot $SYSROOT_DIR is missing"
166 SYSROOT="--sysroot $SYSROOT_DIR"
167 CC="$TOOLCHAIN_TRIPLET-gcc $SYSROOT"
168 CXX="$TOOLCHAIN_TRIPLET-g++ $SYSROOT"
171 NDK_TOOLCHAIN_VERSION=`${TOOLCHAIN_TRIPLET}-gcc --version | head -1 | sed -e 's/.* \([0-9]\+\.[0-9.]\+\)\( \|.*\)$/\1/'`
173 # Define some helper variables.
174 C="--host=$TOOLCHAIN_TRIPLET --prefix=$PREFIX"
175 CM="-Wno-dev -DCMAKE_TOOLCHAIN_FILE=../android.toolchain.cmake -DANDROID_ABI=${TARGET_ARCH} -DCMAKE_INSTALL_PREFIX=${PREFIX}"
176 if [ -n "$STANDALONE_TOOLCHAIN" ]; then
177 CM="$CM -DANDROID_STANDALONE_TOOLCHAIN=${STANDALONE_TOOLCHAIN}"
178 if [ -d "${ANDROID_NDK}/sources/cxx-stl" ]; then
179 CM="$CM -DANDROID_STL_PATH=${ANDROID_NDK}/sources/cxx-stl"
182 CM="$CM -DANDROID_NDK=${ANDROID_NDK}"
183 CM="$CM -DANDROID_NATIVE_API_LEVEL=${NATIVE_API_LEVEL}"
184 CM="$CM -DANDROID_TOOLCHAIN_NAME=${TOOLCHAIN_TRIPLET}-${NDK_TOOLCHAIN_VERSION}"
185 CM="$CM -DCMAKE_MAKE_PROGRAM=${ANDROID_NDK}/prebuilt/linux-x86/bin/make"
188 # Look for STL, needed to build bindings
189 STL_BASE="${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/${NDK_TOOLCHAIN_VERSION}"
190 if [ -d ${STL_BASE}/include ]; then
191 CPPFLAGS_STL="-I${STL_BASE}/include -I${STL_BASE}/libs/${TARGET_ARCH}/include"
192 LDFLAGS_STL="-L${STL_BASE}/libs/${TARGET_ARCH} -Wl,-rpath=${STL_BASE}/libs/${TARGET_ARCH}"
193 BINDINGS_CONFIG="--enable-bindings"
195 echo "Warning: STL unavailable, libsigrok bindings will not be built."
198 BINDINGS_CONFIG="--disable-bindings"
201 # -----------------------------------------------------------------------------
203 # Get the latest versions of config.guess/config.sub that know about Android.
204 $GIT_CLONE http://git.savannah.gnu.org/r/config.git
206 # Get a toolchain for cmake that knows about Android.
207 $WGET https://raw.githubusercontent.com/arithran/android-cmake/master/toolchain/android.toolchain.cmake
208 patch < ../android.toolchain.cmake.patch android.toolchain.cmake
210 # -----------------------------------------------------------------------------
212 # Python (needed for libsigrokdecode)
213 # Don't do parallel Python builds, this doesn't seem to work well.
214 cd Python-$VER_PYTHON
217 patch -p1 < ../../Python-$VER_PYTHON.patch
218 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
219 sed -i "s/^#zlib/zlib/g" Modules/Setup
220 sed -i "s/^#math/math/g" Modules/Setup
221 sed -i "s/^#time/time/g" Modules/Setup
222 sed -i "s/^#_struct/_struct/g" Modules/Setup
223 make PYTHON_FOR_BUILD='_PYTHON_HOST_PLATFORM=$(_PYTHON_HOST_PLATFORM) ./hostpython' install $V
226 # libiconv (needed for glib)
227 $WGET http://ftp.gnu.org/pub/gnu/libiconv/libiconv-$VER_LIBICONV.tar.gz
228 tar xfz libiconv-$VER_LIBICONV.tar.gz
229 cd libiconv-$VER_LIBICONV
230 cp -f ../config/config.guess build-aux
231 cp -f ../config/config.sub build-aux
232 cp -f ../config/config.guess libcharset/build-aux
233 cp -f ../config/config.sub libcharset/build-aux
234 ./configure $C --enable-shared
235 make lib/localcharset.h $V
243 test -d $PREFIX/include || mkdir $PREFIX/include
244 cp include/iconv.h.inst $PREFIX/include/iconv.h
247 # gettext (needed for glib)
248 $WGET http://ftp.gnu.org/pub/gnu/gettext/gettext-$VER_GETTEXT.tar.gz
249 tar xfz gettext-$VER_GETTEXT.tar.gz
250 cd gettext-$VER_GETTEXT
251 ./configure $C --enable-shared --disable-libasprintf
257 # zlib (needed for glib and libzip)
258 $WGET http://zlib.net/zlib-$VER_ZLIB.tar.gz
259 tar xfz zlib-$VER_ZLIB.tar.gz
261 # Note: zlib's configure doesn't understand --host, we need to pass $CC.
262 CC="$TOOLCHAIN_TRIPLET-gcc $SYSROOT" ./configure --prefix=$PREFIX
267 # pcre (needed for glib)
268 $WGET https://ftp.pcre.org/pub/pcre/pcre-$VER_PCRE.tar.gz
269 tar xfz pcre-$VER_PCRE.tar.gz
271 ./configure $C --disable-cpp --enable-utf --enable-unicode-properties
276 # libffi (needed for glib)
277 $WGET ftp://sourceware.org/pub/libffi/libffi-$VER_LIBFFI.tar.gz
278 tar xfz libffi-$VER_LIBFFI.tar.gz
279 cd libffi-$VER_LIBFFI
285 # glib (needed for libsigrok)
286 $WGET http://ftp.gnome.org/pub/gnome/sources/glib/$VER_GLIB_SHORT/glib-$VER_GLIB.tar.xz
287 tar xfJ glib-$VER_GLIB.tar.xz
289 NOCONFIGURE=yes ./autogen.sh
290 # Note: Manual LDFLAGS/CPPFLAGS needed for libiconv, rest uses pkg-config.
291 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
296 # libzip (needed for libsigrok)
297 $WGET http://www.nih.at/libzip/libzip-$VER_LIBZIP.tar.gz
298 tar xfz libzip-$VER_LIBZIP.tar.gz
299 cd libzip-$VER_LIBZIP
300 cp -f ../config/config.guess .
301 cp -f ../config/config.sub .
307 # libusb-1.0 (needed for libsigrok)
308 $WGET http://$SF_MIRROR/project/libusb/libusb-1.0/libusb-$VER_LIBUSB/libusb-$VER_LIBUSB.tar.bz2
309 tar xfj libusb-$VER_LIBUSB.tar.bz2
310 cd libusb-$VER_LIBUSB
311 patch -p1 < ../../libusb-1.0.patch
312 ./configure $C --disable-udev
317 # libftdi1 (needed for libsigrok)
318 $WGET http://www.intra2net.com/en/developer/libftdi/download/libftdi1-$VER_LIBFTDI1.tar.bz2
319 tar xfj libftdi1-$VER_LIBFTDI1.tar.bz2
320 cd libftdi1-$VER_LIBFTDI1
321 cmake $CM -DFTDIPP=no -DDOCUMENTATION=no -DEXAMPLES=no -DFTDI_EEPROM=no -DPYTHON_BINDINGS=no -DBUILD_TESTS=n .
327 $GIT_CLONE $REPO_BASE/libserialport
337 # Build dependencies for libsigrok bindings if needed
339 if [ x"$CPPFLAGS_STL" != x ]; then
341 # libsigc++ (needed for glibmm)
342 $WGET http://ftp.gnome.org/pub/gnome/sources/libsigc++/$VER_LIBSIGCXX_SHORT/libsigc++-$VER_LIBSIGCXX.tar.xz
343 tar xfJ libsigc++-$VER_LIBSIGCXX.tar.xz
344 cd libsigc++-$VER_LIBSIGCXX
345 cp -f ../config/config.guess build
346 cp -f ../config/config.sub build
347 CPPFLAGS="$CPPFLAGS_STL" LDFLAGS="$LDFLAGS_STL -lgnustl_shared" ./configure --disable-documentation $C
352 # glibmm (needed for libsigrok bindings)
353 $WGET http://ftp.gnome.org/pub/gnome/sources/glibmm/$VER_GLIBMM_SHORT/glibmm-$VER_GLIBMM.tar.xz
354 tar xfJ glibmm-$VER_GLIBMM.tar.xz
355 cd glibmm-$VER_GLIBMM
356 CPPFLAGS="$CPPFLAGS_STL" LDFLAGS="$LDFLAGS_STL -lgnustl_shared" ./configure --disable-documentation $C
364 $GIT_CLONE $REPO_BASE/libsigrok
369 CPPFLAGS="$CPPFLAGS_STL" LDFLAGS="$LDFLAGS_STL" JAVAC="javac -source 1.6 -target 1.6" ../configure $C $BINDINGS_CONFIG --datadir=/sdcard
371 make datadir='$(datarootdir)' install $V
375 $GIT_CLONE $REPO_BASE/libsigrokdecode
386 $GIT_CLONE $REPO_BASE/sigrok-firmware
396 # sigrok-firmware-fx2lafw
397 $WGET http://sigrok.org/download/binary/sigrok-firmware-fx2lafw/sigrok-firmware-fx2lafw-bin-$VER_SIGROK_FIRMWARE_FX2LAFW.tar.gz
398 tar xfz sigrok-firmware-fx2lafw-bin-$VER_SIGROK_FIRMWARE_FX2LAFW.tar.gz
399 cd sigrok-firmware-fx2lafw-bin-$VER_SIGROK_FIRMWARE_FX2LAFW
400 cp *.fw $PREFIX/share/sigrok-firmware/
404 $GIT_CLONE $REPO_BASE/sigrok-cli
414 # Check if we have all requirements to build PulseView:
416 if [ -z "$ANDROID_NDK" -o ! -d "$ANDROID_NDK" ]; then
417 echo "Android NDK not available, not building PulseView."
421 if [ -z "$ANDROID_SDK" -o ! -d "$ANDROID_SDK"/platforms/android-$VER_AND_API ]; then
422 echo "Android SDK with platform $VER_AND_API not available, not building PulseView."
426 if [ ! -e "${ANDROID_SDK}/tools/android" ]; then
427 echo "Essential Android build tools not available, not building PulseView."
431 NDK_HOST=`"$ANDROID_NDK/ndk-build" -p 2>/dev/null | awk '$1 == "HOST_TAG" { print $3 }'`
433 # Boost (needed for PulseView)
434 $WGET http://$SF_MIRROR/project/boost/boost/$VER_BOOST/boost_${VER_BOOST//./_}.tar.bz2
435 tar xfj boost_${VER_BOOST//./_}.tar.bz2
436 cd boost_${VER_BOOST//./_}
437 patch -p0 < ../../boost_wchar.patch
438 CC= ./bootstrap.sh --with-toolset=gcc --with-libraries=filesystem,system,serialization,test --without-icu
439 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
440 ./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
443 # Qt (needed for PulseView)
444 $WGET https://download.qt.io/new_archive/qt/${VER_QT_SHORT}/${VER_QT}/single/qt-everywhere-opensource-src-${VER_QT}.tar.xz
445 tar xfi qt-everywhere-opensource-src-${VER_QT}.tar.xz
446 cd qt-everywhere-opensource-src-${VER_QT}
447 patch -p1 < ../../android-qt.patch
448 CC= CXX= ./configure \
451 -xplatform android-g++ \
454 -android-sdk "$ANDROID_SDK" \
455 -android-ndk "$ANDROID_NDK" \
456 -android-ndk-host "$NDK_HOST" \
457 -android-arch "$TARGET_ARCH" \
458 -android-toolchain-version "$NDK_TOOLCHAIN_VERSION" \
459 -skip qtconnectivity \
467 -skip qtxmlpatterns \
468 -opensource -confirm-license -silent -no-warnings-are-errors
469 export ANDROID_API_VERSION=android-$VER_AND_API
470 export ANDROID_BUILD_TOOLS_REVISION=$VER_AND_BT
471 make module-qtbase module-qtandroidextras module-qtsvg module-qtimageformats module-qttranslations $PARALLEL $V
475 # sigrok-androidutils
476 $GIT_CLONE $REPO_BASE/sigrok-androidutils
477 cd sigrok-androidutils
479 ./configure $C --with-android-sdk="${ANDROID_SDK}" --with-android-platform=android-$VER_AND_API
484 # Strip all shared libs to reduce size.
485 find $PREFIX -iname "*.so" -exec ${TOOLCHAIN_TRIPLET}-strip -S {} \;
488 $GIT_CLONE $REPO_BASE/pulseview
490 patch -p1 < ../../pv_cmake_pkgconfig_fix.patch
491 sed -i -e "s,\t\tandroid:versionName=.*$,\t\tandroid:versionName=\"`date -Iseconds`\"," android/AndroidManifest.xml
492 cmake $CM -DENABLE_TESTS=y .
494 ${TOOLCHAIN_TRIPLET}-strip -S libs/$TARGET_ARCH/libpulseview.so
496 "${ANDROID_SDK}/tools/android" update project -p . -t android-$VER_AND_API -n PulseView