]> sigrok.org Git - sigrok-util.git/commitdiff
sigrok-cross-android: PulseView now starts
authorMarcus Comstedt <redacted>
Sat, 12 Apr 2014 12:01:35 +0000 (14:01 +0200)
committerUwe Hermann <redacted>
Mon, 25 Aug 2014 20:38:43 +0000 (22:38 +0200)
SRD has been temporarily disabled, since there was a crash in it.

cross-compile/android/fix-libraries.sh [new file with mode: 0755]
cross-compile/android/pulseview-cpp.patch [new file with mode: 0644]
cross-compile/android/pulseview-java.patch [new file with mode: 0644]
cross-compile/android/sigrok-cross-android

diff --git a/cross-compile/android/fix-libraries.sh b/cross-compile/android/fix-libraries.sh
new file mode 100755 (executable)
index 0000000..8d14940
--- /dev/null
@@ -0,0 +1,71 @@
+#!/bin/sh
+
+set -e
+tmpdir=/tmp/fixlib$$
+trap 'rm -rf "$tmpdir"' 0 1 2 3 15
+mkdir -p "$tmpdir"
+
+if [ $# -lt 3 ]; then
+  echo >&2 "Usage: $0 srclib destlib library ..."
+  exit 1
+fi
+
+: ${READELF=readelf}
+
+srclib="$1"
+destlib="$2"
+shift
+shift
+rm -f "$tmpdir"/todo
+touch "$tmpdir"/todo
+for lib; do
+  echo "$lib" >> "$tmpdir"/todo
+done
+
+process()
+{
+  libname="$1"
+  libfile="$destlib"/"$libname"
+  if [ ! -f "$libfile" ]; then
+    echo >&2 "$libfile not found"
+    exit 1
+  fi
+  "$READELF" -d "$libfile" | awk '$1=="0x00000001" {print $NF}' | tr -d '][' | grep '\.so\.' | sort >> "$tmpdir"/worklist
+}
+
+install()
+{
+  libname="$1"
+  libfile=`echo "$libname" | sed -e 's/\.so\..*/.so/'`
+  cp "$srclib"/"$libname" "$destlib"/"$libfile"
+  echo "$libfile" >> "$tmpdir"/worklist
+  for deplib in `"$READELF" -d "$destlib"/"$libfile" | awk '$1=="0x00000001" {print $NF}' | tr -d '][' | grep '\.so\.' | sort`; do
+    echo "$deplib $libname"  >> "$tmpdir"/liblist
+  done
+}
+
+rm -f "$tmpdir"/liblist
+touch "$tmpdir"/liblist
+sort "$tmpdir"/todo > "$tmpdir"/processed
+while [ -s "$tmpdir"/todo ]; do
+  rm -f "$tmpdir"/worklist
+  touch "$tmpdir"/worklist
+  cat "$tmpdir"/todo | while read lib; do
+    if [ ! -z "$lib" ]; then
+      process "$lib"
+    fi
+  done
+  sort "$tmpdir"/worklist | uniq > "$tmpdir"/todo.tmp
+  comm -13 "$tmpdir"/processed "$tmpdir"/todo.tmp > "$tmpdir"/todo
+  sort -m "$tmpdir"/processed "$tmpdir"/todo | uniq > "$tmpdir"/processed.tmp
+  mv "$tmpdir"/processed.tmp "$tmpdir"/processed
+  rm -f "$tmpdir"/worklist
+  touch "$tmpdir"/worklist
+  cat "$tmpdir"/todo | while read lib; do
+    if [ ! -z "$lib" ]; then
+      install "$lib"
+    fi
+  done
+  mv "$tmpdir"/worklist "$tmpdir"/todo
+done
+tsort "$tmpdir"/liblist
diff --git a/cross-compile/android/pulseview-cpp.patch b/cross-compile/android/pulseview-cpp.patch
new file mode 100644 (file)
index 0000000..496a3dd
--- /dev/null
@@ -0,0 +1,39 @@
+diff --git a/CMakeLists.txt b/CMakeLists.txt
+index 11767a6..b8eed96 100644
+--- a/CMakeLists.txt
++++ b/CMakeLists.txt
+@@ -317,12 +317,21 @@ if(WIN32)
+       list(APPEND PULSEVIEW_LINK_LIBS "-lqsvg")
+ endif()
++if(ANDROID)
++add_library(${PROJECT_NAME} SHARED
++      ${pulseview_SOURCES}
++      ${pulseview_HEADERS_MOC}
++      ${pulseview_FORMS_HEADERS}
++      ${pulseview_RESOURCES_RCC}
++)
++else()
+ add_executable(${PROJECT_NAME}
+       ${pulseview_SOURCES}
+       ${pulseview_HEADERS_MOC}
+       ${pulseview_FORMS_HEADERS}
+       ${pulseview_RESOURCES_RCC}
+ )
++endif()
+ target_link_libraries(${PROJECT_NAME} ${PULSEVIEW_LINK_LIBS})
+diff --git a/pv/view/decodetrace.cpp b/pv/view/decodetrace.cpp
+index e4f0276..861d25b 100644
+--- a/pv/view/decodetrace.cpp
++++ b/pv/view/decodetrace.cpp
+@@ -373,7 +373,7 @@ void DecodeTrace::draw_instant(const pv::data::decode::Annotation &a, QPainter &
+ {
+       const QString text = a.annotations().empty() ?
+               QString() : a.annotations().back();
+-      const double w = min(p.boundingRect(QRectF(), 0, text).width(),
++      const double w = min((double)p.boundingRect(QRectF(), 0, text).width(),
+               0.0) + h;
+       const QRectF rect(x - w / 2, y - h / 2, w, h);
diff --git a/cross-compile/android/pulseview-java.patch b/cross-compile/android/pulseview-java.patch
new file mode 100644 (file)
index 0000000..993f8a3
--- /dev/null
@@ -0,0 +1,118 @@
+diff --git a/java/AndroidManifest.xml b/java/AndroidManifest.xml
+index 0564a8d..0356f33 100644
+--- a/java/AndroidManifest.xml
++++ b/java/AndroidManifest.xml
+@@ -1,5 +1,5 @@
+ <?xml version='1.0' encoding='utf-8'?>
+-<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="org.kde.necessitas.example">
++<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="org.sigrok.pulseview">
+     <application android:name="org.kde.necessitas.origo.QtApplication" android:icon="@drawable/icon" android:label="@string/app_name">
+         <activity android:name="org.kde.necessitas.origo.QtActivity" android:label="@string/app_name" android:configChanges="orientation|locale|fontScale|keyboard|keyboardHidden" >
+             <intent-filter>
+@@ -8,7 +8,7 @@
+             </intent-filter>
+             <meta-data android:name="android.app.qt_libs_resource_id" android:resource="@array/qt_libs"/>
+             <meta-data android:name="android.app.bundled_libs_resource_id" android:resource="@array/bundled_libs"/>
+-            <meta-data android:name="android.app.lib_name" android:value=""/>
++            <meta-data android:name="android.app.lib_name" android:value="pulseview"/>
+             <!--  Messages maps -->
+             <meta-data android:name="android.app.ministro_not_found_msg" android:value="@string/ministro_not_found_msg"/>
+             <meta-data android:name="android.app.ministro_needed_msg" android:value="@string/ministro_needed_msg"/>
+diff --git a/java/res/values/strings.xml b/java/res/values/strings.xml
+index bd6928f..68f017e 100644
+--- a/java/res/values/strings.xml
++++ b/java/res/values/strings.xml
+@@ -1,6 +1,6 @@
+ <?xml version='1.0' encoding='utf-8'?>
+ <resources>
+-    <string name="app_name"></string>
++    <string name="app_name">PulseView</string>
+     <string name="ministro_not_found_msg">Can\'t find Ministro service.\nThe application can\'t start.</string>
+     <string name="ministro_needed_msg">This application requires Ministro service. Would you like to install it?</string>
+     <string name="fatal_error_msg">Your application encountered a fatal error and cannot continue.</string>
+diff --git a/java/src/org/kde/necessitas/origo/QtActivity.java b/java/src/org/kde/necessitas/origo/QtActivity.java
+index 4ebf1f6..f4e3598 100644
+--- a/java/src/org/kde/necessitas/origo/QtActivity.java
++++ b/java/src/org/kde/necessitas/origo/QtActivity.java
+@@ -108,6 +108,12 @@ public class QtActivity extends Activity
+     {
+         try
+         {
++          System.loadLibrary("gnustl_shared");
++            org.sigrok.androidutils.LibWrangler.setupLibs(
++                getAssets().open("liblist.txt"),
++                new File(getApplicationInfo().nativeLibraryDir),
++                new File(getFilesDir(), "lib"));
++
+             if (loaderParams.getInt(ERROR_CODE_KEY) != 0)
+             { // fatal error, show the error and quit
+                 AlertDialog errorDialog = new AlertDialog.Builder(QtActivity.this).create();
+diff --git a/java/src/org/sigrok/androidutils/LibWrangler.java b/java/src/org/sigrok/androidutils/LibWrangler.java
+new file mode 100644
+index 0000000..0c9effe
+--- /dev/null
++++ b/java/src/org/sigrok/androidutils/LibWrangler.java
+@@ -0,0 +1,63 @@
++package org.sigrok.androidutils;
++
++import java.io.InputStream;
++import java.io.InputStreamReader;
++import java.io.BufferedReader;
++import java.io.IOException;
++import java.io.File;
++
++public final class LibWrangler
++{
++    protected static String stripSoVersion(String s)
++    {
++        int p = s.lastIndexOf(".so.");
++        if (p >= 0)
++            s = s.substring(0, p+3);
++        return s;
++    }
++
++    protected static void makeLink(File from, File to)
++        throws IOException
++    {
++        if (to.equals(from.getCanonicalFile())) {
++            // Symlink already correct
++            return;
++        }
++        from.delete();
++        int rc;
++        Process proc =
++            Runtime.getRuntime().exec(new String[]{"ln", "-s",
++                                                   to.getAbsolutePath(),
++                                                   from.getAbsolutePath()});
++        for(;;) {
++            try {
++                rc = proc.waitFor();
++                break;
++            } catch(InterruptedException ie) {
++            }
++        }
++        if (rc != 0)
++            throw new IOException("Failed to create symlink "+from);
++    }
++
++    public static void setupLibs(BufferedReader reader, File libDir1, File libDir2)
++        throws IOException
++    {
++        if (!libDir2.exists())
++            libDir2.mkdir();
++
++        String libname;
++        while ((libname = reader.readLine()) != null) {
++            File shlib = new File(libDir2, libname);
++            makeLink(shlib, new File(libDir1, stripSoVersion(libname)));
++            System.load(shlib.getAbsolutePath());
++        }
++    }
++
++    public static void setupLibs(InputStream is, File libDir1, File libDir2)
++        throws IOException
++    {
++      setupLibs(new BufferedReader(new InputStreamReader(is, "US-ASCII")),
++                libDir1, libDir2);
++    }
++}
index b8450391c7a48a0583f4cd6e61f10d659e513516..c31cb97e649a7c882a8a7d41b68ea570e85c5674 100755 (executable)
@@ -310,7 +310,16 @@ cd ..
 # PulseView
 $GIT_CLONE git://sigrok.org/pulseview
 cd pulseview
-cmake $CM -DQT_QMAKE_EXECUTABLE=${PREFIX}/bin/qmake -DANDROID_STL_PATH=${ANDROID_NDK}/sources/cxx-stl .
-make $PARALLEL VERBOSE=1
-make install
-cd ..
+patch -p1 < ../../pulseview-cpp.patch
+cmake $CM -DQT_QMAKE_EXECUTABLE=${PREFIX}/bin/qmake -DANDROID_STL_PATH=${ANDROID_NDK}/sources/cxx-stl -DENABLE_DECODE=FALSE .
+make $PARALLEL
+cp -r "$PREFIX"/src/android/java .
+cp -r libs java/
+cd java
+patch -p2 < ../../../pulseview-java.patch
+mkdir -p assets
+READELF=$TOOLCHAIN_TRIPLET-readelf ../../../fix-libraries.sh "$PREFIX/lib" libs/"$TARGET_ARCH" libpulseview.so > assets/liblist.txt
+cp ${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/${NDK_TOOLCHAIN_VERSION}/libs/${TARGET_ARCH}/libgnustl_shared.so libs/${TARGET_ARCH}/
+"$ANDROID_TOOLS/android" update project -p . -t android-14 -n PulseView
+ant debug
+cd ../..