diff --git a/drivers/usb-common.h b/drivers/usb-common.h index 76588cad47..0cc760f0f7 100644 --- a/drivers/usb-common.h +++ b/drivers/usb-common.h @@ -377,7 +377,15 @@ /* Note: Checked above that in practice we handle some one libusb API */ #if WITH_LIBUSB_0_1 -# include +# ifdef HAVE_USB_H +# include +# else +# ifdef HAVE_LUSB0_USB_H +# include +# 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 diff --git a/m4/nut_check_libusb.m4 b/m4/nut_check_libusb.m4 index 7574ed207f..c8a7bc155f 100644 --- a/m4/nut_check_libusb.m4 +++ b/m4/nut_check_libusb.m4 @@ -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] )] diff --git a/tools/nut-usbinfo.pl b/tools/nut-usbinfo.pl index 9fd07a1bd2..17fc918bf6 100755 --- a/tools/nut-usbinfo.pl +++ b/tools/nut-usbinfo.pl @@ -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 # Copyright (C) 2013 - 2014 Charles Lepple +# Copyright (C) 2014 - 2022 Jim Klimov # # Based on the usbdevice.pl script, made for the Ubuntu Media Center # for the final use of the LIRC project. @@ -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 \n"; + print $outputDevScanner "# include \n"; print $outputDevScanner "#endif\n"; print $outputDevScanner "#if WITH_LIBUSB_0_1\n"; - print $outputDevScanner " #include \n"; + print $outputDevScanner "# ifdef HAVE_USB_H\n"; + print $outputDevScanner "# include \n"; + print $outputDevScanner "# else\n"; + print $outputDevScanner "# ifdef HAVE_LUSB0_USB_H\n"; + print $outputDevScanner "# include \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";