Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion drivers/usb-common.h
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,15 @@

/* Note: Checked above that in practice we handle some one libusb API */
#if WITH_LIBUSB_0_1
# include <usb.h>
# ifdef HAVE_USB_H
# include <usb.h>
# else
# ifdef HAVE_LUSB0_USB_H
# include <lusb0_usb.h>
# else
# error "configure script error: Neither HAVE_USB_H nor HAVE_LUSB0_USB_H is set for the WITH_LIBUSB_0_1 build"
# endif
# endif
/* Structures */
/* See detailed comments above, in libusb-1.0 definitions
* FIXME: It may make sense to constrain the limits to lowest common
Expand Down
30 changes: 27 additions & 3 deletions m4/nut_check_libusb.m4
Original file line number Diff line number Diff line change
Expand Up @@ -222,15 +222,39 @@ if test -z "${nut_have_libusb_seen}"; then
fi
else
dnl libusb 0.1, or missing pkg-config :
AC_CHECK_HEADERS(usb.h, [nut_have_libusb=yes], [nut_have_libusb=no], [AC_INCLUDES_DEFAULT])
AC_CHECK_HEADERS(usb.h, [nut_have_libusb=yes], [
nut_have_libusb=no
dnl Per https://sourceforge.net/projects/libusb-win32/files/libusb-win32-releases/1.2.6.0/
dnl this project (used among alternatives in MSYS2/MinGW builds)
dnl uses a different include filename to avoid conflict with
dnl a WDK header:
AS_CASE(["${target_os}"],
[*mingw*], [
AC_MSG_NOTICE([try alternate header name for mingw builds with libusb-win32])
AC_CHECK_HEADERS(lusb0_usb.h, [
nut_usb_lib="(libusb-0.1)"
nut_have_libusb=yes
], [], [AC_INCLUDES_DEFAULT])
])
],
[AC_INCLUDES_DEFAULT])
AC_CHECK_FUNCS(usb_init, [], [
dnl Some systems may just have libusb in their standard
dnl paths, but not the pkg-config or libusb-config data
AS_IF([test "${nut_have_libusb}" = "yes" && test "$LIBUSB_VERSION" = "none" && test -z "$LIBS"],
AS_IF([test "${nut_have_libusb}" = "yes" && test "$LIBUSB_VERSION" = "none" && test -z "$LIBS" -o x"$LIBS" = x"-lusb" ],
[AC_MSG_CHECKING([if libusb is just present in path])
LIBS="-L/usr/lib -L/usr/local/lib -lusb"
dnl TODO: Detect bitness for trying /mingw32 or /usr/$ARCH as well?
dnl This currently caters to mingw-w64-x86_64-libusb-win32 of MSYS2:
AS_CASE(["${target_os}"],
[*mingw*], [LIBS="-L/mingw64/lib $LIBS"])
unset ac_cv_func_usb_init || true
AC_CHECK_FUNCS(usb_init, [], [nut_have_libusb=no])
AC_CHECK_FUNCS(usb_init, [], [
AC_MSG_CHECKING([if libusb0 is just present in path])
LIBS="$LIBS"0
unset ac_cv_func_usb_init || true
AC_CHECK_FUNCS(usb_init, [nut_usb_lib="(libusb-0.1)"], [nut_have_libusb=no])
])
AC_MSG_RESULT([${nut_have_libusb}])
], [nut_have_libusb=no]
)]
Expand Down
15 changes: 12 additions & 3 deletions tools/nut-usbinfo.pl
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#!/usr/bin/env perl
# Current Version : 1.3
# Current Version : 1.4
# Copyright (C) 2008 - 2012 dloic (loic.dardant AT gmail DOT com)
# Copyright (C) 2008 - 2015 Arnaud Quette <arnaud.quette@free.fr>
# Copyright (C) 2013 - 2014 Charles Lepple <clepple+nut@gmail.com>
# Copyright (C) 2014 - 2022 Jim Klimov <jimklimov+nut@gmail.com>
#
# Based on the usbdevice.pl script, made for the Ubuntu Media Center
# for the final use of the LIRC project.
Expand Down Expand Up @@ -138,10 +139,18 @@ sub gen_usb_files
print $outputDevScanner "#error \"configure script error: Both WITH_LIBUSB_1_0 and WITH_LIBUSB_0_1 are set\"\n";
print $outputDevScanner "#endif\n\n";
print $outputDevScanner "#if WITH_LIBUSB_1_0\n";
print $outputDevScanner " #include <libusb.h>\n";
print $outputDevScanner "# include <libusb.h>\n";
print $outputDevScanner "#endif\n";
print $outputDevScanner "#if WITH_LIBUSB_0_1\n";
print $outputDevScanner " #include <usb.h>\n";
print $outputDevScanner "# ifdef HAVE_USB_H\n";
print $outputDevScanner "# include <usb.h>\n";
print $outputDevScanner "# else\n";
print $outputDevScanner "# ifdef HAVE_LUSB0_USB_H\n";
print $outputDevScanner "# include <lusb0_usb.h>\n";
print $outputDevScanner "# else\n";
print $outputDevScanner "# error \"configure script error: Neither HAVE_USB_H nor HAVE_LUSB0_USB_H is set for the WITH_LIBUSB_0_1 build\"\n";
print $outputDevScanner "# endif\n";
print $outputDevScanner "# endif\n";
print $outputDevScanner " /* simple remap to avoid bloating structures */\n";
print $outputDevScanner " typedef usb_dev_handle libusb_device_handle;\n";
print $outputDevScanner "#endif\n";
Expand Down