core: Improve error / debug messages for hotplug pipe handling
[libusbx.git] / configure.ac
blob6d6b35d6e41408af2319d306c05390af87871f39
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.
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])
20 # Library versioning
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
24 lt_current="1"
25 lt_revision="0"
26 lt_age="1"
27 LTLDFLAGS="-version-info ${lt_current}:${lt_revision}:${lt_age}"
29 AM_INIT_AUTOMAKE
30 AM_MAINTAINER_MODE
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])])
37 AC_PREREQ([2.50])
38 AC_PROG_CC
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])
45 LTLDFLAGS="${LTLDFLAGS} -no-undefined"
47 AC_MSG_CHECKING([operating system])
49 case $host in
50 *-linux*)
51         AC_MSG_RESULT([Linux])
52         backend="linux"
53         threads="posix"
54         ;;
55 *-darwin*)
56         AC_MSG_RESULT([Darwin/Mac OS X])
57         backend="darwin"
58         threads="posix"
59         ;;
60 *-openbsd*)
61         AC_MSG_RESULT([OpenBSD])
62         backend="bsd"
63         threads="posix"
64         ;;
65 *-netbsd*)
66         AC_MSG_RESULT([NetBSD (using OpenBSD backend)])
67         backend="bsd"
68         threads="posix"
69         ;;
70 *-mingw*)
71         AC_MSG_RESULT([Windows])
72         backend="windows"
73         threads="windows"
74         create_import_lib="yes"
75         AM_CFLAGS="${AM_CFLAGS} -fno-omit-frame-pointer"
76         ;;
77 *-cygwin*)
78         AC_MSG_RESULT([Cygwin (using Windows backend)])
79         backend="windows"
80         threads="posix"
81         ;;
83         AC_MSG_ERROR([unsupported operating system])
84 esac
86 case $backend in
87 linux)
88         AC_DEFINE(OS_LINUX, 1, [Linux backend])
89         AC_SUBST(OS_LINUX)
90         AC_SEARCH_LIBS(clock_gettime, rt, [], [], -pthread)
91         AC_ARG_ENABLE([udev],
92                 [AC_HELP_STRING([--enable-udev], [use udev for device enumeration and hotplug support (recommended, default: yes)])],
93                 [], [enable_udev="yes"])
94                 if test "x$enable_udev" = "xyes" ; then
95                         # system has udev. use it or fail!
96                         AC_CHECK_HEADERS([libudev.h],[],[AC_ERROR(["udev support requested but libudev not installed"])])
97                         AC_CHECK_LIB([udev], [udev_new], [], [AC_ERROR(["udev support requested but libudev not installed"])])
98                         AC_DEFINE(USE_UDEV, 1, [Use udev for device enumeration/hotplug])
99                 else
100                         AC_CHECK_HEADERS([linux/netlink.h linux/filter.h], [], [AC_ERROR(["Linux netlink headers not found"])])
101                 fi
102                 AC_SUBST(USE_UDEV)
103         THREAD_CFLAGS="-pthread"
104         LIBS="${LIBS} -pthread"
105         AC_CHECK_HEADERS([poll.h])
106         AC_DEFINE([POLL_NFDS_TYPE],[nfds_t],[type of second poll() argument])
107         ;;
108 darwin)
109         AC_DEFINE(OS_DARWIN, 1, [Darwin backend])
110         AC_SUBST(OS_DARWIN)
111         LIBS="-lobjc -Wl,-framework,IOKit -Wl,-framework,CoreFoundation"
112         LTLDFLAGS="${LTLDFLAGS} -Wl,-prebind"
113         AC_CHECK_HEADERS([poll.h])
114         AC_CHECK_TYPE([nfds_t],
115                 [AC_DEFINE([POLL_NFDS_TYPE],[nfds_t],[type of second poll() argument])],
116                 [AC_DEFINE([POLL_NFDS_TYPE],[unsigned int],[type of second poll() argument])],
117                 [#include <poll.h>])
118         ;;
119 bsd)
120         AC_DEFINE(OS_OPENBSD, 1, [OpenBSD/NetBSD backend])
121         AC_SUBST(OS_OPENBSD)
122         THREAD_CFLAGS="-pthread"
123         LIBS="-pthread"
124         AC_CHECK_HEADERS([poll.h])
125         AC_DEFINE([POLL_NFDS_TYPE],[nfds_t],[type of second poll() argument])
126         ;;
127 windows)
128         AC_DEFINE(OS_WINDOWS, 1, [Windows backend])
129         AC_SUBST(OS_WINDOWS)
130         LIBS=""
131         LTLDFLAGS="${LTLDFLAGS} -avoid-version -Wl,--add-stdcall-alias"
132         AC_DEFINE([POLL_NFDS_TYPE],[unsigned int],[type of second poll() argument])
133         ;;
134 esac
136 AC_SUBST(LIBS)
138 AM_CONDITIONAL(OS_LINUX, test "x$backend" = xlinux)
139 AM_CONDITIONAL(OS_DARWIN, test "x$backend" = xdarwin)
140 AM_CONDITIONAL(OS_OPENBSD, test "x$backend" = xbsd)
141 AM_CONDITIONAL(OS_WINDOWS, test "x$backend" = xwindows)
142 AM_CONDITIONAL(THREADS_POSIX, test "x$threads" = xposix)
143 AM_CONDITIONAL(CREATE_IMPORT_LIB, test "x$create_import_lib" = "xyes")
144 AM_CONDITIONAL(USE_UDEV, test "x$enable_udev" = xyes)
145 if test "$threads" = posix; then
146         AC_DEFINE(THREADS_POSIX, 1, [Use POSIX Threads])
149 # timerfd
150 AC_CHECK_HEADER([sys/timerfd.h], [timerfd_h=1], [timerfd_h=0])
151 AC_ARG_ENABLE([timerfd],
152         [AS_HELP_STRING([--enable-timerfd],
153                 [use timerfd for timing (default auto)])],
154         [use_timerfd=$enableval], [use_timerfd='auto'])
156 if test "x$use_timerfd" = "xyes" -a "x$timerfd_h" = "x0"; then
157         AC_MSG_ERROR([timerfd header not available; glibc 2.9+ required])
160 AC_CHECK_DECL([TFD_NONBLOCK], [tfd_hdr_ok=yes], [tfd_hdr_ok=no], [#include <sys/timerfd.h>])
161 if test "x$use_timerfd" = "xyes" -a "x$tfd_hdr_ok" = "xno"; then
162         AC_MSG_ERROR([timerfd header not usable; glibc 2.9+ required])
165 AC_MSG_CHECKING([whether to use timerfd for timing])
166 if test "x$use_timerfd" = "xno"; then
167         AC_MSG_RESULT([no (disabled by user)])
168 else
169         if test "x$timerfd_h" = "x1" -a "x$tfd_hdr_ok" = "xyes"; then
170                 AC_MSG_RESULT([yes])
171                 AC_DEFINE(USBI_TIMERFD_AVAILABLE, 1, [timerfd headers available])
172         else
173                 AC_MSG_RESULT([no (header not available)])
174         fi
177 AC_CHECK_TYPES(struct timespec)
179 # Message logging
180 AC_ARG_ENABLE([log], [AS_HELP_STRING([--disable-log], [disable all logging])],
181         [log_enabled=$enableval],
182         [log_enabled='yes'])
183 if test "x$log_enabled" != "xno"; then
184         AC_DEFINE([ENABLE_LOGGING], 1, [Message logging])
187 AC_ARG_ENABLE([debug-log], [AS_HELP_STRING([--enable-debug-log],
188         [start with debug message logging enabled (default n)])],
189         [debug_log_enabled=$enableval],
190         [debug_log_enabled='no'])
191 if test "x$debug_log_enabled" != "xno"; then
192         AC_DEFINE([ENABLE_DEBUG_LOGGING], 1, [Start with debug message logging enabled])
195 # Examples build
196 AC_ARG_ENABLE([examples-build], [AS_HELP_STRING([--enable-examples-build],
197         [build example applications (default n)])],
198         [build_examples=$enableval],
199         [build_examples='no'])
200 AM_CONDITIONAL([BUILD_EXAMPLES], [test "x$build_examples" != "xno"])
202 # Tests build
203 AC_ARG_ENABLE([tests-build], [AS_HELP_STRING([--enable-tests-build],
204         [build test applications (default n)])],
205         [build_tests=$enableval],
206         [build_tests='no'])
207 AM_CONDITIONAL([BUILD_TESTS], [test "x$build_tests" != "xno"])
209 # check for -fvisibility=hidden compiler support (GCC >= 3.4)
210 saved_cflags="$CFLAGS"
211 # -Werror required for cygwin
212 CFLAGS="$CFLAGS -Werror -fvisibility=hidden"
213 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
214         [VISIBILITY_CFLAGS="-fvisibility=hidden"
215          AC_DEFINE([DEFAULT_VISIBILITY], [__attribute__((visibility("default")))], [Default visibility]) ],
216         [ VISIBILITY_CFLAGS=""
217          AC_DEFINE([DEFAULT_VISIBILITY], [], [Default visibility]) ],
218         ])
219 CFLAGS="$saved_cflags"
221 # check for -Wno-pointer-sign compiler support (GCC >= 4)
222 saved_cflags="$CFLAGS"
223 CFLAGS="$CFLAGS -Wno-pointer-sign"
224 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
225         nopointersign_cflags="-Wno-pointer-sign", nopointersign_cflags="")
226 CFLAGS="$saved_cflags"
228 # sigaction not available on MinGW
229 AC_CHECK_FUNC([sigaction], [have_sigaction=yes], [have_sigaction=no])
230 AM_CONDITIONAL([HAVE_SIGACTION], [test "x$have_sigaction" = "xyes"])
232 # headers not available on all platforms but required on others
233 AC_CHECK_HEADERS([sys/time.h])
234 AC_CHECK_FUNCS(gettimeofday)
235 AC_CHECK_HEADERS([signal.h])
237 AM_CFLAGS="${AM_CFLAGS} -std=gnu99 -Wall -Wundef -Wunused -Wstrict-prototypes -Werror-implicit-function-declaration $nopointersign_cflags -Wshadow ${THREAD_CFLAGS} ${VISIBILITY_CFLAGS}"
239 AC_SUBST(AM_CFLAGS)
240 AC_SUBST(LTLDFLAGS)
242 AC_CONFIG_FILES([libusb-1.0.pc])
243 AC_CONFIG_FILES([Makefile])
244 AC_CONFIG_FILES([libusb/Makefile])
245 AC_CONFIG_FILES([examples/Makefile])
246 AC_CONFIG_FILES([tests/Makefile])
247 AC_CONFIG_FILES([doc/Makefile])
248 AC_CONFIG_FILES([doc/doxygen.cfg])
249 AC_OUTPUT