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([libusbx],[LIBUSB_MAJOR[.]LIBUSB_MINOR[.]LIBUSB_MICRO[]LIBUSB_RC],[libusbx-devel@lists.sourceforge.net],[libusbx],[http://libusbx.org])
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])])
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])
51 AC_MSG_RESULT([Linux])
56 AC_MSG_RESULT([Darwin/Mac OS X])
61 AC_MSG_RESULT([OpenBSD])
66 AC_MSG_RESULT([NetBSD (using OpenBSD backend)])
71 AC_MSG_RESULT([Windows])
74 create_import_lib="yes"
75 AM_CFLAGS="${AM_CFLAGS} -fno-omit-frame-pointer"
78 AC_MSG_RESULT([Cygwin (using Windows backend)])
83 AC_MSG_ERROR([unsupported operating system])
88 AC_DEFINE(OS_LINUX, 1, [Linux backend])
90 AC_CHECK_LIB(rt, clock_gettime, PC_LIBS_PRIVATE="-lrt")
91 THREAD_CFLAGS="-pthread"
92 PC_LIBS_PRIVATE="${PC_LIBS_PRIVATE} -pthread"
93 AC_CHECK_HEADERS([poll.h])
94 AC_DEFINE([POLL_NFDS_TYPE],[nfds_t],[type of second poll() argument])
97 AC_DEFINE(OS_DARWIN, 1, [Darwin backend])
99 PC_LIBS_PRIVATE="-lobjc -Wl,-framework,IOKit -Wl,-framework,CoreFoundation"
100 LTLDFLAGS="${LTLDFLAGS} -Wl,-prebind"
101 AC_CHECK_HEADERS([poll.h])
102 AC_CHECK_TYPE([nfds_t],
103 [AC_DEFINE([POLL_NFDS_TYPE],[nfds_t],[type of second poll() argument])],
104 [AC_DEFINE([POLL_NFDS_TYPE],[unsigned int],[type of second poll() argument])],
108 AC_DEFINE(OS_OPENBSD, 1, [OpenBSD/NetBSD backend])
110 THREAD_CFLAGS="-pthread"
111 PC_LIBS_PRIVATE="-pthread"
112 AC_CHECK_HEADERS([poll.h])
113 AC_DEFINE([POLL_NFDS_TYPE],[nfds_t],[type of second poll() argument])
116 AC_DEFINE(OS_WINDOWS, 1, [Windows backend])
119 LTLDFLAGS="${LTLDFLAGS} -avoid-version -Wl,--add-stdcall-alias"
120 AC_DEFINE([POLL_NFDS_TYPE],[unsigned int],[type of second poll() argument])
124 AC_SUBST(THREAD_CFLAGS)
125 AC_SUBST(PC_LIBS_PRIVATE)
126 LIBS="${LIBS} ${PC_LIBS_PRIVATE}"
128 AM_CONDITIONAL(OS_LINUX, test "x$backend" = xlinux)
129 AM_CONDITIONAL(OS_DARWIN, test "x$backend" = xdarwin)
130 AM_CONDITIONAL(OS_OPENBSD, test "x$backend" = xbsd)
131 AM_CONDITIONAL(OS_WINDOWS, test "x$backend" = xwindows)
132 AM_CONDITIONAL(THREADS_POSIX, test "x$threads" = xposix)
133 AM_CONDITIONAL(CREATE_IMPORT_LIB, test "x$create_import_lib" = "xyes")
134 if test "$threads" = posix; then
135 AC_DEFINE(THREADS_POSIX, 1, [Use POSIX Threads])
139 AC_CHECK_HEADER([sys/timerfd.h], [timerfd_h=1], [timerfd_h=0])
140 AC_ARG_ENABLE([timerfd],
141 [AS_HELP_STRING([--enable-timerfd],
142 [use timerfd for timing (default auto)])],
143 [use_timerfd=$enableval], [use_timerfd='auto'])
145 if test "x$use_timerfd" = "xyes" -a "x$timerfd_h" = "x0"; then
146 AC_MSG_ERROR([timerfd header not available; glibc 2.9+ required])
149 AC_CHECK_DECL([TFD_NONBLOCK], [tfd_hdr_ok=yes], [tfd_hdr_ok=no], [#include <sys/timerfd.h>])
150 if test "x$use_timerfd" = "xyes" -a "x$tfd_hdr_ok" = "xno"; then
151 AC_MSG_ERROR([timerfd header not usable; glibc 2.9+ required])
154 AC_MSG_CHECKING([whether to use timerfd for timing])
155 if test "x$use_timerfd" = "xno"; then
156 AC_MSG_RESULT([no (disabled by user)])
158 if test "x$timerfd_h" = "x1" -a "x$tfd_hdr_ok" = "xyes"; then
160 AC_DEFINE(USBI_TIMERFD_AVAILABLE, 1, [timerfd headers available])
162 AC_MSG_RESULT([no (header not available)])
166 AC_CHECK_TYPES(struct timespec)
169 AC_ARG_ENABLE([log], [AS_HELP_STRING([--disable-log], [disable all logging])],
170 [log_enabled=$enableval],
172 if test "x$log_enabled" != "xno"; then
173 AC_DEFINE([ENABLE_LOGGING], 1, [Message logging])
176 AC_ARG_ENABLE([debug-log], [AS_HELP_STRING([--enable-debug-log],
177 [start with debug message logging enabled (default n)])],
178 [debug_log_enabled=$enableval],
179 [debug_log_enabled='no'])
180 if test "x$debug_log_enabled" != "xno"; then
181 AC_DEFINE([ENABLE_DEBUG_LOGGING], 1, [Start with debug message logging enabled])
185 AC_ARG_ENABLE([examples-build], [AS_HELP_STRING([--enable-examples-build],
186 [build example applications (default n)])],
187 [build_examples=$enableval],
188 [build_examples='no'])
189 AM_CONDITIONAL([BUILD_EXAMPLES], [test "x$build_examples" != "xno"])
191 # check for -fvisibility=hidden compiler support (GCC >= 3.4)
192 saved_cflags="$CFLAGS"
193 # -Werror required for cygwin
194 CFLAGS="$CFLAGS -Werror -fvisibility=hidden"
195 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
196 [VISIBILITY_CFLAGS="-fvisibility=hidden"
197 AC_DEFINE([DEFAULT_VISIBILITY], [__attribute__((visibility("default")))], [Default visibility]) ],
198 [ VISIBILITY_CFLAGS=""
199 AC_DEFINE([DEFAULT_VISIBILITY], [], [Default visibility]) ],
201 CFLAGS="$saved_cflags"
203 # check for -Wno-pointer-sign compiler support (GCC >= 4)
204 saved_cflags="$CFLAGS"
205 CFLAGS="$CFLAGS -Wno-pointer-sign"
206 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
207 nopointersign_cflags="-Wno-pointer-sign", nopointersign_cflags="")
208 CFLAGS="$saved_cflags"
210 # sigaction not available on MinGW
211 AC_CHECK_FUNC([sigaction], [have_sigaction=yes], [have_sigaction=no])
212 AM_CONDITIONAL([HAVE_SIGACTION], [test "x$have_sigaction" = "xyes"])
214 # headers not available on all platforms but required on others
215 AC_CHECK_HEADERS([sys/time.h])
216 AC_CHECK_FUNCS(gettimeofday)
218 AM_CFLAGS="${AM_CFLAGS} -std=gnu99 -Wall -Wundef -Wunused -Wstrict-prototypes -Werror-implicit-function-declaration $nopointersign_cflags -Wshadow"
220 AC_SUBST(VISIBILITY_CFLAGS)
224 AC_CONFIG_FILES([libusb-1.0.pc])
225 AC_CONFIG_FILES([Makefile])
226 AC_CONFIG_FILES([libusb/Makefile])
227 AC_CONFIG_FILES([examples/Makefile])
228 AC_CONFIG_FILES([doc/Makefile])
229 AC_CONFIG_FILES([doc/doxygen.cfg])