blob: 5b880f6e06e08cc771f3cdd81e1981f5627bd0b2 [file] [log] [blame]
Peter Stuge85a14f42011-05-09 08:12:24 +02001dnl These m4 macros are whitespace sensitive and break if moved around much.
2m4_define([LU_VERSION_H], m4_include([libusb/version.h]))
3m4_define([LU_DEFINE_VERSION_ATOM],
4 [m4_define([$1], m4_bregexp(LU_VERSION_H,
5 [^#define\s*$1\s*\([0-9]*\).*], [\1]))])
Peter Stugecbc2d7b2011-09-15 16:48:35 +02006m4_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 Stuge85a14f42011-05-09 08:12:24 +02009dnl The m4_bregexp() returns (only) the numbers following the #define named
10dnl in the first macro parameter. m4_define() then defines the name for use
Ludovic Rousseauc9d41fe2012-06-01 11:30:00 +020011dnl in AC_INIT.
Pete Batard9a4249f2010-07-10 17:51:13 -060012
Peter Stuge85a14f42011-05-09 08:12:24 +020013LU_DEFINE_VERSION_ATOM([LIBUSB_MAJOR])
14LU_DEFINE_VERSION_ATOM([LIBUSB_MINOR])
15LU_DEFINE_VERSION_ATOM([LIBUSB_MICRO])
Peter Stugecbc2d7b2011-09-15 16:48:35 +020016LU_DEFINE_VERSION_RC_ATOM([LIBUSB_RC])
Daniel Draked7c25452010-10-04 20:03:58 +010017
Chris Dickens9a1bc8c2020-03-30 12:28:11 -070018AC_PREREQ([2.69])
Chris Dickens4a5540a2020-03-25 00:09:26 -070019AC_INIT([libusb-1.0], [LIBUSB_MAJOR[.]LIBUSB_MINOR[.]LIBUSB_MICRO[]LIBUSB_RC], [libusb-devel@lists.sourceforge.net], [libusb-1.0], [http://libusb.info])
Chris Dickens9a1bc8c2020-03-30 12:28:11 -070020AC_CONFIG_HEADERS([config.h])
21AC_CONFIG_SRCDIR([libusb/core.c])
22AC_CONFIG_MACRO_DIR([m4])
23AC_PROG_CC
24AC_PROG_CXX
25AC_C_INLINE
26AM_INIT_AUTOMAKE
27LT_INIT
28LT_LANG([Windows Resource])
Daniel Draked7c25452010-10-04 20:03:58 +010029
Chris Dickensd5bb64b2020-01-22 17:39:14 -080030dnl Library versioning
31dnl These numbers should be tweaked on every release. Read carefully:
32dnl http://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html
33dnl http://sourceware.org/autobook/autobook/autobook_91.html
Chris Dickensc6a35c52020-12-10 10:53:59 -080034lt_current=3
Chris Dickenscb77a252017-02-20 00:18:33 -080035lt_revision=0
Chris Dickensc6a35c52020-12-10 10:53:59 -080036lt_age=3
Chris Dickens9a1bc8c2020-03-30 12:28:11 -070037LT_LDFLAGS="-version-info ${lt_current}:${lt_revision}:${lt_age} -no-undefined"
Pete Batard9a4249f2010-07-10 17:51:13 -060038
Daniel Drake9b120c22009-11-07 10:03:07 +000039m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])])
Daniel Drake852bba42007-11-28 13:48:45 +000040
Chris Dickens6f0330c2020-04-09 11:46:03 -070041EXTRA_CPPFLAGS=
Chris Dickens7c0cea72020-04-09 11:30:19 -070042EXTRA_CFLAGS=
43
Chris Dickens9a1bc8c2020-03-30 12:28:11 -070044dnl check for -std=gnu11 compiler support (optional)
Chris Dickens7c0cea72020-04-09 11:30:19 -070045dnl note that we don't just check if the compiler accepts '-std=x11'
Chris Dickens9a1bc8c2020-03-30 12:28:11 -070046dnl but also that it supports the _Thread_local keyword because some compilers
47dnl (e.g. gcc 4.8) accept the command line option but do not implement TLS
48saved_CFLAGS="${CFLAGS}"
49CFLAGS="-std=gnu11"
Chris Dickens7c0cea72020-04-09 11:30:19 -070050AC_MSG_CHECKING([if $CC supports -std=gnu11])
Chris Dickens9a1bc8c2020-03-30 12:28:11 -070051AC_COMPILE_IFELSE([AC_LANG_PROGRAM([_Thread_local int x;], [x = 42;])],
52 [AC_MSG_RESULT([yes])
Chris Dickens7c0cea72020-04-09 11:30:19 -070053 c_dialect=gnu],
Chris Dickens9a1bc8c2020-03-30 12:28:11 -070054 [AC_MSG_RESULT([no])
Chris Dickens7c0cea72020-04-09 11:30:19 -070055 c_dialect=])
56if test "x$c_dialect" != xgnu; then
Chris Dickens9a1bc8c2020-03-30 12:28:11 -070057 dnl fallback check for -std=c11 compiler support (required)
Chris Dickens9a1bc8c2020-03-30 12:28:11 -070058 CFLAGS="-std=c11"
Chris Dickens7c0cea72020-04-09 11:30:19 -070059 AC_MSG_CHECKING([if $CC supports -std=c11])
Chris Dickens9a1bc8c2020-03-30 12:28:11 -070060 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 Dickens7c0cea72020-04-09 11:30:19 -070064 c_dialect=c
Chris Dickens9a1bc8c2020-03-30 12:28:11 -070065fi
Chris Dickens7c0cea72020-04-09 11:30:19 -070066CFLAGS="${saved_CFLAGS}"
Peter Stuge717f4762010-11-15 19:58:51 +010067
Chris Dickens9a1bc8c2020-03-30 12:28:11 -070068AC_DEFINE([_GNU_SOURCE], [1], [Enable GNU extensions.])
69AC_DEFINE([DEFAULT_VISIBILITY], [__attribute__ ((visibility ("default")))], [Define to the attribute for default visibility.])
Chris Dickensf2e551a2020-11-27 15:22:29 -080070AC_DEFINE([PRINTF_FORMAT(a, b)], [__attribute__ ((__format__ (__printf__, a, b)))], [Define to the attribute for enabling parameter checks on printf-like functions.])
Chris Dickens9a1bc8c2020-03-30 12:28:11 -070071
72create_import_lib=
73is_android_linux=
Daniel Drakec0c94322008-03-13 12:36:56 +000074AC_MSG_CHECKING([operating system])
Kuangye Guo7e3de5d2013-10-21 18:36:15 -070075case $host in
Nathan Hjelmb49f6bf2009-02-16 21:39:29 -030076*-darwin*)
Peter Stuge0bd4a4d2011-02-26 04:08:38 +010077 AC_MSG_RESULT([Darwin/Mac OS X])
Chris Dickenscb77a252017-02-20 00:18:33 -080078 backend=darwin
Chris Dickensda5df372020-08-26 15:42:39 -070079 platform=posix
Pete Batard9a4249f2010-07-10 17:51:13 -060080 ;;
Akshay Jaggidc974252014-09-24 22:46:17 +010081*-haiku*)
82 AC_MSG_RESULT([Haiku])
Chris Dickenscb77a252017-02-20 00:18:33 -080083 backend=haiku
Chris Dickensda5df372020-08-26 15:42:39 -070084 platform=posix
Chris Dickensd5bb64b2020-01-22 17:39:14 -080085 ;;
86*-linux* | *-uclinux*)
Chris Dickens9a1bc8c2020-03-30 12:28:11 -070087 dnl on Android Linux, some functions are in different places
Chris Dickensd5bb64b2020-01-22 17:39:14 -080088 case $host in
89 *-linux-android*)
Chris Dickens9a1bc8c2020-03-30 12:28:11 -070090 AC_MSG_RESULT([Android Linux])
91 is_android_linux=yes
Chris Dickensd5bb64b2020-01-22 17:39:14 -080092 ;;
93 *)
94 AC_MSG_RESULT([Linux])
Chris Dickensd5bb64b2020-01-22 17:39:14 -080095 ;;
96 esac
97 backend=linux
Chris Dickensda5df372020-08-26 15:42:39 -070098 platform=posix
Chris Dickensd5bb64b2020-01-22 17:39:14 -080099 ;;
100*-netbsd*)
101 AC_MSG_RESULT([NetBSD])
102 backend=netbsd
Chris Dickensda5df372020-08-26 15:42:39 -0700103 platform=posix
Chris Dickensd5bb64b2020-01-22 17:39:14 -0800104 ;;
105*-openbsd*)
106 AC_MSG_RESULT([OpenBSD])
107 backend=openbsd
Chris Dickensda5df372020-08-26 15:42:39 -0700108 platform=posix
Akshay Jaggidc974252014-09-24 22:46:17 +0100109 ;;
Lei Cheneefd3222016-02-19 11:58:39 +0800110*-solaris*)
111 AC_MSG_RESULT([SunOS])
Chris Dickenscb77a252017-02-20 00:18:33 -0800112 backend=sunos
Chris Dickensda5df372020-08-26 15:42:39 -0700113 platform=posix
Lei Cheneefd3222016-02-19 11:58:39 +0800114 ;;
Chris Dickensd5bb64b2020-01-22 17:39:14 -0800115*-cygwin*)
116 AC_MSG_RESULT([Windows (using Cygwin)])
117 backend=windows
Chris Dickensda5df372020-08-26 15:42:39 -0700118 platform=windows
119 EXTRA_CFLAGS="-mwin32"
Chris Dickensd5bb64b2020-01-22 17:39:14 -0800120 ;;
121*-mingw* | *msys*)
122 AC_MSG_RESULT([Windows])
123 backend=windows
Chris Dickensda5df372020-08-26 15:42:39 -0700124 platform=windows
Chris Dickens4a5540a2020-03-25 00:09:26 -0700125 test "x$enable_shared" = xyes && create_import_lib=yes
Chris Dickensda5df372020-08-26 15:42:39 -0700126 EXTRA_CFLAGS="-mwin32 -fno-omit-frame-pointer"
Chris Dickensd5bb64b2020-01-22 17:39:14 -0800127 ;;
Daniel Drakec0c94322008-03-13 12:36:56 +0000128*)
Pino Toscano53572d72019-12-27 18:41:28 +0100129 AC_MSG_RESULT([Null])
Chris Dickens9a1bc8c2020-03-30 12:28:11 -0700130 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 Dickensda5df372020-08-26 15:42:39 -0700132 backend=null
133 platform=posix
Chris Dickensd5bb64b2020-01-22 17:39:14 -0800134 ;;
Daniel Drakec0c94322008-03-13 12:36:56 +0000135esac
Pete Batard968df122012-04-19 18:01:04 +0100136
Chris Dickensda5df372020-08-26 15:42:39 -0700137if test "x$platform" = xposix; then
138 AC_DEFINE([PLATFORM_POSIX], [1], [Define to 1 if compiling for a POSIX platform.])
Chris Dickens9a1bc8c2020-03-30 12:28:11 -0700139 AC_CHECK_TYPES([nfds_t], [], [], [[#include <poll.h>]])
140 AC_CHECK_FUNCS([pipe2])
Chris Dickens33b3ba32020-04-09 12:05:16 -0700141 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 Dickens9a1bc8c2020-03-30 12:28:11 -0700150 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 Dickens33b3ba32020-04-09 12:05:16 -0700152 AC_SEARCH_LIBS([pthread_create], [pthread],
153 [test "x$ac_cv_search_pthread_create" != "xnone required" && AC_SUBST(THREAD_LIBS, [-lpthread])],
154 [], [])
Chris Dickensda5df372020-08-26 15:42:39 -0700155elif test "x$platform" = xwindows; then
156 AC_DEFINE([PLATFORM_WINDOWS], [1], [Define to 1 if compiling for a Windows platform.])
Chris Dickens9a1bc8c2020-03-30 12:28:11 -0700157else
Chris Dickensda5df372020-08-26 15:42:39 -0700158 AC_MSG_ERROR([Unknown platform])
Chris Dickens9a1bc8c2020-03-30 12:28:11 -0700159fi
160
Pete Batard968df122012-04-19 18:01:04 +0100161case $backend in
Chris Dickensd5bb64b2020-01-22 17:39:14 -0800162darwin)
Chris Dickens30b56ba2020-03-27 00:03:41 -0700163 AC_CHECK_FUNCS([pthread_threadid_np])
Chris Dickens9a1bc8c2020-03-30 12:28:11 -0700164 LIBS="${LIBS} -lobjc -Wl,-framework,IOKit -Wl,-framework,CoreFoundation"
Chris Dickensd5bb64b2020-01-22 17:39:14 -0800165 ;;
166haiku)
Chris Dickens9a1bc8c2020-03-30 12:28:11 -0700167 LIBS="${LIBS} -lbe"
Chris Dickensd5bb64b2020-01-22 17:39:14 -0800168 ;;
Pete Batard968df122012-04-19 18:01:04 +0100169linux)
Chris Dickens9a1bc8c2020-03-30 12:28:11 -0700170 AC_SEARCH_LIBS([clock_gettime], [rt], [], [], [])
171 AC_CHECK_FUNCS([pthread_setname_np])
Nathan Hjelm68532912012-11-29 16:14:03 -0700172 AC_ARG_ENABLE([udev],
Toby Gray9222a542013-07-09 16:05:39 +0100173 [AC_HELP_STRING([--enable-udev], [use udev for device enumeration and hotplug support (recommended) [default=yes]])],
Chris Dickens9a1bc8c2020-03-30 12:28:11 -0700174 [use_udev=$enableval], [use_udev=yes])
175 if test "x$use_udev" = xyes; then
Chris Dickensd5bb64b2020-01-22 17:39:14 -0800176 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 Dickensd5bb64b2020-01-22 17:39:14 -0800184 ;;
185sunos)
Chris Dickens9a1bc8c2020-03-30 12:28:11 -0700186 LIBS="${LIBS} -ldevinfo"
Chris Dickensd5bb64b2020-01-22 17:39:14 -0800187 ;;
188windows)
Chris Dickensd5bb64b2020-01-22 17:39:14 -0800189 AC_CHECK_TYPES([struct timespec], [], [], [[#include <time.h>]])
Chris Dickens9a1bc8c2020-03-30 12:28:11 -0700190 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 Dickensd5bb64b2020-01-22 17:39:14 -0800192 ;;
193*)
Chris Dickens9a1bc8c2020-03-30 12:28:11 -0700194 dnl no special handling required
Pino Toscano53572d72019-12-27 18:41:28 +0100195 ;;
Pete Batard968df122012-04-19 18:01:04 +0100196esac
197
Chris Dickensd5bb64b2020-01-22 17:39:14 -0800198dnl headers not available on all platforms but required on others
199AC_CHECK_HEADERS([sys/time.h])
200
Chris Dickensc3e292c2020-08-27 13:46:32 -0700201if test "x$platform" = xposix; then
202 dnl the clock_gettime() function needs certain clock IDs defined
203 AC_CHECK_FUNCS([clock_gettime], [have_clock_gettime=yes], [have_clock_gettime=])
204 if test "x$have_clock_gettime" = xyes; then
205 AC_CHECK_DECL([CLOCK_MONOTONIC], [], [AC_MSG_ERROR([C library headers missing definition for CLOCK_MONOTONIC])], [[#include <time.h>]])
Chris Dickensccba4882020-08-27 13:54:21 -0700206 dnl use the monotonic clock for condition variable timed waits if possible
207 AC_CHECK_FUNCS([pthread_condattr_setclock], [need_clock_realtime=], [need_clock_realtime=yes])
208 if test "x$need_clock_realtime" = xyes; then
209 AC_CHECK_DECL([CLOCK_REALTIME], [], [AC_MSG_ERROR([C library headers missing definition for CLOCK_REALTIME])], [[#include <time.h>]])
210 fi
Chris Dickensc3e292c2020-08-27 13:46:32 -0700211 elif test "x$backend" != xdarwin; then
212 AC_MSG_ERROR([clock_gettime() is required on this platform])
213 fi
Chris Dickens26b16eb2020-01-26 22:43:28 -0800214fi
215
Chris Dickensb40a26f2020-08-12 18:44:31 -0700216dnl eventfd support
217if test "x$backend" = xlinux || test "x$backend" = xsunos; then
218 AC_ARG_ENABLE([eventfd],
219 [AS_HELP_STRING([--enable-eventfd], [use eventfd for signalling [default=auto]])],
220 [use_eventfd=$enableval],
221 [use_eventfd=auto])
222 if test "x$use_eventfd" != xno; then
223 AC_CHECK_HEADER([sys/eventfd.h], [eventfd_h=yes], [eventfd_h=])
224 if test "x$eventfd_h" = xyes; then
225 AC_CHECK_DECLS([EFD_NONBLOCK, EFD_CLOEXEC], [eventfd_h_ok=yes], [eventfd_h_ok=], [[#include <sys/eventfd.h>]])
226 if test "x$eventfd_h_ok" = xyes; then
227 AC_CHECK_FUNC([eventfd], [eventfd_ok=yes], [eventfd_ok=])
228 if test "x$eventfd_ok" = xyes; then
229 AC_DEFINE([HAVE_EVENTFD], [1], [Define to 1 if the system has eventfd functionality.])
230 elif test "x$use_eventfd" = xyes; then
231 AC_MSG_ERROR([eventfd() function not found; glibc 2.9+ required])
232 fi
233 elif test "x$use_eventfd" = xyes; then
234 AC_MSG_ERROR([eventfd header not usable; glibc 2.9+ required])
235 fi
236 elif test "x$use_eventfd" = xyes; then
237 AC_MSG_ERROR([eventfd header not available; glibc 2.9+ required])
238 fi
239 fi
240 AC_MSG_CHECKING([whether to use eventfd for signalling])
241 if test "x$use_eventfd" = xno; then
242 AC_MSG_RESULT([no (disabled by user)])
243 elif test "x$eventfd_h" != xyes; then
244 AC_MSG_RESULT([no (header not available)])
245 elif test "x$eventfd_h_ok" != xyes; then
246 AC_MSG_RESULT([no (header not usable)])
247 elif test "x$eventfd_ok" != xyes; then
248 AC_MSG_RESULT([no (functions not available)])
249 else
250 AC_MSG_RESULT([yes])
251 fi
252fi
253
Chris Dickensd5bb64b2020-01-22 17:39:14 -0800254dnl timerfd support
255if test "x$backend" = xlinux || test "x$backend" = xsunos; then
256 AC_ARG_ENABLE([timerfd],
257 [AS_HELP_STRING([--enable-timerfd], [use timerfd for timing [default=auto]])],
258 [use_timerfd=$enableval],
259 [use_timerfd=auto])
260 if test "x$use_timerfd" != xno; then
Chris Dickens9a1bc8c2020-03-30 12:28:11 -0700261 AC_CHECK_HEADER([sys/timerfd.h], [timerfd_h=yes], [timerfd_h=])
Chris Dickensd5bb64b2020-01-22 17:39:14 -0800262 if test "x$timerfd_h" = xyes; then
Chris Dickens9a1bc8c2020-03-30 12:28:11 -0700263 AC_CHECK_DECLS([TFD_NONBLOCK, TFD_CLOEXEC], [timerfd_h_ok=yes], [timerfd_h_ok=], [[#include <sys/timerfd.h>]])
Chris Dickensd5bb64b2020-01-22 17:39:14 -0800264 if test "x$timerfd_h_ok" = xyes; then
Chris Dickens9a1bc8c2020-03-30 12:28:11 -0700265 AC_CHECK_FUNC([timerfd_create], [timerfd_ok=yes], [timerfd_ok=])
Chris Dickensd5bb64b2020-01-22 17:39:14 -0800266 if test "x$timerfd_ok" = xyes; then
Chris Dickens9a1bc8c2020-03-30 12:28:11 -0700267 AC_DEFINE([HAVE_TIMERFD], [1], [Define to 1 if the system has timerfd functionality.])
Chris Dickensd5bb64b2020-01-22 17:39:14 -0800268 elif test "x$use_timerfd" = xyes; then
269 AC_MSG_ERROR([timerfd_create() function not found; glibc 2.9+ required])
270 fi
271 elif test "x$use_timerfd" = xyes; then
272 AC_MSG_ERROR([timerfd header not usable; glibc 2.9+ required])
273 fi
274 elif test "x$use_timerfd" = xyes; then
275 AC_MSG_ERROR([timerfd header not available; glibc 2.9+ required])
276 fi
277 fi
278 AC_MSG_CHECKING([whether to use timerfd for timing])
279 if test "x$use_timerfd" = xno; then
280 AC_MSG_RESULT([no (disabled by user)])
Chris Dickens9a1bc8c2020-03-30 12:28:11 -0700281 elif test "x$timerfd_h" != xyes; then
Daniel Drake47830082009-10-28 20:33:49 +0545282 AC_MSG_RESULT([no (header not available)])
Chris Dickens9a1bc8c2020-03-30 12:28:11 -0700283 elif test "x$timerfd_h_ok" != xyes; then
284 AC_MSG_RESULT([no (header not usable)])
285 elif test "x$timerfd_ok" != xyes; then
Chris Dickensd5bb64b2020-01-22 17:39:14 -0800286 AC_MSG_RESULT([no (functions not available)])
287 else
288 AC_MSG_RESULT([yes])
Daniel Drake47830082009-10-28 20:33:49 +0545289 fi
290fi
291
Chris Dickensd5bb64b2020-01-22 17:39:14 -0800292dnl Message logging
293AC_ARG_ENABLE([log],
294 [AS_HELP_STRING([--disable-log], [disable all logging])],
Daniel Drake852bba42007-11-28 13:48:45 +0000295 [log_enabled=$enableval],
Chris Dickenscb77a252017-02-20 00:18:33 -0800296 [log_enabled=yes])
Chris Dickens94178682017-01-12 13:50:35 -0800297if test "x$log_enabled" != xno; then
Chris Dickens9a1bc8c2020-03-30 12:28:11 -0700298 AC_DEFINE([ENABLE_LOGGING], [1], [Define to 1 to enable message logging.])
Daniel Drake852bba42007-11-28 13:48:45 +0000299fi
300
Chris Dickensd5bb64b2020-01-22 17:39:14 -0800301AC_ARG_ENABLE([debug-log],
302 [AS_HELP_STRING([--enable-debug-log], [start with debug message logging enabled [default=no]])],
Daniel Drake852bba42007-11-28 13:48:45 +0000303 [debug_log_enabled=$enableval],
Chris Dickenscb77a252017-02-20 00:18:33 -0800304 [debug_log_enabled=no])
Chris Dickens94178682017-01-12 13:50:35 -0800305if test "x$debug_log_enabled" != xno; then
Chris Dickens9a1bc8c2020-03-30 12:28:11 -0700306 AC_DEFINE([ENABLE_DEBUG_LOGGING], [1], [Define to 1 to start with debug message logging enabled.])
Daniel Drake852bba42007-11-28 13:48:45 +0000307fi
308
Chris Dickensd5bb64b2020-01-22 17:39:14 -0800309AC_ARG_ENABLE([system-log],
Chris Dickens9a1bc8c2020-03-30 12:28:11 -0700310 [AS_HELP_STRING([--enable-system-log], [output logging messages to the systemwide log, if supported by the OS [default=no]])],
Toby Gray9222a542013-07-09 16:05:39 +0100311 [system_log_enabled=$enableval],
Chris Dickenscb77a252017-02-20 00:18:33 -0800312 [system_log_enabled=no])
Chris Dickens94178682017-01-12 13:50:35 -0800313if test "x$system_log_enabled" != xno; then
Chris Dickens9a1bc8c2020-03-30 12:28:11 -0700314 AC_DEFINE([USE_SYSTEM_LOGGING_FACILITY], [1], [Define to 1 to output logging messages to the systemwide log.])
315 if test "x$backend" != xwindows && test "x$is_android_linux" != xyes; then
Chris Dickensd5bb64b2020-01-22 17:39:14 -0800316 dnl Check if syslog is available in standard C library
Chris Dickens9a1bc8c2020-03-30 12:28:11 -0700317 AC_CHECK_HEADER([syslog.h], [syslog_h=yes], [syslog_h=])
Chris Dickensd5bb64b2020-01-22 17:39:14 -0800318 if test "x$syslog_h" = xyes; then
319 AC_CHECK_FUNCS([syslog])
320 fi
Chris Dickens94178682017-01-12 13:50:35 -0800321 fi
Toby Gray9222a542013-07-09 16:05:39 +0100322fi
323
Chris Dickensd5bb64b2020-01-22 17:39:14 -0800324dnl Examples build
325AC_ARG_ENABLE([examples-build],
326 [AS_HELP_STRING([--enable-examples-build], [build example applications [default=no]])],
Daniel Drake852bba42007-11-28 13:48:45 +0000327 [build_examples=$enableval],
Chris Dickenscb77a252017-02-20 00:18:33 -0800328 [build_examples=no])
Daniel Drake852bba42007-11-28 13:48:45 +0000329
Chris Dickensd5bb64b2020-01-22 17:39:14 -0800330dnl Tests build
331AC_ARG_ENABLE([tests-build],
332 [AS_HELP_STRING([--enable-tests-build], [build test applications [default=no]])],
Toby Gray21cf6e42012-11-21 14:00:31 +0000333 [build_tests=$enableval],
Chris Dickenscb77a252017-02-20 00:18:33 -0800334 [build_tests=no])
Chris Dickens9a1bc8c2020-03-30 12:28:11 -0700335
336AM_CONDITIONAL([BUILD_EXAMPLES], [test "x$build_examples" != xno])
Chris Dickensd5bb64b2020-01-22 17:39:14 -0800337AM_CONDITIONAL([BUILD_TESTS], [test "x$build_tests" != xno])
Chris Dickens9a1bc8c2020-03-30 12:28:11 -0700338AM_CONDITIONAL([CREATE_IMPORT_LIB], [test "x$create_import_lib" = xyes])
Chris Dickens9a1bc8c2020-03-30 12:28:11 -0700339AM_CONDITIONAL([OS_DARWIN], [test "x$backend" = xdarwin])
340AM_CONDITIONAL([OS_HAIKU], [test "x$backend" = xhaiku])
341AM_CONDITIONAL([OS_LINUX], [test "x$backend" = xlinux])
342AM_CONDITIONAL([OS_NETBSD], [test "x$backend" = xnetbsd])
343AM_CONDITIONAL([OS_NULL], [test "x$backend" = xnull])
344AM_CONDITIONAL([OS_OPENBSD], [test "x$backend" = xopenbsd])
345AM_CONDITIONAL([OS_SUNOS], [test "x$backend" = xsunos])
346AM_CONDITIONAL([OS_WINDOWS], [test "x$backend" = xwindows])
Chris Dickensda5df372020-08-26 15:42:39 -0700347AM_CONDITIONAL([PLATFORM_POSIX], [test "x$platform" = xposix])
348AM_CONDITIONAL([PLATFORM_WINDOWS], [test "x$platform" = xwindows])
Chris Dickens9a1bc8c2020-03-30 12:28:11 -0700349AM_CONDITIONAL([USE_UDEV], [test "x$use_udev" = xyes])
Chris Dickens94178682017-01-12 13:50:35 -0800350
Chris Dickens95bbfb62020-03-30 12:38:47 -0700351dnl The -Wcast-function-type warning causes a flurry of warnings when compiling
352dnl Windows with GCC 8 or later because of dynamically loaded functions
353if test "x$backend" = xwindows; then
354 saved_CFLAGS="${CFLAGS}"
355 CFLAGS="-Werror -Wcast-function-type"
356 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])],
Chris Dickens7c0cea72020-04-09 11:30:19 -0700357 [EXTRA_CFLAGS="${EXTRA_CFLAGS} -Wno-cast-function-type"],
Chris Dickens95bbfb62020-03-30 12:38:47 -0700358 [])
359 CFLAGS="${saved_CFLAGS}"
360fi
361
Chris Dickens7c0cea72020-04-09 11:30:19 -0700362SHARED_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"
363
Chris Dickens6f0330c2020-04-09 11:46:03 -0700364AM_CPPFLAGS="${EXTRA_CPPFLAGS}"
365AC_SUBST(AM_CPPFLAGS)
366
Chris Dickens7c0cea72020-04-09 11:30:19 -0700367AM_CFLAGS="-std=${c_dialect}11 ${EXTRA_CFLAGS} ${SHARED_CFLAGS}"
Daniel Drake852bba42007-11-28 13:48:45 +0000368AC_SUBST(AM_CFLAGS)
Chris Dickens9a1bc8c2020-03-30 12:28:11 -0700369
Chris Dickens7c0cea72020-04-09 11:30:19 -0700370AM_CXXFLAGS="-std=${c_dialect}++11 ${EXTRA_CFLAGS} ${SHARED_CFLAGS} -Wmissing-declarations"
Chris Dickens9a1bc8c2020-03-30 12:28:11 -0700371AC_SUBST(AM_CXXFLAGS)
372
373AC_SUBST(LT_LDFLAGS)
Daniel Drake852bba42007-11-28 13:48:45 +0000374
Chris Dickens4a5540a2020-03-25 00:09:26 -0700375dnl set name of html output directory for doxygen
376AC_SUBST(DOXYGEN_HTMLDIR, [api-1.0])
377
Peter Stugeef39d152011-02-25 02:33:29 +0100378AC_CONFIG_FILES([libusb-1.0.pc])
379AC_CONFIG_FILES([Makefile])
380AC_CONFIG_FILES([libusb/Makefile])
Peter Stugeef39d152011-02-25 02:33:29 +0100381AC_CONFIG_FILES([examples/Makefile])
Toby Gray21cf6e42012-11-21 14:00:31 +0000382AC_CONFIG_FILES([tests/Makefile])
Peter Stugeef39d152011-02-25 02:33:29 +0100383AC_CONFIG_FILES([doc/Makefile])
384AC_CONFIG_FILES([doc/doxygen.cfg])
Daniel Drake852bba42007-11-28 13:48:45 +0000385AC_OUTPUT