linux_netlink: Remove unnecessary header includes and conditionals
[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([libusb],[LIBUSB_MAJOR[.]LIBUSB_MINOR[.]LIBUSB_MICRO[]LIBUSB_RC],[libusb-devel@lists.sourceforge.net],[libusb],[http://libusb.info])
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 AC_CONFIG_HEADERS([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_CXX
40 LT_INIT
41 LT_LANG([Windows Resource])
42 AC_C_INLINE
43 AM_PROG_CC_C_O
44 AC_DEFINE([_GNU_SOURCE], 1, [Use GNU extensions])
45
46 LTLDFLAGS="${LTLDFLAGS} -no-undefined"
47
48 AC_MSG_CHECKING([operating system])
49
50 dnl on linux-android platform, some functions are in different places
51 case $host in
52 *-linux-android*)
53         AC_MSG_RESULT([This is a Linux-Android system])
54         is_backend_android="yes"
55         ;;
56 *)
57         is_backend_android="no"
58 esac
59
60 case $host in
61 *-linux* | *-uclinux*)
62         AC_MSG_RESULT([Linux])
63         backend="linux"
64         threads="posix"
65         ;;
66 *-darwin*)
67         AC_MSG_RESULT([Darwin/Mac OS X])
68         backend="darwin"
69         threads="posix"
70         ;;
71 *-openbsd*)
72         AC_MSG_RESULT([OpenBSD])
73         backend="openbsd"
74         threads="posix"
75         ;;
76 *-netbsd*)
77         AC_MSG_RESULT([NetBSD])
78         backend="netbsd"
79         threads="posix"
80         ;;
81 *-mingw*)
82         AC_MSG_RESULT([Windows])
83         backend="windows"
84         threads="windows"
85         create_import_lib="yes"
86         AM_CFLAGS="${AM_CFLAGS} -fno-omit-frame-pointer"
87         ;;
88 *-cygwin*)
89         AC_MSG_RESULT([Cygwin (using Windows backend)])
90         backend="windows"
91         threads="posix"
92         ;;
93 *-haiku*)
94         AC_MSG_RESULT([Haiku])
95         backend="haiku"
96         threads="posix"
97         ;;
98 *)
99         AC_MSG_ERROR([unsupported operating system])
100 esac
101
102 case $backend in
103 linux)
104         AC_DEFINE(OS_LINUX, 1, [Linux backend])
105         AC_SUBST(OS_LINUX)
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])
115                 else
116                         AC_CHECK_HEADERS([asm/types.h], [], [])
117                         AC_CHECK_HEADERS([sys/socket.h linux/netlink.h], [], [AC_ERROR(["Linux netlink headers not found"])], [
118 #ifdef HAVE_ASM_TYPES_H
119 #include <asm/types.h>
120 #endif
121 #include <sys/socket.h>
122 ])
123                 fi
124                 AC_SUBST(USE_UDEV)
125
126 case $is_backend_android in
127 yes)
128         dnl there are gettimeofday function but configure doesn't seem to be able to find it.
129         AC_DEFINE([HAVE_GETTIMEOFDAY], [1], [Define if you have gettimeofday])
130         ;;
131 *)
132         THREAD_CFLAGS="-pthread"
133         LIBS="${LIBS} -pthread"
134 esac
135
136         AC_CHECK_HEADERS([poll.h])
137         AC_DEFINE([POLL_NFDS_TYPE],[nfds_t],[type of second poll() argument])
138         ;;
139 darwin)
140         AC_DEFINE(OS_DARWIN, 1, [Darwin backend])
141         AC_SUBST(OS_DARWIN)
142         LIBS="-lobjc -Wl,-framework,IOKit -Wl,-framework,CoreFoundation"
143         LTLDFLAGS="${LTLDFLAGS} -Wl,-prebind"
144         AC_CHECK_HEADERS([poll.h])
145         AC_CHECK_TYPE([nfds_t],
146                 [AC_DEFINE([POLL_NFDS_TYPE],[nfds_t],[type of second poll() argument])],
147                 [AC_DEFINE([POLL_NFDS_TYPE],[unsigned int],[type of second poll() argument])],
148                 [#include <poll.h>])
149         ;;
150 openbsd)
151         AC_DEFINE(OS_OPENBSD, 1, [OpenBSD backend])
152         AC_SUBST(OS_OPENBSD)
153         THREAD_CFLAGS="-pthread"
154         LIBS="-pthread"
155         AC_CHECK_HEADERS([poll.h])
156         AC_DEFINE([POLL_NFDS_TYPE],[nfds_t],[type of second poll() argument])
157         ;;
158 netbsd)
159         AC_DEFINE(OS_NETBSD, 1, [NetBSD backend])
160         AC_SUBST(OS_NETBSD)
161         THREAD_CFLAGS="-pthread"
162         LIBS="-pthread"
163         AC_CHECK_HEADERS([poll.h])
164         AC_DEFINE([POLL_NFDS_TYPE],[nfds_t],[type of second poll() argument])
165         ;;
166 windows)
167         AC_DEFINE(OS_WINDOWS, 1, [Windows backend])
168         AC_SUBST(OS_WINDOWS)
169         LIBS=""
170         LTLDFLAGS="${LTLDFLAGS} -avoid-version -Wl,--add-stdcall-alias"
171         AC_DEFINE([POLL_NFDS_TYPE],[unsigned int],[type of second poll() argument])
172         AC_DEFINE([WINVER], 0x0501, [Oldest Windows version supported])
173
174         AC_ARG_ENABLE([usbdk],
175                 [AC_HELP_STRING([--enable-usbdk], [use UsbDk Windows backend [default=no]])],
176                 [], [enable_usbdk="no"])
177                 if test "x$enable_usbdk" = "xyes" ; then
178                     AC_DEFINE(USE_USBDK, 1, [Use UsbDk Windows backend])
179                 fi
180                 AC_SUBST(USE_USBDK)
181         ;;
182 haiku)
183         AC_DEFINE(OS_HAIKU, 1, [Haiku backend])
184         AC_SUBST(OS_HAIKU)
185         LIBS="${LIBS} -lbe"
186         AC_CHECK_HEADERS([poll.h])
187         AC_DEFINE([POLL_NFDS_TYPE],[nfds_t],[type of second poll() argument])
188         ;;
189 esac
190
191 AC_SUBST(LIBS)
192
193 AM_CONDITIONAL(OS_LINUX, test "x$backend" = xlinux)
194 AM_CONDITIONAL(OS_DARWIN, test "x$backend" = xdarwin)
195 AM_CONDITIONAL(OS_OPENBSD, test "x$backend" = xopenbsd)
196 AM_CONDITIONAL(OS_NETBSD, test "x$backend" = xnetbsd)
197 AM_CONDITIONAL(OS_WINDOWS, test "x$backend" = xwindows)
198 AM_CONDITIONAL(OS_HAIKU, test "x$backend" = xhaiku)
199 AM_CONDITIONAL(THREADS_POSIX, test "x$threads" = xposix)
200 AM_CONDITIONAL(CREATE_IMPORT_LIB, test "x$create_import_lib" = "xyes")
201 AM_CONDITIONAL(USE_UDEV, test "x$enable_udev" = xyes)
202 AM_CONDITIONAL(USE_USBDK, test "x$enable_usbdk" = xyes)
203 if test "$threads" = posix; then
204         AC_DEFINE(THREADS_POSIX, 1, [Use POSIX Threads])
205 fi
206
207 # timerfd
208 AC_CHECK_HEADER([sys/timerfd.h], [timerfd_h=1], [timerfd_h=0])
209 AC_ARG_ENABLE([timerfd],
210         [AS_HELP_STRING([--enable-timerfd],
211                 [use timerfd for timing [default=auto]])],
212         [use_timerfd=$enableval], [use_timerfd='auto'])
213
214 if test "x$use_timerfd" = "xyes" -a "x$timerfd_h" = "x0"; then
215         AC_MSG_ERROR([timerfd header not available; glibc 2.9+ required])
216 fi
217
218 AC_CHECK_DECL([TFD_NONBLOCK], [tfd_hdr_ok=yes], [tfd_hdr_ok=no], [#include <sys/timerfd.h>])
219 if test "x$use_timerfd" = "xyes" -a "x$tfd_hdr_ok" = "xno"; then
220         AC_MSG_ERROR([timerfd header not usable; glibc 2.9+ required])
221 fi
222
223 AC_MSG_CHECKING([whether to use timerfd for timing])
224 if test "x$use_timerfd" = "xno"; then
225         AC_MSG_RESULT([no (disabled by user)])
226 else
227         if test "x$timerfd_h" = "x1" -a "x$tfd_hdr_ok" = "xyes"; then
228                 AC_MSG_RESULT([yes])
229                 AC_DEFINE(USBI_TIMERFD_AVAILABLE, 1, [timerfd headers available])
230         else
231                 AC_MSG_RESULT([no (header not available)])
232         fi
233 fi
234
235 AC_CHECK_TYPES(struct timespec)
236
237 # Message logging
238 AC_ARG_ENABLE([log], [AS_HELP_STRING([--disable-log], [disable all logging])],
239         [log_enabled=$enableval],
240         [log_enabled='yes'])
241 if test "x$log_enabled" != "xno"; then
242         AC_DEFINE([ENABLE_LOGGING], 1, [Message logging])
243 fi
244
245 AC_ARG_ENABLE([debug-log], [AS_HELP_STRING([--enable-debug-log],
246         [start with debug message logging enabled [default=no]])],
247         [debug_log_enabled=$enableval],
248         [debug_log_enabled='no'])
249 if test "x$debug_log_enabled" != "xno"; then
250         AC_DEFINE([ENABLE_DEBUG_LOGGING], 1, [Start with debug message logging enabled])
251 fi
252
253 AC_ARG_ENABLE([system-log], [AS_HELP_STRING([--enable-system-log],
254         [output logging messages to system wide log, if supported by the OS [default=no]])],
255         [system_log_enabled=$enableval],
256         [system_log_enabled='no'])
257 if test "x$system_log_enabled" != "xno"; then
258         AC_DEFINE([USE_SYSTEM_LOGGING_FACILITY], 1, [Enable output to system log])
259 fi
260
261 # Check if syslog is available in standard C library
262 AC_CHECK_HEADERS(syslog.h)
263 AC_CHECK_FUNC([syslog], [have_syslog=yes], [have_syslog=no])
264 if test "x$have_syslog" != "xno"; then
265         AC_DEFINE([HAVE_SYSLOG_FUNC], 1, [syslog() function available])
266 fi
267
268 # Examples build
269 AC_ARG_ENABLE([examples-build], [AS_HELP_STRING([--enable-examples-build],
270         [build example applications [default=no]])],
271         [build_examples=$enableval],
272         [build_examples='no'])
273 AM_CONDITIONAL([BUILD_EXAMPLES], [test "x$build_examples" != "xno"])
274
275 # Tests build
276 AC_ARG_ENABLE([tests-build], [AS_HELP_STRING([--enable-tests-build],
277         [build test applications [default=no]])],
278         [build_tests=$enableval],
279         [build_tests='no'])
280 AM_CONDITIONAL([BUILD_TESTS], [test "x$build_tests" != "xno"])
281
282 # check for -fvisibility=hidden compiler support (GCC >= 3.4)
283 saved_cflags="$CFLAGS"
284 # -Werror required for cygwin
285 CFLAGS="$CFLAGS -Werror -fvisibility=hidden"
286 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
287         [VISIBILITY_CFLAGS="-fvisibility=hidden"
288          AC_DEFINE([DEFAULT_VISIBILITY], [__attribute__((visibility("default")))], [Default visibility]) ],
289         [ VISIBILITY_CFLAGS=""
290          AC_DEFINE([DEFAULT_VISIBILITY], [], [Default visibility]) ],
291         ])
292 CFLAGS="$saved_cflags"
293
294 # check for -Wno-pointer-sign compiler support (GCC >= 4)
295 saved_cflags="$CFLAGS"
296 CFLAGS="$CFLAGS -Wno-pointer-sign"
297 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
298         nopointersign_cflags="-Wno-pointer-sign", nopointersign_cflags="")
299 CFLAGS="$saved_cflags"
300
301 # sigaction not available on MinGW
302 AC_CHECK_FUNC([sigaction], [have_sigaction=yes], [have_sigaction=no])
303 AM_CONDITIONAL([HAVE_SIGACTION], [test "x$have_sigaction" = "xyes"])
304
305 # headers not available on all platforms but required on others
306 AC_CHECK_HEADERS([sys/time.h])
307 AC_CHECK_FUNCS(gettimeofday)
308 AC_CHECK_HEADERS([signal.h])
309
310 # check for -std=gnu99 compiler support
311 saved_cflags="$CFLAGS"
312 CFLAGS="-std=gnu99"
313 AC_MSG_CHECKING([whether CC supports -std=gnu99])
314 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
315     [AC_MSG_RESULT([yes])]
316     [AM_CFLAGS="${AM_CFLAGS} -std=gnu99"],
317     [AC_MSG_RESULT([no])]
318 )
319 CFLAGS="$saved_cflags"
320
321 AM_CFLAGS="${AM_CFLAGS} -Wall -Wundef -Wunused -Wstrict-prototypes -Werror-implicit-function-declaration $nopointersign_cflags -Wshadow ${THREAD_CFLAGS} ${VISIBILITY_CFLAGS}"
322
323 AC_SUBST(AM_CFLAGS)
324 AC_SUBST(LTLDFLAGS)
325
326 AC_CONFIG_FILES([libusb-1.0.pc])
327 AC_CONFIG_FILES([Makefile])
328 AC_CONFIG_FILES([libusb/Makefile])
329 AC_CONFIG_FILES([examples/Makefile])
330 AC_CONFIG_FILES([tests/Makefile])
331 AC_CONFIG_FILES([doc/Makefile])
332 AC_CONFIG_FILES([doc/doxygen.cfg])
333 AC_OUTPUT