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}"
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])
49 dnl on linux-android platform, some functions are in different places
52 AC_MSG_RESULT([This is a Linux-Android system])
53 is_backend_android="yes"
56 is_backend_android="no"
60 *-linux* | *-uclinux*)
61 AC_MSG_RESULT([Linux])
66 AC_MSG_RESULT([Darwin/Mac OS X])
71 AC_MSG_RESULT([OpenBSD])
76 AC_MSG_RESULT([NetBSD])
81 AC_MSG_RESULT([Windows])
84 create_import_lib="yes"
85 AM_CFLAGS="${AM_CFLAGS} -fno-omit-frame-pointer"
88 AC_MSG_RESULT([Cygwin (using Windows backend)])
93 AC_MSG_RESULT([Haiku])
98 AC_MSG_RESULT([SunOS])
103 AC_MSG_ERROR([unsupported operating system $host])
108 AC_DEFINE(OS_LINUX, 1, [Linux backend])
110 AC_SEARCH_LIBS(clock_gettime, rt, [], [], -pthread)
111 AC_ARG_ENABLE([udev],
112 [AC_HELP_STRING([--enable-udev], [use udev for device enumeration and hotplug support (recommended) [default=yes]])],
113 [], [enable_udev="yes"])
114 if test "x$enable_udev" = "xyes" ; then
115 # system has udev. use it or fail!
116 AC_CHECK_HEADERS([libudev.h],[],[AC_ERROR(["udev support requested but libudev not installed"])])
117 AC_CHECK_LIB([udev], [udev_new], [], [AC_ERROR(["udev support requested but libudev not installed"])])
118 AC_DEFINE(USE_UDEV, 1, [Use udev for device enumeration/hotplug])
120 AC_CHECK_HEADERS([asm/types.h], [], [])
121 AC_CHECK_HEADERS([sys/socket.h linux/netlink.h], [], [AC_ERROR(["Linux netlink headers not found"])], [
122 #ifdef HAVE_ASM_TYPES_H
123 #include <asm/types.h>
125 #include <sys/socket.h>
130 if test "x$is_backend_android" != xyes; then
131 THREAD_CFLAGS="-pthread"
132 LIBS="${LIBS} -pthread"
135 AC_CHECK_HEADERS([poll.h])
136 AC_DEFINE([POLL_NFDS_TYPE],[nfds_t],[type of second poll() argument])
139 AC_DEFINE(OS_DARWIN, 1, [Darwin backend])
141 LIBS="-lobjc -Wl,-framework,IOKit -Wl,-framework,CoreFoundation"
142 LTLDFLAGS="${LTLDFLAGS} -Wl,-prebind"
143 AC_CHECK_HEADERS([poll.h])
144 AC_CHECK_TYPE([nfds_t],
145 [AC_DEFINE([POLL_NFDS_TYPE],[nfds_t],[type of second poll() argument])],
146 [AC_DEFINE([POLL_NFDS_TYPE],[unsigned int],[type of second poll() argument])],
150 AC_DEFINE(OS_OPENBSD, 1, [OpenBSD backend])
152 THREAD_CFLAGS="-pthread"
154 AC_CHECK_HEADERS([poll.h])
155 AC_DEFINE([POLL_NFDS_TYPE],[nfds_t],[type of second poll() argument])
158 AC_DEFINE(OS_SUNOS, 1, [SunOS backend])
160 THREAD_CFLAGS="-pthread"
161 LIBS="-pthread -ldevinfo"
162 AC_CHECK_HEADERS([poll.h])
163 AC_DEFINE([POLL_NFDS_TYPE],[nfds_t],[type of second poll() argument])
166 AC_DEFINE(OS_NETBSD, 1, [NetBSD backend])
168 THREAD_CFLAGS="-pthread"
170 AC_CHECK_HEADERS([poll.h])
171 AC_DEFINE([POLL_NFDS_TYPE],[nfds_t],[type of second poll() argument])
174 AC_DEFINE(OS_WINDOWS, 1, [Windows backend])
177 LTLDFLAGS="${LTLDFLAGS} -avoid-version -Wl,--add-stdcall-alias"
178 AC_DEFINE([POLL_NFDS_TYPE],[unsigned int],[type of second poll() argument])
179 AC_DEFINE([WINVER], 0x0501, [Oldest Windows version supported])
181 AC_ARG_ENABLE([usbdk],
182 [AC_HELP_STRING([--enable-usbdk], [use UsbDk Windows backend [default=no]])],
183 [], [enable_usbdk="no"])
184 if test "x$enable_usbdk" = xyes; then
185 AC_DEFINE(USE_USBDK, 1, [Use UsbDk Windows backend])
190 AC_DEFINE(OS_HAIKU, 1, [Haiku backend])
193 AC_CHECK_HEADERS([poll.h])
194 AC_DEFINE([POLL_NFDS_TYPE],[nfds_t],[type of second poll() argument])
200 AM_CONDITIONAL(OS_LINUX, test "x$backend" = xlinux)
201 AM_CONDITIONAL(OS_DARWIN, test "x$backend" = xdarwin)
202 AM_CONDITIONAL(OS_OPENBSD, test "x$backend" = xopenbsd)
203 AM_CONDITIONAL(OS_SUNOS, test "x$backend" = xsunos)
204 AM_CONDITIONAL(OS_NETBSD, test "x$backend" = xnetbsd)
205 AM_CONDITIONAL(OS_WINDOWS, test "x$backend" = xwindows)
206 AM_CONDITIONAL(OS_HAIKU, test "x$backend" = xhaiku)
207 AM_CONDITIONAL(THREADS_POSIX, test "x$threads" = xposix)
208 AM_CONDITIONAL(CREATE_IMPORT_LIB, test "x$create_import_lib" = xyes)
209 AM_CONDITIONAL(USE_UDEV, test "x$enable_udev" = xyes)
210 AM_CONDITIONAL(USE_USBDK, test "x$enable_usbdk" = xyes)
211 if test "$threads" = posix; then
212 AC_DEFINE(THREADS_POSIX, 1, [Use POSIX Threads])
216 AC_CHECK_HEADER([sys/timerfd.h], [timerfd_h=1], [timerfd_h=0])
217 AC_ARG_ENABLE([timerfd],
218 [AS_HELP_STRING([--enable-timerfd],
219 [use timerfd for timing [default=auto]])],
220 [use_timerfd=$enableval], [use_timerfd='auto'])
222 if test "x$use_timerfd" = xyes -a "x$timerfd_h" = x0; then
223 AC_MSG_ERROR([timerfd header not available; glibc 2.9+ required])
226 AC_CHECK_DECL([TFD_NONBLOCK], [tfd_hdr_ok=yes], [tfd_hdr_ok=no], [#include <sys/timerfd.h>])
227 if test "x$use_timerfd" = xyes -a "x$tfd_hdr_ok" = xno; then
228 AC_MSG_ERROR([timerfd header not usable; glibc 2.9+ required])
231 AC_MSG_CHECKING([whether to use timerfd for timing])
232 if test "x$use_timerfd" = xno; then
233 AC_MSG_RESULT([no (disabled by user)])
235 if test "x$timerfd_h" = x1 -a "x$tfd_hdr_ok" = xyes; then
237 AC_DEFINE(USBI_TIMERFD_AVAILABLE, 1, [timerfd headers available])
239 AC_MSG_RESULT([no (header not available)])
243 AC_CHECK_TYPES(struct timespec)
246 AC_ARG_ENABLE([log], [AS_HELP_STRING([--disable-log], [disable all logging])],
247 [log_enabled=$enableval],
249 if test "x$log_enabled" != xno; then
250 AC_DEFINE([ENABLE_LOGGING], 1, [Message logging])
253 AC_ARG_ENABLE([debug-log], [AS_HELP_STRING([--enable-debug-log],
254 [start with debug message logging enabled [default=no]])],
255 [debug_log_enabled=$enableval],
256 [debug_log_enabled='no'])
257 if test "x$debug_log_enabled" != xno; then
258 AC_DEFINE([ENABLE_DEBUG_LOGGING], 1, [Start with debug message logging enabled])
261 AC_ARG_ENABLE([system-log], [AS_HELP_STRING([--enable-system-log],
262 [output logging messages to system wide log, if supported by the OS [default=no]])],
263 [system_log_enabled=$enableval],
264 [system_log_enabled='no'])
265 if test "x$system_log_enabled" != xno; then
266 AC_DEFINE([USE_SYSTEM_LOGGING_FACILITY], 1, [Enable output to system log])
268 # Check if syslog is available in standard C library
269 AC_CHECK_HEADERS(syslog.h)
270 AC_CHECK_FUNC([syslog], [have_syslog=yes], [have_syslog=no])
271 if test "x$have_syslog" != xno; then
272 AC_DEFINE([HAVE_SYSLOG_FUNC], 1, [syslog() function available])
277 AC_ARG_ENABLE([examples-build], [AS_HELP_STRING([--enable-examples-build],
278 [build example applications [default=no]])],
279 [build_examples=$enableval],
280 [build_examples='no'])
281 AM_CONDITIONAL(BUILD_EXAMPLES, test "x$build_examples" != xno)
284 AC_ARG_ENABLE([tests-build], [AS_HELP_STRING([--enable-tests-build],
285 [build test applications [default=no]])],
286 [build_tests=$enableval],
288 AM_CONDITIONAL(BUILD_TESTS, test "x$build_tests" != xno)
290 # headers not available on all platforms but required on others
291 AC_CHECK_HEADERS([sys/time.h])
293 # sigaction not available on MinGW
294 AC_CHECK_FUNC([sigaction], [have_sigaction=yes], [have_sigaction=no])
295 AM_CONDITIONAL(HAVE_SIGACTION, test "x$have_sigaction" = xyes)
297 # check for -fvisibility=hidden compiler support (GCC >= 3.4)
298 saved_cflags="$CFLAGS"
299 # -Werror required for cygwin
300 CFLAGS="$CFLAGS -Werror -fvisibility=hidden"
301 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
302 [VISIBILITY_CFLAGS="-fvisibility=hidden"
303 AC_DEFINE([DEFAULT_VISIBILITY], [__attribute__((visibility("default")))], [Default visibility]) ],
304 [ VISIBILITY_CFLAGS=""
305 AC_DEFINE([DEFAULT_VISIBILITY], [], [Default visibility]) ],
307 CFLAGS="$saved_cflags"
309 # check for -Wno-pointer-sign compiler support (GCC >= 4)
310 saved_cflags="$CFLAGS"
311 CFLAGS="$CFLAGS -Wno-pointer-sign"
312 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
313 nopointersign_cflags="-Wno-pointer-sign", nopointersign_cflags="")
314 CFLAGS="$saved_cflags"
316 # check for -std=gnu99 compiler support
317 saved_cflags="$CFLAGS"
319 AC_MSG_CHECKING([whether CC supports -std=gnu99])
320 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
321 [AC_MSG_RESULT([yes])]
322 [AM_CFLAGS="${AM_CFLAGS} -std=gnu99"],
323 [AC_MSG_RESULT([no])]
325 CFLAGS="$saved_cflags"
327 AM_CFLAGS="${AM_CFLAGS} -Wall -Wundef -Wunused -Wstrict-prototypes -Werror-implicit-function-declaration $nopointersign_cflags -Wshadow ${THREAD_CFLAGS} ${VISIBILITY_CFLAGS}"
332 AC_CONFIG_FILES([libusb-1.0.pc])
333 AC_CONFIG_FILES([Makefile])
334 AC_CONFIG_FILES([libusb/Makefile])
335 AC_CONFIG_FILES([examples/Makefile])
336 AC_CONFIG_FILES([tests/Makefile])
337 AC_CONFIG_FILES([doc/Makefile])
338 AC_CONFIG_FILES([doc/doxygen.cfg])