m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])])
+EXTRA_CPPFLAGS=
+EXTRA_CFLAGS=
+
dnl check for -std=gnu11 compiler support (optional)
-dnl note that we don't just check whether the compiler accepts '-std=x11'
+dnl note that we don't just check if the compiler accepts '-std=x11'
dnl but also that it supports the _Thread_local keyword because some compilers
dnl (e.g. gcc 4.8) accept the command line option but do not implement TLS
saved_CFLAGS="${CFLAGS}"
CFLAGS="-std=gnu11"
-AC_MSG_CHECKING([whether CC supports -std=gnu11])
+AC_MSG_CHECKING([if $CC supports -std=gnu11])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([_Thread_local int x;], [x = 42;])],
[AC_MSG_RESULT([yes])
- cc_supports_gnu11=yes],
+ c_dialect=gnu],
[AC_MSG_RESULT([no])
- cc_supports_gnu11=])
-CFLAGS="${saved_CFLAGS}"
-
-if test "x$cc_supports_gnu11" = xyes; then
- AM_CFLAGS="-std=gnu11"
-else
+ c_dialect=])
+if test "x$c_dialect" != xgnu; then
dnl fallback check for -std=c11 compiler support (required)
- saved_CFLAGS="${CFLAGS}"
CFLAGS="-std=c11"
- AC_MSG_CHECKING([whether CC supports -std=c11])
+ AC_MSG_CHECKING([if $CC supports -std=c11])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([_Thread_local int x;], [x = 42;])],
[AC_MSG_RESULT([yes])],
[AC_MSG_RESULT([no])
AC_MSG_ERROR([compiler with C11 support is required to build libusb])])
- CFLAGS="${saved_CFLAGS}"
- AM_CFLAGS="-std=c11"
+ c_dialect=c
fi
+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.])
*-darwin*)
AC_MSG_RESULT([Darwin/Mac OS X])
backend=darwin
- poll=posix
- threads=posix
+ platform=posix
;;
*-haiku*)
AC_MSG_RESULT([Haiku])
backend=haiku
- poll=posix
- threads=posix
+ platform=posix
;;
*-linux* | *-uclinux*)
dnl on Android Linux, some functions are in different places
;;
esac
backend=linux
- poll=posix
- threads=posix
+ platform=posix
;;
*-netbsd*)
AC_MSG_RESULT([NetBSD])
backend=netbsd
- poll=posix
- threads=posix
+ platform=posix
;;
*-openbsd*)
AC_MSG_RESULT([OpenBSD])
backend=openbsd
- poll=posix
- threads=posix
+ platform=posix
;;
*-solaris*)
AC_MSG_RESULT([SunOS])
backend=sunos
- poll=posix
- threads=posix
+ platform=posix
;;
*-cygwin*)
AC_MSG_RESULT([Windows (using Cygwin)])
backend=windows
- poll=windows
- threads=posix
+ platform=windows
+ EXTRA_CFLAGS="-mwin32"
;;
*-mingw* | *msys*)
AC_MSG_RESULT([Windows])
backend=windows
- poll=windows
- threads=windows
+ platform=windows
test "x$enable_shared" = xyes && create_import_lib=yes
- AM_CFLAGS="${AM_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"
- poll=posix
- threads="posix"
+ backend=null
+ platform=posix
;;
esac
-if test "x$poll" = xposix; then
- AC_DEFINE([POLL_POSIX], [1], [Define to 1 if using the POSIX poll() implementation.])
+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$poll" = xwindows; then
- AC_DEFINE([POLL_WINDOWS], [1], [Define to 1 if using the Windows poll() implementation.])
-else
- AC_MSG_ERROR([Unknown poll implementation])
-fi
-
-if test "x$threads" = xposix; then
- AC_DEFINE([THREADS_POSIX], [1], [Define to 1 if using POSIX threads.])
- AC_SUBST(THREAD_CFLAGS, [-pthread])
+ dnl Some compilers do not support the '-pthread' option so check for it here
+ saved_CFLAGS="${CFLAGS}"
+ CFLAGS="-Wall -Werror -pthread"
+ AC_MSG_CHECKING([if $CC recognizes -pthread])
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])],
+ [AC_MSG_RESULT([yes])
+ AC_SUBST(THREAD_CFLAGS, [-pthread])],
+ [AC_MSG_RESULT([no])])
+ CFLAGS="${saved_CFLAGS}"
dnl Android Linux and Darwin provide pthread functions directly in libc
dnl glibc also provides some pthread functions directly, so search for a thread-specific function
- AC_SEARCH_LIBS([pthread_key_create], [pthread], [AC_SUBST(THREAD_LIBS, [-lpthread])], [], [])
-elif test "x$threads" = xwindows; then
- AC_DEFINE([THREADS_WINDOWS], [1], [Define to 1 if using Windows threads.])
+ AC_SEARCH_LIBS([pthread_create], [pthread],
+ [test "x$ac_cv_search_pthread_create" != "xnone required" && AC_SUBST(THREAD_LIBS, [-lpthread])],
+ [], [])
+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
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 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_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
+ elif test "x$backend" != xdarwin; then
+ AC_MSG_ERROR([clock_gettime() is required on this platform])
+ 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
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([POLL_POSIX], [test "x$poll" = xposix])
-AM_CONDITIONAL([POLL_WINDOWS], [test "x$poll" = 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_CFLAGS="${AM_CFLAGS} -Wall -Wshadow -Wstrict-prototypes -Wundef -Wunused -Werror=implicit-function-declaration"
+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
+if test "x$backend" = xwindows; then
+ saved_CFLAGS="${CFLAGS}"
+ CFLAGS="-Werror -Wcast-function-type"
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])],
+ [EXTRA_CFLAGS="${EXTRA_CFLAGS} -Wno-cast-function-type"],
+ [])
+ CFLAGS="${saved_CFLAGS}"
+fi
+
+SHARED_CFLAGS="-Wall -Wextra -Wshadow -Wunused -Wwrite-strings -Werror=format-security -Werror=implicit-function-declaration -Werror=implicit-int -Werror=init-self -Werror=missing-prototypes -Werror=strict-prototypes -Werror=undef -Werror=uninitialized"
+
+AM_CPPFLAGS="${EXTRA_CPPFLAGS}"
+AC_SUBST(AM_CPPFLAGS)
+
+AM_CFLAGS="-std=${c_dialect}11 ${EXTRA_CFLAGS} ${SHARED_CFLAGS}"
AC_SUBST(AM_CFLAGS)
-AM_CXXFLAGS="${AM_CFLAGS}"
+AM_CXXFLAGS="-std=${c_dialect}++11 ${EXTRA_CFLAGS} ${SHARED_CFLAGS} -Wmissing-declarations"
AC_SUBST(AM_CXXFLAGS)
AC_SUBST(LT_LDFLAGS)