Peter Stuge | 85a14f4 | 2011-05-09 08:12:24 +0200 | [diff] [blame] | 1 | dnl These m4 macros are whitespace sensitive and break if moved around much. |
| 2 | m4_define([LU_VERSION_H], m4_include([libusb/version.h])) |
| 3 | m4_define([LU_DEFINE_VERSION_ATOM], |
| 4 | [m4_define([$1], m4_bregexp(LU_VERSION_H, |
| 5 | [^#define\s*$1\s*\([0-9]*\).*], [\1]))]) |
Peter Stuge | cbc2d7b | 2011-09-15 16:48:35 +0200 | [diff] [blame] | 6 | m4_define([LU_DEFINE_VERSION_RC_ATOM], |
| 7 | [m4_define([$1], m4_bregexp(LU_VERSION_H, |
| 8 | [^#define\s*$1\s*"\(-rc[0-9]*\)".*], [\1]))]) |
Peter Stuge | 85a14f4 | 2011-05-09 08:12:24 +0200 | [diff] [blame] | 9 | dnl The m4_bregexp() returns (only) the numbers following the #define named |
| 10 | dnl in the first macro parameter. m4_define() then defines the name for use |
Ludovic Rousseau | c9d41fe | 2012-06-01 11:30:00 +0200 | [diff] [blame] | 11 | dnl in AC_INIT. |
Pete Batard | 9a4249f | 2010-07-10 17:51:13 -0600 | [diff] [blame] | 12 | |
Peter Stuge | 85a14f4 | 2011-05-09 08:12:24 +0200 | [diff] [blame] | 13 | LU_DEFINE_VERSION_ATOM([LIBUSB_MAJOR]) |
| 14 | LU_DEFINE_VERSION_ATOM([LIBUSB_MINOR]) |
| 15 | LU_DEFINE_VERSION_ATOM([LIBUSB_MICRO]) |
Peter Stuge | cbc2d7b | 2011-09-15 16:48:35 +0200 | [diff] [blame] | 16 | LU_DEFINE_VERSION_RC_ATOM([LIBUSB_RC]) |
Daniel Drake | d7c2545 | 2010-10-04 20:03:58 +0100 | [diff] [blame] | 17 | |
Chris Dickens | 9a1bc8c | 2020-03-30 12:28:11 -0700 | [diff] [blame] | 18 | AC_PREREQ([2.69]) |
Chris Dickens | 4a5540a | 2020-03-25 00:09:26 -0700 | [diff] [blame] | 19 | AC_INIT([libusb-1.0], [LIBUSB_MAJOR[.]LIBUSB_MINOR[.]LIBUSB_MICRO[]LIBUSB_RC], [libusb-devel@lists.sourceforge.net], [libusb-1.0], [http://libusb.info]) |
Chris Dickens | 9a1bc8c | 2020-03-30 12:28:11 -0700 | [diff] [blame] | 20 | AC_CONFIG_HEADERS([config.h]) |
| 21 | AC_CONFIG_SRCDIR([libusb/core.c]) |
| 22 | AC_CONFIG_MACRO_DIR([m4]) |
| 23 | AC_PROG_CC |
| 24 | AC_PROG_CXX |
| 25 | AC_C_INLINE |
| 26 | AM_INIT_AUTOMAKE |
| 27 | LT_INIT |
| 28 | LT_LANG([Windows Resource]) |
Daniel Drake | d7c2545 | 2010-10-04 20:03:58 +0100 | [diff] [blame] | 29 | |
Chris Dickens | d5bb64b | 2020-01-22 17:39:14 -0800 | [diff] [blame] | 30 | dnl Library versioning |
| 31 | dnl These numbers should be tweaked on every release. Read carefully: |
| 32 | dnl http://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html |
| 33 | dnl http://sourceware.org/autobook/autobook/autobook_91.html |
Chris Dickens | c6a35c5 | 2020-12-10 10:53:59 -0800 | [diff] [blame] | 34 | lt_current=3 |
Chris Dickens | cb77a25 | 2017-02-20 00:18:33 -0800 | [diff] [blame] | 35 | lt_revision=0 |
Chris Dickens | c6a35c5 | 2020-12-10 10:53:59 -0800 | [diff] [blame] | 36 | lt_age=3 |
Chris Dickens | 9a1bc8c | 2020-03-30 12:28:11 -0700 | [diff] [blame] | 37 | LT_LDFLAGS="-version-info ${lt_current}:${lt_revision}:${lt_age} -no-undefined" |
Pete Batard | 9a4249f | 2010-07-10 17:51:13 -0600 | [diff] [blame] | 38 | |
Daniel Drake | 9b120c2 | 2009-11-07 10:03:07 +0000 | [diff] [blame] | 39 | m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])]) |
Daniel Drake | 852bba4 | 2007-11-28 13:48:45 +0000 | [diff] [blame] | 40 | |
Chris Dickens | 6f0330c | 2020-04-09 11:46:03 -0700 | [diff] [blame] | 41 | EXTRA_CPPFLAGS= |
Chris Dickens | 7c0cea7 | 2020-04-09 11:30:19 -0700 | [diff] [blame] | 42 | EXTRA_CFLAGS= |
| 43 | |
Chris Dickens | 9a1bc8c | 2020-03-30 12:28:11 -0700 | [diff] [blame] | 44 | dnl check for -std=gnu11 compiler support (optional) |
Chris Dickens | 7c0cea7 | 2020-04-09 11:30:19 -0700 | [diff] [blame] | 45 | dnl note that we don't just check if the compiler accepts '-std=x11' |
Chris Dickens | 9a1bc8c | 2020-03-30 12:28:11 -0700 | [diff] [blame] | 46 | dnl but also that it supports the _Thread_local keyword because some compilers |
| 47 | dnl (e.g. gcc 4.8) accept the command line option but do not implement TLS |
| 48 | saved_CFLAGS="${CFLAGS}" |
| 49 | CFLAGS="-std=gnu11" |
Chris Dickens | 7c0cea7 | 2020-04-09 11:30:19 -0700 | [diff] [blame] | 50 | AC_MSG_CHECKING([if $CC supports -std=gnu11]) |
Chris Dickens | 9a1bc8c | 2020-03-30 12:28:11 -0700 | [diff] [blame] | 51 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM([_Thread_local int x;], [x = 42;])], |
| 52 | [AC_MSG_RESULT([yes]) |
Chris Dickens | 7c0cea7 | 2020-04-09 11:30:19 -0700 | [diff] [blame] | 53 | c_dialect=gnu], |
Chris Dickens | 9a1bc8c | 2020-03-30 12:28:11 -0700 | [diff] [blame] | 54 | [AC_MSG_RESULT([no]) |
Chris Dickens | 7c0cea7 | 2020-04-09 11:30:19 -0700 | [diff] [blame] | 55 | c_dialect=]) |
| 56 | if test "x$c_dialect" != xgnu; then |
Chris Dickens | 9a1bc8c | 2020-03-30 12:28:11 -0700 | [diff] [blame] | 57 | dnl fallback check for -std=c11 compiler support (required) |
Chris Dickens | 9a1bc8c | 2020-03-30 12:28:11 -0700 | [diff] [blame] | 58 | CFLAGS="-std=c11" |
Chris Dickens | 7c0cea7 | 2020-04-09 11:30:19 -0700 | [diff] [blame] | 59 | AC_MSG_CHECKING([if $CC supports -std=c11]) |
Chris Dickens | 9a1bc8c | 2020-03-30 12:28:11 -0700 | [diff] [blame] | 60 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM([_Thread_local int x;], [x = 42;])], |
| 61 | [AC_MSG_RESULT([yes])], |
| 62 | [AC_MSG_RESULT([no]) |
| 63 | AC_MSG_ERROR([compiler with C11 support is required to build libusb])]) |
Chris Dickens | 7c0cea7 | 2020-04-09 11:30:19 -0700 | [diff] [blame] | 64 | c_dialect=c |
Chris Dickens | 9a1bc8c | 2020-03-30 12:28:11 -0700 | [diff] [blame] | 65 | fi |
Chris Dickens | 7c0cea7 | 2020-04-09 11:30:19 -0700 | [diff] [blame] | 66 | CFLAGS="${saved_CFLAGS}" |
Peter Stuge | 717f476 | 2010-11-15 19:58:51 +0100 | [diff] [blame] | 67 | |
Chris Dickens | 9a1bc8c | 2020-03-30 12:28:11 -0700 | [diff] [blame] | 68 | AC_DEFINE([_GNU_SOURCE], [1], [Enable GNU extensions.]) |
| 69 | AC_DEFINE([DEFAULT_VISIBILITY], [__attribute__ ((visibility ("default")))], [Define to the attribute for default visibility.]) |
Chris Dickens | f2e551a | 2020-11-27 15:22:29 -0800 | [diff] [blame] | 70 | AC_DEFINE([PRINTF_FORMAT(a, b)], [__attribute__ ((__format__ (__printf__, a, b)))], [Define to the attribute for enabling parameter checks on printf-like functions.]) |
Chris Dickens | 9a1bc8c | 2020-03-30 12:28:11 -0700 | [diff] [blame] | 71 | |
| 72 | create_import_lib= |
| 73 | is_android_linux= |
Daniel Drake | c0c9432 | 2008-03-13 12:36:56 +0000 | [diff] [blame] | 74 | AC_MSG_CHECKING([operating system]) |
Kuangye Guo | 7e3de5d | 2013-10-21 18:36:15 -0700 | [diff] [blame] | 75 | case $host in |
Nathan Hjelm | b49f6bf | 2009-02-16 21:39:29 -0300 | [diff] [blame] | 76 | *-darwin*) |
Peter Stuge | 0bd4a4d | 2011-02-26 04:08:38 +0100 | [diff] [blame] | 77 | AC_MSG_RESULT([Darwin/Mac OS X]) |
Chris Dickens | cb77a25 | 2017-02-20 00:18:33 -0800 | [diff] [blame] | 78 | backend=darwin |
Chris Dickens | da5df37 | 2020-08-26 15:42:39 -0700 | [diff] [blame] | 79 | platform=posix |
Pete Batard | 9a4249f | 2010-07-10 17:51:13 -0600 | [diff] [blame] | 80 | ;; |
Akshay Jaggi | dc97425 | 2014-09-24 22:46:17 +0100 | [diff] [blame] | 81 | *-haiku*) |
| 82 | AC_MSG_RESULT([Haiku]) |
Chris Dickens | cb77a25 | 2017-02-20 00:18:33 -0800 | [diff] [blame] | 83 | backend=haiku |
Chris Dickens | da5df37 | 2020-08-26 15:42:39 -0700 | [diff] [blame] | 84 | platform=posix |
Chris Dickens | d5bb64b | 2020-01-22 17:39:14 -0800 | [diff] [blame] | 85 | ;; |
| 86 | *-linux* | *-uclinux*) |
Chris Dickens | 9a1bc8c | 2020-03-30 12:28:11 -0700 | [diff] [blame] | 87 | dnl on Android Linux, some functions are in different places |
Chris Dickens | d5bb64b | 2020-01-22 17:39:14 -0800 | [diff] [blame] | 88 | case $host in |
| 89 | *-linux-android*) |
Chris Dickens | 9a1bc8c | 2020-03-30 12:28:11 -0700 | [diff] [blame] | 90 | AC_MSG_RESULT([Android Linux]) |
| 91 | is_android_linux=yes |
Chris Dickens | d5bb64b | 2020-01-22 17:39:14 -0800 | [diff] [blame] | 92 | ;; |
| 93 | *) |
| 94 | AC_MSG_RESULT([Linux]) |
Chris Dickens | d5bb64b | 2020-01-22 17:39:14 -0800 | [diff] [blame] | 95 | ;; |
| 96 | esac |
| 97 | backend=linux |
Chris Dickens | da5df37 | 2020-08-26 15:42:39 -0700 | [diff] [blame] | 98 | platform=posix |
Chris Dickens | d5bb64b | 2020-01-22 17:39:14 -0800 | [diff] [blame] | 99 | ;; |
| 100 | *-netbsd*) |
| 101 | AC_MSG_RESULT([NetBSD]) |
| 102 | backend=netbsd |
Chris Dickens | da5df37 | 2020-08-26 15:42:39 -0700 | [diff] [blame] | 103 | platform=posix |
Chris Dickens | d5bb64b | 2020-01-22 17:39:14 -0800 | [diff] [blame] | 104 | ;; |
| 105 | *-openbsd*) |
| 106 | AC_MSG_RESULT([OpenBSD]) |
| 107 | backend=openbsd |
Chris Dickens | da5df37 | 2020-08-26 15:42:39 -0700 | [diff] [blame] | 108 | platform=posix |
Akshay Jaggi | dc97425 | 2014-09-24 22:46:17 +0100 | [diff] [blame] | 109 | ;; |
Lei Chen | eefd322 | 2016-02-19 11:58:39 +0800 | [diff] [blame] | 110 | *-solaris*) |
| 111 | AC_MSG_RESULT([SunOS]) |
Chris Dickens | cb77a25 | 2017-02-20 00:18:33 -0800 | [diff] [blame] | 112 | backend=sunos |
Chris Dickens | da5df37 | 2020-08-26 15:42:39 -0700 | [diff] [blame] | 113 | platform=posix |
Lei Chen | eefd322 | 2016-02-19 11:58:39 +0800 | [diff] [blame] | 114 | ;; |
Chris Dickens | d5bb64b | 2020-01-22 17:39:14 -0800 | [diff] [blame] | 115 | *-cygwin*) |
| 116 | AC_MSG_RESULT([Windows (using Cygwin)]) |
| 117 | backend=windows |
Chris Dickens | da5df37 | 2020-08-26 15:42:39 -0700 | [diff] [blame] | 118 | platform=windows |
| 119 | EXTRA_CFLAGS="-mwin32" |
Chris Dickens | d5bb64b | 2020-01-22 17:39:14 -0800 | [diff] [blame] | 120 | ;; |
| 121 | *-mingw* | *msys*) |
| 122 | AC_MSG_RESULT([Windows]) |
| 123 | backend=windows |
Chris Dickens | da5df37 | 2020-08-26 15:42:39 -0700 | [diff] [blame] | 124 | platform=windows |
Chris Dickens | 4a5540a | 2020-03-25 00:09:26 -0700 | [diff] [blame] | 125 | test "x$enable_shared" = xyes && create_import_lib=yes |
Chris Dickens | da5df37 | 2020-08-26 15:42:39 -0700 | [diff] [blame] | 126 | EXTRA_CFLAGS="-mwin32 -fno-omit-frame-pointer" |
Chris Dickens | d5bb64b | 2020-01-22 17:39:14 -0800 | [diff] [blame] | 127 | ;; |
Daniel Drake | c0c9432 | 2008-03-13 12:36:56 +0000 | [diff] [blame] | 128 | *) |
Pino Toscano | 53572d7 | 2019-12-27 18:41:28 +0100 | [diff] [blame] | 129 | AC_MSG_RESULT([Null]) |
Chris Dickens | 9a1bc8c | 2020-03-30 12:28:11 -0700 | [diff] [blame] | 130 | AC_MSG_WARN([The host being compiled for is not supported.]) |
| 131 | AC_MSG_WARN([The library may compile but will not function in any useful manner.]) |
Chris Dickens | da5df37 | 2020-08-26 15:42:39 -0700 | [diff] [blame] | 132 | backend=null |
| 133 | platform=posix |
Chris Dickens | d5bb64b | 2020-01-22 17:39:14 -0800 | [diff] [blame] | 134 | ;; |
Daniel Drake | c0c9432 | 2008-03-13 12:36:56 +0000 | [diff] [blame] | 135 | esac |
Pete Batard | 968df12 | 2012-04-19 18:01:04 +0100 | [diff] [blame] | 136 | |
Chris Dickens | da5df37 | 2020-08-26 15:42:39 -0700 | [diff] [blame] | 137 | if test "x$platform" = xposix; then |
| 138 | AC_DEFINE([PLATFORM_POSIX], [1], [Define to 1 if compiling for a POSIX platform.]) |
Chris Dickens | 9a1bc8c | 2020-03-30 12:28:11 -0700 | [diff] [blame] | 139 | AC_CHECK_TYPES([nfds_t], [], [], [[#include <poll.h>]]) |
| 140 | AC_CHECK_FUNCS([pipe2]) |
Chris Dickens | 33b3ba3 | 2020-04-09 12:05:16 -0700 | [diff] [blame] | 141 | dnl Some compilers do not support the '-pthread' option so check for it here |
| 142 | saved_CFLAGS="${CFLAGS}" |
| 143 | CFLAGS="-Wall -Werror -pthread" |
| 144 | AC_MSG_CHECKING([if $CC recognizes -pthread]) |
| 145 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])], |
| 146 | [AC_MSG_RESULT([yes]) |
| 147 | AC_SUBST(THREAD_CFLAGS, [-pthread])], |
| 148 | [AC_MSG_RESULT([no])]) |
| 149 | CFLAGS="${saved_CFLAGS}" |
Chris Dickens | 9a1bc8c | 2020-03-30 12:28:11 -0700 | [diff] [blame] | 150 | dnl Android Linux and Darwin provide pthread functions directly in libc |
| 151 | dnl glibc also provides some pthread functions directly, so search for a thread-specific function |
Chris Dickens | 33b3ba3 | 2020-04-09 12:05:16 -0700 | [diff] [blame] | 152 | AC_SEARCH_LIBS([pthread_create], [pthread], |
| 153 | [test "x$ac_cv_search_pthread_create" != "xnone required" && AC_SUBST(THREAD_LIBS, [-lpthread])], |
| 154 | [], []) |
Chris Dickens | da5df37 | 2020-08-26 15:42:39 -0700 | [diff] [blame] | 155 | elif test "x$platform" = xwindows; then |
| 156 | AC_DEFINE([PLATFORM_WINDOWS], [1], [Define to 1 if compiling for a Windows platform.]) |
Chris Dickens | 9a1bc8c | 2020-03-30 12:28:11 -0700 | [diff] [blame] | 157 | else |
Chris Dickens | da5df37 | 2020-08-26 15:42:39 -0700 | [diff] [blame] | 158 | AC_MSG_ERROR([Unknown platform]) |
Chris Dickens | 9a1bc8c | 2020-03-30 12:28:11 -0700 | [diff] [blame] | 159 | fi |
| 160 | |
Pete Batard | 968df12 | 2012-04-19 18:01:04 +0100 | [diff] [blame] | 161 | case $backend in |
Chris Dickens | d5bb64b | 2020-01-22 17:39:14 -0800 | [diff] [blame] | 162 | darwin) |
Chris Dickens | 30b56ba | 2020-03-27 00:03:41 -0700 | [diff] [blame] | 163 | AC_CHECK_FUNCS([pthread_threadid_np]) |
Chris Dickens | 9a1bc8c | 2020-03-30 12:28:11 -0700 | [diff] [blame] | 164 | LIBS="${LIBS} -lobjc -Wl,-framework,IOKit -Wl,-framework,CoreFoundation" |
Chris Dickens | d5bb64b | 2020-01-22 17:39:14 -0800 | [diff] [blame] | 165 | ;; |
| 166 | haiku) |
Chris Dickens | 9a1bc8c | 2020-03-30 12:28:11 -0700 | [diff] [blame] | 167 | LIBS="${LIBS} -lbe" |
Chris Dickens | d5bb64b | 2020-01-22 17:39:14 -0800 | [diff] [blame] | 168 | ;; |
Pete Batard | 968df12 | 2012-04-19 18:01:04 +0100 | [diff] [blame] | 169 | linux) |
Chris Dickens | 9a1bc8c | 2020-03-30 12:28:11 -0700 | [diff] [blame] | 170 | AC_SEARCH_LIBS([clock_gettime], [rt], [], [], []) |
| 171 | AC_CHECK_FUNCS([pthread_setname_np]) |
Nathan Hjelm | 6853291 | 2012-11-29 16:14:03 -0700 | [diff] [blame] | 172 | AC_ARG_ENABLE([udev], |
Toby Gray | 9222a54 | 2013-07-09 16:05:39 +0100 | [diff] [blame] | 173 | [AC_HELP_STRING([--enable-udev], [use udev for device enumeration and hotplug support (recommended) [default=yes]])], |
Chris Dickens | 9a1bc8c | 2020-03-30 12:28:11 -0700 | [diff] [blame] | 174 | [use_udev=$enableval], [use_udev=yes]) |
| 175 | if test "x$use_udev" = xyes; then |
Chris Dickens | d5bb64b | 2020-01-22 17:39:14 -0800 | [diff] [blame] | 176 | dnl system has udev. use it or fail! |
| 177 | AC_CHECK_HEADER([libudev.h], [], [AC_MSG_ERROR([udev support requested but libudev header not installed])]) |
| 178 | AC_CHECK_LIB([udev], [udev_new], [], [AC_MSG_ERROR([udev support requested but libudev not installed])]) |
| 179 | else |
| 180 | AC_CHECK_HEADERS([asm/types.h]) |
| 181 | AC_CHECK_HEADER([linux/netlink.h], [], [AC_MSG_ERROR([Linux netlink header not found])]) |
| 182 | AC_CHECK_HEADER([sys/socket.h], [], [AC_MSG_ERROR([Linux socket header not found])]) |
| 183 | fi |
Chris Dickens | d5bb64b | 2020-01-22 17:39:14 -0800 | [diff] [blame] | 184 | ;; |
| 185 | sunos) |
Chris Dickens | 9a1bc8c | 2020-03-30 12:28:11 -0700 | [diff] [blame] | 186 | LIBS="${LIBS} -ldevinfo" |
Chris Dickens | d5bb64b | 2020-01-22 17:39:14 -0800 | [diff] [blame] | 187 | ;; |
| 188 | windows) |
Chris Dickens | d5bb64b | 2020-01-22 17:39:14 -0800 | [diff] [blame] | 189 | AC_CHECK_TYPES([struct timespec], [], [], [[#include <time.h>]]) |
Chris Dickens | 9a1bc8c | 2020-03-30 12:28:11 -0700 | [diff] [blame] | 190 | AC_DEFINE([_WIN32_WINNT], [_WIN32_WINNT_VISTA], [Define to the oldest supported Windows version.]) |
| 191 | LT_LDFLAGS="${LT_LDFLAGS} -avoid-version -Wl,--add-stdcall-alias" |
Chris Dickens | d5bb64b | 2020-01-22 17:39:14 -0800 | [diff] [blame] | 192 | ;; |
| 193 | *) |
Chris Dickens | 9a1bc8c | 2020-03-30 12:28:11 -0700 | [diff] [blame] | 194 | dnl no special handling required |
Pino Toscano | 53572d7 | 2019-12-27 18:41:28 +0100 | [diff] [blame] | 195 | ;; |
Pete Batard | 968df12 | 2012-04-19 18:01:04 +0100 | [diff] [blame] | 196 | esac |
| 197 | |
Chris Dickens | d5bb64b | 2020-01-22 17:39:14 -0800 | [diff] [blame] | 198 | dnl headers not available on all platforms but required on others |
| 199 | AC_CHECK_HEADERS([sys/time.h]) |
| 200 | |
Chris Dickens | c3e292c | 2020-08-27 13:46:32 -0700 | [diff] [blame] | 201 | if test "x$platform" = xposix; then |
Chris Dickens | 08e0029 | 2021-01-15 12:42:35 -0800 | [diff] [blame] | 202 | dnl check availability of clock_gettime() |
| 203 | if test "x$backend" = xdarwin; then |
| 204 | dnl need to verify that OS X target is 10.12 or later for clock_gettime() |
| 205 | AC_MSG_CHECKING([whether OS X target version is 10.12 or later]) |
| 206 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM([ |
| 207 | #include <AvailabilityMacros.h> |
| 208 | #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_12 |
| 209 | # error "Target OS X version is too old" |
| 210 | #endif |
| 211 | ], [])], |
| 212 | [AC_MSG_RESULT([yes]) |
| 213 | osx_10_12_or_later=yes], |
| 214 | [AC_MSG_RESULT([no]) |
| 215 | osx_10_12_or_later=]) |
| 216 | if test "x$osx_10_12_or_later" = xyes; then |
| 217 | AC_CHECK_FUNCS([clock_gettime], [have_clock_gettime=yes], [have_clock_gettime=]) |
| 218 | else |
| 219 | AC_MSG_NOTICE([clock_gettime() is not available on target OS X version]) |
| 220 | fi |
| 221 | else |
| 222 | AC_CHECK_FUNCS([clock_gettime], [have_clock_gettime=yes], [AC_MSG_ERROR([clock_gettime() is required on this platform])]) |
| 223 | fi |
| 224 | |
Chris Dickens | c3e292c | 2020-08-27 13:46:32 -0700 | [diff] [blame] | 225 | if test "x$have_clock_gettime" = xyes; then |
Chris Dickens | 08e0029 | 2021-01-15 12:42:35 -0800 | [diff] [blame] | 226 | dnl the clock_gettime() function needs certain clock IDs defined |
Chris Dickens | c3e292c | 2020-08-27 13:46:32 -0700 | [diff] [blame] | 227 | AC_CHECK_DECL([CLOCK_MONOTONIC], [], [AC_MSG_ERROR([C library headers missing definition for CLOCK_MONOTONIC])], [[#include <time.h>]]) |
Chris Dickens | ccba488 | 2020-08-27 13:54:21 -0700 | [diff] [blame] | 228 | dnl use the monotonic clock for condition variable timed waits if possible |
| 229 | AC_CHECK_FUNCS([pthread_condattr_setclock], [need_clock_realtime=], [need_clock_realtime=yes]) |
| 230 | if test "x$need_clock_realtime" = xyes; then |
| 231 | AC_CHECK_DECL([CLOCK_REALTIME], [], [AC_MSG_ERROR([C library headers missing definition for CLOCK_REALTIME])], [[#include <time.h>]]) |
| 232 | fi |
Chris Dickens | c3e292c | 2020-08-27 13:46:32 -0700 | [diff] [blame] | 233 | fi |
Chris Dickens | 26b16eb | 2020-01-26 22:43:28 -0800 | [diff] [blame] | 234 | fi |
| 235 | |
Chris Dickens | b40a26f | 2020-08-12 18:44:31 -0700 | [diff] [blame] | 236 | dnl eventfd support |
| 237 | if test "x$backend" = xlinux || test "x$backend" = xsunos; then |
| 238 | AC_ARG_ENABLE([eventfd], |
| 239 | [AS_HELP_STRING([--enable-eventfd], [use eventfd for signalling [default=auto]])], |
| 240 | [use_eventfd=$enableval], |
| 241 | [use_eventfd=auto]) |
| 242 | if test "x$use_eventfd" != xno; then |
| 243 | AC_CHECK_HEADER([sys/eventfd.h], [eventfd_h=yes], [eventfd_h=]) |
| 244 | if test "x$eventfd_h" = xyes; then |
| 245 | AC_CHECK_DECLS([EFD_NONBLOCK, EFD_CLOEXEC], [eventfd_h_ok=yes], [eventfd_h_ok=], [[#include <sys/eventfd.h>]]) |
| 246 | if test "x$eventfd_h_ok" = xyes; then |
| 247 | AC_CHECK_FUNC([eventfd], [eventfd_ok=yes], [eventfd_ok=]) |
| 248 | if test "x$eventfd_ok" = xyes; then |
| 249 | AC_DEFINE([HAVE_EVENTFD], [1], [Define to 1 if the system has eventfd functionality.]) |
| 250 | elif test "x$use_eventfd" = xyes; then |
| 251 | AC_MSG_ERROR([eventfd() function not found; glibc 2.9+ required]) |
| 252 | fi |
| 253 | elif test "x$use_eventfd" = xyes; then |
| 254 | AC_MSG_ERROR([eventfd header not usable; glibc 2.9+ required]) |
| 255 | fi |
| 256 | elif test "x$use_eventfd" = xyes; then |
| 257 | AC_MSG_ERROR([eventfd header not available; glibc 2.9+ required]) |
| 258 | fi |
| 259 | fi |
| 260 | AC_MSG_CHECKING([whether to use eventfd for signalling]) |
| 261 | if test "x$use_eventfd" = xno; then |
| 262 | AC_MSG_RESULT([no (disabled by user)]) |
| 263 | elif test "x$eventfd_h" != xyes; then |
| 264 | AC_MSG_RESULT([no (header not available)]) |
| 265 | elif test "x$eventfd_h_ok" != xyes; then |
| 266 | AC_MSG_RESULT([no (header not usable)]) |
| 267 | elif test "x$eventfd_ok" != xyes; then |
| 268 | AC_MSG_RESULT([no (functions not available)]) |
| 269 | else |
| 270 | AC_MSG_RESULT([yes]) |
| 271 | fi |
| 272 | fi |
| 273 | |
Chris Dickens | d5bb64b | 2020-01-22 17:39:14 -0800 | [diff] [blame] | 274 | dnl timerfd support |
| 275 | if test "x$backend" = xlinux || test "x$backend" = xsunos; then |
| 276 | AC_ARG_ENABLE([timerfd], |
| 277 | [AS_HELP_STRING([--enable-timerfd], [use timerfd for timing [default=auto]])], |
| 278 | [use_timerfd=$enableval], |
| 279 | [use_timerfd=auto]) |
| 280 | if test "x$use_timerfd" != xno; then |
Chris Dickens | 9a1bc8c | 2020-03-30 12:28:11 -0700 | [diff] [blame] | 281 | AC_CHECK_HEADER([sys/timerfd.h], [timerfd_h=yes], [timerfd_h=]) |
Chris Dickens | d5bb64b | 2020-01-22 17:39:14 -0800 | [diff] [blame] | 282 | if test "x$timerfd_h" = xyes; then |
Chris Dickens | 9a1bc8c | 2020-03-30 12:28:11 -0700 | [diff] [blame] | 283 | AC_CHECK_DECLS([TFD_NONBLOCK, TFD_CLOEXEC], [timerfd_h_ok=yes], [timerfd_h_ok=], [[#include <sys/timerfd.h>]]) |
Chris Dickens | d5bb64b | 2020-01-22 17:39:14 -0800 | [diff] [blame] | 284 | if test "x$timerfd_h_ok" = xyes; then |
Chris Dickens | 9a1bc8c | 2020-03-30 12:28:11 -0700 | [diff] [blame] | 285 | AC_CHECK_FUNC([timerfd_create], [timerfd_ok=yes], [timerfd_ok=]) |
Chris Dickens | d5bb64b | 2020-01-22 17:39:14 -0800 | [diff] [blame] | 286 | if test "x$timerfd_ok" = xyes; then |
Chris Dickens | 9a1bc8c | 2020-03-30 12:28:11 -0700 | [diff] [blame] | 287 | AC_DEFINE([HAVE_TIMERFD], [1], [Define to 1 if the system has timerfd functionality.]) |
Chris Dickens | d5bb64b | 2020-01-22 17:39:14 -0800 | [diff] [blame] | 288 | elif test "x$use_timerfd" = xyes; then |
| 289 | AC_MSG_ERROR([timerfd_create() function not found; glibc 2.9+ required]) |
| 290 | fi |
| 291 | elif test "x$use_timerfd" = xyes; then |
| 292 | AC_MSG_ERROR([timerfd header not usable; glibc 2.9+ required]) |
| 293 | fi |
| 294 | elif test "x$use_timerfd" = xyes; then |
| 295 | AC_MSG_ERROR([timerfd header not available; glibc 2.9+ required]) |
| 296 | fi |
| 297 | fi |
| 298 | AC_MSG_CHECKING([whether to use timerfd for timing]) |
| 299 | if test "x$use_timerfd" = xno; then |
| 300 | AC_MSG_RESULT([no (disabled by user)]) |
Chris Dickens | 9a1bc8c | 2020-03-30 12:28:11 -0700 | [diff] [blame] | 301 | elif test "x$timerfd_h" != xyes; then |
Daniel Drake | 4783008 | 2009-10-28 20:33:49 +0545 | [diff] [blame] | 302 | AC_MSG_RESULT([no (header not available)]) |
Chris Dickens | 9a1bc8c | 2020-03-30 12:28:11 -0700 | [diff] [blame] | 303 | elif test "x$timerfd_h_ok" != xyes; then |
| 304 | AC_MSG_RESULT([no (header not usable)]) |
| 305 | elif test "x$timerfd_ok" != xyes; then |
Chris Dickens | d5bb64b | 2020-01-22 17:39:14 -0800 | [diff] [blame] | 306 | AC_MSG_RESULT([no (functions not available)]) |
| 307 | else |
| 308 | AC_MSG_RESULT([yes]) |
Daniel Drake | 4783008 | 2009-10-28 20:33:49 +0545 | [diff] [blame] | 309 | fi |
| 310 | fi |
| 311 | |
Chris Dickens | d5bb64b | 2020-01-22 17:39:14 -0800 | [diff] [blame] | 312 | dnl Message logging |
| 313 | AC_ARG_ENABLE([log], |
| 314 | [AS_HELP_STRING([--disable-log], [disable all logging])], |
Daniel Drake | 852bba4 | 2007-11-28 13:48:45 +0000 | [diff] [blame] | 315 | [log_enabled=$enableval], |
Chris Dickens | cb77a25 | 2017-02-20 00:18:33 -0800 | [diff] [blame] | 316 | [log_enabled=yes]) |
Chris Dickens | 9417868 | 2017-01-12 13:50:35 -0800 | [diff] [blame] | 317 | if test "x$log_enabled" != xno; then |
Chris Dickens | 9a1bc8c | 2020-03-30 12:28:11 -0700 | [diff] [blame] | 318 | AC_DEFINE([ENABLE_LOGGING], [1], [Define to 1 to enable message logging.]) |
Daniel Drake | 852bba4 | 2007-11-28 13:48:45 +0000 | [diff] [blame] | 319 | fi |
| 320 | |
Chris Dickens | d5bb64b | 2020-01-22 17:39:14 -0800 | [diff] [blame] | 321 | AC_ARG_ENABLE([debug-log], |
| 322 | [AS_HELP_STRING([--enable-debug-log], [start with debug message logging enabled [default=no]])], |
Daniel Drake | 852bba4 | 2007-11-28 13:48:45 +0000 | [diff] [blame] | 323 | [debug_log_enabled=$enableval], |
Chris Dickens | cb77a25 | 2017-02-20 00:18:33 -0800 | [diff] [blame] | 324 | [debug_log_enabled=no]) |
Chris Dickens | 9417868 | 2017-01-12 13:50:35 -0800 | [diff] [blame] | 325 | if test "x$debug_log_enabled" != xno; then |
Chris Dickens | 9a1bc8c | 2020-03-30 12:28:11 -0700 | [diff] [blame] | 326 | AC_DEFINE([ENABLE_DEBUG_LOGGING], [1], [Define to 1 to start with debug message logging enabled.]) |
Daniel Drake | 852bba4 | 2007-11-28 13:48:45 +0000 | [diff] [blame] | 327 | fi |
| 328 | |
Chris Dickens | d5bb64b | 2020-01-22 17:39:14 -0800 | [diff] [blame] | 329 | AC_ARG_ENABLE([system-log], |
Chris Dickens | 9a1bc8c | 2020-03-30 12:28:11 -0700 | [diff] [blame] | 330 | [AS_HELP_STRING([--enable-system-log], [output logging messages to the systemwide log, if supported by the OS [default=no]])], |
Toby Gray | 9222a54 | 2013-07-09 16:05:39 +0100 | [diff] [blame] | 331 | [system_log_enabled=$enableval], |
Chris Dickens | cb77a25 | 2017-02-20 00:18:33 -0800 | [diff] [blame] | 332 | [system_log_enabled=no]) |
Chris Dickens | 9417868 | 2017-01-12 13:50:35 -0800 | [diff] [blame] | 333 | if test "x$system_log_enabled" != xno; then |
Chris Dickens | 9a1bc8c | 2020-03-30 12:28:11 -0700 | [diff] [blame] | 334 | AC_DEFINE([USE_SYSTEM_LOGGING_FACILITY], [1], [Define to 1 to output logging messages to the systemwide log.]) |
| 335 | if test "x$backend" != xwindows && test "x$is_android_linux" != xyes; then |
Chris Dickens | d5bb64b | 2020-01-22 17:39:14 -0800 | [diff] [blame] | 336 | dnl Check if syslog is available in standard C library |
Chris Dickens | 9a1bc8c | 2020-03-30 12:28:11 -0700 | [diff] [blame] | 337 | AC_CHECK_HEADER([syslog.h], [syslog_h=yes], [syslog_h=]) |
Chris Dickens | d5bb64b | 2020-01-22 17:39:14 -0800 | [diff] [blame] | 338 | if test "x$syslog_h" = xyes; then |
| 339 | AC_CHECK_FUNCS([syslog]) |
| 340 | fi |
Chris Dickens | 9417868 | 2017-01-12 13:50:35 -0800 | [diff] [blame] | 341 | fi |
Toby Gray | 9222a54 | 2013-07-09 16:05:39 +0100 | [diff] [blame] | 342 | fi |
| 343 | |
Chris Dickens | d5bb64b | 2020-01-22 17:39:14 -0800 | [diff] [blame] | 344 | dnl Examples build |
| 345 | AC_ARG_ENABLE([examples-build], |
| 346 | [AS_HELP_STRING([--enable-examples-build], [build example applications [default=no]])], |
Daniel Drake | 852bba4 | 2007-11-28 13:48:45 +0000 | [diff] [blame] | 347 | [build_examples=$enableval], |
Chris Dickens | cb77a25 | 2017-02-20 00:18:33 -0800 | [diff] [blame] | 348 | [build_examples=no]) |
Daniel Drake | 852bba4 | 2007-11-28 13:48:45 +0000 | [diff] [blame] | 349 | |
Chris Dickens | d5bb64b | 2020-01-22 17:39:14 -0800 | [diff] [blame] | 350 | dnl Tests build |
| 351 | AC_ARG_ENABLE([tests-build], |
| 352 | [AS_HELP_STRING([--enable-tests-build], [build test applications [default=no]])], |
Toby Gray | 21cf6e4 | 2012-11-21 14:00:31 +0000 | [diff] [blame] | 353 | [build_tests=$enableval], |
Chris Dickens | cb77a25 | 2017-02-20 00:18:33 -0800 | [diff] [blame] | 354 | [build_tests=no]) |
Chris Dickens | 9a1bc8c | 2020-03-30 12:28:11 -0700 | [diff] [blame] | 355 | |
| 356 | AM_CONDITIONAL([BUILD_EXAMPLES], [test "x$build_examples" != xno]) |
Chris Dickens | d5bb64b | 2020-01-22 17:39:14 -0800 | [diff] [blame] | 357 | AM_CONDITIONAL([BUILD_TESTS], [test "x$build_tests" != xno]) |
Chris Dickens | 9a1bc8c | 2020-03-30 12:28:11 -0700 | [diff] [blame] | 358 | AM_CONDITIONAL([CREATE_IMPORT_LIB], [test "x$create_import_lib" = xyes]) |
Chris Dickens | 9a1bc8c | 2020-03-30 12:28:11 -0700 | [diff] [blame] | 359 | AM_CONDITIONAL([OS_DARWIN], [test "x$backend" = xdarwin]) |
| 360 | AM_CONDITIONAL([OS_HAIKU], [test "x$backend" = xhaiku]) |
| 361 | AM_CONDITIONAL([OS_LINUX], [test "x$backend" = xlinux]) |
| 362 | AM_CONDITIONAL([OS_NETBSD], [test "x$backend" = xnetbsd]) |
| 363 | AM_CONDITIONAL([OS_NULL], [test "x$backend" = xnull]) |
| 364 | AM_CONDITIONAL([OS_OPENBSD], [test "x$backend" = xopenbsd]) |
| 365 | AM_CONDITIONAL([OS_SUNOS], [test "x$backend" = xsunos]) |
| 366 | AM_CONDITIONAL([OS_WINDOWS], [test "x$backend" = xwindows]) |
Chris Dickens | da5df37 | 2020-08-26 15:42:39 -0700 | [diff] [blame] | 367 | AM_CONDITIONAL([PLATFORM_POSIX], [test "x$platform" = xposix]) |
| 368 | AM_CONDITIONAL([PLATFORM_WINDOWS], [test "x$platform" = xwindows]) |
Chris Dickens | 9a1bc8c | 2020-03-30 12:28:11 -0700 | [diff] [blame] | 369 | AM_CONDITIONAL([USE_UDEV], [test "x$use_udev" = xyes]) |
Chris Dickens | 9417868 | 2017-01-12 13:50:35 -0800 | [diff] [blame] | 370 | |
Chris Dickens | 95bbfb6 | 2020-03-30 12:38:47 -0700 | [diff] [blame] | 371 | dnl The -Wcast-function-type warning causes a flurry of warnings when compiling |
| 372 | dnl Windows with GCC 8 or later because of dynamically loaded functions |
| 373 | if test "x$backend" = xwindows; then |
| 374 | saved_CFLAGS="${CFLAGS}" |
| 375 | CFLAGS="-Werror -Wcast-function-type" |
| 376 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])], |
Chris Dickens | 7c0cea7 | 2020-04-09 11:30:19 -0700 | [diff] [blame] | 377 | [EXTRA_CFLAGS="${EXTRA_CFLAGS} -Wno-cast-function-type"], |
Chris Dickens | 95bbfb6 | 2020-03-30 12:38:47 -0700 | [diff] [blame] | 378 | []) |
| 379 | CFLAGS="${saved_CFLAGS}" |
| 380 | fi |
| 381 | |
Chris Dickens | 7c0cea7 | 2020-04-09 11:30:19 -0700 | [diff] [blame] | 382 | 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" |
| 383 | |
Chris Dickens | 6f0330c | 2020-04-09 11:46:03 -0700 | [diff] [blame] | 384 | AM_CPPFLAGS="${EXTRA_CPPFLAGS}" |
| 385 | AC_SUBST(AM_CPPFLAGS) |
| 386 | |
Chris Dickens | 7c0cea7 | 2020-04-09 11:30:19 -0700 | [diff] [blame] | 387 | AM_CFLAGS="-std=${c_dialect}11 ${EXTRA_CFLAGS} ${SHARED_CFLAGS}" |
Daniel Drake | 852bba4 | 2007-11-28 13:48:45 +0000 | [diff] [blame] | 388 | AC_SUBST(AM_CFLAGS) |
Chris Dickens | 9a1bc8c | 2020-03-30 12:28:11 -0700 | [diff] [blame] | 389 | |
Chris Dickens | 7c0cea7 | 2020-04-09 11:30:19 -0700 | [diff] [blame] | 390 | AM_CXXFLAGS="-std=${c_dialect}++11 ${EXTRA_CFLAGS} ${SHARED_CFLAGS} -Wmissing-declarations" |
Chris Dickens | 9a1bc8c | 2020-03-30 12:28:11 -0700 | [diff] [blame] | 391 | AC_SUBST(AM_CXXFLAGS) |
| 392 | |
| 393 | AC_SUBST(LT_LDFLAGS) |
Daniel Drake | 852bba4 | 2007-11-28 13:48:45 +0000 | [diff] [blame] | 394 | |
Chris Dickens | 4a5540a | 2020-03-25 00:09:26 -0700 | [diff] [blame] | 395 | dnl set name of html output directory for doxygen |
| 396 | AC_SUBST(DOXYGEN_HTMLDIR, [api-1.0]) |
| 397 | |
Peter Stuge | ef39d15 | 2011-02-25 02:33:29 +0100 | [diff] [blame] | 398 | AC_CONFIG_FILES([libusb-1.0.pc]) |
| 399 | AC_CONFIG_FILES([Makefile]) |
| 400 | AC_CONFIG_FILES([libusb/Makefile]) |
Peter Stuge | ef39d15 | 2011-02-25 02:33:29 +0100 | [diff] [blame] | 401 | AC_CONFIG_FILES([examples/Makefile]) |
Toby Gray | 21cf6e4 | 2012-11-21 14:00:31 +0000 | [diff] [blame] | 402 | AC_CONFIG_FILES([tests/Makefile]) |
Peter Stuge | ef39d15 | 2011-02-25 02:33:29 +0100 | [diff] [blame] | 403 | AC_CONFIG_FILES([doc/Makefile]) |
| 404 | AC_CONFIG_FILES([doc/doxygen.cfg]) |
Daniel Drake | 852bba4 | 2007-11-28 13:48:45 +0000 | [diff] [blame] | 405 | AC_OUTPUT |