threads_posix: Improve usbi_get_tid() for various platforms
[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_INIT([libusb-1.0], [LIBUSB_MAJOR[.]LIBUSB_MINOR[.]LIBUSB_MICRO[]LIBUSB_RC], [libusb-devel@lists.sourceforge.net], [libusb-1.0], [http://libusb.info])
19
20 dnl Library versioning
21 dnl These numbers should be tweaked on every release. Read carefully:
22 dnl http://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html
23 dnl http://sourceware.org/autobook/autobook/autobook_91.html
24 lt_current=2
25 lt_revision=0
26 lt_age=2
27 LTLDFLAGS="-version-info ${lt_current}:${lt_revision}:${lt_age}"
28
29 AM_INIT_AUTOMAKE
30
31 AC_CONFIG_SRCDIR([libusb/core.c])
32 AC_CONFIG_MACRO_DIR([m4])
33 AC_CONFIG_HEADERS([config.h])
34 m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])])
35
36 AC_PREREQ([2.69])
37 AC_PROG_CC
38 AC_PROG_CXX
39 LT_INIT
40 LT_LANG([Windows Resource])
41 AC_C_INLINE
42 AM_PROG_CC_C_O
43 AC_DEFINE([_GNU_SOURCE], [1], [Use GNU extensions])
44
45 LTLDFLAGS="${LTLDFLAGS} -no-undefined"
46
47 AC_MSG_CHECKING([operating system])
48 case $host in
49 *-darwin*)
50         AC_MSG_RESULT([Darwin/Mac OS X])
51         backend=darwin
52         poll=posix
53         threads=posix
54         ;;
55 *-haiku*)
56         AC_MSG_RESULT([Haiku])
57         backend=haiku
58         poll=posix
59         threads=posix
60         ;;
61 *-linux* | *-uclinux*)
62         dnl on linux-android platform, some functions are in different places
63         case $host in
64         *-linux-android*)
65                 AC_MSG_RESULT([Linux (Android system)])
66                 is_backend_android=yes
67                 ;;
68         *)
69                 AC_MSG_RESULT([Linux])
70                 is_backend_android=no
71                 ;;
72         esac
73         backend=linux
74         poll=posix
75         threads=posix
76         ;;
77 *-netbsd*)
78         AC_MSG_RESULT([NetBSD])
79         backend=netbsd
80         poll=posix
81         threads=posix
82         ;;
83 *-openbsd*)
84         AC_MSG_RESULT([OpenBSD])
85         backend=openbsd
86         poll=posix
87         threads=posix
88         ;;
89 *-solaris*)
90         AC_MSG_RESULT([SunOS])
91         backend=sunos
92         poll=posix
93         threads=posix
94         ;;
95 *-cygwin*)
96         AC_MSG_RESULT([Windows (using Cygwin)])
97         backend=windows
98         poll=windows
99         threads=posix
100         ;;
101 *-mingw* | *msys*)
102         AC_MSG_RESULT([Windows])
103         backend=windows
104         poll=windows
105         threads=windows
106         test "x$enable_shared" = xyes && create_import_lib=yes
107         AM_CFLAGS="${AM_CFLAGS} -fno-omit-frame-pointer"
108         ;;
109 *)
110         AC_MSG_RESULT([Null])
111         backend="null"
112         poll=posix
113         threads="posix"
114         ;;
115 esac
116
117 case $backend in
118 darwin)
119         AC_DEFINE([OS_DARWIN], [1], [Darwin backend])
120         AC_CHECK_FUNCS([pthread_threadid_np])
121         LIBS="-lobjc -Wl,-framework,IOKit -Wl,-framework,CoreFoundation"
122         LTLDFLAGS="${LTLDFLAGS} -Wl,-prebind"
123         ;;
124 haiku)
125         AC_DEFINE([OS_HAIKU], [1], [Haiku backend])
126         LIBS="-lbe"
127         ;;
128 linux)
129         AC_DEFINE([OS_LINUX], [1], [Linux backend])
130         AC_SEARCH_LIBS([clock_gettime], [rt], [], [], [-pthread])
131         AC_ARG_ENABLE([udev],
132                 [AC_HELP_STRING([--enable-udev], [use udev for device enumeration and hotplug support (recommended) [default=yes]])],
133                 [], [enable_udev=yes])
134         if test "x$enable_udev" = xyes ; then
135                 dnl system has udev. use it or fail!
136                 AC_CHECK_HEADER([libudev.h], [], [AC_MSG_ERROR([udev support requested but libudev header not installed])])
137                 AC_CHECK_LIB([udev], [udev_new], [], [AC_MSG_ERROR([udev support requested but libudev not installed])])
138         else
139                 AC_CHECK_HEADERS([asm/types.h])
140                 AC_CHECK_HEADER([linux/netlink.h], [], [AC_MSG_ERROR([Linux netlink header not found])])
141                 AC_CHECK_HEADER([sys/socket.h], [], [AC_MSG_ERROR([Linux socket header not found])])
142         fi
143         if test "x$is_backend_android" != xyes; then
144                 THREAD_CFLAGS="-pthread"
145                 LIBS="${LIBS} -pthread"
146         fi
147         AC_CHECK_FUNCS([pthread_setname_np])
148         ;;
149 netbsd)
150         AC_DEFINE([OS_NETBSD], [1], [NetBSD backend])
151         THREAD_CFLAGS="-pthread"
152         LIBS="-pthread"
153         ;;
154 null)
155         AC_DEFINE([OS_NULL], [1], [Null backend])
156         THREAD_CFLAGS="-pthread"
157         LIBS="-pthread"
158         ;;
159 openbsd)
160         AC_DEFINE([OS_OPENBSD], [1], [OpenBSD backend])
161         THREAD_CFLAGS="-pthread"
162         LIBS="-pthread"
163         ;;
164 sunos)
165         AC_DEFINE([OS_SUNOS], [1], [SunOS backend])
166         THREAD_CFLAGS="-pthread"
167         LIBS="-pthread -ldevinfo"
168         ;;
169 windows)
170         AC_DEFINE([OS_WINDOWS], [1], [Windows backend])
171         AC_CHECK_TYPES([struct timespec], [], [], [[#include <time.h>]])
172         LIBS=""
173         LTLDFLAGS="${LTLDFLAGS} -avoid-version -Wl,--add-stdcall-alias"
174         AC_DEFINE([_WIN32_WINNT], [_WIN32_WINNT_VISTA], [Oldest Windows version supported (Vista)])
175         ;;
176 *)
177         AC_MSG_ERROR([Unknown backend])
178         ;;
179 esac
180
181 AC_SUBST(LIBS)
182
183 AM_CONDITIONAL([OS_DARWIN], [test "x$backend" = xdarwin])
184 AM_CONDITIONAL([OS_HAIKU], [test "x$backend" = xhaiku])
185 AM_CONDITIONAL([OS_LINUX], [test "x$backend" = xlinux])
186 AM_CONDITIONAL([OS_NETBSD], [test "x$backend" = xnetbsd])
187 AM_CONDITIONAL([OS_NULL], [test "x$backend" = xnull])
188 AM_CONDITIONAL([OS_OPENBSD], [test "x$backend" = xopenbsd])
189 AM_CONDITIONAL([OS_SUNOS], [test "x$backend" = xsunos])
190 AM_CONDITIONAL([OS_WINDOWS], [test "x$backend" = xwindows])
191 AM_CONDITIONAL([POLL_POSIX], [test "x$poll" = xposix])
192 AM_CONDITIONAL([POLL_WINDOWS], [test "x$poll" = xwindows])
193 AM_CONDITIONAL([THREADS_POSIX], [test "x$threads" = xposix])
194 AM_CONDITIONAL([THREADS_WINDOWS], [test "x$threads" = xwindows])
195 AM_CONDITIONAL([CREATE_IMPORT_LIB], [test "x$create_import_lib" = xyes])
196 AM_CONDITIONAL([USE_UDEV], [test "x$enable_udev" = xyes])
197
198 if test "x$poll" = xposix; then
199         AC_DEFINE([POLL_POSIX], [1], [Use POSIX poll() implementation])
200         AC_CHECK_TYPES([nfds_t], [], [], [[#include <poll.h>]])
201         AC_CHECK_FUNCS([pipe2])
202 elif test "x$poll" = xwindows; then
203         AC_DEFINE([POLL_WINDOWS], [1], [Use Windows poll() implementation])
204 else
205         AC_MSG_ERROR([Unknown poll implementation])
206 fi
207
208 if test "x$threads" = xposix; then
209         AC_DEFINE([THREADS_POSIX], [1], [Use POSIX Threads])
210 elif test "x$threads" = xwindows; then
211         AC_DEFINE([THREADS_WINDOWS], [1], [Use Windows Threads])
212 else
213         AC_MSG_ERROR([Unknown threads implementation])
214 fi
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_clockgettime=no])
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 timerfd support
229 if test "x$backend" = xlinux || test "x$backend" = xsunos; then
230         AC_ARG_ENABLE([timerfd],
231                 [AS_HELP_STRING([--enable-timerfd], [use timerfd for timing [default=auto]])],
232                 [use_timerfd=$enableval],
233                 [use_timerfd=auto])
234         if test "x$use_timerfd" != xno; then
235                 AC_CHECK_HEADER([sys/timerfd.h], [timerfd_h=yes], [timerfd_h=no])
236                 if test "x$timerfd_h" = xyes; then
237                         AC_CHECK_DECLS([TFD_NONBLOCK, TFD_CLOEXEC], [timerfd_h_ok=yes], [timerfd_h_ok=no], [[#include <sys/timerfd.h>]])
238                         if test "x$timerfd_h_ok" = xyes; then
239                                 AC_CHECK_FUNC([timerfd_create], [timerfd_ok=yes], [timerfd_ok=no])
240                                 if test "x$timerfd_ok" = xyes; then
241                                         AC_DEFINE([HAVE_TIMERFD], [1], [Define if the system has timerfd functionality])
242                                 elif test "x$use_timerfd" = xyes; then
243                                         AC_MSG_ERROR([timerfd_create() function not found; glibc 2.9+ required])
244                                 fi
245                         elif test "x$use_timerfd" = xyes; then
246                                 AC_MSG_ERROR([timerfd header not usable; glibc 2.9+ required])
247                         fi
248                 elif test "x$use_timerfd" = xyes; then
249                         AC_MSG_ERROR([timerfd header not available; glibc 2.9+ required])
250                 fi
251         fi
252         AC_MSG_CHECKING([whether to use timerfd for timing])
253         if test "x$use_timerfd" = xno; then
254                 AC_MSG_RESULT([no (disabled by user)])
255         elif test "x$timerfd_h" = xno; then
256                 AC_MSG_RESULT([no (header not usable)])
257         elif test "x$timerfd_h_ok" = xno; then
258                 AC_MSG_RESULT([no (header not available)])
259         elif test "x$timerfd_ok" = xno; then
260                 AC_MSG_RESULT([no (functions not available)])
261         else
262                 AC_MSG_RESULT([yes])
263         fi
264 fi
265
266 dnl Message logging
267 AC_ARG_ENABLE([log],
268         [AS_HELP_STRING([--disable-log], [disable all logging])],
269         [log_enabled=$enableval],
270         [log_enabled=yes])
271 if test "x$log_enabled" != xno; then
272         AC_DEFINE([ENABLE_LOGGING], [1], [Message logging])
273 fi
274
275 AC_ARG_ENABLE([debug-log],
276         [AS_HELP_STRING([--enable-debug-log], [start with debug message logging enabled [default=no]])],
277         [debug_log_enabled=$enableval],
278         [debug_log_enabled=no])
279 if test "x$debug_log_enabled" != xno; then
280         AC_DEFINE([ENABLE_DEBUG_LOGGING], [1], [Start with debug message logging enabled])
281 fi
282
283 AC_ARG_ENABLE([system-log],
284         [AS_HELP_STRING([--enable-system-log], [output logging messages to system wide log, if supported by the OS [default=no]])],
285         [system_log_enabled=$enableval],
286         [system_log_enabled=no])
287 if test "x$system_log_enabled" != xno; then
288         AC_DEFINE([USE_SYSTEM_LOGGING_FACILITY], [1], [Enable output to system log])
289         if test "x$backend" != xwindows && test "x$is_backend_android" != xyes; then
290                 dnl Check if syslog is available in standard C library
291                 AC_CHECK_HEADER([syslog.h], [syslog_h=yes], [syslog_h=no])
292                 if test "x$syslog_h" = xyes; then
293                         AC_CHECK_FUNCS([syslog])
294                 fi
295         fi
296 fi
297
298 dnl Examples build
299 AC_ARG_ENABLE([examples-build],
300         [AS_HELP_STRING([--enable-examples-build], [build example applications [default=no]])],
301         [build_examples=$enableval],
302         [build_examples=no])
303 AM_CONDITIONAL([BUILD_EXAMPLES], [test "x$build_examples" != xno])
304
305 dnl Tests build
306 AC_ARG_ENABLE([tests-build],
307         [AS_HELP_STRING([--enable-tests-build], [build test applications [default=no]])],
308         [build_tests=$enableval],
309         [build_tests=no])
310 AM_CONDITIONAL([BUILD_TESTS], [test "x$build_tests" != xno])
311
312 dnl sigaction needed for some example programs
313 if test "x$build_examples" != xno; then
314         AC_CHECK_FUNC([sigaction], [have_sigaction=yes], [have_sigaction=no])
315 fi
316 AM_CONDITIONAL([HAVE_SIGACTION], [test "x$have_sigaction" = xyes])
317
318 dnl check for -fvisibility=hidden compiler support (GCC >= 3.4)
319 saved_CFLAGS="${CFLAGS}"
320 dnl -Werror required for cygwin
321 CFLAGS="${CFLAGS} -Werror -fvisibility=hidden"
322 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
323         [VISIBILITY_CFLAGS="-fvisibility=hidden"
324          AC_DEFINE([DEFAULT_VISIBILITY], [__attribute__((visibility("default")))], [Default visibility])],
325         [VISIBILITY_CFLAGS=""
326          AC_DEFINE([DEFAULT_VISIBILITY], [], [Default visibility])],
327         ])
328 CFLAGS="${saved_CFLAGS}"
329
330 dnl check for -Wno-pointer-sign compiler support (GCC >= 4)
331 saved_CFLAGS="${CFLAGS}"
332 CFLAGS="${CFLAGS} -Wno-pointer-sign"
333 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
334         nopointersign_cflags="-Wno-pointer-sign", nopointersign_cflags="")
335 CFLAGS="${saved_CFLAGS}"
336
337 dnl check for -std=gnu11 compiler support
338 saved_CFLAGS="${CFLAGS}"
339 CFLAGS="-std=gnu11"
340 AC_MSG_CHECKING([whether CC supports -std=gnu11])
341 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
342         [AC_MSG_RESULT([yes])
343          AM_CFLAGS="${AM_CFLAGS} -std=gnu11"],
344         [AC_MSG_RESULT([no])])
345 CFLAGS="${saved_CFLAGS}"
346
347 dnl check for _Thread_local compiler support
348 if test "x$backend" != xwindows; then
349         saved_CFLAGS="${CFLAGS}"
350         saved_LDFLAGS="${LDFLAGS}"
351         CFLAGS="${CFLAGS} -fPIC"
352         LDFLAGS="${LDFLAGS} -shared"
353         AC_MSG_CHECKING([whether CC supports _Thread_local])
354         AC_LINK_IFELSE([AC_LANG_PROGRAM([], [static _Thread_local int v])],
355                 [AC_MSG_RESULT([yes])
356                  AC_DEFINE([HAVE_CC_THREAD_LOCAL], [1], [Define to 1 if the compiler supports _Thread_local.])],
357                 [AC_MSG_RESULT([no])])
358         CFLAGS="${saved_CFLAGS}"
359         LDFLAGS="${saved_LDFLAGS}"
360 fi
361
362 AM_CFLAGS="${AM_CFLAGS} -Wall -Wundef -Wunused -Wstrict-prototypes -Werror-implicit-function-declaration ${nopointersign_cflags} -Wshadow ${THREAD_CFLAGS} ${VISIBILITY_CFLAGS}"
363
364 AC_SUBST(AM_CFLAGS)
365 AC_SUBST(LTLDFLAGS)
366
367 dnl set name of html output directory for doxygen
368 AC_SUBST(DOXYGEN_HTMLDIR, [api-1.0])
369
370 AC_CONFIG_FILES([libusb-1.0.pc])
371 AC_CONFIG_FILES([Makefile])
372 AC_CONFIG_FILES([libusb/Makefile])
373 AC_CONFIG_FILES([examples/Makefile])
374 AC_CONFIG_FILES([tests/Makefile])
375 AC_CONFIG_FILES([doc/Makefile])
376 AC_CONFIG_FILES([doc/doxygen.cfg])
377 AC_OUTPUT