From c1c3da42a1612030dc896587f8f0e52c95886a51 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Sun, 28 Aug 2022 21:10:59 +0200 Subject: [PATCH 1/7] m4/nut_check_libusb.m4: detect mingw-w64-x86_64-libusb-win32 as libusb-0.1 variant --- m4/nut_check_libusb.m4 | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) 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] )] From 2924043777bf6eb5b5c935a02927e4469146d249 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Sun, 28 Aug 2022 21:13:51 +0200 Subject: [PATCH 2/7] drivers/usb-common.h: build against mingw-w64-x86_64-libusb-win32 as libusb-0.1 variant --- drivers/usb-common.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/usb-common.h b/drivers/usb-common.h index 76588cad47..04097d7636 100644 --- a/drivers/usb-common.h +++ b/drivers/usb-common.h @@ -377,7 +377,13 @@ /* Note: Checked above that in practice we handle some one libusb API */ #if WITH_LIBUSB_0_1 -# include +# ifdef HAVE_LIBUSB_H +# include +# else +# ifdef HAVE_LUSB0_USB_H +# include +# endif +# endif /* Structures */ /* See detailed comments above, in libusb-1.0 definitions * FIXME: It may make sense to constrain the limits to lowest common From 3c264f571ad60c2b6c5786e7365b79e19548129e Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Sun, 28 Aug 2022 22:54:07 +0200 Subject: [PATCH 3/7] tools/nut-usbinfo.pl: build against mingw-w64-x86_64-libusb-win32 as libusb-0.1 variant --- tools/nut-usbinfo.pl | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tools/nut-usbinfo.pl b/tools/nut-usbinfo.pl index 9fd07a1bd2..f39dd70297 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,16 @@ 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_LIBUSB_H\n"; + print $outputDevScanner "# include \n"; + print $outputDevScanner "# else\n"; + print $outputDevScanner "# ifdef HAVE_LUSB0_USB_H\n"; + print $outputDevScanner "# include \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"; From 9324a42b8a061a1b23ac732aefca7a0b78d53866 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Mon, 29 Aug 2022 12:16:18 +0200 Subject: [PATCH 4/7] Update usb-common.h Typo fix for `ifdef HAVE_USB_H` (libusb-0.1 header) --- drivers/usb-common.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb-common.h b/drivers/usb-common.h index 04097d7636..9e38ae4b6f 100644 --- a/drivers/usb-common.h +++ b/drivers/usb-common.h @@ -377,7 +377,7 @@ /* Note: Checked above that in practice we handle some one libusb API */ #if WITH_LIBUSB_0_1 -# ifdef HAVE_LIBUSB_H +# ifdef HAVE_USB_H # include # else # ifdef HAVE_LUSB0_USB_H From f2e8da311645c1bb4d869c7accd8eb4a74f66a13 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Mon, 29 Aug 2022 12:16:22 +0200 Subject: [PATCH 5/7] Update nut-usbinfo.pl Typo fix for `ifdef HAVE_USB_H` (libusb-0.1 header) --- tools/nut-usbinfo.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/nut-usbinfo.pl b/tools/nut-usbinfo.pl index f39dd70297..bf516702b5 100755 --- a/tools/nut-usbinfo.pl +++ b/tools/nut-usbinfo.pl @@ -142,7 +142,7 @@ sub gen_usb_files print $outputDevScanner "# include \n"; print $outputDevScanner "#endif\n"; print $outputDevScanner "#if WITH_LIBUSB_0_1\n"; - print $outputDevScanner "# ifdef HAVE_LIBUSB_H\n"; + print $outputDevScanner "# ifdef HAVE_USB_H\n"; print $outputDevScanner "# include \n"; print $outputDevScanner "# else\n"; print $outputDevScanner "# ifdef HAVE_LUSB0_USB_H\n"; From 5a2c1ffa6e74d455c2d64f0303eca4322b4097d1 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Mon, 29 Aug 2022 12:24:06 +0200 Subject: [PATCH 6/7] Update nut-usbinfo.pl Detect configure script error: Neither HAVE_USB_H nor HAVE_LUSB0_USB_H is set for the WITH_LIBUSB_0_1 build --- tools/nut-usbinfo.pl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/nut-usbinfo.pl b/tools/nut-usbinfo.pl index bf516702b5..17fc918bf6 100755 --- a/tools/nut-usbinfo.pl +++ b/tools/nut-usbinfo.pl @@ -147,6 +147,8 @@ sub gen_usb_files 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"; From 328d5cd24d53ae872c5ad5bce2ea5844bb348612 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Mon, 29 Aug 2022 12:24:09 +0200 Subject: [PATCH 7/7] Update usb-common.h Detect configure script error: Neither HAVE_USB_H nor HAVE_LUSB0_USB_H is set for the WITH_LIBUSB_0_1 build --- drivers/usb-common.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/usb-common.h b/drivers/usb-common.h index 9e38ae4b6f..0cc760f0f7 100644 --- a/drivers/usb-common.h +++ b/drivers/usb-common.h @@ -382,6 +382,8 @@ # 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 */