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
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])
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])
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
27 LTLDFLAGS="-version-info ${lt_current}:${lt_revision}:${lt_age}"
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])])
40 LT_LANG([Windows Resource])
43 AC_DEFINE([_GNU_SOURCE], [1], [Use GNU extensions])
45 LTLDFLAGS="${LTLDFLAGS} -no-undefined"
47 AC_MSG_CHECKING([operating system])
50 AC_MSG_RESULT([Darwin/Mac OS X])
56 AC_MSG_RESULT([Haiku])
61 *-linux* | *-uclinux*)
62 dnl on linux-android platform, some functions are in different places
65 AC_MSG_RESULT([Linux (Android system)])
66 is_backend_android=yes
69 AC_MSG_RESULT([Linux])
78 AC_MSG_RESULT([NetBSD])
84 AC_MSG_RESULT([OpenBSD])
90 AC_MSG_RESULT([SunOS])
96 AC_MSG_RESULT([Windows (using Cygwin)])
102 AC_MSG_RESULT([Windows])
106 test "x$enable_shared" = xyes && create_import_lib=yes
107 AM_CFLAGS="${AM_CFLAGS} -fno-omit-frame-pointer"
110 AC_MSG_RESULT([Null])
119 AC_CHECK_FUNCS([pthread_threadid_np])
120 LIBS="-lobjc -Wl,-framework,IOKit -Wl,-framework,CoreFoundation"
121 LTLDFLAGS="${LTLDFLAGS} -Wl,-prebind"
127 AC_SEARCH_LIBS([clock_gettime], [rt], [], [], [-pthread])
128 AC_ARG_ENABLE([udev],
129 [AC_HELP_STRING([--enable-udev], [use udev for device enumeration and hotplug support (recommended) [default=yes]])],
130 [], [enable_udev=yes])
131 if test "x$enable_udev" = xyes ; then
132 dnl system has udev. use it or fail!
133 AC_CHECK_HEADER([libudev.h], [], [AC_MSG_ERROR([udev support requested but libudev header not installed])])
134 AC_CHECK_LIB([udev], [udev_new], [], [AC_MSG_ERROR([udev support requested but libudev not installed])])
136 AC_CHECK_HEADERS([asm/types.h])
137 AC_CHECK_HEADER([linux/netlink.h], [], [AC_MSG_ERROR([Linux netlink header not found])])
138 AC_CHECK_HEADER([sys/socket.h], [], [AC_MSG_ERROR([Linux socket header not found])])
140 if test "x$is_backend_android" != xyes; then
141 THREAD_CFLAGS="-pthread"
142 LIBS="${LIBS} -pthread"
144 AC_CHECK_FUNCS([pthread_setname_np])
147 THREAD_CFLAGS="-pthread"
151 THREAD_CFLAGS="-pthread"
155 THREAD_CFLAGS="-pthread"
159 THREAD_CFLAGS="-pthread"
160 LIBS="-pthread -ldevinfo"
163 AC_CHECK_TYPES([struct timespec], [], [], [[#include <time.h>]])
165 LTLDFLAGS="${LTLDFLAGS} -avoid-version -Wl,--add-stdcall-alias"
166 AC_DEFINE([_WIN32_WINNT], [_WIN32_WINNT_VISTA], [Oldest Windows version supported (Vista)])
169 AC_MSG_ERROR([Unknown backend])
175 AM_CONDITIONAL([OS_DARWIN], [test "x$backend" = xdarwin])
176 AM_CONDITIONAL([OS_HAIKU], [test "x$backend" = xhaiku])
177 AM_CONDITIONAL([OS_LINUX], [test "x$backend" = xlinux])
178 AM_CONDITIONAL([OS_NETBSD], [test "x$backend" = xnetbsd])
179 AM_CONDITIONAL([OS_NULL], [test "x$backend" = xnull])
180 AM_CONDITIONAL([OS_OPENBSD], [test "x$backend" = xopenbsd])
181 AM_CONDITIONAL([OS_SUNOS], [test "x$backend" = xsunos])
182 AM_CONDITIONAL([OS_WINDOWS], [test "x$backend" = xwindows])
183 AM_CONDITIONAL([POLL_POSIX], [test "x$poll" = xposix])
184 AM_CONDITIONAL([POLL_WINDOWS], [test "x$poll" = xwindows])
185 AM_CONDITIONAL([THREADS_POSIX], [test "x$threads" = xposix])
186 AM_CONDITIONAL([THREADS_WINDOWS], [test "x$threads" = xwindows])
187 AM_CONDITIONAL([CREATE_IMPORT_LIB], [test "x$create_import_lib" = xyes])
188 AM_CONDITIONAL([USE_UDEV], [test "x$enable_udev" = xyes])
190 if test "x$poll" = xposix; then
191 AC_DEFINE([POLL_POSIX], [1], [Use POSIX poll() implementation])
192 AC_CHECK_TYPES([nfds_t], [], [], [[#include <poll.h>]])
193 AC_CHECK_FUNCS([pipe2])
194 elif test "x$poll" = xwindows; then
195 AC_DEFINE([POLL_WINDOWS], [1], [Use Windows poll() implementation])
197 AC_MSG_ERROR([Unknown poll implementation])
200 if test "x$threads" = xposix; then
201 AC_DEFINE([THREADS_POSIX], [1], [Use POSIX Threads])
202 elif test "x$threads" = xwindows; then
203 AC_DEFINE([THREADS_WINDOWS], [1], [Use Windows Threads])
205 AC_MSG_ERROR([Unknown threads implementation])
208 dnl headers not available on all platforms but required on others
209 AC_CHECK_HEADERS([sys/time.h])
211 dnl the clock_gettime() function needs certain clock IDs defined
212 AC_CHECK_FUNCS([clock_gettime], [have_clock_gettime=yes], [have_clockgettime=no])
213 if test "x$have_clock_gettime" = xyes; then
214 AC_CHECK_DECL([CLOCK_REALTIME], [], [AC_MSG_ERROR([C library headers missing definition for CLOCK_REALTIME])], [[#include <time.h>]])
215 AC_CHECK_DECL([CLOCK_MONOTONIC], [], [AC_MSG_ERROR([C library headers missing definition for CLOCK_MONOTONIC])], [[#include <time.h>]])
216 elif test "x$backend" != xdarwin && test "x$backend" != xwindows; then
217 AC_MSG_ERROR([clock_gettime() is required on this platform])
221 if test "x$backend" = xlinux || test "x$backend" = xsunos; then
222 AC_ARG_ENABLE([timerfd],
223 [AS_HELP_STRING([--enable-timerfd], [use timerfd for timing [default=auto]])],
224 [use_timerfd=$enableval],
226 if test "x$use_timerfd" != xno; then
227 AC_CHECK_HEADER([sys/timerfd.h], [timerfd_h=yes], [timerfd_h=no])
228 if test "x$timerfd_h" = xyes; then
229 AC_CHECK_DECLS([TFD_NONBLOCK, TFD_CLOEXEC], [timerfd_h_ok=yes], [timerfd_h_ok=no], [[#include <sys/timerfd.h>]])
230 if test "x$timerfd_h_ok" = xyes; then
231 AC_CHECK_FUNC([timerfd_create], [timerfd_ok=yes], [timerfd_ok=no])
232 if test "x$timerfd_ok" = xyes; then
233 AC_DEFINE([HAVE_TIMERFD], [1], [Define if the system has timerfd functionality])
234 elif test "x$use_timerfd" = xyes; then
235 AC_MSG_ERROR([timerfd_create() function not found; glibc 2.9+ required])
237 elif test "x$use_timerfd" = xyes; then
238 AC_MSG_ERROR([timerfd header not usable; glibc 2.9+ required])
240 elif test "x$use_timerfd" = xyes; then
241 AC_MSG_ERROR([timerfd header not available; glibc 2.9+ required])
244 AC_MSG_CHECKING([whether to use timerfd for timing])
245 if test "x$use_timerfd" = xno; then
246 AC_MSG_RESULT([no (disabled by user)])
247 elif test "x$timerfd_h" = xno; then
248 AC_MSG_RESULT([no (header not usable)])
249 elif test "x$timerfd_h_ok" = xno; then
250 AC_MSG_RESULT([no (header not available)])
251 elif test "x$timerfd_ok" = xno; then
252 AC_MSG_RESULT([no (functions not available)])
260 [AS_HELP_STRING([--disable-log], [disable all logging])],
261 [log_enabled=$enableval],
263 if test "x$log_enabled" != xno; then
264 AC_DEFINE([ENABLE_LOGGING], [1], [Message logging])
267 AC_ARG_ENABLE([debug-log],
268 [AS_HELP_STRING([--enable-debug-log], [start with debug message logging enabled [default=no]])],
269 [debug_log_enabled=$enableval],
270 [debug_log_enabled=no])
271 if test "x$debug_log_enabled" != xno; then
272 AC_DEFINE([ENABLE_DEBUG_LOGGING], [1], [Start with debug message logging enabled])
275 AC_ARG_ENABLE([system-log],
276 [AS_HELP_STRING([--enable-system-log], [output logging messages to system wide log, if supported by the OS [default=no]])],
277 [system_log_enabled=$enableval],
278 [system_log_enabled=no])
279 if test "x$system_log_enabled" != xno; then
280 AC_DEFINE([USE_SYSTEM_LOGGING_FACILITY], [1], [Enable output to system log])
281 if test "x$backend" != xwindows && test "x$is_backend_android" != xyes; then
282 dnl Check if syslog is available in standard C library
283 AC_CHECK_HEADER([syslog.h], [syslog_h=yes], [syslog_h=no])
284 if test "x$syslog_h" = xyes; then
285 AC_CHECK_FUNCS([syslog])
291 AC_ARG_ENABLE([examples-build],
292 [AS_HELP_STRING([--enable-examples-build], [build example applications [default=no]])],
293 [build_examples=$enableval],
295 AM_CONDITIONAL([BUILD_EXAMPLES], [test "x$build_examples" != xno])
298 AC_ARG_ENABLE([tests-build],
299 [AS_HELP_STRING([--enable-tests-build], [build test applications [default=no]])],
300 [build_tests=$enableval],
302 AM_CONDITIONAL([BUILD_TESTS], [test "x$build_tests" != xno])
304 dnl sigaction needed for some example programs
305 if test "x$build_examples" != xno; then
306 AC_CHECK_FUNC([sigaction], [have_sigaction=yes], [have_sigaction=no])
308 AM_CONDITIONAL([HAVE_SIGACTION], [test "x$have_sigaction" = xyes])
310 dnl check for -fvisibility=hidden compiler support (GCC >= 3.4)
311 saved_CFLAGS="${CFLAGS}"
312 dnl -Werror required for cygwin
313 CFLAGS="${CFLAGS} -Werror -fvisibility=hidden"
314 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
315 [VISIBILITY_CFLAGS="-fvisibility=hidden"
316 AC_DEFINE([DEFAULT_VISIBILITY], [__attribute__((visibility("default")))], [Default visibility])],
317 [VISIBILITY_CFLAGS=""
318 AC_DEFINE([DEFAULT_VISIBILITY], [], [Default visibility])],
320 CFLAGS="${saved_CFLAGS}"
322 dnl check for -Wno-pointer-sign compiler support (GCC >= 4)
323 saved_CFLAGS="${CFLAGS}"
324 CFLAGS="${CFLAGS} -Wno-pointer-sign"
325 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
326 nopointersign_cflags="-Wno-pointer-sign", nopointersign_cflags="")
327 CFLAGS="${saved_CFLAGS}"
329 dnl check for -std=gnu11 compiler support
330 saved_CFLAGS="${CFLAGS}"
332 AC_MSG_CHECKING([whether CC supports -std=gnu11])
333 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
334 [AC_MSG_RESULT([yes])
335 AM_CFLAGS="${AM_CFLAGS} -std=gnu11"],
336 [AC_MSG_RESULT([no])])
337 CFLAGS="${saved_CFLAGS}"
339 dnl check for _Thread_local compiler support
340 if test "x$backend" != xwindows; then
341 saved_CFLAGS="${CFLAGS}"
342 saved_LDFLAGS="${LDFLAGS}"
343 CFLAGS="${CFLAGS} -fPIC"
344 LDFLAGS="${LDFLAGS} -shared"
345 AC_MSG_CHECKING([whether CC supports _Thread_local])
346 AC_LINK_IFELSE([AC_LANG_PROGRAM([], [static _Thread_local int v])],
347 [AC_MSG_RESULT([yes])
348 AC_DEFINE([HAVE_CC_THREAD_LOCAL], [1], [Define to 1 if the compiler supports _Thread_local.])],
349 [AC_MSG_RESULT([no])])
350 CFLAGS="${saved_CFLAGS}"
351 LDFLAGS="${saved_LDFLAGS}"
354 AM_CFLAGS="${AM_CFLAGS} -Wall -Wundef -Wunused -Wstrict-prototypes -Werror-implicit-function-declaration ${nopointersign_cflags} -Wshadow ${THREAD_CFLAGS} ${VISIBILITY_CFLAGS}"
359 dnl set name of html output directory for doxygen
360 AC_SUBST(DOXYGEN_HTMLDIR, [api-1.0])
362 AC_CONFIG_FILES([libusb-1.0.pc])
363 AC_CONFIG_FILES([Makefile])
364 AC_CONFIG_FILES([libusb/Makefile])
365 AC_CONFIG_FILES([examples/Makefile])
366 AC_CONFIG_FILES([tests/Makefile])
367 AC_CONFIG_FILES([doc/Makefile])
368 AC_CONFIG_FILES([doc/doxygen.cfg])