nut/m4/nut_check_libusb.m4

80 lines
2.2 KiB
Text
Raw Permalink Normal View History

2010-03-25 23:20:59 +00:00
dnl Check for LIBUSB compiler flags. On success, set nut_have_libusb="yes"
2011-01-26 09:35:08 +00:00
dnl and set LIBUSB_CFLAGS and LIBUSB_LIBS. On failure, set
2010-03-25 23:20:59 +00:00
dnl nut_have_libusb="no". This macro can be run multiple times, but will
dnl do the checking only once.
AC_DEFUN([NUT_CHECK_LIBUSB],
[
if test -z "${nut_have_libusb_seen}"; then
nut_have_libusb_seen=yes
2011-01-26 09:35:08 +00:00
dnl save CFLAGS and LIBS
2010-03-25 23:20:59 +00:00
CFLAGS_ORIG="${CFLAGS}"
2011-01-26 09:35:08 +00:00
LIBS_ORIG="${LIBS}"
2010-03-25 23:20:59 +00:00
AC_MSG_CHECKING(for libusb version via pkg-config)
2011-01-26 09:35:08 +00:00
LIBUSB_VERSION="`pkg-config --silence-errors --modversion libusb 2>/dev/null`"
if test "$?" = "0" -a -n "${LIBUSB_VERSION}"; then
CFLAGS="`pkg-config --silence-errors --cflags libusb 2>/dev/null`"
LIBS="`pkg-config --silence-errors --libs libusb 2>/dev/null`"
2010-03-25 23:20:59 +00:00
else
AC_MSG_CHECKING(via libusb-config)
2011-01-26 09:35:08 +00:00
LIBUSB_VERSION="`libusb-config --version 2>/dev/null`"
if test "$?" = "0" -a -n "${LIBUSB_VERSION}"; then
2010-03-25 23:20:59 +00:00
CFLAGS="`libusb-config --cflags 2>/dev/null`"
2011-01-26 09:35:08 +00:00
LIBS="`libusb-config --libs 2>/dev/null`"
2010-03-25 23:20:59 +00:00
else
2011-01-26 09:35:08 +00:00
LIBUSB_VERSION="none"
2010-03-25 23:20:59 +00:00
CFLAGS=""
2011-01-26 09:35:08 +00:00
LIBS="-lusb"
2010-03-25 23:20:59 +00:00
fi
fi
2011-01-26 09:35:08 +00:00
AC_MSG_RESULT(${LIBUSB_VERSION} found)
2010-03-25 23:20:59 +00:00
AC_MSG_CHECKING(for libusb cflags)
2011-01-26 09:35:08 +00:00
AC_ARG_WITH(usb-includes,
AS_HELP_STRING([@<:@--with-usb-includes=CFLAGS@:>@], [include flags for the libusb library]),
[
case "${withval}" in
yes|no)
AC_MSG_ERROR(invalid option --with(out)-usb-includes - see docs/configure.txt)
;;
*)
CFLAGS="${withval}"
;;
esac
], [])
2010-03-25 23:20:59 +00:00
AC_MSG_RESULT([${CFLAGS}])
AC_MSG_CHECKING(for libusb ldflags)
2011-01-26 09:35:08 +00:00
AC_ARG_WITH(usb-libs,
AS_HELP_STRING([@<:@--with-usb-libs=LIBS@:>@], [linker flags for the libusb library]),
[
case "${withval}" in
yes|no)
AC_MSG_ERROR(invalid option --with(out)-usb-libs - see docs/configure.txt)
;;
*)
LIBS="${withval}"
;;
esac
], [])
AC_MSG_RESULT([${LIBS}])
2010-03-25 23:20:59 +00:00
dnl check if libusb is usable
AC_CHECK_HEADERS(usb.h, [nut_have_libusb=yes], [nut_have_libusb=no], [AC_INCLUDES_DEFAULT])
AC_CHECK_FUNCS(usb_init, [], [nut_have_libusb=no])
if test "${nut_have_libusb}" = "yes"; then
dnl Check for libusb "force driver unbind" availability
AC_CHECK_FUNCS(usb_detach_kernel_driver_np)
LIBUSB_CFLAGS="${CFLAGS}"
2011-01-26 09:35:08 +00:00
LIBUSB_LIBS="${LIBS}"
2010-03-25 23:20:59 +00:00
fi
2011-01-26 09:35:08 +00:00
dnl restore original CFLAGS and LIBS
2010-03-25 23:20:59 +00:00
CFLAGS="${CFLAGS_ORIG}"
2011-01-26 09:35:08 +00:00
LIBS="${LIBS_ORIG}"
2010-03-25 23:20:59 +00:00
fi
])