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