[prev in list] [next in list] [prev in thread] [next in thread] 

List:       openocd-development
Subject:    [OpenOCD-devel] [PATCH]: ee56fe3 libusb: enable (optional) pkg-config support
From:       gerrit () openocd ! zylin ! com
Date:       2013-06-28 22:01:11
Message-ID: 20130628220112.2F511242C3 () openocd ! zylin ! com
[Download RAW message or body]

This is an automated email from Gerrit.

Paul Fertser (fercerpav@gmail.com) just uploaded a new patch set to Gerrit, which you \
can find at http://openocd.zylin.com/1465

-- gerrit

commit ee56fe3ce45f20710852116af1b3ccc2021cc96f
Author: Paul Fertser <fercerpav@gmail.com>
Date:   Sat Jun 29 01:28:23 2013 +0400

    libusb: enable (optional) pkg-config support
    
    This patch would be >12 lines and one LIBUSB_HEADER silliness less if
    pkg-config support would be required. pkg-config is the standard way on
    GNU/Linux and FreeBSD at least, and it works nicely on other platforms too;
    easy overriding for both PACKAGE_CFLAGS and PACKAGE_LIBS is available.
    
    This patch tries to discover libusb-1.0 and libusb-0.1 presence and
    parameters by querying pkg-config when available, and falls back to
    the previously used autoconf checks and guesses when it's not.
    
    It should make it possible to compile OpenOCD without changes and extra
    effort on GNU/Linux, FreeBSD users should better supply a .pc file (if it's
    still not included by default) but probably the guessed values are good
    enough already.
    
    Tested in various combinations with libusb-1.0, libusb-0.1 and
    libusb-compat-0.1.
    
    Checkpatch complains about #define LIBUSB_HEADER <*libusb.h> macros but
    I consider that to be a false positive here; Jenkins will refuse to
    build-test this, unfortunately, any suggestions about how to proceed
    and if that's needed are appreciated.
    
    Change-Id: I5adf9a906513c388990e8158ce35d18dfc866535
    Signed-off-by: Paul Fertser <fercerpav@gmail.com>

diff --git a/configure.ac b/configure.ac
index 6e3f986..f16877f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1195,32 +1195,53 @@ if test $build_ftdi = yes -o $build_hladapter_icdi = yes -o \
   need_usb_ng=yes
 fi
 
+m4_ifdef([PKG_PROG_PKG_CONFIG],
+  [PKG_PROG_PKG_CONFIG])
+
 # check for libusb library if necessary
 use_libusb1=no
 if test $need_usb = yes -o $need_usb_ng = yes; then
-  AC_CHECK_HEADER([libusb-1.0/libusb.h], [
+  m4_ifdef([PKG_CHECK_MODULES],
+	[PKG_CHECK_MODULES([LIBUSB1], [libusb-1.0], [use_libusb1=yes], [ ])])
+
+  if test x$use_libusb1 != xyes; then
+	AC_CHECK_HEADERS([libusb-1.0/libusb.h libusb.h],
+		[use_libusb1=yes; LIBUSB1_LIBS=-lusb-1.0; break])
+  fi
+
+  if test x$use_libusb1 = xyes; then
 	AC_DEFINE([HAVE_LIBUSB1], [1], [Define if you have libusb-1.x])
-	use_libusb1=yes
-	AC_SEARCH_LIBS([libusb_error_name], [usb-1.0],
+	AC_SUBST([LIBUSB1_CFLAGS])
+	AC_SUBST([LIBUSB1_LIBS])
+	LIBS="$LIBUSB1_LIBS $LIBS"
+	AC_SEARCH_LIBS([libusb_error_name], [],
 		[AC_DEFINE([HAVE_LIBUSB_ERROR_NAME], [1], [Define if your libusb has \
libusb_error_name()])],  [AC_MSG_WARN([libusb-1.x older than 1.0.9 detected, consider \
                updating])])
-  ], [
+  else
 	if test $need_usb_ng = yes; then
 	  AC_MSG_ERROR([libusb-1.x is required for some driver(s) you've selected])
 	else
 	  AC_MSG_WARN([Trying legacy libusb-0.1 as a fallback, consider installing libusb-1 \
instead])  need_usb0=yes
 	fi
-  ])
+  fi
 fi
 
 use_libusb0=no
 if test $need_usb0 = yes; then
-	AC_CHECK_HEADERS([usb.h], [
-			use_libusb0=yes
-		], [
-			AC_MSG_ERROR([libusb-0.1 is required to build some OpenOCD driver(s)])
-		])
+  m4_ifdef([PKG_CHECK_MODULES],
+	[PKG_CHECK_MODULES([LIBUSB0], [libusb], [use_libusb0=yes], [ ])])
+
+  if test x$use_libusb0 != xyes; then
+	AC_CHECK_HEADERS([usb.h], [use_libusb0=yes; LIBUSB0_LIBS=-lusb])
+  fi
+
+  if test x$use_libusb0 != xyes; then
+	AC_MSG_ERROR([libusb-0.1 is required to build some OpenOCD driver(s)])
+  fi
+
+  AC_SUBST([LIBUSB0_CFLAGS])
+  AC_SUBST([LIBUSB0_LIBS])
 fi
 
 AM_CONDITIONAL([RELEASE], [test $build_release = yes])
diff --git a/src/Makefile.am b/src/Makefile.am
index badc80d..1f4cd32 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -75,11 +75,11 @@ endif
 
 LIBUSB =
 if USE_LIBUSB1
-LIBUSB += -lusb-1.0
+LIBUSB += $(LIBUSB1_LIBS)
 endif
 
 if USE_LIBUSB0
-LIBUSB += -lusb
+LIBUSB += $(LIBUSB0_LIBS)
 endif
 
 libopenocd_la_LIBADD = \
diff --git a/src/helper/replacements.c b/src/helper/replacements.c
index d8d8fd0..efd46c6 100644
--- a/src/helper/replacements.c
+++ b/src/helper/replacements.c
@@ -278,7 +278,7 @@ int win_select(int max_fd, fd_set *rfds, fd_set *wfds, fd_set \
*efds, struct time  #endif
 
 #if defined HAVE_LIBUSB1 && !defined HAVE_LIBUSB_ERROR_NAME
-#include <libusb-1.0/libusb.h>
+#include LIBUSB_HEADER
 /* Verbatim from git://git.libusb.org/libusb.git tag 1.0.9
  * The libusb_error enum is compatible down to v0.9.1
  */
diff --git a/src/helper/replacements.h b/src/helper/replacements.h
index 565fe9d..dfb9769 100644
--- a/src/helper/replacements.h
+++ b/src/helper/replacements.h
@@ -283,4 +283,10 @@ typedef struct {
 const char *libusb_error_name(int error_code);
 #endif /* defined HAVE_LIBUSB1 && !defined HAVE_LIBUSB_ERROR_NAME */
 
+#if !defined HAVE_LIBUSB_1_0_LIBUSB_H
+#define LIBUSB_HEADER <libusb.h>
+#else
+#define LIBUSB_HEADER <libusb-1.0/libusb.h>
+#endif /* !defined HAVE_LIBUSB_1_0_LIBUSB_H */
+
 #endif	/* REPLACEMENTS_H */
diff --git a/src/jtag/drivers/Makefile.am b/src/jtag/drivers/Makefile.am
index 22bc89b..5a56c64 100644
--- a/src/jtag/drivers/Makefile.am
+++ b/src/jtag/drivers/Makefile.am
@@ -6,6 +6,8 @@ libocdjtagdrivers_la_LIBADD =
 libocdjtagdrivers_la_SOURCES = \
 	$(DRIVERFILES)
 
+libocdjtagdrivers_la_CPPFLAGS = $(AM_CPPFLAGS) $(LIBUSB1_CFLAGS) $(LIBUSB0_CFLAGS)
+
 ocddatadir = $(pkglibdir)
 nobase_dist_ocddata_DATA =
 
diff --git a/src/jtag/drivers/libusb1_common.h b/src/jtag/drivers/libusb1_common.h
index 8b2792c..f24f8c6 100644
--- a/src/jtag/drivers/libusb1_common.h
+++ b/src/jtag/drivers/libusb1_common.h
@@ -22,7 +22,7 @@
 #ifndef JTAG_LIBUSB_COMMON_H
 #define JTAG_LIBUSB_COMMON_H
 
-#include <libusb-1.0/libusb.h>
+#include LIBUSB_HEADER
 
 #define jtag_libusb_device			libusb_device
 #define jtag_libusb_device_handle		libusb_device_handle
diff --git a/src/jtag/drivers/mpsse.c b/src/jtag/drivers/mpsse.c
index 82703bf..3b49613 100644
--- a/src/jtag/drivers/mpsse.c
+++ b/src/jtag/drivers/mpsse.c
@@ -24,7 +24,7 @@
 
 #include "mpsse.h"
 #include "helper/log.h"
-#include <libusb-1.0/libusb.h>
+#include LIBUSB_HEADER
 
 /* Compatibility define for older libusb-1.0 */
 #ifndef LIBUSB_CALL
diff --git a/src/jtag/drivers/ti_icdi_usb.c b/src/jtag/drivers/ti_icdi_usb.c
index c0c0718..c3b369e 100644
--- a/src/jtag/drivers/ti_icdi_usb.c
+++ b/src/jtag/drivers/ti_icdi_usb.c
@@ -33,7 +33,7 @@
 
 #include <target/cortex_m.h>
 
-#include <libusb-1.0/libusb.h>
+#include LIBUSB_HEADER
 
 #define ICDI_WRITE_ENDPOINT 0x02
 #define ICDI_READ_ENDPOINT 0x83

-- 

------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:

Build for Windows Store.

http://p.sf.net/sfu/windows-dev2dev
_______________________________________________
OpenOCD-devel mailing list
OpenOCD-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openocd-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic