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],[LIBUSB_MAJOR[.]LIBUSB_MINOR[.]LIBUSB_MICRO[]LIBUSB_RC],[libusb-devel@lists.sourceforge.net],[libusb],[http://libusb.info])
21 # These numbers should be tweaked on every release. Read carefully:
22 # http://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html
23 # http://sourceware.org/autobook/autobook/autobook_91.html
27 LTLDFLAGS="-version-info ${lt_current}:${lt_revision}:${lt_age}"
32 AC_CONFIG_SRCDIR([libusb/core.c])
33 AC_CONFIG_MACRO_DIR([m4])
34 AC_CONFIG_HEADERS([config.h])
35 m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])])
41 LT_LANG([Windows Resource])
44 AC_DEFINE([_GNU_SOURCE], 1, [Use GNU extensions])
46 LTLDFLAGS="${LTLDFLAGS} -no-undefined"
48 AC_MSG_CHECKING([operating system])
50 dnl on linux-android platform, some functions are in different places
53 AC_MSG_RESULT([This is a Linux-Android system])
54 is_backend_android="yes"
57 is_backend_android="no"
61 *-linux* | *-uclinux*)
62 AC_MSG_RESULT([Linux])
67 AC_MSG_RESULT([Darwin/Mac OS X])
72 AC_MSG_RESULT([OpenBSD])
77 AC_MSG_RESULT([NetBSD])
82 AC_MSG_RESULT([Windows])
85 create_import_lib="yes"
86 AM_CFLAGS="${AM_CFLAGS} -fno-omit-frame-pointer"
89 AC_MSG_RESULT([Cygwin (using Windows backend)])
94 AC_MSG_RESULT([Haiku])
99 AC_MSG_ERROR([unsupported operating system])
104 AC_DEFINE(OS_LINUX, 1, [Linux backend])
106 AC_SEARCH_LIBS(clock_gettime, rt, [], [], -pthread)
107 AC_ARG_ENABLE([udev],
108 [AC_HELP_STRING([--enable-udev], [use udev for device enumeration and hotplug support (recommended) [default=yes]])],
109 [], [enable_udev="yes"])
110 if test "x$enable_udev" = "xyes" ; then
111 # system has udev. use it or fail!
112 AC_CHECK_HEADERS([libudev.h],[],[AC_ERROR(["udev support requested but libudev not installed"])])
113 AC_CHECK_LIB([udev], [udev_new], [], [AC_ERROR(["udev support requested but libudev not installed"])])
114 AC_DEFINE(USE_UDEV, 1, [Use udev for device enumeration/hotplug])
116 AC_CHECK_HEADERS([asm/types.h sys/socket.h], [], [])
117 AC_CHECK_HEADERS([linux/netlink.h linux/filter.h], [], [AC_ERROR(["Linux netlink headers not found"])], [
118 #ifdef HAVE_ASM_TYPES_H
119 #include <asm/types.h>
121 #ifdef HAVE_SYS_SOCKET_H
122 #include <sys/socket.h>
128 case $is_backend_android in
130 dnl there are gettimeofday function but configure doesn't seem to be able to find it.
131 AC_DEFINE([HAVE_GETTIMEOFDAY], [1], [Define if you have gettimeofday])
134 THREAD_CFLAGS="-pthread"
135 LIBS="${LIBS} -pthread"
138 AC_CHECK_HEADERS([poll.h])
139 AC_DEFINE([POLL_NFDS_TYPE],[nfds_t],[type of second poll() argument])
142 AC_DEFINE(OS_DARWIN, 1, [Darwin backend])
144 LIBS="-lobjc -Wl,-framework,IOKit -Wl,-framework,CoreFoundation"
145 LTLDFLAGS="${LTLDFLAGS} -Wl,-prebind"
146 AC_CHECK_HEADERS([poll.h])
147 AC_CHECK_TYPE([nfds_t],
148 [AC_DEFINE([POLL_NFDS_TYPE],[nfds_t],[type of second poll() argument])],
149 [AC_DEFINE([POLL_NFDS_TYPE],[unsigned int],[type of second poll() argument])],
153 AC_DEFINE(OS_OPENBSD, 1, [OpenBSD backend])
155 THREAD_CFLAGS="-pthread"
157 AC_CHECK_HEADERS([poll.h])
158 AC_DEFINE([POLL_NFDS_TYPE],[nfds_t],[type of second poll() argument])
161 AC_DEFINE(OS_NETBSD, 1, [NetBSD backend])
163 THREAD_CFLAGS="-pthread"
165 AC_CHECK_HEADERS([poll.h])
166 AC_DEFINE([POLL_NFDS_TYPE],[nfds_t],[type of second poll() argument])
169 AC_DEFINE(OS_WINDOWS, 1, [Windows backend])
172 LTLDFLAGS="${LTLDFLAGS} -avoid-version -Wl,--add-stdcall-alias"
173 AC_DEFINE([POLL_NFDS_TYPE],[unsigned int],[type of second poll() argument])
174 AC_DEFINE([WINVER], 0x0501, [Oldest Windows version supported])
177 AC_DEFINE(OS_HAIKU, 1, [Haiku backend])
180 AC_CHECK_HEADERS([poll.h])
181 AC_DEFINE([POLL_NFDS_TYPE],[nfds_t],[type of second poll() argument])
187 AM_CONDITIONAL(OS_LINUX, test "x$backend" = xlinux)
188 AM_CONDITIONAL(OS_DARWIN, test "x$backend" = xdarwin)
189 AM_CONDITIONAL(OS_OPENBSD, test "x$backend" = xopenbsd)
190 AM_CONDITIONAL(OS_NETBSD, test "x$backend" = xnetbsd)
191 AM_CONDITIONAL(OS_WINDOWS, test "x$backend" = xwindows)
192 AM_CONDITIONAL(OS_HAIKU, test "x$backend" = xhaiku)
193 AM_CONDITIONAL(THREADS_POSIX, test "x$threads" = xposix)
194 AM_CONDITIONAL(CREATE_IMPORT_LIB, test "x$create_import_lib" = "xyes")
195 AM_CONDITIONAL(USE_UDEV, test "x$enable_udev" = xyes)
196 if test "$threads" = posix; then
197 AC_DEFINE(THREADS_POSIX, 1, [Use POSIX Threads])
201 AC_CHECK_HEADER([sys/timerfd.h], [timerfd_h=1], [timerfd_h=0])
202 AC_ARG_ENABLE([timerfd],
203 [AS_HELP_STRING([--enable-timerfd],
204 [use timerfd for timing [default=auto]])],
205 [use_timerfd=$enableval], [use_timerfd='auto'])
207 if test "x$use_timerfd" = "xyes" -a "x$timerfd_h" = "x0"; then
208 AC_MSG_ERROR([timerfd header not available; glibc 2.9+ required])
211 AC_CHECK_DECL([TFD_NONBLOCK], [tfd_hdr_ok=yes], [tfd_hdr_ok=no], [#include <sys/timerfd.h>])
212 if test "x$use_timerfd" = "xyes" -a "x$tfd_hdr_ok" = "xno"; then
213 AC_MSG_ERROR([timerfd header not usable; glibc 2.9+ required])
216 AC_MSG_CHECKING([whether to use timerfd for timing])
217 if test "x$use_timerfd" = "xno"; then
218 AC_MSG_RESULT([no (disabled by user)])
220 if test "x$timerfd_h" = "x1" -a "x$tfd_hdr_ok" = "xyes"; then
222 AC_DEFINE(USBI_TIMERFD_AVAILABLE, 1, [timerfd headers available])
224 AC_MSG_RESULT([no (header not available)])
228 AC_CHECK_TYPES(struct timespec)
231 AC_ARG_ENABLE([log], [AS_HELP_STRING([--disable-log], [disable all logging])],
232 [log_enabled=$enableval],
234 if test "x$log_enabled" != "xno"; then
235 AC_DEFINE([ENABLE_LOGGING], 1, [Message logging])
238 AC_ARG_ENABLE([debug-log], [AS_HELP_STRING([--enable-debug-log],
239 [start with debug message logging enabled [default=no]])],
240 [debug_log_enabled=$enableval],
241 [debug_log_enabled='no'])
242 if test "x$debug_log_enabled" != "xno"; then
243 AC_DEFINE([ENABLE_DEBUG_LOGGING], 1, [Start with debug message logging enabled])
246 AC_ARG_ENABLE([system-log], [AS_HELP_STRING([--enable-system-log],
247 [output logging messages to system wide log, if supported by the OS [default=no]])],
248 [system_log_enabled=$enableval],
249 [system_log_enabled='no'])
250 if test "x$system_log_enabled" != "xno"; then
251 AC_DEFINE([USE_SYSTEM_LOGGING_FACILITY], 1, [Enable output to system log])
254 # Check if syslog is available in standard C library
255 AC_CHECK_HEADERS(syslog.h)
256 AC_CHECK_FUNC([syslog], [have_syslog=yes], [have_syslog=no])
257 if test "x$have_syslog" != "xno"; then
258 AC_DEFINE([HAVE_SYSLOG_FUNC], 1, [syslog() function available])
262 AC_ARG_ENABLE([examples-build], [AS_HELP_STRING([--enable-examples-build],
263 [build example applications [default=no]])],
264 [build_examples=$enableval],
265 [build_examples='no'])
266 AM_CONDITIONAL([BUILD_EXAMPLES], [test "x$build_examples" != "xno"])
269 AC_ARG_ENABLE([tests-build], [AS_HELP_STRING([--enable-tests-build],
270 [build test applications [default=no]])],
271 [build_tests=$enableval],
273 AM_CONDITIONAL([BUILD_TESTS], [test "x$build_tests" != "xno"])
275 # check for -fvisibility=hidden compiler support (GCC >= 3.4)
276 saved_cflags="$CFLAGS"
277 # -Werror required for cygwin
278 CFLAGS="$CFLAGS -Werror -fvisibility=hidden"
279 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
280 [VISIBILITY_CFLAGS="-fvisibility=hidden"
281 AC_DEFINE([DEFAULT_VISIBILITY], [__attribute__((visibility("default")))], [Default visibility]) ],
282 [ VISIBILITY_CFLAGS=""
283 AC_DEFINE([DEFAULT_VISIBILITY], [], [Default visibility]) ],
285 CFLAGS="$saved_cflags"
287 # check for -Wno-pointer-sign compiler support (GCC >= 4)
288 saved_cflags="$CFLAGS"
289 CFLAGS="$CFLAGS -Wno-pointer-sign"
290 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
291 nopointersign_cflags="-Wno-pointer-sign", nopointersign_cflags="")
292 CFLAGS="$saved_cflags"
294 # sigaction not available on MinGW
295 AC_CHECK_FUNC([sigaction], [have_sigaction=yes], [have_sigaction=no])
296 AM_CONDITIONAL([HAVE_SIGACTION], [test "x$have_sigaction" = "xyes"])
298 # headers not available on all platforms but required on others
299 AC_CHECK_HEADERS([sys/time.h])
300 AC_CHECK_FUNCS(gettimeofday)
301 AC_CHECK_HEADERS([signal.h])
303 # check for -std=gnu99 compiler support
304 saved_cflags="$CFLAGS"
306 AC_MSG_CHECKING([whether CC supports -std=gnu99])
307 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
308 [AC_MSG_RESULT([yes])]
309 [AM_CFLAGS="${AM_CFLAGS} -std=gnu99"],
310 [AC_MSG_RESULT([no])]
312 CFLAGS="$saved_cflags"
314 AM_CFLAGS="${AM_CFLAGS} -Wall -Wundef -Wunused -Wstrict-prototypes -Werror-implicit-function-declaration $nopointersign_cflags -Wshadow ${THREAD_CFLAGS} ${VISIBILITY_CFLAGS}"
319 AC_CONFIG_FILES([libusb-1.0.pc])
320 AC_CONFIG_FILES([Makefile])
321 AC_CONFIG_FILES([libusb/Makefile])
322 AC_CONFIG_FILES([examples/Makefile])
323 AC_CONFIG_FILES([tests/Makefile])
324 AC_CONFIG_FILES([doc/Makefile])
325 AC_CONFIG_FILES([doc/doxygen.cfg])