On 09/07/13 18:06, Toby Gray wrote:
Hi,

I've attached two patches which improve the logging in non-console applications and three patches which add Android support to libusbx.

The first patch adds a configure option "--enable-system-log". This also enable output of libusbx log messages to the debugger output in Windows.

The second patch makes the "--enable-system-log" option make use of syslog on platforms which support it. I've only tested this on 64-bit desktop Ubuntu 12.04 at the moment. I'm not sure if non-Linux platforms, e.g.

While looking at this logging I discovered that the Android logging code doesn't even compile. This appears to be because there aren't any build files for Android in the libusbx source tree. The third patch adds build files for Android.

The forth patch updates the logging code and a couple of other files so that libusbx almost builds for Android.


I've attached a rebase of patches 1 to 4 onto the master branch of libusbx.

The fifth and final patch modifies the hotplug netlink code so that it doesn't use pthread_cancel. This is because Android doesn't have pthread_cancel, so alternative ways of stopping the hotplug thread are needed.

This fix has already been introduced to master by Hans de Goede.


I've not done much testing with libusbx on Android other than using listdevs. I'll try to find time to:
* Add building for Android of more of the samples.

This is included in the attached patch number 5.

* Add building for Android of the tests.

This is also included in patch number 5. This needed a slight change to stress.c which I added in patch number 6.

* Add some documentation about how to build libusbx for Android.

I've merged this into the 3rd patch.

* Check that the Android.mk is suitable for easily including in other Android projects. This is really a case of making sure that all the paths are correctly set in relation to the location of the make file.

I've checked this and it works fine.

Regards,

Toby
>From e4ea88aac8fea2753387708a0860935762197a0d Mon Sep 17 00:00:00 2001
From: Toby Gray <toby.g...@realvnc.com>
Date: Tue, 9 Jul 2013 16:05:39 +0100
Subject: [PATCH 1/6] Windows: Add compile time option to log messages to the
 debugger.

This change makes it considerably easier to debug issues in UI applications
which don't necessarily have a console connected to stderr.

Outputting to the debugger shouldn't occur in normal situations so
this change has to be explicitly enabled by a build-time config flag.
---
 configure.ac  |  8 ++++++++
 libusb/core.c | 10 ++++++++++
 msvc/config.h |  3 +++
 3 files changed, 21 insertions(+)

diff --git a/configure.ac b/configure.ac
index 669fcf8..11f2b21 100644
--- a/configure.ac
+++ b/configure.ac
@@ -200,6 +200,14 @@ if test "x$debug_log_enabled" != "xno"; then
 	AC_DEFINE([ENABLE_DEBUG_LOGGING], 1, [Start with debug message logging enabled])
 fi
 
+AC_ARG_ENABLE([system-log], [AS_HELP_STRING([--enable-system-log],
+	[output logging messages to system wide log])],
+	[system_log_enabled=$enableval],
+	[system_log_enabled='no'])
+if test "x$system_log_enabled" != "xno"; then
+	AC_DEFINE([USE_SYSTEM_LOGGING_FACILITY], 1, [Enable output to system log])
+fi
+
 # Examples build
 AC_ARG_ENABLE([examples-build], [AS_HELP_STRING([--enable-examples-build],
 	[build example applications (default n)])],
diff --git a/libusb/core.c b/libusb/core.c
index 4f2f366..1608792 100644
--- a/libusb/core.c
+++ b/libusb/core.c
@@ -2028,6 +2028,16 @@ int usbi_gettimeofday(struct timeval *tp, void *tzp)
 
 static void usbi_log_str(struct libusb_context *ctx, const char * str)
 {
+#ifdef USE_SYSTEM_LOGGING_FACILITY
+#if defined(OS_WINDOWS)
+	OutputDebugStringA(str);
+#elif defined(OS_WINCE)
+	/* Windows CE only supports the unicode version of OutputDebugString. */
+	WCHAR wbuf[USBI_MAX_LOG_LEN];
+	MultiByteToWideChar(CP_ACP, 0, str, -1, wbuf, sizeof(wbuf));
+	OutputDebugStringW(wbuf);
+#endif
+#endif /* USE_SYSTEM_LOGGING_FACILITY */
 	UNUSED(ctx);
 	fputs(str, stderr);
 }
diff --git a/msvc/config.h b/msvc/config.h
index bb542c5..4b418db 100644
--- a/msvc/config.h
+++ b/msvc/config.h
@@ -25,6 +25,9 @@
 /* Uncomment to start with debug message logging enabled */
 // #define ENABLE_DEBUG_LOGGING 1
 
+/* Uncomment to enabling logging to system log */
+// #define USE_SYSTEM_LOGGING_FACILITY
+
 /* type of second poll() argument */
 #define POLL_NFDS_TYPE unsigned int
 
-- 
1.8.3.4

>From 45d5f1105dabfe4a8a4239855c47bb7e29794607 Mon Sep 17 00:00:00 2001
From: Toby Gray <toby.g...@realvnc.com>
Date: Tue, 9 Jul 2013 16:30:55 +0100
Subject: [PATCH 2/6] Core: Adding support for syslog if --enable-system-log is
 passed to configure.

This change allows log messages to go to syslog if enabled at
compilation time by using --enable-system-log.

The syslog.h header and syslog() function are used to provide the
logging.
---
 configure.ac  |  7 +++++++
 libusb/core.c | 22 ++++++++++++++++++----
 2 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/configure.ac b/configure.ac
index 11f2b21..4220185 100644
--- a/configure.ac
+++ b/configure.ac
@@ -208,6 +208,13 @@ if test "x$system_log_enabled" != "xno"; then
 	AC_DEFINE([USE_SYSTEM_LOGGING_FACILITY], 1, [Enable output to system log])
 fi
 
+# Check if syslog is available in standard C library
+AC_CHECK_HEADERS(syslog.h)
+AC_CHECK_FUNC([syslog], [have_syslog=yes], [have_syslog=no])
+if test "x$have_syslog" != "xno"; then
+	AC_DEFINE([HAVE_SYSLOG_FUNC], 1, [syslog() function available])
+fi
+
 # Examples build
 AC_ARG_ENABLE([examples-build], [AS_HELP_STRING([--enable-examples-build],
 	[build example applications (default n)])],
diff --git a/libusb/core.c b/libusb/core.c
index 1608792..ee34a7e 100644
--- a/libusb/core.c
+++ b/libusb/core.c
@@ -33,6 +33,9 @@
 #ifdef HAVE_SYS_TIME_H
 #include <sys/time.h>
 #endif
+#ifdef HAVE_SYSLOG_H
+#include <syslog.h>
+#endif
 
 #ifdef __ANDROID__
 #include <android/log.h>
@@ -2026,7 +2029,8 @@ int usbi_gettimeofday(struct timeval *tp, void *tzp)
 }
 #endif
 
-static void usbi_log_str(struct libusb_context *ctx, const char * str)
+static void usbi_log_str(struct libusb_context *ctx,
+	enum libusb_log_level level, const char * str)
 {
 #ifdef USE_SYSTEM_LOGGING_FACILITY
 #if defined(OS_WINDOWS)
@@ -2036,6 +2040,16 @@ static void usbi_log_str(struct libusb_context *ctx, const char * str)
 	WCHAR wbuf[USBI_MAX_LOG_LEN];
 	MultiByteToWideChar(CP_ACP, 0, str, -1, wbuf, sizeof(wbuf));
 	OutputDebugStringW(wbuf);
+#elif defined(HAVE_SYSLOG_FUNC)
+	int syslog_level = LOG_INFO;
+	switch (level) {
+	case LIBUSB_LOG_LEVEL_INFO: syslog_level = LOG_INFO; break;
+	case LIBUSB_LOG_LEVEL_WARNING: syslog_level = LOG_WARNING; break;
+	case LIBUSB_LOG_LEVEL_ERROR: syslog_level = LOG_ERR; break;
+	case LIBUSB_LOG_LEVEL_DEBUG: syslog_level = LOG_DEBUG; break;
+	case LIBUSB_LOG_LEVEL_NONE: break;
+	}
+	syslog(syslog_level, "%s", str);
 #endif
 #endif /* USE_SYSTEM_LOGGING_FACILITY */
 	UNUSED(ctx);
@@ -2094,8 +2108,8 @@ void usbi_log_v(struct libusb_context *ctx, enum libusb_log_level level,
 	usbi_gettimeofday(&now, NULL);
 	if ((global_debug) && (!has_debug_header_been_displayed)) {
 		has_debug_header_been_displayed = 1;
-		usbi_log_str(ctx, "[timestamp] [threadID] facility level [function call] <message>\n");
-		usbi_log_str(ctx, "--------------------------------------------------------------------------------\n");
+		usbi_log_str(ctx, LIBUSB_LOG_LEVEL_DEBUG, "[timestamp] [threadID] facility level [function call] <message>\n");
+		usbi_log_str(ctx, LIBUSB_LOG_LEVEL_DEBUG, "--------------------------------------------------------------------------------\n");
 	}
 	if (now.tv_usec < timestamp_origin.tv_usec) {
 		now.tv_sec--;
@@ -2153,7 +2167,7 @@ void usbi_log_v(struct libusb_context *ctx, enum libusb_log_level level,
 	}
 	strcpy(buf + header_len + text_len, USBI_LOG_LINE_END);
 
-	usbi_log_str(ctx, buf);
+	usbi_log_str(ctx, level, buf);
 #endif
 }
 
-- 
1.8.3.4

>From 0a5048ec27231921822583c3bf59ced57bc22ce8 Mon Sep 17 00:00:00 2001
From: Toby Gray <toby.g...@realvnc.com>
Date: Tue, 9 Jul 2013 16:43:53 +0100
Subject: [PATCH 3/6] Android: Adding Android build files.

---
 android/README             | 24 ++++++++++++++++++
 android/config.h           | 56 +++++++++++++++++++++++++++++++++++++++++
 android/jni/Android.mk     | 63 ++++++++++++++++++++++++++++++++++++++++++++++
 android/jni/Application.mk | 19 ++++++++++++++
 4 files changed, 162 insertions(+)
 create mode 100644 android/README
 create mode 100644 android/config.h
 create mode 100644 android/jni/Android.mk
 create mode 100644 android/jni/Application.mk

diff --git a/android/README b/android/README
new file mode 100644
index 0000000..3602cde
--- /dev/null
+++ b/android/README
@@ -0,0 +1,24 @@
+libusb for Android
+==================
+
+To build libusb for Android do the following:
+
+ 1. Download the latest NDK from:
+
+   http://developer.android.com/tools/sdk/ndk/index.html
+
+ 2. Extract the NDK.
+
+ 3. Open a shell and change directory to "android"
+
+ 4. Run "ndk-build" from the NDK that you extracted.
+
+The libusb library, examples and tests can then be found in:
+
+  "android/libs/$ARCH"
+
+Where $ARCH is one of:
+
+  armeabi
+  armeabi-v7a
+  x86
diff --git a/android/config.h b/android/config.h
new file mode 100644
index 0000000..7943384
--- /dev/null
+++ b/android/config.h
@@ -0,0 +1,56 @@
+/*
+ * Android build config for libusbx
+ * Copyright © 2012-2013 RealVNC Ltd. <toby.g...@realvnc.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/* Start with debug message logging enabled */
+/* #undef ENABLE_DEBUG_LOGGING */
+
+/* Message logging */
+#define ENABLE_LOGGING
+
+/* Linux backend */
+#define OS_LINUX 1
+
+/* Enable output to system log */
+#define USE_SYSTEM_LOGGING_FACILITY 1
+
+/* type of second poll() argument */
+#define POLL_NFDS_TYPE nfds_t
+
+/* Use POSIX Threads */
+#define THREADS_POSIX 1
+
+/* Default visibility */
+#define DEFAULT_VISIBILITY __attribute__((visibility("default")))
+
+/* Define to 1 if you have the <memory.h> header file. */
+#define HAVE_MEMORY_H 1
+
+/* Define to 1 if you have the <poll.h> header file. */
+#define HAVE_POLL_H 1
+
+/* Define to 1 if you have the <signal.h> header file. */
+#define HAVE_SIGNAL_H 1
+
+#ifndef TIMESPEC_TO_TIMEVAL
+#define TIMESPEC_TO_TIMEVAL(tv, ts)                                     \
+        do {                                                            \
+                (tv)->tv_sec = (ts)->tv_sec;                            \
+                (tv)->tv_usec = (ts)->tv_nsec / 1000;                   \
+        } while (0)
+#endif
diff --git a/android/jni/Android.mk b/android/jni/Android.mk
new file mode 100644
index 0000000..c00c8ac
--- /dev/null
+++ b/android/jni/Android.mk
@@ -0,0 +1,63 @@
+#
+# Android build config for libusbx
+# Copyright © 2012-2013 RealVNC Ltd. <toby.g...@realvnc.com>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+#
+
+LOCAL_PATH:= $(call my-dir)
+
+# libusb
+
+include $(CLEAR_VARS)
+
+LIBUSB_ROOT_REL:= ../..
+LIBUSB_ROOT_ABS:= $(LOCAL_PATH)/../..
+
+LOCAL_SRC_FILES := \
+  $(LIBUSB_ROOT_REL)/libusb/core.c \
+  $(LIBUSB_ROOT_REL)/libusb/descriptor.c \
+  $(LIBUSB_ROOT_REL)/libusb/io.c \
+  $(LIBUSB_ROOT_REL)/libusb/sync.c \
+  $(LIBUSB_ROOT_REL)/libusb/os/linux_usbfs.c
+
+LOCAL_C_INCLUDES += \
+  $(LOCAL_PATH)/.. \
+  $(LIBUSB_ROOT_ABS)/libusb \
+  $(LIBUSB_ROOT_ABS)/libusb/os
+
+LOCAL_EXPORT_C_INCLUDES := \
+  $(LIBUSB_ROOT_ABS)/libusb
+
+LOCAL_MODULE := libusb1.0
+
+include $(BUILD_SHARED_LIBRARY)
+
+
+# listdevs
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := \
+  $(LIBUSB_ROOT_REL)/examples/listdevs.c
+
+LOCAL_C_INCLUDES += \
+  $(LIBUSB_ROOT_ABS)
+
+LOCAL_SHARED_LIBRARIES += libusb1.0
+
+LOCAL_MODULE:= listdevs
+
+include $(BUILD_EXECUTABLE)
diff --git a/android/jni/Application.mk b/android/jni/Application.mk
new file mode 100644
index 0000000..4ab1012
--- /dev/null
+++ b/android/jni/Application.mk
@@ -0,0 +1,19 @@
+# Android application build config for libusb
+# Copyright © 2012-2013 RealVNC Ltd. <toby.g...@realvnc.com>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+#
+
+APP_ABI := armeabi armeabi-v7a x86
-- 
1.8.3.4

>From 3eb0dabdf10df3f2f507808afbea57d190fb9a3f Mon Sep 17 00:00:00 2001
From: Toby Gray <toby.g...@realvnc.com>
Date: Tue, 9 Jul 2013 17:05:22 +0100
Subject: [PATCH 4/6] Android: Fix the majority of Android OS build issues.

This commit fixes the majority of Android OS build issues so that
it is almost possible to build libusbx for Android OS.
---
 android/config.h          | 34 ++++++++++++++++++++++++++++++++++
 android/jni/Android.mk    |  8 +++++++-
 libusb/core.c             | 34 +++++++++++-----------------------
 libusb/os/threads_posix.c |  4 +++-
 4 files changed, 55 insertions(+), 25 deletions(-)

diff --git a/android/config.h b/android/config.h
index 7943384..c1594cf 100644
--- a/android/config.h
+++ b/android/config.h
@@ -23,6 +23,15 @@
 /* Message logging */
 #define ENABLE_LOGGING
 
+/* Define to 1 if you have the <dlfcn.h> header file. */
+#define HAVE_DLFCN_H 1
+
+/* Define to 1 if you have the `gettimeofday' function. */
+#define HAVE_GETTIMEOFDAY 1
+
+/* Define to 1 if you have the <inttypes.h> header file. */
+#define HAVE_INTTYPES_H 1
+
 /* Linux backend */
 #define OS_LINUX 1
 
@@ -47,6 +56,31 @@
 /* Define to 1 if you have the <signal.h> header file. */
 #define HAVE_SIGNAL_H 1
 
+/* Define to 1 if you have the <sys/stat.h> header file. */
+#define HAVE_SYS_STAT_H 1
+
+/* Define to 1 if you have the <sys/time.h> header file. */
+#define HAVE_SYS_TIME_H 1
+
+/* Define to 1 if you have the <sys/types.h> header file. */
+#define HAVE_SYS_TYPES_H 1
+
+/* Define to 1 if you have the <unistd.h> header file. */
+#define HAVE_UNISTD_H 1
+
+/* Define to 1 if you have the <linux/filter.h> header file. */
+#define HAVE_LINUX_FILTER_H 1
+
+/* Define to 1 if you have the <linux/netlink.h> header file. */
+#define HAVE_LINUX_NETLINK_H 1
+
+/* Define to 1 if you have the <asm/types.h> header file. */
+#define HAVE_ASM_TYPES_H 1
+
+/* Define to 1 if you have the <sys/socket.h> header file. */
+#define HAVE_SYS_SOCKET_H 1
+
+/* Add defines which Android is missing */
 #ifndef TIMESPEC_TO_TIMEVAL
 #define TIMESPEC_TO_TIMEVAL(tv, ts)                                     \
         do {                                                            \
diff --git a/android/jni/Android.mk b/android/jni/Android.mk
index c00c8ac..8f9f66c 100644
--- a/android/jni/Android.mk
+++ b/android/jni/Android.mk
@@ -29,9 +29,13 @@ LIBUSB_ROOT_ABS:= $(LOCAL_PATH)/../..
 LOCAL_SRC_FILES := \
   $(LIBUSB_ROOT_REL)/libusb/core.c \
   $(LIBUSB_ROOT_REL)/libusb/descriptor.c \
+  $(LIBUSB_ROOT_REL)/libusb/hotplug.c \
   $(LIBUSB_ROOT_REL)/libusb/io.c \
   $(LIBUSB_ROOT_REL)/libusb/sync.c \
-  $(LIBUSB_ROOT_REL)/libusb/os/linux_usbfs.c
+  $(LIBUSB_ROOT_REL)/libusb/os/linux_usbfs.c \
+  $(LIBUSB_ROOT_REL)/libusb/os/poll_posix.c \
+  $(LIBUSB_ROOT_REL)/libusb/os/threads_posix.c \
+  $(LIBUSB_ROOT_REL)/libusb/os/linux_netlink.c
 
 LOCAL_C_INCLUDES += \
   $(LOCAL_PATH)/.. \
@@ -41,6 +45,8 @@ LOCAL_C_INCLUDES += \
 LOCAL_EXPORT_C_INCLUDES := \
   $(LIBUSB_ROOT_ABS)/libusb
 
+LOCAL_LDLIBS := -llog
+
 LOCAL_MODULE := libusb1.0
 
 include $(BUILD_SHARED_LIBRARY)
diff --git a/libusb/core.c b/libusb/core.c
index ee34a7e..e9c642f 100644
--- a/libusb/core.c
+++ b/libusb/core.c
@@ -2040,6 +2040,17 @@ static void usbi_log_str(struct libusb_context *ctx,
 	WCHAR wbuf[USBI_MAX_LOG_LEN];
 	MultiByteToWideChar(CP_ACP, 0, str, -1, wbuf, sizeof(wbuf));
 	OutputDebugStringW(wbuf);
+#elif defined(__ANDROID__)
+	int prio;
+	switch (level) {
+	case LIBUSB_LOG_LEVEL_INFO: prio = ANDROID_LOG_INFO; break;
+	case LIBUSB_LOG_LEVEL_WARNING: prio = ANDROID_LOG_WARN; break;
+	case LIBUSB_LOG_LEVEL_ERROR: prio = ANDROID_LOG_ERROR; break;
+	case LIBUSB_LOG_LEVEL_DEBUG: prio = ANDROID_LOG_DEBUG; break;
+	default: prio = ANDROID_LOG_UNKNOWN; break;
+	}
+
+	__android_log_write(prio, "LibUsb", str);
 #elif defined(HAVE_SYSLOG_FUNC)
 	int syslog_level = LOG_INFO;
 	switch (level) {
@@ -2083,28 +2094,6 @@ void usbi_log_v(struct libusb_context *ctx, enum libusb_log_level level,
 		return;
 #endif
 
-#ifdef __ANDROID__
-	int prio;
-	switch (level) {
-	case LOG_LEVEL_INFO:
-		prio = ANDROID_LOG_INFO;
-		break;
-	case LOG_LEVEL_WARNING:
-		prio = ANDROID_LOG_WARN;
-		break;
-	case LOG_LEVEL_ERROR:
-		prio = ANDROID_LOG_ERROR;
-		break;
-	case LOG_LEVEL_DEBUG:
-		prio = ANDROID_LOG_DEBUG;
-		break;
-	default:
-		prio = ANDROID_LOG_UNKNOWN;
-		break;
-	}
-
-	__android_log_vprint(prio, "LibUsb", format, args);
-#else
 	usbi_gettimeofday(&now, NULL);
 	if ((global_debug) && (!has_debug_header_been_displayed)) {
 		has_debug_header_been_displayed = 1;
@@ -2168,7 +2157,6 @@ void usbi_log_v(struct libusb_context *ctx, enum libusb_log_level level,
 	strcpy(buf + header_len + text_len, USBI_LOG_LINE_END);
 
 	usbi_log_str(ctx, level, buf);
-#endif
 }
 
 void usbi_log(struct libusb_context *ctx, enum libusb_log_level level,
diff --git a/libusb/os/threads_posix.c b/libusb/os/threads_posix.c
index 9769f58..edf7063 100644
--- a/libusb/os/threads_posix.c
+++ b/libusb/os/threads_posix.c
@@ -63,7 +63,9 @@ finish:
 int usbi_get_tid(void)
 {
 	int ret = -1;
-#if defined(__linux__)
+#if defined(__ANDROID__)
+	ret = gettid();
+#elif defined(__linux__)
 	ret = syscall(SYS_gettid);
 #elif defined(__OpenBSD__)
 	/* The following only works with OpenBSD > 5.1 as it requires
-- 
1.8.3.4

>From 5b635d1aad2f901b42a60ab800519b6daae6bb6c Mon Sep 17 00:00:00 2001
From: Toby Gray <toby.g...@realvnc.com>
Date: Thu, 8 Aug 2013 18:22:21 +0100
Subject: [PATCH 5/6] Android: adding examples and tests to Android build
 scripts.

---
 android/jni/Android.mk  |  54 ++-----------------
 android/jni/examples.mk | 134 ++++++++++++++++++++++++++++++++++++++++++++++++
 android/jni/libusb.mk   |  54 +++++++++++++++++++
 android/jni/tests.mk    |  56 ++++++++++++++++++++
 4 files changed, 248 insertions(+), 50 deletions(-)
 create mode 100644 android/jni/examples.mk
 create mode 100644 android/jni/libusb.mk
 create mode 100644 android/jni/tests.mk

diff --git a/android/jni/Android.mk b/android/jni/Android.mk
index 8f9f66c..6a32b50 100644
--- a/android/jni/Android.mk
+++ b/android/jni/Android.mk
@@ -1,5 +1,4 @@
-#
-# Android build config for libusbx
+# Android build config for libusb, examples and tests
 # Copyright © 2012-2013 RealVNC Ltd. <toby.g...@realvnc.com>
 #
 # This library is free software; you can redistribute it and/or
@@ -19,51 +18,6 @@
 
 LOCAL_PATH:= $(call my-dir)
 
-# libusb
-
-include $(CLEAR_VARS)
-
-LIBUSB_ROOT_REL:= ../..
-LIBUSB_ROOT_ABS:= $(LOCAL_PATH)/../..
-
-LOCAL_SRC_FILES := \
-  $(LIBUSB_ROOT_REL)/libusb/core.c \
-  $(LIBUSB_ROOT_REL)/libusb/descriptor.c \
-  $(LIBUSB_ROOT_REL)/libusb/hotplug.c \
-  $(LIBUSB_ROOT_REL)/libusb/io.c \
-  $(LIBUSB_ROOT_REL)/libusb/sync.c \
-  $(LIBUSB_ROOT_REL)/libusb/os/linux_usbfs.c \
-  $(LIBUSB_ROOT_REL)/libusb/os/poll_posix.c \
-  $(LIBUSB_ROOT_REL)/libusb/os/threads_posix.c \
-  $(LIBUSB_ROOT_REL)/libusb/os/linux_netlink.c
-
-LOCAL_C_INCLUDES += \
-  $(LOCAL_PATH)/.. \
-  $(LIBUSB_ROOT_ABS)/libusb \
-  $(LIBUSB_ROOT_ABS)/libusb/os
-
-LOCAL_EXPORT_C_INCLUDES := \
-  $(LIBUSB_ROOT_ABS)/libusb
-
-LOCAL_LDLIBS := -llog
-
-LOCAL_MODULE := libusb1.0
-
-include $(BUILD_SHARED_LIBRARY)
-
-
-# listdevs
-
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := \
-  $(LIBUSB_ROOT_REL)/examples/listdevs.c
-
-LOCAL_C_INCLUDES += \
-  $(LIBUSB_ROOT_ABS)
-
-LOCAL_SHARED_LIBRARIES += libusb1.0
-
-LOCAL_MODULE:= listdevs
-
-include $(BUILD_EXECUTABLE)
+include $(LOCAL_PATH)/libusb.mk
+include $(LOCAL_PATH)/examples.mk
+include $(LOCAL_PATH)/tests.mk
diff --git a/android/jni/examples.mk b/android/jni/examples.mk
new file mode 100644
index 0000000..05609cc
--- /dev/null
+++ b/android/jni/examples.mk
@@ -0,0 +1,134 @@
+# Android build config for libusb examples
+# Copyright © 2012-2013 RealVNC Ltd. <toby.g...@realvnc.com>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+#
+
+LOCAL_PATH:= $(call my-dir)
+LIBUSB_ROOT_REL:= ../..
+LIBUSB_ROOT_ABS:= $(LOCAL_PATH)/../..
+
+# listdevs
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := \
+  $(LIBUSB_ROOT_REL)/examples/listdevs.c
+
+LOCAL_C_INCLUDES += \
+  $(LIBUSB_ROOT_ABS)
+
+LOCAL_SHARED_LIBRARIES += libusb1.0
+
+LOCAL_MODULE:= listdevs
+
+include $(BUILD_EXECUTABLE)
+
+# xusb
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := \
+  $(LIBUSB_ROOT_REL)/examples/xusb.c
+
+LOCAL_C_INCLUDES += \
+  $(LIBUSB_ROOT_ABS)
+
+LOCAL_SHARED_LIBRARIES += libusb1.0
+
+LOCAL_MODULE:= xusb
+
+include $(BUILD_EXECUTABLE)
+
+# hotplugtest
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := \
+  $(LIBUSB_ROOT_REL)/examples/hotplugtest.c
+
+LOCAL_C_INCLUDES += \
+  $(LIBUSB_ROOT_ABS)
+
+LOCAL_SHARED_LIBRARIES += libusb1.0
+
+LOCAL_MODULE:= hotplugtest
+
+include $(BUILD_EXECUTABLE)
+
+# fxload
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := \
+  $(LIBUSB_ROOT_REL)/examples/fxload.c \
+  $(LIBUSB_ROOT_REL)/examples/ezusb.c
+
+LOCAL_C_INCLUDES += \
+  $(LIBUSB_ROOT_ABS)
+
+LOCAL_SHARED_LIBRARIES += libusb1.0
+
+LOCAL_MODULE:= fxload
+
+include $(BUILD_EXECUTABLE)
+
+# sam3u_benchmake
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := \
+  $(LIBUSB_ROOT_REL)/examples/sam3u_benchmark.c
+
+LOCAL_C_INCLUDES += \
+  $(LIBUSB_ROOT_ABS)
+
+LOCAL_SHARED_LIBRARIES += libusb1.0
+
+LOCAL_MODULE:= sam3u_benchmark
+
+include $(BUILD_EXECUTABLE)
+
+# dpfp
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := \
+  $(LIBUSB_ROOT_REL)/examples/dpfp.c
+
+LOCAL_C_INCLUDES += \
+  $(LIBUSB_ROOT_ABS)
+
+LOCAL_SHARED_LIBRARIES += libusb1.0
+
+LOCAL_MODULE:= dpfp
+
+include $(BUILD_EXECUTABLE)
+
+# dpfp_threaded
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := \
+  $(LIBUSB_ROOT_REL)/examples/dpfp_threaded.c
+
+LOCAL_C_INCLUDES += \
+  $(LIBUSB_ROOT_ABS)
+
+LOCAL_SHARED_LIBRARIES += libusb1.0
+
+LOCAL_MODULE:= dpfp_threaded
+
+include $(BUILD_EXECUTABLE)
diff --git a/android/jni/libusb.mk b/android/jni/libusb.mk
new file mode 100644
index 0000000..f4896b2
--- /dev/null
+++ b/android/jni/libusb.mk
@@ -0,0 +1,54 @@
+# Android build config for libusb
+# Copyright © 2012-2013 RealVNC Ltd. <toby.g...@realvnc.com>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+#
+
+LOCAL_PATH:= $(call my-dir)
+LIBUSB_ROOT_REL:= ../..
+LIBUSB_ROOT_ABS:= $(LOCAL_PATH)/../..
+
+# libusb
+
+include $(CLEAR_VARS)
+
+LIBUSB_ROOT_REL:= ../..
+LIBUSB_ROOT_ABS:= $(LOCAL_PATH)/../..
+
+LOCAL_SRC_FILES := \
+  $(LIBUSB_ROOT_REL)/libusb/core.c \
+  $(LIBUSB_ROOT_REL)/libusb/descriptor.c \
+  $(LIBUSB_ROOT_REL)/libusb/hotplug.c \
+  $(LIBUSB_ROOT_REL)/libusb/io.c \
+  $(LIBUSB_ROOT_REL)/libusb/sync.c \
+  $(LIBUSB_ROOT_REL)/libusb/strerror.c \
+  $(LIBUSB_ROOT_REL)/libusb/os/linux_usbfs.c \
+  $(LIBUSB_ROOT_REL)/libusb/os/poll_posix.c \
+  $(LIBUSB_ROOT_REL)/libusb/os/threads_posix.c \
+  $(LIBUSB_ROOT_REL)/libusb/os/linux_netlink.c
+
+LOCAL_C_INCLUDES += \
+  $(LOCAL_PATH)/.. \
+  $(LIBUSB_ROOT_ABS)/libusb \
+  $(LIBUSB_ROOT_ABS)/libusb/os
+
+LOCAL_EXPORT_C_INCLUDES := \
+  $(LIBUSB_ROOT_ABS)/libusb
+
+LOCAL_LDLIBS := -llog
+
+LOCAL_MODULE := libusb1.0
+
+include $(BUILD_SHARED_LIBRARY)
diff --git a/android/jni/tests.mk b/android/jni/tests.mk
new file mode 100644
index 0000000..93d5516
--- /dev/null
+++ b/android/jni/tests.mk
@@ -0,0 +1,56 @@
+# Android build config for libusb tests
+# Copyright © 2012-2013 RealVNC Ltd. <toby.g...@realvnc.com>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+#
+
+LOCAL_PATH:= $(call my-dir)
+LIBUSB_ROOT_REL:= ../..
+LIBUSB_ROOT_ABS:= $(LOCAL_PATH)/../..
+
+# testlib
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := \
+  $(LIBUSB_ROOT_REL)/tests/testlib.c
+
+LOCAL_C_INCLUDES += \
+  $(LIBUSB_ROOT_ABS)/tests
+
+LOCAL_EXPORT_C_INCLUDES := \
+  $(LIBUSB_ROOT_ABS)/tests
+
+LOCAL_MODULE := testlib
+
+include $(BUILD_STATIC_LIBRARY)
+
+
+# stress
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := \
+  $(LIBUSB_ROOT_REL)/tests/stress.c
+
+LOCAL_C_INCLUDES += \
+  $(LIBUSB_ROOT_ABS)
+
+LOCAL_SHARED_LIBRARIES += libusb1.0
+LOCAL_STATIC_LIBRARIES += testlib
+
+LOCAL_MODULE:= stress
+
+include $(BUILD_EXECUTABLE)
-- 
1.8.3.4

>From cbeba78da346dfcd3232201dc8374c3d941f8e55 Mon Sep 17 00:00:00 2001
From: Toby Gray <toby.g...@realvnc.com>
Date: Thu, 8 Aug 2013 18:23:05 +0100
Subject: [PATCH 6/6] tests: Add missing include to stress.c for memset.

---
 tests/stress.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tests/stress.c b/tests/stress.c
index e53f415..db8d233 100644
--- a/tests/stress.c
+++ b/tests/stress.c
@@ -18,6 +18,7 @@
  */
 
 #include <stdio.h>
+#include <string.h>
 #include <memory.h>
 
 #include "libusb.h"
-- 
1.8.3.4

------------------------------------------------------------------------------
Get 100% visibility into Java/.NET code with AppDynamics Lite!
It's a free troubleshooting tool designed for production.
Get down to code-level detail for bottlenecks, with <2% overhead. 
Download for free and get started troubleshooting in minutes. 
http://pubads.g.doubleclick.net/gampad/clk?id=48897031&iu=/4140/ostg.clktrk
_______________________________________________
libusbx-devel mailing list
libusbx-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libusbx-devel

Reply via email to