Core: Add a timestamping and thread ID to logging
[platform/upstream/libusb.git] / configure.ac
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().
12
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])
17
18 AC_INIT([libusbx], LIBUSB_MAJOR[.]LIBUSB_MINOR[.]LIBUSB_MICRO[]LIBUSB_RC, [libusbx-devel@lists.sourceforge.net], [libusbx], [http://www.libusbx.org/])
19
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}"
28
29 AM_INIT_AUTOMAKE
30 AM_MAINTAINER_MODE
31
32 AC_CONFIG_SRCDIR([libusb/core.c])
33 AC_CONFIG_MACRO_DIR([m4])
34 AM_CONFIG_HEADER([config.h])
35 m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])])
36
37 AC_PREREQ([2.50])
38 AC_PROG_CC
39 AC_PROG_LIBTOOL
40 LT_LANG([Windows Resource])
41 AC_C_INLINE
42 AM_PROG_CC_C_O
43 AC_DEFINE([_GNU_SOURCE], 1, [Use GNU extensions])
44
45 LTLDFLAGS="${LTLDFLAGS} -no-undefined"
46
47 AC_MSG_CHECKING([operating system])
48
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         ;;
75 *-cygwin*)
76         AC_MSG_RESULT([Cygwin (using Windows backend)])
77         backend="windows"
78         threads="posix"
79         ;;
80 *)
81         AC_MSG_ERROR([unsupported operating system])
82 esac
83
84 case $backend in
85 linux)
86         AC_DEFINE(OS_LINUX, 1, [Linux backend])
87         AC_SUBST(OS_LINUX)
88         AC_CHECK_LIB(rt, clock_gettime, PC_LIBS_PRIVATE="-lrt")
89         THREAD_CFLAGS="-pthread"
90         PC_LIBS_PRIVATE="${PC_LIBS_PRIVATE} -pthread"
91         AC_CHECK_HEADERS([poll.h])
92         AC_DEFINE([POLL_NFDS_TYPE],[nfds_t],[type of second poll() argument])
93         ;;
94 darwin)
95         AC_DEFINE(OS_DARWIN, 1, [Darwin backend])
96         AC_SUBST(OS_DARWIN)
97         PC_LIBS_PRIVATE="-lobjc -Wl,-framework,IOKit -Wl,-framework,CoreFoundation"
98         LTLDFLAGS="${LTLDFLAGS} -Wl,-prebind"
99         AC_CHECK_HEADERS([poll.h])
100         AC_CHECK_TYPE([nfds_t],
101                 [AC_DEFINE([POLL_NFDS_TYPE],[nfds_t],[type of second poll() argument])],
102                 [AC_DEFINE([POLL_NFDS_TYPE],[unsigned int],[type of second poll() argument])],
103                 [#include <poll.h>])
104         ;;
105 bsd)
106         AC_DEFINE(OS_OPENBSD, 1, [OpenBSD/NetBSD backend])
107         AC_SUBST(OS_OPENBSD)
108         THREAD_CFLAGS="-pthread"
109         PC_LIBS_PRIVATE="-pthread"
110         AC_CHECK_HEADERS([poll.h])
111         AC_DEFINE([POLL_NFDS_TYPE],[nfds_t],[type of second poll() argument])
112         ;;
113 windows)
114         AC_DEFINE(OS_WINDOWS, 1, [Windows backend])
115         AC_SUBST(OS_WINDOWS)
116         PC_LIBS_PRIVATE=""
117         LTLDFLAGS="${LTLDFLAGS} -avoid-version -Wl,--add-stdcall-alias"
118         AC_DEFINE([POLL_NFDS_TYPE],[unsigned int],[type of second poll() argument])
119         ;;
120 esac
121
122 AC_SUBST(THREAD_CFLAGS)
123 AC_SUBST(PC_LIBS_PRIVATE)
124 LIBS="${LIBS} ${PC_LIBS_PRIVATE}"
125
126 AM_CONDITIONAL(OS_LINUX, test "x$backend" = xlinux)
127 AM_CONDITIONAL(OS_DARWIN, test "x$backend" = xdarwin)
128 AM_CONDITIONAL(OS_OPENBSD, test "x$backend" = xbsd)
129 AM_CONDITIONAL(OS_WINDOWS, test "x$backend" = xwindows)
130 AM_CONDITIONAL(THREADS_POSIX, test "x$threads" = xposix)
131 if test "$threads" = posix; then
132         AC_DEFINE(THREADS_POSIX, 1, [Use POSIX Threads])
133 fi
134
135 # timerfd
136 AC_CHECK_HEADER([sys/timerfd.h], [timerfd_h=1], [timerfd_h=0])
137 AC_ARG_ENABLE([timerfd],
138         [AS_HELP_STRING([--enable-timerfd],
139                 [use timerfd for timing (default auto)])],
140         [use_timerfd=$enableval], [use_timerfd='auto'])
141
142 if test "x$use_timerfd" = "xyes" -a "x$timerfd_h" = "x0"; then
143         AC_MSG_ERROR([timerfd header not available; glibc 2.9+ required])
144 fi
145
146 AC_CHECK_DECL([TFD_NONBLOCK], [tfd_hdr_ok=yes], [tfd_hdr_ok=no], [#include <sys/timerfd.h>])
147 if test "x$use_timerfd" = "xyes" -a "x$tfd_hdr_ok" = "xno"; then
148         AC_MSG_ERROR([timerfd header not usable; glibc 2.9+ required])
149 fi
150
151 AC_MSG_CHECKING([whether to use timerfd for timing])
152 if test "x$use_timerfd" = "xno"; then
153         AC_MSG_RESULT([no (disabled by user)])
154 else
155         if test "x$timerfd_h" = "x1" -a "x$tfd_hdr_ok" = "xyes"; then
156                 AC_MSG_RESULT([yes])
157                 AC_DEFINE(USBI_TIMERFD_AVAILABLE, 1, [timerfd headers available])
158         else
159                 AC_MSG_RESULT([no (header not available)])
160         fi
161 fi
162
163 AC_CHECK_TYPES(struct timespec)
164
165 # Message logging
166 AC_ARG_ENABLE([log], [AS_HELP_STRING([--disable-log], [disable all logging])],
167         [log_enabled=$enableval],
168         [log_enabled='yes'])
169 if test "x$log_enabled" != "xno"; then
170         AC_DEFINE([ENABLE_LOGGING], 1, [Message logging])
171 fi
172
173 AC_ARG_ENABLE([debug-log], [AS_HELP_STRING([--enable-debug-log],
174         [enable debug logging (default n)])],
175         [debug_log_enabled=$enableval],
176         [debug_log_enabled='no'])
177 if test "x$debug_log_enabled" != "xno"; then
178         AC_DEFINE([ENABLE_DEBUG_LOGGING], 1, [Debug message logging])
179 fi
180
181 # Examples build
182 AC_ARG_ENABLE([examples-build], [AS_HELP_STRING([--enable-examples-build],
183         [build example applications (default n)])],
184         [build_examples=$enableval],
185         [build_examples='no'])
186 AM_CONDITIONAL([BUILD_EXAMPLES], [test "x$build_examples" != "xno"])
187
188 # check for -fvisibility=hidden compiler support (GCC >= 3.4)
189 saved_cflags="$CFLAGS"
190 # -Werror required for cygwin
191 CFLAGS="$CFLAGS -Werror -fvisibility=hidden"
192 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
193         [VISIBILITY_CFLAGS="-fvisibility=hidden"
194          AC_DEFINE([DEFAULT_VISIBILITY], [__attribute__((visibility("default")))], [Default visibility]) ],
195         [ VISIBILITY_CFLAGS=""
196          AC_DEFINE([DEFAULT_VISIBILITY], [], [Default visibility]) ],
197         ])
198 CFLAGS="$saved_cflags"
199
200 # check for -Wno-pointer-sign compiler support (GCC >= 4)
201 saved_cflags="$CFLAGS"
202 CFLAGS="$CFLAGS -Wno-pointer-sign"
203 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
204         nopointersign_cflags="-Wno-pointer-sign", nopointersign_cflags="")
205 CFLAGS="$saved_cflags"
206
207 # sigaction not available on MinGW
208 AC_CHECK_FUNC([sigaction], [have_sigaction=yes], [have_sigaction=no])
209 AM_CONDITIONAL([HAVE_SIGACTION], [test "x$have_sigaction" = "xyes"])
210
211 # headers not available on all platforms but required on others
212 AC_CHECK_HEADERS([sys/time.h])
213 AC_CHECK_FUNCS(gettimeofday)
214
215 AM_CFLAGS="-std=gnu99 -Wall -Wundef -Wunused -Wstrict-prototypes -Werror-implicit-function-declaration $nopointersign_cflags -Wshadow"
216
217 AC_SUBST(VISIBILITY_CFLAGS)
218 AC_SUBST(AM_CFLAGS)
219 AC_SUBST(LTLDFLAGS)
220
221 AC_CONFIG_FILES([libusb-1.0.pc])
222 AC_CONFIG_FILES([Makefile])
223 AC_CONFIG_FILES([libusb/Makefile])
224 AC_CONFIG_FILES([examples/Makefile])
225 AC_CONFIG_FILES([doc/Makefile])
226 AC_CONFIG_FILES([doc/doxygen.cfg])
227 AC_OUTPUT