io: Track device in usbi_transfer
[platform/upstream/libusb.git] / configure.ac
index 4d3cfae..a99faf2 100644 (file)
@@ -31,9 +31,9 @@ dnl Library versioning
 dnl These numbers should be tweaked on every release. Read carefully:
 dnl http://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html
 dnl http://sourceware.org/autobook/autobook/autobook_91.html
-lt_current=2
+lt_current=3
 lt_revision=0
-lt_age=2
+lt_age=3
 LT_LDFLAGS="-version-info ${lt_current}:${lt_revision}:${lt_age} -no-undefined"
 
 m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])])
@@ -67,6 +67,7 @@ CFLAGS="${saved_CFLAGS}"
 
 AC_DEFINE([_GNU_SOURCE], [1], [Enable GNU extensions.])
 AC_DEFINE([DEFAULT_VISIBILITY], [__attribute__ ((visibility ("default")))], [Define to the attribute for default visibility.])
+AC_DEFINE([PRINTF_FORMAT(a, b)], [__attribute__ ((__format__ (__printf__, a, b)))], [Define to the attribute for enabling parameter checks on printf-like functions.])
 
 create_import_lib=
 is_android_linux=
@@ -75,14 +76,12 @@ case $host in
 *-darwin*)
        AC_MSG_RESULT([Darwin/Mac OS X])
        backend=darwin
-       events=posix
-       threads=posix
+       platform=posix
        ;;
 *-haiku*)
        AC_MSG_RESULT([Haiku])
        backend=haiku
-       events=posix
-       threads=posix
+       platform=posix
        ;;
 *-linux* | *-uclinux*)
        dnl on Android Linux, some functions are in different places
@@ -96,63 +95,49 @@ case $host in
                ;;
        esac
        backend=linux
-       events=posix
-       threads=posix
+       platform=posix
        ;;
 *-netbsd*)
        AC_MSG_RESULT([NetBSD])
        backend=netbsd
-       events=posix
-       threads=posix
+       platform=posix
        ;;
 *-openbsd*)
        AC_MSG_RESULT([OpenBSD])
        backend=openbsd
-       events=posix
-       threads=posix
+       platform=posix
        ;;
 *-solaris*)
        AC_MSG_RESULT([SunOS])
        backend=sunos
-       events=posix
-       threads=posix
+       platform=posix
        ;;
 *-cygwin*)
        AC_MSG_RESULT([Windows (using Cygwin)])
        backend=windows
-       events=windows
-       threads=posix
+       platform=windows
+       EXTRA_CFLAGS="-mwin32"
        ;;
 *-mingw* | *msys*)
        AC_MSG_RESULT([Windows])
        backend=windows
-       events=windows
-       threads=windows
+       platform=windows
        test "x$enable_shared" = xyes && create_import_lib=yes
-       EXTRA_CFLAGS="-fno-omit-frame-pointer"
+       EXTRA_CFLAGS="-mwin32 -fno-omit-frame-pointer"
        ;;
 *)
        AC_MSG_RESULT([Null])
        AC_MSG_WARN([The host being compiled for is not supported.])
        AC_MSG_WARN([The library may compile but will not function in any useful manner.])
-       backend="null"
-       events=posix
-       threads="posix"
+       backend=null
+       platform=posix
        ;;
 esac
 
-if test "x$events" = xposix; then
-       AC_DEFINE([EVENTS_POSIX], [1], [Define to 1 if using the POSIX events abstraction.])
+if test "x$platform" = xposix; then
+       AC_DEFINE([PLATFORM_POSIX], [1], [Define to 1 if compiling for a POSIX platform.])
        AC_CHECK_TYPES([nfds_t], [], [], [[#include <poll.h>]])
        AC_CHECK_FUNCS([pipe2])
-elif test "x$events" = xwindows; then
-       AC_DEFINE([EVENTS_WINDOWS], [1], [Define to 1 if using the Windows events abstraction.])
-else
-       AC_MSG_ERROR([Unknown events abstraction])
-fi
-
-if test "x$threads" = xposix; then
-       AC_DEFINE([THREADS_POSIX], [1], [Define to 1 if using POSIX threads.])
        dnl Some compilers do not support the '-pthread' option so check for it here
        saved_CFLAGS="${CFLAGS}"
        CFLAGS="-Wall -Werror -pthread"
@@ -167,25 +152,36 @@ if test "x$threads" = xposix; then
        AC_SEARCH_LIBS([pthread_create], [pthread],
                [test "x$ac_cv_search_pthread_create" != "xnone required" && AC_SUBST(THREAD_LIBS, [-lpthread])],
                [], [])
-elif test "x$threads" = xwindows; then
-       AC_DEFINE([THREADS_WINDOWS], [1], [Define to 1 if using Windows threads.])
+elif test "x$platform" = xwindows; then
+       AC_DEFINE([PLATFORM_WINDOWS], [1], [Define to 1 if compiling for a Windows platform.])
 else
-       AC_MSG_ERROR([Unknown threads implementation])
+       AC_MSG_ERROR([Unknown platform])
 fi
 
 case $backend in
 darwin)
        AC_CHECK_FUNCS([pthread_threadid_np])
-       LIBS="${LIBS} -lobjc -Wl,-framework,IOKit -Wl,-framework,CoreFoundation"
+       LIBS="${LIBS} -lobjc -Wl,-framework,IOKit -Wl,-framework,CoreFoundation -Wl,-framework,Security"
+       AC_CHECK_HEADERS([IOKit/usb/IOUSBHostFamilyDefinitions.h])
        ;;
 haiku)
        LIBS="${LIBS} -lbe"
        ;;
 linux)
+       AC_ARG_ENABLE([usbhost_api],
+               [AC_HELP_STRING([--enable-usbhost-api], [Request to deviced to obtain dev node fds [default=no]])],
+               [], [enable_usbhost_api="no"])
+       if test "x$enable_usbhost_api" = "xyes"; then
+          PKG_CHECK_MODULES([USBHOST_API], [dbus-1])
+          AC_DEFINE(USE_USBHOST_API, 1, [Request to deviced to obtain dev node fds])
+       fi
+
+       AC_SUBST(USE_USBHOST_API)
+
        AC_SEARCH_LIBS([clock_gettime], [rt], [], [], [])
        AC_CHECK_FUNCS([pthread_setname_np])
        AC_ARG_ENABLE([udev],
-               [AC_HELP_STRING([--enable-udev], [use udev for device enumeration and hotplug support (recommended) [default=yes]])],
+               [AS_HELP_STRING([--enable-udev], [use udev for device enumeration and hotplug support (recommended) [default=yes]])],
                [use_udev=$enableval], [use_udev=yes])
        if test "x$use_udev" = xyes; then
                dnl system has udev. use it or fail!
@@ -203,9 +199,6 @@ sunos)
 windows)
        AC_CHECK_TYPES([struct timespec], [], [], [[#include <time.h>]])
        AC_DEFINE([_WIN32_WINNT], [_WIN32_WINNT_VISTA], [Define to the oldest supported Windows version.])
-       dnl Cygwin and MSYS compilers do not define _WIN32 as MinGW and MSVC do
-       dnl simplify checks for Windows compilation by ensuring it is always defined
-       EXTRA_CPPFLAGS="-D_WIN32"
        LT_LDFLAGS="${LT_LDFLAGS} -avoid-version -Wl,--add-stdcall-alias"
        ;;
 *)
@@ -216,13 +209,77 @@ esac
 dnl headers not available on all platforms but required on others
 AC_CHECK_HEADERS([sys/time.h])
 
-dnl the clock_gettime() function needs certain clock IDs defined
-AC_CHECK_FUNCS([clock_gettime], [have_clock_gettime=yes], [have_clock_gettime=])
-if test "x$have_clock_gettime" = xyes; then
-       AC_CHECK_DECL([CLOCK_REALTIME], [], [AC_MSG_ERROR([C library headers missing definition for CLOCK_REALTIME])], [[#include <time.h>]])
-       AC_CHECK_DECL([CLOCK_MONOTONIC], [], [AC_MSG_ERROR([C library headers missing definition for CLOCK_MONOTONIC])], [[#include <time.h>]])
-elif test "x$backend" != xdarwin && test "x$backend" != xwindows; then
-       AC_MSG_ERROR([clock_gettime() is required on this platform])
+if test "x$platform" = xposix; then
+       dnl check availability of clock_gettime()
+       if test "x$backend" = xdarwin; then
+               dnl need to verify that OS X target is 10.12 or later for clock_gettime()
+               AC_MSG_CHECKING([whether OS X target version is 10.12 or later])
+               AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
+                               #include <AvailabilityMacros.h>
+                               #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_12
+                               # error "Target OS X version is too old"
+                               #endif
+                       ], [])],
+                       [AC_MSG_RESULT([yes])
+                        osx_10_12_or_later=yes],
+                       [AC_MSG_RESULT([no])
+                        osx_10_12_or_later=])
+               if test "x$osx_10_12_or_later" = xyes; then
+                       AC_CHECK_FUNCS([clock_gettime], [have_clock_gettime=yes], [have_clock_gettime=])
+               else
+                       AC_MSG_NOTICE([clock_gettime() is not available on target OS X version])
+               fi
+       else
+               AC_CHECK_FUNCS([clock_gettime], [have_clock_gettime=yes], [AC_MSG_ERROR([clock_gettime() is required on this platform])])
+       fi
+
+       if test "x$have_clock_gettime" = xyes; then
+               dnl the clock_gettime() function needs certain clock IDs defined
+               AC_CHECK_DECL([CLOCK_MONOTONIC], [], [AC_MSG_ERROR([C library headers missing definition for CLOCK_MONOTONIC])], [[#include <time.h>]])
+               dnl use the monotonic clock for condition variable timed waits if possible
+               AC_CHECK_FUNCS([pthread_condattr_setclock], [need_clock_realtime=], [need_clock_realtime=yes])
+               if test "x$need_clock_realtime" = xyes; then
+                       AC_CHECK_DECL([CLOCK_REALTIME], [], [AC_MSG_ERROR([C library headers missing definition for CLOCK_REALTIME])], [[#include <time.h>]])
+               fi
+       fi
+fi
+
+dnl eventfd support
+if test "x$backend" = xlinux || test "x$backend" = xsunos; then
+       AC_ARG_ENABLE([eventfd],
+               [AS_HELP_STRING([--enable-eventfd], [use eventfd for signalling [default=auto]])],
+               [use_eventfd=$enableval],
+               [use_eventfd=auto])
+       if test "x$use_eventfd" != xno; then
+               AC_CHECK_HEADER([sys/eventfd.h], [eventfd_h=yes], [eventfd_h=])
+               if test "x$eventfd_h" = xyes; then
+                       AC_CHECK_DECLS([EFD_NONBLOCK, EFD_CLOEXEC], [eventfd_h_ok=yes], [eventfd_h_ok=], [[#include <sys/eventfd.h>]])
+                       if test "x$eventfd_h_ok" = xyes; then
+                               AC_CHECK_FUNC([eventfd], [eventfd_ok=yes], [eventfd_ok=])
+                               if test "x$eventfd_ok" = xyes; then
+                                       AC_DEFINE([HAVE_EVENTFD], [1], [Define to 1 if the system has eventfd functionality.])
+                               elif test "x$use_eventfd" = xyes; then
+                                       AC_MSG_ERROR([eventfd() function not found; glibc 2.9+ required])
+                               fi
+                       elif test "x$use_eventfd" = xyes; then
+                               AC_MSG_ERROR([eventfd header not usable; glibc 2.9+ required])
+                       fi
+               elif test "x$use_eventfd" = xyes; then
+                       AC_MSG_ERROR([eventfd header not available; glibc 2.9+ required])
+               fi
+       fi
+       AC_MSG_CHECKING([whether to use eventfd for signalling])
+       if test "x$use_eventfd" = xno; then
+               AC_MSG_RESULT([no (disabled by user)])
+       elif test "x$eventfd_h" != xyes; then
+               AC_MSG_RESULT([no (header not available)])
+       elif test "x$eventfd_h_ok" != xyes; then
+               AC_MSG_RESULT([no (header not usable)])
+       elif test "x$eventfd_ok" != xyes; then
+               AC_MSG_RESULT([no (functions not available)])
+       else
+               AC_MSG_RESULT([yes])
+       fi
 fi
 
 dnl timerfd support
@@ -300,10 +357,6 @@ AC_ARG_ENABLE([examples-build],
        [AS_HELP_STRING([--enable-examples-build], [build example applications [default=no]])],
        [build_examples=$enableval],
        [build_examples=no])
-if test "x$build_examples" != xno; then
-       dnl sigaction needed for some example programs
-       AC_CHECK_FUNC([sigaction], [have_sigaction=yes], [have_sigaction=])
-fi
 
 dnl Tests build
 AC_ARG_ENABLE([tests-build],
@@ -314,9 +367,6 @@ AC_ARG_ENABLE([tests-build],
 AM_CONDITIONAL([BUILD_EXAMPLES], [test "x$build_examples" != xno])
 AM_CONDITIONAL([BUILD_TESTS], [test "x$build_tests" != xno])
 AM_CONDITIONAL([CREATE_IMPORT_LIB], [test "x$create_import_lib" = xyes])
-AM_CONDITIONAL([EVENTS_POSIX], [test "x$events" = xposix])
-AM_CONDITIONAL([EVENTS_WINDOWS], [test "x$events" = xwindows])
-AM_CONDITIONAL([HAVE_SIGACTION], [test "x$have_sigaction" = xyes])
 AM_CONDITIONAL([OS_DARWIN], [test "x$backend" = xdarwin])
 AM_CONDITIONAL([OS_HAIKU], [test "x$backend" = xhaiku])
 AM_CONDITIONAL([OS_LINUX], [test "x$backend" = xlinux])
@@ -325,9 +375,10 @@ AM_CONDITIONAL([OS_NULL], [test "x$backend" = xnull])
 AM_CONDITIONAL([OS_OPENBSD], [test "x$backend" = xopenbsd])
 AM_CONDITIONAL([OS_SUNOS], [test "x$backend" = xsunos])
 AM_CONDITIONAL([OS_WINDOWS], [test "x$backend" = xwindows])
-AM_CONDITIONAL([THREADS_POSIX], [test "x$threads" = xposix])
-AM_CONDITIONAL([THREADS_WINDOWS], [test "x$threads" = xwindows])
+AM_CONDITIONAL([PLATFORM_POSIX], [test "x$platform" = xposix])
+AM_CONDITIONAL([PLATFORM_WINDOWS], [test "x$platform" = xwindows])
 AM_CONDITIONAL([USE_UDEV], [test "x$use_udev" = xyes])
+AM_CONDITIONAL([USE_USBHOST_API], [test "x$enable_usbhost_api" = "xyes"])
 
 dnl The -Wcast-function-type warning causes a flurry of warnings when compiling
 dnl Windows with GCC 8 or later because of dynamically loaded functions