blob: ebbc107883f4ab7f8175b28126a4e8de0be6335a [file] [log] [blame]
Peter Stuge85a14f42011-05-09 08:12:24 +02001dnl These m4 macros are whitespace sensitive and break if moved around much.
2m4_define([LU_VERSION_H], m4_include([libusb/version.h]))
3m4_define([LU_DEFINE_VERSION_ATOM],
4 [m4_define([$1], m4_bregexp(LU_VERSION_H,
5 [^#define\s*$1\s*\([0-9]*\).*], [\1]))])
Peter Stugecbc2d7b2011-09-15 16:48:35 +02006m4_define([LU_DEFINE_VERSION_RC_ATOM],
7 [m4_define([$1], m4_bregexp(LU_VERSION_H,
8 [^#define\s*$1\s*"\(-rc[0-9]*\)".*], [\1]))])
Peter Stuge85a14f42011-05-09 08:12:24 +02009dnl The m4_bregexp() returns (only) the numbers following the #define named
10dnl in the first macro parameter. m4_define() then defines the name for use
11dnl in AC_INIT().
Pete Batard9a4249f2010-07-10 17:51:13 -060012
Peter Stuge85a14f42011-05-09 08:12:24 +020013LU_DEFINE_VERSION_ATOM([LIBUSB_MAJOR])
14LU_DEFINE_VERSION_ATOM([LIBUSB_MINOR])
15LU_DEFINE_VERSION_ATOM([LIBUSB_MICRO])
Peter Stugecbc2d7b2011-09-15 16:48:35 +020016LU_DEFINE_VERSION_RC_ATOM([LIBUSB_RC])
Daniel Draked7c25452010-10-04 20:03:58 +010017
Peter Stugecbc2d7b2011-09-15 16:48:35 +020018AC_INIT([libusb], LIBUSB_MAJOR[.]LIBUSB_MINOR[.]LIBUSB_MICRO[]LIBUSB_RC, [libusb-devel@lists.sourceforge.net], [libusb], [http://www.libusb.org/])
Daniel Draked7c25452010-10-04 20:03:58 +010019
Daniel Draked192c5b2010-10-04 18:45:18 +010020# 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
24lt_current="1"
25lt_revision="0"
26lt_age="1"
Peter Stuge717f4762010-11-15 19:58:51 +010027LTLDFLAGS="-version-info ${lt_current}:${lt_revision}:${lt_age}"
Pete Batard9a4249f2010-07-10 17:51:13 -060028
Daniel Drake852bba42007-11-28 13:48:45 +000029AM_INIT_AUTOMAKE
Peter Stuge6e52ea02010-11-21 23:37:27 +010030AM_MAINTAINER_MODE
31
Daniel Drakee9364d72008-01-04 00:40:49 +000032AC_CONFIG_SRCDIR([libusb/core.c])
Daniel Drake8be25602009-06-13 17:19:07 +010033AC_CONFIG_MACRO_DIR([m4])
Daniel Drake852bba42007-11-28 13:48:45 +000034AM_CONFIG_HEADER([config.h])
Daniel Drake9b120c22009-11-07 10:03:07 +000035m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])])
Daniel Drake852bba42007-11-28 13:48:45 +000036
37AC_PREREQ([2.50])
38AC_PROG_CC
39AC_PROG_LIBTOOL
Peter Stugefa9b6822011-09-22 21:17:37 +020040LT_LANG([Windows Resource])
Daniel Drake852bba42007-11-28 13:48:45 +000041AC_C_INLINE
42AM_PROG_CC_C_O
Peter Stuge19d58822010-11-21 23:09:02 +010043AC_DEFINE([_GNU_SOURCE], 1, [Use GNU extensions])
Daniel Drake852bba42007-11-28 13:48:45 +000044
Peter Stuge717f4762010-11-15 19:58:51 +010045LTLDFLAGS="${LTLDFLAGS} -no-undefined"
46
Daniel Drakec0c94322008-03-13 12:36:56 +000047AC_MSG_CHECKING([operating system])
48case $host in
49*-linux*)
Peter Stuge19d58822010-11-21 23:09:02 +010050 AC_DEFINE(OS_LINUX, 1, [Linux backend])
Daniel Drakec0c94322008-03-13 12:36:56 +000051 AC_SUBST(OS_LINUX)
52 AC_MSG_RESULT([Linux])
53 backend="linux"
Mike Frysingera6fb54e2010-10-04 20:01:07 +010054 AC_CHECK_LIB(rt, clock_gettime, PC_LIBS_PRIVATE="-lrt")
Peter Stuge23b5db82010-05-11 00:51:43 +010055 threads="posix"
56 THREAD_CFLAGS="-pthread"
Mike Frysingera6fb54e2010-10-04 20:01:07 +010057 PC_LIBS_PRIVATE="${PC_LIBS_PRIVATE} -pthread"
Peter Stugea1207472010-10-30 22:07:37 +020058 AC_CHECK_HEADERS([poll.h])
59 AC_DEFINE([POLL_NFDS_TYPE],[nfds_t],[type of second poll() argument])
Nathan Hjelmb49f6bf2009-02-16 21:39:29 -030060 ;;
61*-darwin*)
Peter Stuge19d58822010-11-21 23:09:02 +010062 AC_DEFINE(OS_DARWIN, 1, [Darwin backend])
Nathan Hjelmb49f6bf2009-02-16 21:39:29 -030063 AC_SUBST(OS_DARWIN)
Peter Stuge0bd4a4d2011-02-26 04:08:38 +010064 AC_MSG_RESULT([Darwin/Mac OS X])
Nathan Hjelmb49f6bf2009-02-16 21:39:29 -030065 backend="darwin"
Peter Stuge23b5db82010-05-11 00:51:43 +010066 threads="posix"
Xiaofan Chend2285742012-01-13 18:07:34 +010067 PC_LIBS_PRIVATE="-lobjc -Wl,-framework,IOKit -Wl,-framework,CoreFoundation"
Peter Stuge717f4762010-11-15 19:58:51 +010068 LTLDFLAGS="${LTLDFLAGS} -Wl,-prebind"
Peter Stugea1207472010-10-30 22:07:37 +020069 AC_CHECK_HEADERS([poll.h])
70 AC_CHECK_TYPE([nfds_t],
71 [AC_DEFINE([POLL_NFDS_TYPE],[nfds_t],[type of second poll() argument])],
72 [AC_DEFINE([POLL_NFDS_TYPE],[unsigned int],[type of second poll() argument])],
73 [#include <poll.h>])
Peter Stuge6e52ea02010-11-21 23:37:27 +010074 ;;
Martin Pieuchotc5682882012-01-30 09:59:30 +010075*-openbsd*)
76 AC_DEFINE(OS_OPENBSD, 1, [OpenBSD backend])
77 AC_SUBST(OS_OPENBSD)
78 AC_MSG_RESULT([OpenBSD])
79 backend="openbsd"
80 threads="posix"
81 THREAD_CFLAGS="-pthread"
82 PC_LIBS_PRIVATE="-pthread"
83 AC_CHECK_HEADERS([poll.h])
84 AC_DEFINE([POLL_NFDS_TYPE],[nfds_t],[type of second poll() argument])
85 ;;
Pete Batard9a4249f2010-07-10 17:51:13 -060086*-mingw*)
Pete Batard9a4249f2010-07-10 17:51:13 -060087 AC_MSG_RESULT([Windows])
88 backend="windows"
Pete Batard9a4249f2010-07-10 17:51:13 -060089 ;;
90*-cygwin*)
Peter Stuge0bd4a4d2011-02-26 04:08:38 +010091 AC_MSG_RESULT([Cygwin (using Windows backend)])
Pete Batard9a4249f2010-07-10 17:51:13 -060092 backend="windows"
93 threads="posix"
Pete Batard9a4249f2010-07-10 17:51:13 -060094 ;;
Daniel Drakec0c94322008-03-13 12:36:56 +000095*)
96 AC_MSG_ERROR([unsupported operating system])
97esac
Peter Stuge1a2d21f2011-02-26 04:21:05 +010098if test "$backend" = windows; then
99 AC_DEFINE(OS_WINDOWS, 1, [Windows backend])
100 AC_SUBST(OS_WINDOWS)
Pete Batardae675c12011-03-08 17:16:23 +0000101 PC_LIBS_PRIVATE=""
Peter Stuge1a2d21f2011-02-26 04:21:05 +0100102 LTLDFLAGS="${LTLDFLAGS} -avoid-version -Wl,--add-stdcall-alias"
103 AC_CHECK_TOOL(RC, windres, no)
104 AC_DEFINE([POLL_NFDS_TYPE],[unsigned int],[type of second poll() argument])
105fi
Peter Stuge6e52ea02010-11-21 23:37:27 +0100106AC_SUBST(THREAD_CFLAGS)
Mike Frysingera6fb54e2010-10-04 20:01:07 +0100107AC_SUBST(PC_LIBS_PRIVATE)
Peter Stugec24649d2010-10-30 22:28:59 +0200108LIBS="${LIBS} ${PC_LIBS_PRIVATE}"
Daniel Drakec0c94322008-03-13 12:36:56 +0000109
Peter Stugec24649d2010-10-30 22:28:59 +0200110AM_CONDITIONAL(OS_LINUX, test "x$backend" = xlinux)
111AM_CONDITIONAL(OS_DARWIN, test "x$backend" = xdarwin)
Martin Pieuchotc5682882012-01-30 09:59:30 +0100112AM_CONDITIONAL(OS_OPENBSD, test "x$backend" = xopenbsd)
Peter Stugec24649d2010-10-30 22:28:59 +0200113AM_CONDITIONAL(OS_WINDOWS, test "x$backend" = xwindows)
114AM_CONDITIONAL(THREADS_POSIX, test "x$threads" = xposix)
115if test "$threads" = posix; then
116 AC_DEFINE(THREADS_POSIX, 1, [Use POSIX Threads])
117fi
Daniel Drakec0c94322008-03-13 12:36:56 +0000118
Daniel Drake47830082009-10-28 20:33:49 +0545119# timerfd
120AC_CHECK_HEADER([sys/timerfd.h], [timerfd_h=1], [timerfd_h=0])
121AC_ARG_ENABLE([timerfd],
122 [AS_HELP_STRING([--enable-timerfd],
123 [use timerfd for timing (default auto)])],
124 [use_timerfd=$enableval], [use_timerfd='auto'])
125
126if test "x$use_timerfd" = "xyes" -a "x$timerfd_h" = "x0"; then
Daniel Drake0bd7ef52009-11-21 16:57:25 +0000127 AC_MSG_ERROR([timerfd header not available; glibc 2.9+ required])
128fi
129
130AC_CHECK_DECL([TFD_NONBLOCK], [tfd_hdr_ok=yes], [tfd_hdr_ok=no], [#include <sys/timerfd.h>])
131if test "x$use_timerfd" = "xyes" -a "x$tfd_hdr_ok" = "xno"; then
132 AC_MSG_ERROR([timerfd header not usable; glibc 2.9+ required])
Daniel Drake47830082009-10-28 20:33:49 +0545133fi
134
135AC_MSG_CHECKING([whether to use timerfd for timing])
136if test "x$use_timerfd" = "xno"; then
137 AC_MSG_RESULT([no (disabled by user)])
138else
Daniel Drake0bd7ef52009-11-21 16:57:25 +0000139 if test "x$timerfd_h" = "x1" -a "x$tfd_hdr_ok" = "xyes"; then
Daniel Drake47830082009-10-28 20:33:49 +0545140 AC_MSG_RESULT([yes])
Peter Stuge19d58822010-11-21 23:09:02 +0100141 AC_DEFINE(USBI_TIMERFD_AVAILABLE, 1, [timerfd headers available])
Daniel Drake47830082009-10-28 20:33:49 +0545142 else
143 AC_MSG_RESULT([no (header not available)])
144 fi
145fi
146
Pete Batard9a4249f2010-07-10 17:51:13 -0600147AC_CHECK_TYPES(struct timespec)
148
Daniel Drake852bba42007-11-28 13:48:45 +0000149# Message logging
150AC_ARG_ENABLE([log], [AS_HELP_STRING([--disable-log], [disable all logging])],
151 [log_enabled=$enableval],
152 [log_enabled='yes'])
153if test "x$log_enabled" != "xno"; then
154 AC_DEFINE([ENABLE_LOGGING], 1, [Message logging])
155fi
156
157AC_ARG_ENABLE([debug-log], [AS_HELP_STRING([--enable-debug-log],
158 [enable debug logging (default n)])],
159 [debug_log_enabled=$enableval],
160 [debug_log_enabled='no'])
161if test "x$debug_log_enabled" != "xno"; then
162 AC_DEFINE([ENABLE_DEBUG_LOGGING], 1, [Debug message logging])
163fi
164
165# Examples build
166AC_ARG_ENABLE([examples-build], [AS_HELP_STRING([--enable-examples-build],
167 [build example applications (default n)])],
168 [build_examples=$enableval],
169 [build_examples='no'])
170AM_CONDITIONAL([BUILD_EXAMPLES], [test "x$build_examples" != "xno"])
171
Alex Vatchenkob5017952009-05-28 15:58:50 -0400172# check for -fvisibility=hidden compiler support (GCC >= 3.4)
173saved_cflags="$CFLAGS"
Pete Batard9a4249f2010-07-10 17:51:13 -0600174# -Werror required for cygwin
175CFLAGS="$CFLAGS -Werror -fvisibility=hidden"
Peter Stuge44b85da2010-11-21 23:10:35 +0100176AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
Alex Vatchenkob5017952009-05-28 15:58:50 -0400177 [VISIBILITY_CFLAGS="-fvisibility=hidden"
Pete Batard29f9f9e2010-08-13 11:59:49 +0100178 AC_DEFINE([DEFAULT_VISIBILITY], [__attribute__((visibility("default")))], [Default visibility]) ],
Alex Vatchenkob5017952009-05-28 15:58:50 -0400179 [ VISIBILITY_CFLAGS=""
Pete Batard29f9f9e2010-08-13 11:59:49 +0100180 AC_DEFINE([DEFAULT_VISIBILITY], [], [Default visibility]) ],
Alex Vatchenkob5017952009-05-28 15:58:50 -0400181 ])
182CFLAGS="$saved_cflags"
Nathan Hjelmb49f6bf2009-02-16 21:39:29 -0300183
Alex Vatchenkob5017952009-05-28 15:58:50 -0400184# check for -Wno-pointer-sign compiler support (GCC >= 4)
185saved_cflags="$CFLAGS"
186CFLAGS="$CFLAGS -Wno-pointer-sign"
Peter Stuge44b85da2010-11-21 23:10:35 +0100187AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
Alex Vatchenkob5017952009-05-28 15:58:50 -0400188 nopointersign_cflags="-Wno-pointer-sign", nopointersign_cflags="")
189CFLAGS="$saved_cflags"
190
Daniel Drakea516fcb2010-07-21 17:49:21 -0600191# sigaction not available on MinGW
192AC_CHECK_FUNC([sigaction], [have_sigaction=yes], [have_sigaction=no])
193AM_CONDITIONAL([HAVE_SIGACTION], [test "x$have_sigaction" = "xyes"])
194
Daniel Drake7211aba2010-06-25 12:01:58 -0500195# headers not available on all platforms but required on others
196AC_CHECK_HEADERS([sys/time.h])
197
Sean McBridebb8854f2011-06-13 22:26:43 +0200198AM_CFLAGS="-std=gnu99 -Wall -Wundef -Wunused -Wstrict-prototypes -Werror-implicit-function-declaration $nopointersign_cflags -Wshadow"
Alex Vatchenkob5017952009-05-28 15:58:50 -0400199
200AC_SUBST(VISIBILITY_CFLAGS)
Daniel Drake852bba42007-11-28 13:48:45 +0000201AC_SUBST(AM_CFLAGS)
Peter Stuge717f4762010-11-15 19:58:51 +0100202AC_SUBST(LTLDFLAGS)
Daniel Drake852bba42007-11-28 13:48:45 +0000203
Peter Stugeef39d152011-02-25 02:33:29 +0100204AC_CONFIG_FILES([libusb-1.0.pc])
205AC_CONFIG_FILES([Makefile])
206AC_CONFIG_FILES([libusb/Makefile])
Peter Stugeef39d152011-02-25 02:33:29 +0100207AC_CONFIG_FILES([examples/Makefile])
208AC_CONFIG_FILES([doc/Makefile])
209AC_CONFIG_FILES([doc/doxygen.cfg])
Daniel Drake852bba42007-11-28 13:48:45 +0000210AC_OUTPUT