io: Track device in usbi_transfer
[platform/upstream/libusb.git] / configure.ac
index c6515ad..a99faf2 100644 (file)
-m4_define(LIBUSB_MAJOR, [1])
-m4_define(LIBUSB_MINOR, [0])
-m4_define(LIBUSB_MICRO, [8])
-
-AC_INIT([libusb], LIBUSB_MAJOR.LIBUSB_MINOR.LIBUSB_MICRO, [libusb-devel@lists.sourceforge.net], [libusb], [http://www.libusb.org/])
-
-AC_SUBST([LIBUSB_VERSION_MAJOR], [LIBUSB_MAJOR])
-AC_SUBST([LIBUSB_VERSION_MINOR], [LIBUSB_MINOR])
-AC_SUBST([LIBUSB_VERSION_MICRO], [LIBUSB_MICRO])
-
-# Library versioning
-# These numbers should be tweaked on every release. Read carefully:
-# http://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html
-# http://sourceware.org/autobook/autobook/autobook_91.html
-lt_current="1"
-lt_revision="0"
-lt_age="1"
-AC_SUBST(lt_current)
-AC_SUBST(lt_revision)
-AC_SUBST(lt_age)
+dnl These m4 macros are whitespace sensitive and break if moved around much.
+m4_define([LU_VERSION_H], m4_include([libusb/version.h]))
+m4_define([LU_DEFINE_VERSION_ATOM],
+       [m4_define([$1], m4_bregexp(LU_VERSION_H,
+       [^#define\s*$1\s*\([0-9]*\).*], [\1]))])
+m4_define([LU_DEFINE_VERSION_RC_ATOM],
+       [m4_define([$1], m4_bregexp(LU_VERSION_H,
+       [^#define\s*$1\s*"\(-rc[0-9]*\)".*], [\1]))])
+dnl The m4_bregexp() returns (only) the numbers following the #define named
+dnl in the first macro parameter. m4_define() then defines the name for use
+dnl in AC_INIT.
 
-AM_INIT_AUTOMAKE
+LU_DEFINE_VERSION_ATOM([LIBUSB_MAJOR])
+LU_DEFINE_VERSION_ATOM([LIBUSB_MINOR])
+LU_DEFINE_VERSION_ATOM([LIBUSB_MICRO])
+LU_DEFINE_VERSION_RC_ATOM([LIBUSB_RC])
+
+AC_PREREQ([2.69])
+AC_INIT([libusb-1.0], [LIBUSB_MAJOR[.]LIBUSB_MINOR[.]LIBUSB_MICRO[]LIBUSB_RC], [libusb-devel@lists.sourceforge.net], [libusb-1.0], [http://libusb.info])
+AC_CONFIG_HEADERS([config.h])
 AC_CONFIG_SRCDIR([libusb/core.c])
 AC_CONFIG_MACRO_DIR([m4])
-AM_CONFIG_HEADER([config.h])
-m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])])
-
-AC_PREREQ([2.50])
 AC_PROG_CC
-AC_PROG_LIBTOOL
+AC_PROG_CXX
 AC_C_INLINE
-AM_PROG_CC_C_O
-AC_DEFINE([_GNU_SOURCE], [], [Use GNU extensions])
+AM_INIT_AUTOMAKE
+LT_INIT
+LT_LANG([Windows Resource])
 
-AM_MAINTAINER_MODE
+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=3
+lt_revision=0
+lt_age=3
+LT_LDFLAGS="-version-info ${lt_current}:${lt_revision}:${lt_age} -no-undefined"
 
+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 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([if $CC supports -std=gnu11])
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([_Thread_local int x;], [x = 42;])],
+       [AC_MSG_RESULT([yes])
+        c_dialect=gnu],
+       [AC_MSG_RESULT([no])
+        c_dialect=])
+if test "x$c_dialect" != xgnu; then
+       dnl fallback check for -std=c11 compiler support (required)
+       CFLAGS="-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])])
+       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.])
+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=
 AC_MSG_CHECKING([operating system])
-PC_LIBS_PRIVATE=
 case $host in
-*-linux*)
-       AC_DEFINE(OS_LINUX, [], [Linux backend])
-       AC_SUBST(OS_LINUX)
-       AC_DEFINE([THREADS_POSIX], [], [Use Posix Threads])
-       AC_MSG_RESULT([Linux])
-       backend="linux"
-       AC_CHECK_LIB(rt, clock_gettime, PC_LIBS_PRIVATE="-lrt")
-       LIBS="${LIBS} ${PC_LIBS_PRIVATE}"
-       threads="posix"
-       THREAD_CFLAGS="-pthread"
-       PC_LIBS_PRIVATE="${PC_LIBS_PRIVATE} -pthread"
-       AM_LDFLAGS=""
-       AC_CHECK_HEADERS([poll.h])
-       AC_DEFINE([POLL_NFDS_TYPE],[nfds_t],[type of second poll() argument])
-       ;;
 *-darwin*)
-       AC_DEFINE(OS_DARWIN, [], [Darwin backend])
-       AC_SUBST(OS_DARWIN)
-       AC_DEFINE([THREADS_POSIX], [], [Use Posix Threads])
-       AC_MSG_RESULT([Darwin/MacOS X])
-       backend="darwin"
-       threads="posix"
-       THREAD_CFLAGS="-pthread"
-       PC_LIBS_PRIVATE="-Wl,-framework,IOKit -Wl,-framework,CoreFoundation -Wl,-prebind -no-undefined -pthread"
-       AM_LDFLAGS=${PC_LIBS_PRIVATE}
-       AC_CHECK_HEADERS([poll.h])
-       AC_CHECK_TYPE([nfds_t],
-               [AC_DEFINE([POLL_NFDS_TYPE],[nfds_t],[type of second poll() argument])],
-               [AC_DEFINE([POLL_NFDS_TYPE],[unsigned int],[type of second poll() argument])],
-               [#include <poll.h>])
-;;
-*-mingw*)
-       AC_DEFINE(OS_WINDOWS, [], [Windows backend])
-       AC_SUBST(OS_WINDOWS)
-       AC_MSG_RESULT([Windows])
-       backend="windows"
-       threads="windows"
-       PC_LIBS_PRIVATE="-lsetupapi -lole32 -ladvapi32"
-       LIBS="${LIBS} ${PC_LIBS_PRIVATE}"
-       # -avoid-version to avoid a naming scheme such as libusb-0.dll
-       AM_LDFLAGS="-no-undefined -avoid-version --add-stdcall-alias"
-       AC_CHECK_TOOL(RC, windres, no)
-       AC_DEFINE([POLL_NFDS_TYPE],[unsigned int],[type of second poll() argument])
+       AC_MSG_RESULT([Darwin/Mac OS X])
+       backend=darwin
+       platform=posix
+       ;;
+*-haiku*)
+       AC_MSG_RESULT([Haiku])
+       backend=haiku
+       platform=posix
+       ;;
+*-linux* | *-uclinux*)
+       dnl on Android Linux, some functions are in different places
+       case $host in
+       *-linux-android*)
+               AC_MSG_RESULT([Android Linux])
+               is_android_linux=yes
+               ;;
+       *)
+               AC_MSG_RESULT([Linux])
+               ;;
+       esac
+       backend=linux
+       platform=posix
+       ;;
+*-netbsd*)
+       AC_MSG_RESULT([NetBSD])
+       backend=netbsd
+       platform=posix
+       ;;
+*-openbsd*)
+       AC_MSG_RESULT([OpenBSD])
+       backend=openbsd
+       platform=posix
+       ;;
+*-solaris*)
+       AC_MSG_RESULT([SunOS])
+       backend=sunos
+       platform=posix
        ;;
 *-cygwin*)
-       AC_DEFINE(OS_WINDOWS, [], [Windows backend])
-       AC_SUBST(OS_WINDOWS)
-       AC_DEFINE([THREADS_POSIX], [], [Use Posix Threads])
+       AC_MSG_RESULT([Windows (using Cygwin)])
+       backend=windows
+       platform=windows
+       EXTRA_CFLAGS="-mwin32"
+       ;;
+*-mingw* | *msys*)
        AC_MSG_RESULT([Windows])
-       backend="windows"
-       threads="posix"
-       PC_LIBS_PRIVATE="-lsetupapi -lole32 -ladvapi32"
-       LIBS="${LIBS} ${PC_LIBS_PRIVATE}"
-       AM_LDFLAGS="-no-undefined -avoid-version"
-       AC_CHECK_TOOL(RC, windres, no)
-       AC_DEFINE([POLL_NFDS_TYPE],[unsigned int],[type of second poll() argument])
+       backend=windows
+       platform=windows
+       test "x$enable_shared" = xyes && create_import_lib=yes
+       EXTRA_CFLAGS="-mwin32 -fno-omit-frame-pointer"
        ;;
 *)
-       AC_MSG_ERROR([unsupported operating system])
+       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
+       platform=posix
+       ;;
 esac
-AC_SUBST(PC_LIBS_PRIVATE)
-
-AM_CONDITIONAL([OS_LINUX], [test "x$backend" = "xlinux"])
-AM_CONDITIONAL([OS_DARWIN], [test "x$backend" = "xdarwin"])
-AM_CONDITIONAL([OS_WINDOWS], [test "x$backend" = "xwindows"])
-AM_CONDITIONAL([THREADS_POSIX], [test "x$threads" = "xposix"])
-
-# timerfd
-AC_CHECK_HEADER([sys/timerfd.h], [timerfd_h=1], [timerfd_h=0])
-AC_ARG_ENABLE([timerfd],
-       [AS_HELP_STRING([--enable-timerfd],
-               [use timerfd for timing (default auto)])],
-       [use_timerfd=$enableval], [use_timerfd='auto'])
-
-if test "x$use_timerfd" = "xyes" -a "x$timerfd_h" = "x0"; then
-       AC_MSG_ERROR([timerfd header not available; glibc 2.9+ required])
-fi
 
-AC_CHECK_DECL([TFD_NONBLOCK], [tfd_hdr_ok=yes], [tfd_hdr_ok=no], [#include <sys/timerfd.h>])
-if test "x$use_timerfd" = "xyes" -a "x$tfd_hdr_ok" = "xno"; then
-       AC_MSG_ERROR([timerfd header not usable; glibc 2.9+ required])
+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])
+       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_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 platform])
 fi
 
-AC_MSG_CHECKING([whether to use timerfd for timing])
-if test "x$use_timerfd" = "xno"; then
-       AC_MSG_RESULT([no (disabled by user)])
-else
-       if test "x$timerfd_h" = "x1" -a "x$tfd_hdr_ok" = "xyes"; then
-               AC_MSG_RESULT([yes])
-               AC_DEFINE(USBI_TIMERFD_AVAILABLE, [], [timerfd headers available])
+case $backend in
+darwin)
+       AC_CHECK_FUNCS([pthread_threadid_np])
+       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],
+               [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!
+               AC_CHECK_HEADER([libudev.h], [], [AC_MSG_ERROR([udev support requested but libudev header not installed])])
+               AC_CHECK_LIB([udev], [udev_new], [], [AC_MSG_ERROR([udev support requested but libudev not installed])])
+       else
+               AC_CHECK_HEADERS([asm/types.h])
+               AC_CHECK_HEADER([linux/netlink.h], [], [AC_MSG_ERROR([Linux netlink header not found])])
+               AC_CHECK_HEADER([sys/socket.h], [], [AC_MSG_ERROR([Linux socket header not found])])
+       fi
+       ;;
+sunos)
+       LIBS="${LIBS} -ldevinfo"
+       ;;
+windows)
+       AC_CHECK_TYPES([struct timespec], [], [], [[#include <time.h>]])
+       AC_DEFINE([_WIN32_WINNT], [_WIN32_WINNT_VISTA], [Define to the oldest supported Windows version.])
+       LT_LDFLAGS="${LT_LDFLAGS} -avoid-version -Wl,--add-stdcall-alias"
+       ;;
+*)
+       dnl no special handling required
+       ;;
+esac
+
+dnl headers not available on all platforms but required on others
+AC_CHECK_HEADERS([sys/time.h])
+
+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
 
-AC_CHECK_TYPES(struct timespec)
+dnl timerfd support
+if test "x$backend" = xlinux || test "x$backend" = xsunos; then
+       AC_ARG_ENABLE([timerfd],
+               [AS_HELP_STRING([--enable-timerfd], [use timerfd for timing [default=auto]])],
+               [use_timerfd=$enableval],
+               [use_timerfd=auto])
+       if test "x$use_timerfd" != xno; then
+               AC_CHECK_HEADER([sys/timerfd.h], [timerfd_h=yes], [timerfd_h=])
+               if test "x$timerfd_h" = xyes; then
+                       AC_CHECK_DECLS([TFD_NONBLOCK, TFD_CLOEXEC], [timerfd_h_ok=yes], [timerfd_h_ok=], [[#include <sys/timerfd.h>]])
+                       if test "x$timerfd_h_ok" = xyes; then
+                               AC_CHECK_FUNC([timerfd_create], [timerfd_ok=yes], [timerfd_ok=])
+                               if test "x$timerfd_ok" = xyes; then
+                                       AC_DEFINE([HAVE_TIMERFD], [1], [Define to 1 if the system has timerfd functionality.])
+                               elif test "x$use_timerfd" = xyes; then
+                                       AC_MSG_ERROR([timerfd_create() function not found; glibc 2.9+ required])
+                               fi
+                       elif test "x$use_timerfd" = xyes; then
+                               AC_MSG_ERROR([timerfd header not usable; glibc 2.9+ required])
+                       fi
+               elif test "x$use_timerfd" = xyes; then
+                       AC_MSG_ERROR([timerfd header not available; glibc 2.9+ required])
+               fi
+       fi
+       AC_MSG_CHECKING([whether to use timerfd for timing])
+       if test "x$use_timerfd" = xno; then
+               AC_MSG_RESULT([no (disabled by user)])
+       elif test "x$timerfd_h" != xyes; then
+               AC_MSG_RESULT([no (header not available)])
+       elif test "x$timerfd_h_ok" != xyes; then
+               AC_MSG_RESULT([no (header not usable)])
+       elif test "x$timerfd_ok" != xyes; then
+               AC_MSG_RESULT([no (functions not available)])
+       else
+               AC_MSG_RESULT([yes])
+       fi
+fi
 
-# Message logging
-AC_ARG_ENABLE([log], [AS_HELP_STRING([--disable-log], [disable all logging])],
+dnl Message logging
+AC_ARG_ENABLE([log],
+       [AS_HELP_STRING([--disable-log], [disable all logging])],
        [log_enabled=$enableval],
-       [log_enabled='yes'])
-if test "x$log_enabled" != "xno"; then
-       AC_DEFINE([ENABLE_LOGGING], 1, [Message logging])
+       [log_enabled=yes])
+if test "x$log_enabled" != xno; then
+       AC_DEFINE([ENABLE_LOGGING], [1], [Define to 1 to enable message logging.])
 fi
 
-AC_ARG_ENABLE([debug-log], [AS_HELP_STRING([--enable-debug-log],
-       [enable debug logging (default n)])],
+AC_ARG_ENABLE([debug-log],
+       [AS_HELP_STRING([--enable-debug-log], [start with debug message logging enabled [default=no]])],
        [debug_log_enabled=$enableval],
-       [debug_log_enabled='no'])
-if test "x$debug_log_enabled" != "xno"; then
-       AC_DEFINE([ENABLE_DEBUG_LOGGING], 1, [Debug message logging])
+       [debug_log_enabled=no])
+if test "x$debug_log_enabled" != xno; then
+       AC_DEFINE([ENABLE_DEBUG_LOGGING], [1], [Define to 1 to start with debug message logging enabled.])
 fi
 
-# Examples build
-AC_ARG_ENABLE([examples-build], [AS_HELP_STRING([--enable-examples-build],
-       [build example applications (default n)])],
+AC_ARG_ENABLE([system-log],
+       [AS_HELP_STRING([--enable-system-log], [output logging messages to the systemwide log, if supported by the OS [default=no]])],
+       [system_log_enabled=$enableval],
+       [system_log_enabled=no])
+if test "x$system_log_enabled" != xno; then
+       AC_DEFINE([USE_SYSTEM_LOGGING_FACILITY], [1], [Define to 1 to output logging messages to the systemwide log.])
+       if test "x$backend" != xwindows && test "x$is_android_linux" != xyes; then
+               dnl Check if syslog is available in standard C library
+               AC_CHECK_HEADER([syslog.h], [syslog_h=yes], [syslog_h=])
+               if test "x$syslog_h" = xyes; then
+                       AC_CHECK_FUNCS([syslog])
+               fi
+       fi
+fi
+
+dnl Examples build
+AC_ARG_ENABLE([examples-build],
+       [AS_HELP_STRING([--enable-examples-build], [build example applications [default=no]])],
        [build_examples=$enableval],
-       [build_examples='no'])
-AM_CONDITIONAL([BUILD_EXAMPLES], [test "x$build_examples" != "xno"])
-
-# Restore gnu89 inline semantics on gcc 4.3 and newer
-saved_cflags="$CFLAGS"
-CFLAGS="$CFLAGS -fgnu89-inline"
-AC_COMPILE_IFELSE(AC_LANG_PROGRAM([]), inline_cflags="-fgnu89-inline", inline_cflags="")
-CFLAGS="$saved_cflags"
-
-# check for -fvisibility=hidden compiler support (GCC >= 3.4)
-saved_cflags="$CFLAGS"
-# -Werror required for cygwin
-CFLAGS="$CFLAGS -Werror -fvisibility=hidden"
-AC_COMPILE_IFELSE(AC_LANG_PROGRAM([]),
-       [VISIBILITY_CFLAGS="-fvisibility=hidden"
-        AC_DEFINE([DEFAULT_VISIBILITY], [__attribute__((visibility("default")))], [Default visibility]) ],
-       [ VISIBILITY_CFLAGS=""
-        AC_DEFINE([DEFAULT_VISIBILITY], [], [Default visibility]) ],
-       ])
-CFLAGS="$saved_cflags"
-
-# check for -Wno-pointer-sign compiler support (GCC >= 4)
-saved_cflags="$CFLAGS"
-CFLAGS="$CFLAGS -Wno-pointer-sign"
-AC_COMPILE_IFELSE(AC_LANG_PROGRAM([]),
-       nopointersign_cflags="-Wno-pointer-sign", nopointersign_cflags="")
-CFLAGS="$saved_cflags"
-
-# sigaction not available on MinGW
-AC_CHECK_FUNC([sigaction], [have_sigaction=yes], [have_sigaction=no])
-AM_CONDITIONAL([HAVE_SIGACTION], [test "x$have_sigaction" = "xyes"])
-
-# headers not available on all platforms but required on others
-AC_CHECK_HEADERS([sys/time.h])
+       [build_examples=no])
 
-AC_SUBST([THREAD_CFLAGS])
+dnl Tests build
+AC_ARG_ENABLE([tests-build],
+       [AS_HELP_STRING([--enable-tests-build], [build test applications [default=no]])],
+       [build_tests=$enableval],
+       [build_tests=no])
 
-AM_CFLAGS="-std=gnu99 $inline_cflags -Wall -Wundef -Wunused -Wstrict-prototypes -Werror-implicit-function-declaration $nopointersign_cflags -Wshadow"
+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([OS_DARWIN], [test "x$backend" = xdarwin])
+AM_CONDITIONAL([OS_HAIKU], [test "x$backend" = xhaiku])
+AM_CONDITIONAL([OS_LINUX], [test "x$backend" = xlinux])
+AM_CONDITIONAL([OS_NETBSD], [test "x$backend" = xnetbsd])
+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([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"])
 
-AC_SUBST(VISIBILITY_CFLAGS)
+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)
-AC_SUBST(AM_LDFLAGS)
 
-AC_CONFIG_FILES([libusb-1.0.pc] [Makefile] [libusb/Makefile] [libusb/libusb-1.0.rc] [examples/Makefile] [doc/Makefile] [doc/doxygen.cfg])
-AC_OUTPUT
+AM_CXXFLAGS="-std=${c_dialect}++11 ${EXTRA_CFLAGS} ${SHARED_CFLAGS} -Wmissing-declarations"
+AC_SUBST(AM_CXXFLAGS)
+
+AC_SUBST(LT_LDFLAGS)
 
+dnl set name of html output directory for doxygen
+AC_SUBST(DOXYGEN_HTMLDIR, [api-1.0])
+
+AC_CONFIG_FILES([libusb-1.0.pc])
+AC_CONFIG_FILES([Makefile])
+AC_CONFIG_FILES([libusb/Makefile])
+AC_CONFIG_FILES([examples/Makefile])
+AC_CONFIG_FILES([tests/Makefile])
+AC_CONFIG_FILES([doc/Makefile])
+AC_CONFIG_FILES([doc/doxygen.cfg])
+AC_OUTPUT