Tweak the libusb detection.

1. Try to use pkg-config to locate libusb;
  2. Try with libusb-config if not found;
  3. Try to locate headers and lib if still not found.

This would hopefully prevent build failures in some very particular cases, such as cross compiling libnfc on a FreeBSD version for another FreeBSD version that does not use the same libusb.

http://www.freebsd.org/cgi/query-pr.cgi?pr=ports/142836

Reported by:	Dmitry Marakasov
This commit is contained in:
Romain Tartiere 2010-01-28 13:56:04 +00:00
parent d7aeb8fb5b
commit 7d20198520

View file

@ -109,55 +109,44 @@ then
fi
AM_CONDITIONAL(DOC_ENABLED, [test x"$enable_doc" = xyes])
AC_ARG_WITH([os-version], [AS_HELP_STRING([--with-os-version], [For FreeBSD users, use this option to override the detected OSVERSION.])])
case "$build_os" in
freebsd*)
AC_MSG_CHECKING([the FreeBSD operating system release])
if test -n "$with_os_version"; then
OSVERSION="$with_os_version"
else
OSVERSION=`/sbin/sysctl -n kern.osreldate`
fi
AC_MSG_RESULT([$OSVERSION])
AC_MSG_CHECKING([which usb library to use])
if test "$OSVERSION" -lt "800069"; then
system_has_libusb="no"
AC_MSG_RESULT([devel/libusb])
else
system_has_libusb="yes"
AC_MSG_RESULT(system)
LIBUSB_LIBS="-lusb"
fi
esac
# Dependencies
PKG_CONFIG_REQUIRES=""
## libusb
if test "x$enable_libusb" = "xyes"; then
if test x"$system_has_libusb" != "xyes"; then
if test x"$PKG_CONFIG" = "x"; then
AC_PATH_PROG(LIBUSB_CONFIG,libusb-config)
if test x"$LIBUSB_CONFIG" = "x" ; then
WITH_USB=0
else
LIBUSB_CFLAGS=`$LIBUSB_CONFIG --cflags`
LIBUSB_LIBS=`$LIBUSB_CONFIG --libs`
WITH_USB=1
fi
else
WITH_USB=0
# Search using pkg-config
if test x"$PKG_CONFIG" != "x"; then
PKG_CHECK_MODULES(LIBUSB, libusb, [WITH_USB=1], [WITH_USB=0])
if test x"$PKG_CONFIG_REQUIRES" != x""; then
PKG_CONFIG_REQUIRES="$PKG_CONFIG_REQUIRES,"
fi
PKG_CONFIG_REQUIRES="$PKG_CONFIG_REQUIRES libusb"
fi
# Search using libusb-config
if test x"$WITH_USB" = "x0"; then
AC_PATH_PROG(LIBUSB_CONFIG,libusb-config)
if test x"$LIBUSB_CONFIG" != "x" ; then
LIBUSB_CFLAGS=`$LIBUSB_CONFIG --cflags`
LIBUSB_LIBS=`$LIBUSB_CONFIG --libs`
WITH_USB=1
fi
fi
# Search the library and headers directly (last chance)
if test x"$WITH_USB" = "x0"; then
AC_CHECK_HEADER(usb.h, [], [AC_MSG_ERROR([The libusb headers are missing])])
AC_CHECK_LIB(usb, libusb_init, [], [AC_MSG_ERROR([The libusb library is missing])])
LIBUSB_LIBS="-lusb"
WITH_USB=1
fi
if test x"$WITH_USB" = "x0"; then
AC_MSG_ERROR([libusb is mandatory.])
fi
fi
AC_SUBST(LIBUSB_LIBS)
AC_SUBST(LIBUSB_CFLAGS)
fi