core: Add support for eventfd
[platform/upstream/libusb.git] / configure.ac
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]))])
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]))])
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
11 dnl in AC_INIT.
12
13 LU_DEFINE_VERSION_ATOM([LIBUSB_MAJOR])
14 LU_DEFINE_VERSION_ATOM([LIBUSB_MINOR])
15 LU_DEFINE_VERSION_ATOM([LIBUSB_MICRO])
16 LU_DEFINE_VERSION_RC_ATOM([LIBUSB_RC])
17
18 AC_PREREQ([2.69])
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])
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])
29
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
34 lt_current=2
35 lt_revision=0
36 lt_age=2
37 LT_LDFLAGS="-version-info ${lt_current}:${lt_revision}:${lt_age} -no-undefined"
38
39 m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])])
40
41 EXTRA_CPPFLAGS=
42 EXTRA_CFLAGS=
43
44 dnl check for -std=gnu11 compiler support (optional)
45 dnl note that we don't just check if the compiler accepts '-std=x11'
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"
50 AC_MSG_CHECKING([if $CC supports -std=gnu11])
51 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([_Thread_local int x;], [x = 42;])],
52         [AC_MSG_RESULT([yes])
53          c_dialect=gnu],
54         [AC_MSG_RESULT([no])
55          c_dialect=])
56 if test "x$c_dialect" != xgnu; then
57         dnl fallback check for -std=c11 compiler support (required)
58         CFLAGS="-std=c11"
59         AC_MSG_CHECKING([if $CC supports -std=c11])
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])])
64         c_dialect=c
65 fi
66 CFLAGS="${saved_CFLAGS}"
67
68 AC_DEFINE([_GNU_SOURCE], [1], [Enable GNU extensions.])
69 AC_DEFINE([DEFAULT_VISIBILITY], [__attribute__ ((visibility ("default")))], [Define to the attribute for default visibility.])
70
71 create_import_lib=
72 is_android_linux=
73 AC_MSG_CHECKING([operating system])
74 case $host in
75 *-darwin*)
76         AC_MSG_RESULT([Darwin/Mac OS X])
77         backend=darwin
78         events=posix
79         threads=posix
80         ;;
81 *-haiku*)
82         AC_MSG_RESULT([Haiku])
83         backend=haiku
84         events=posix
85         threads=posix
86         ;;
87 *-linux* | *-uclinux*)
88         dnl on Android Linux, some functions are in different places
89         case $host in
90         *-linux-android*)
91                 AC_MSG_RESULT([Android Linux])
92                 is_android_linux=yes
93                 ;;
94         *)
95                 AC_MSG_RESULT([Linux])
96                 ;;
97         esac
98         backend=linux
99         events=posix
100         threads=posix
101         ;;
102 *-netbsd*)
103         AC_MSG_RESULT([NetBSD])
104         backend=netbsd
105         events=posix
106         threads=posix
107         ;;
108 *-openbsd*)
109         AC_MSG_RESULT([OpenBSD])
110         backend=openbsd
111         events=posix
112         threads=posix
113         ;;
114 *-solaris*)
115         AC_MSG_RESULT([SunOS])
116         backend=sunos
117         events=posix
118         threads=posix
119         ;;
120 *-cygwin*)
121         AC_MSG_RESULT([Windows (using Cygwin)])
122         backend=windows
123         events=windows
124         threads=posix
125         ;;
126 *-mingw* | *msys*)
127         AC_MSG_RESULT([Windows])
128         backend=windows
129         events=windows
130         threads=windows
131         test "x$enable_shared" = xyes && create_import_lib=yes
132         EXTRA_CFLAGS="-fno-omit-frame-pointer"
133         ;;
134 *)
135         AC_MSG_RESULT([Null])
136         AC_MSG_WARN([The host being compiled for is not supported.])
137         AC_MSG_WARN([The library may compile but will not function in any useful manner.])
138         backend="null"
139         events=posix
140         threads="posix"
141         ;;
142 esac
143
144 if test "x$events" = xposix; then
145         AC_DEFINE([EVENTS_POSIX], [1], [Define to 1 if using the POSIX events abstraction.])
146         AC_CHECK_TYPES([nfds_t], [], [], [[#include <poll.h>]])
147         AC_CHECK_FUNCS([pipe2])
148 elif test "x$events" = xwindows; then
149         AC_DEFINE([EVENTS_WINDOWS], [1], [Define to 1 if using the Windows events abstraction.])
150 else
151         AC_MSG_ERROR([Unknown events abstraction])
152 fi
153
154 if test "x$threads" = xposix; then
155         AC_DEFINE([THREADS_POSIX], [1], [Define to 1 if using POSIX threads.])
156         dnl Some compilers do not support the '-pthread' option so check for it here
157         saved_CFLAGS="${CFLAGS}"
158         CFLAGS="-Wall -Werror -pthread"
159         AC_MSG_CHECKING([if $CC recognizes -pthread])
160         AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])],
161                 [AC_MSG_RESULT([yes])
162                  AC_SUBST(THREAD_CFLAGS, [-pthread])],
163                 [AC_MSG_RESULT([no])])
164         CFLAGS="${saved_CFLAGS}"
165         dnl Android Linux and Darwin provide pthread functions directly in libc
166         dnl glibc also provides some pthread functions directly, so search for a thread-specific function
167         AC_SEARCH_LIBS([pthread_create], [pthread],
168                 [test "x$ac_cv_search_pthread_create" != "xnone required" && AC_SUBST(THREAD_LIBS, [-lpthread])],
169                 [], [])
170 elif test "x$threads" = xwindows; then
171         AC_DEFINE([THREADS_WINDOWS], [1], [Define to 1 if using Windows threads.])
172 else
173         AC_MSG_ERROR([Unknown threads implementation])
174 fi
175
176 case $backend in
177 darwin)
178         AC_CHECK_FUNCS([pthread_threadid_np])
179         LIBS="${LIBS} -lobjc -Wl,-framework,IOKit -Wl,-framework,CoreFoundation"
180         ;;
181 haiku)
182         LIBS="${LIBS} -lbe"
183         ;;
184 linux)
185         AC_SEARCH_LIBS([clock_gettime], [rt], [], [], [])
186         AC_CHECK_FUNCS([pthread_setname_np])
187         AC_ARG_ENABLE([udev],
188                 [AC_HELP_STRING([--enable-udev], [use udev for device enumeration and hotplug support (recommended) [default=yes]])],
189                 [use_udev=$enableval], [use_udev=yes])
190         if test "x$use_udev" = xyes; then
191                 dnl system has udev. use it or fail!
192                 AC_CHECK_HEADER([libudev.h], [], [AC_MSG_ERROR([udev support requested but libudev header not installed])])
193                 AC_CHECK_LIB([udev], [udev_new], [], [AC_MSG_ERROR([udev support requested but libudev not installed])])
194         else
195                 AC_CHECK_HEADERS([asm/types.h])
196                 AC_CHECK_HEADER([linux/netlink.h], [], [AC_MSG_ERROR([Linux netlink header not found])])
197                 AC_CHECK_HEADER([sys/socket.h], [], [AC_MSG_ERROR([Linux socket header not found])])
198         fi
199         ;;
200 sunos)
201         LIBS="${LIBS} -ldevinfo"
202         ;;
203 windows)
204         AC_CHECK_TYPES([struct timespec], [], [], [[#include <time.h>]])
205         AC_DEFINE([_WIN32_WINNT], [_WIN32_WINNT_VISTA], [Define to the oldest supported Windows version.])
206         dnl Cygwin and MSYS compilers do not define _WIN32 as MinGW and MSVC do
207         dnl simplify checks for Windows compilation by ensuring it is always defined
208         EXTRA_CPPFLAGS="-D_WIN32"
209         LT_LDFLAGS="${LT_LDFLAGS} -avoid-version -Wl,--add-stdcall-alias"
210         ;;
211 *)
212         dnl no special handling required
213         ;;
214 esac
215
216 dnl headers not available on all platforms but required on others
217 AC_CHECK_HEADERS([sys/time.h])
218
219 dnl the clock_gettime() function needs certain clock IDs defined
220 AC_CHECK_FUNCS([clock_gettime], [have_clock_gettime=yes], [have_clock_gettime=])
221 if test "x$have_clock_gettime" = xyes; then
222         AC_CHECK_DECL([CLOCK_REALTIME], [], [AC_MSG_ERROR([C library headers missing definition for CLOCK_REALTIME])], [[#include <time.h>]])
223         AC_CHECK_DECL([CLOCK_MONOTONIC], [], [AC_MSG_ERROR([C library headers missing definition for CLOCK_MONOTONIC])], [[#include <time.h>]])
224 elif test "x$backend" != xdarwin && test "x$backend" != xwindows; then
225         AC_MSG_ERROR([clock_gettime() is required on this platform])
226 fi
227
228 dnl eventfd support
229 if test "x$backend" = xlinux || test "x$backend" = xsunos; then
230         AC_ARG_ENABLE([eventfd],
231                 [AS_HELP_STRING([--enable-eventfd], [use eventfd for signalling [default=auto]])],
232                 [use_eventfd=$enableval],
233                 [use_eventfd=auto])
234         if test "x$use_eventfd" != xno; then
235                 AC_CHECK_HEADER([sys/eventfd.h], [eventfd_h=yes], [eventfd_h=])
236                 if test "x$eventfd_h" = xyes; then
237                         AC_CHECK_DECLS([EFD_NONBLOCK, EFD_CLOEXEC], [eventfd_h_ok=yes], [eventfd_h_ok=], [[#include <sys/eventfd.h>]])
238                         if test "x$eventfd_h_ok" = xyes; then
239                                 AC_CHECK_FUNC([eventfd], [eventfd_ok=yes], [eventfd_ok=])
240                                 if test "x$eventfd_ok" = xyes; then
241                                         AC_DEFINE([HAVE_EVENTFD], [1], [Define to 1 if the system has eventfd functionality.])
242                                 elif test "x$use_eventfd" = xyes; then
243                                         AC_MSG_ERROR([eventfd() function not found; glibc 2.9+ required])
244                                 fi
245                         elif test "x$use_eventfd" = xyes; then
246                                 AC_MSG_ERROR([eventfd header not usable; glibc 2.9+ required])
247                         fi
248                 elif test "x$use_eventfd" = xyes; then
249                         AC_MSG_ERROR([eventfd header not available; glibc 2.9+ required])
250                 fi
251         fi
252         AC_MSG_CHECKING([whether to use eventfd for signalling])
253         if test "x$use_eventfd" = xno; then
254                 AC_MSG_RESULT([no (disabled by user)])
255         elif test "x$eventfd_h" != xyes; then
256                 AC_MSG_RESULT([no (header not available)])
257         elif test "x$eventfd_h_ok" != xyes; then
258                 AC_MSG_RESULT([no (header not usable)])
259         elif test "x$eventfd_ok" != xyes; then
260                 AC_MSG_RESULT([no (functions not available)])
261         else
262                 AC_MSG_RESULT([yes])
263         fi
264 fi
265
266 dnl timerfd support
267 if test "x$backend" = xlinux || test "x$backend" = xsunos; then
268         AC_ARG_ENABLE([timerfd],
269                 [AS_HELP_STRING([--enable-timerfd], [use timerfd for timing [default=auto]])],
270                 [use_timerfd=$enableval],
271                 [use_timerfd=auto])
272         if test "x$use_timerfd" != xno; then
273                 AC_CHECK_HEADER([sys/timerfd.h], [timerfd_h=yes], [timerfd_h=])
274                 if test "x$timerfd_h" = xyes; then
275                         AC_CHECK_DECLS([TFD_NONBLOCK, TFD_CLOEXEC], [timerfd_h_ok=yes], [timerfd_h_ok=], [[#include <sys/timerfd.h>]])
276                         if test "x$timerfd_h_ok" = xyes; then
277                                 AC_CHECK_FUNC([timerfd_create], [timerfd_ok=yes], [timerfd_ok=])
278                                 if test "x$timerfd_ok" = xyes; then
279                                         AC_DEFINE([HAVE_TIMERFD], [1], [Define to 1 if the system has timerfd functionality.])
280                                 elif test "x$use_timerfd" = xyes; then
281                                         AC_MSG_ERROR([timerfd_create() function not found; glibc 2.9+ required])
282                                 fi
283                         elif test "x$use_timerfd" = xyes; then
284                                 AC_MSG_ERROR([timerfd header not usable; glibc 2.9+ required])
285                         fi
286                 elif test "x$use_timerfd" = xyes; then
287                         AC_MSG_ERROR([timerfd header not available; glibc 2.9+ required])
288                 fi
289         fi
290         AC_MSG_CHECKING([whether to use timerfd for timing])
291         if test "x$use_timerfd" = xno; then
292                 AC_MSG_RESULT([no (disabled by user)])
293         elif test "x$timerfd_h" != xyes; then
294                 AC_MSG_RESULT([no (header not available)])
295         elif test "x$timerfd_h_ok" != xyes; then
296                 AC_MSG_RESULT([no (header not usable)])
297         elif test "x$timerfd_ok" != xyes; then
298                 AC_MSG_RESULT([no (functions not available)])
299         else
300                 AC_MSG_RESULT([yes])
301         fi
302 fi
303
304 dnl Message logging
305 AC_ARG_ENABLE([log],
306         [AS_HELP_STRING([--disable-log], [disable all logging])],
307         [log_enabled=$enableval],
308         [log_enabled=yes])
309 if test "x$log_enabled" != xno; then
310         AC_DEFINE([ENABLE_LOGGING], [1], [Define to 1 to enable message logging.])
311 fi
312
313 AC_ARG_ENABLE([debug-log],
314         [AS_HELP_STRING([--enable-debug-log], [start with debug message logging enabled [default=no]])],
315         [debug_log_enabled=$enableval],
316         [debug_log_enabled=no])
317 if test "x$debug_log_enabled" != xno; then
318         AC_DEFINE([ENABLE_DEBUG_LOGGING], [1], [Define to 1 to start with debug message logging enabled.])
319 fi
320
321 AC_ARG_ENABLE([system-log],
322         [AS_HELP_STRING([--enable-system-log], [output logging messages to the systemwide log, if supported by the OS [default=no]])],
323         [system_log_enabled=$enableval],
324         [system_log_enabled=no])
325 if test "x$system_log_enabled" != xno; then
326         AC_DEFINE([USE_SYSTEM_LOGGING_FACILITY], [1], [Define to 1 to output logging messages to the systemwide log.])
327         if test "x$backend" != xwindows && test "x$is_android_linux" != xyes; then
328                 dnl Check if syslog is available in standard C library
329                 AC_CHECK_HEADER([syslog.h], [syslog_h=yes], [syslog_h=])
330                 if test "x$syslog_h" = xyes; then
331                         AC_CHECK_FUNCS([syslog])
332                 fi
333         fi
334 fi
335
336 dnl Examples build
337 AC_ARG_ENABLE([examples-build],
338         [AS_HELP_STRING([--enable-examples-build], [build example applications [default=no]])],
339         [build_examples=$enableval],
340         [build_examples=no])
341 if test "x$build_examples" != xno; then
342         dnl sigaction needed for some example programs
343         AC_CHECK_FUNC([sigaction], [have_sigaction=yes], [have_sigaction=])
344 fi
345
346 dnl Tests build
347 AC_ARG_ENABLE([tests-build],
348         [AS_HELP_STRING([--enable-tests-build], [build test applications [default=no]])],
349         [build_tests=$enableval],
350         [build_tests=no])
351
352 AM_CONDITIONAL([BUILD_EXAMPLES], [test "x$build_examples" != xno])
353 AM_CONDITIONAL([BUILD_TESTS], [test "x$build_tests" != xno])
354 AM_CONDITIONAL([CREATE_IMPORT_LIB], [test "x$create_import_lib" = xyes])
355 AM_CONDITIONAL([EVENTS_POSIX], [test "x$events" = xposix])
356 AM_CONDITIONAL([EVENTS_WINDOWS], [test "x$events" = xwindows])
357 AM_CONDITIONAL([HAVE_SIGACTION], [test "x$have_sigaction" = xyes])
358 AM_CONDITIONAL([OS_DARWIN], [test "x$backend" = xdarwin])
359 AM_CONDITIONAL([OS_HAIKU], [test "x$backend" = xhaiku])
360 AM_CONDITIONAL([OS_LINUX], [test "x$backend" = xlinux])
361 AM_CONDITIONAL([OS_NETBSD], [test "x$backend" = xnetbsd])
362 AM_CONDITIONAL([OS_NULL], [test "x$backend" = xnull])
363 AM_CONDITIONAL([OS_OPENBSD], [test "x$backend" = xopenbsd])
364 AM_CONDITIONAL([OS_SUNOS], [test "x$backend" = xsunos])
365 AM_CONDITIONAL([OS_WINDOWS], [test "x$backend" = xwindows])
366 AM_CONDITIONAL([THREADS_POSIX], [test "x$threads" = xposix])
367 AM_CONDITIONAL([THREADS_WINDOWS], [test "x$threads" = xwindows])
368 AM_CONDITIONAL([USE_UDEV], [test "x$use_udev" = xyes])
369
370 dnl The -Wcast-function-type warning causes a flurry of warnings when compiling
371 dnl Windows with GCC 8 or later because of dynamically loaded functions
372 if test "x$backend" = xwindows; then
373         saved_CFLAGS="${CFLAGS}"
374         CFLAGS="-Werror -Wcast-function-type"
375         AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])],
376                 [EXTRA_CFLAGS="${EXTRA_CFLAGS} -Wno-cast-function-type"],
377                 [])
378         CFLAGS="${saved_CFLAGS}"
379 fi
380
381 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"
382
383 AM_CPPFLAGS="${EXTRA_CPPFLAGS}"
384 AC_SUBST(AM_CPPFLAGS)
385
386 AM_CFLAGS="-std=${c_dialect}11 ${EXTRA_CFLAGS} ${SHARED_CFLAGS}"
387 AC_SUBST(AM_CFLAGS)
388
389 AM_CXXFLAGS="-std=${c_dialect}++11 ${EXTRA_CFLAGS} ${SHARED_CFLAGS} -Wmissing-declarations"
390 AC_SUBST(AM_CXXFLAGS)
391
392 AC_SUBST(LT_LDFLAGS)
393
394 dnl set name of html output directory for doxygen
395 AC_SUBST(DOXYGEN_HTMLDIR, [api-1.0])
396
397 AC_CONFIG_FILES([libusb-1.0.pc])
398 AC_CONFIG_FILES([Makefile])
399 AC_CONFIG_FILES([libusb/Makefile])
400 AC_CONFIG_FILES([examples/Makefile])
401 AC_CONFIG_FILES([tests/Makefile])
402 AC_CONFIG_FILES([doc/Makefile])
403 AC_CONFIG_FILES([doc/doxygen.cfg])
404 AC_OUTPUT