configure.ac 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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. LU_DEFINE_VERSION_ATOM([LIBUSB_MAJOR])
  13. LU_DEFINE_VERSION_ATOM([LIBUSB_MINOR])
  14. LU_DEFINE_VERSION_ATOM([LIBUSB_MICRO])
  15. LU_DEFINE_VERSION_RC_ATOM([LIBUSB_RC])
  16. AC_INIT([libusb], LIBUSB_MAJOR[.]LIBUSB_MINOR[.]LIBUSB_MICRO[]LIBUSB_RC, [libusb-devel@lists.sourceforge.net], [libusb], [http://www.libusb.org/])
  17. # Library versioning
  18. # These numbers should be tweaked on every release. Read carefully:
  19. # http://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html
  20. # http://sourceware.org/autobook/autobook/autobook_91.html
  21. lt_current="2"
  22. lt_revision="0"
  23. lt_age="0"
  24. LTLDFLAGS="-version-info ${lt_current}:${lt_revision}:${lt_age}"
  25. AM_INIT_AUTOMAKE([foreign subdir-objects])
  26. AM_MAINTAINER_MODE
  27. AC_CONFIG_SRCDIR([libusb/core.c])
  28. AC_CONFIG_MACRO_DIR([m4])
  29. AC_CONFIG_HEADERS([config.h])
  30. m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])])
  31. AC_PREREQ([2.50])
  32. AC_PROG_CC
  33. AC_PROG_LIBTOOL
  34. LT_LANG([Windows Resource])
  35. AC_C_INLINE
  36. AM_PROG_CC_C_O
  37. AC_DEFINE([_GNU_SOURCE], 1, [Use GNU extensions])
  38. LTLDFLAGS="${LTLDFLAGS} -no-undefined"
  39. AC_MSG_CHECKING([operating system])
  40. case $host in
  41. *-linux*)
  42. AC_MSG_RESULT([Linux])
  43. backend="linux"
  44. ;;
  45. *-darwin*)
  46. AC_MSG_RESULT([Darwin/Mac OS X])
  47. backend="darwin"
  48. ;;
  49. *-openbsd*)
  50. AC_MSG_RESULT([OpenBSD])
  51. backend="openbsd"
  52. ;;
  53. *-netbsd*)
  54. AC_MSG_RESULT([NetBSD (using OpenBSD backend)])
  55. backend="openbsd"
  56. ;;
  57. *-mingw*)
  58. AC_MSG_RESULT([Windows])
  59. backend="windows"
  60. ;;
  61. *-cygwin*)
  62. AC_MSG_RESULT([Cygwin (using Windows backend)])
  63. backend="windows"
  64. threads="posix"
  65. ;;
  66. *)
  67. AC_MSG_ERROR([unsupported operating system])
  68. esac
  69. case $backend in
  70. linux)
  71. AC_DEFINE(OS_LINUX, 1, [Linux backend])
  72. AC_SUBST(OS_LINUX)
  73. AC_CHECK_LIB(rt, clock_gettime, -pthread)
  74. AC_ARG_ENABLE([udev],
  75. [AC_HELP_STRING([--with-udev], [use udev for device enumeration and hotplug support (recommended, default: yes)])],
  76. [], [enable_udev="yes"])
  77. if test "x$enable_udev" = "xyes" ; then
  78. # system has udev. use it or fail!
  79. AC_CHECK_HEADERS([libudev.h],[],[AC_ERROR(["udev support requested but libudev not installed"])])
  80. AC_CHECK_LIB([udev], [udev_new], [], [AC_ERROR(["udev support requested but libudev not installed"])])
  81. AC_DEFINE(USE_UDEV, 1, [Use udev for device enumeration/hotplug])
  82. else
  83. AC_CHECK_HEADERS([linux/netlink.h linux/filter.h], [], [AC_ERROR(["Linux netlink headers not found"])])
  84. fi
  85. AC_SUBST(USE_UDEV)
  86. threads="posix"
  87. THREAD_CFLAGS="-pthread"
  88. LIBS="${LIBS} -pthread"
  89. AC_CHECK_HEADERS([poll.h])
  90. AC_DEFINE([POLL_NFDS_TYPE],[nfds_t],[type of second poll() argument])
  91. ;;
  92. darwin)
  93. AC_DEFINE(OS_DARWIN, 1, [Darwin backend])
  94. AC_SUBST(OS_DARWIN)
  95. threads="posix"
  96. LIBS="-lobjc -Wl,-framework,IOKit -Wl,-framework,CoreFoundation"
  97. LTLDFLAGS="${LTLDFLAGS} -Wl,-prebind"
  98. AC_CHECK_HEADERS([poll.h])
  99. AC_CHECK_TYPE([nfds_t],
  100. [AC_DEFINE([POLL_NFDS_TYPE],[nfds_t],[type of second poll() argument])],
  101. [AC_DEFINE([POLL_NFDS_TYPE],[unsigned int],[type of second poll() argument])],
  102. [#include <poll.h>])
  103. ;;
  104. openbsd)
  105. AC_DEFINE(OS_OPENBSD, 1, [OpenBSD backend])
  106. AC_SUBST(OS_OPENBSD)
  107. threads="posix"
  108. THREAD_CFLAGS="-pthread"
  109. LIBS="-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. LIBS=""
  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. AC_SUBST(LIBS)
  122. AM_CONDITIONAL(OS_LINUX, test "x$backend" = xlinux)
  123. AM_CONDITIONAL(OS_DARWIN, test "x$backend" = xdarwin)
  124. AM_CONDITIONAL(OS_OPENBSD, test "x$backend" = xopenbsd)
  125. AM_CONDITIONAL(OS_WINDOWS, test "x$backend" = xwindows)
  126. AM_CONDITIONAL(THREADS_POSIX, test "x$threads" = xposix)
  127. AM_CONDITIONAL(USE_UDEV, test "x$enable_udev" = xyes)
  128. if test "$threads" = posix; then
  129. AC_DEFINE(THREADS_POSIX, 1, [Use POSIX Threads])
  130. fi
  131. # timerfd
  132. AC_CHECK_HEADER([sys/timerfd.h], [timerfd_h=1], [timerfd_h=0])
  133. AC_ARG_ENABLE([timerfd],
  134. [AS_HELP_STRING([--enable-timerfd],
  135. [use timerfd for timing (default auto)])],
  136. [use_timerfd=$enableval], [use_timerfd='auto'])
  137. if test "x$use_timerfd" = "xyes" -a "x$timerfd_h" = "x0"; then
  138. AC_MSG_ERROR([timerfd header not available; glibc 2.9+ required])
  139. fi
  140. AC_CHECK_DECL([TFD_NONBLOCK], [tfd_hdr_ok=yes], [tfd_hdr_ok=no], [#include <sys/timerfd.h>])
  141. if test "x$use_timerfd" = "xyes" -a "x$tfd_hdr_ok" = "xno"; then
  142. AC_MSG_ERROR([timerfd header not usable; glibc 2.9+ required])
  143. fi
  144. AC_MSG_CHECKING([whether to use timerfd for timing])
  145. if test "x$use_timerfd" = "xno"; then
  146. AC_MSG_RESULT([no (disabled by user)])
  147. else
  148. if test "x$timerfd_h" = "x1" -a "x$tfd_hdr_ok" = "xyes"; then
  149. AC_MSG_RESULT([yes])
  150. AC_DEFINE(USBI_TIMERFD_AVAILABLE, 1, [timerfd headers available])
  151. else
  152. AC_MSG_RESULT([no (header not available)])
  153. fi
  154. fi
  155. AC_CHECK_TYPES(struct timespec)
  156. # Message logging
  157. AC_ARG_ENABLE([log], [AS_HELP_STRING([--disable-log], [disable all logging])],
  158. [log_enabled=$enableval],
  159. [log_enabled='yes'])
  160. if test "x$log_enabled" != "xno"; then
  161. AC_DEFINE([ENABLE_LOGGING], 1, [Message logging])
  162. fi
  163. AC_ARG_ENABLE([debug-log], [AS_HELP_STRING([--enable-debug-log],
  164. [enable debug logging (default n)])],
  165. [debug_log_enabled=$enableval],
  166. [debug_log_enabled='no'])
  167. if test "x$debug_log_enabled" != "xno"; then
  168. AC_DEFINE([ENABLE_DEBUG_LOGGING], 1, [Debug message logging])
  169. fi
  170. # Examples build
  171. AC_ARG_ENABLE([examples-build], [AS_HELP_STRING([--enable-examples-build],
  172. [build example applications (default n)])],
  173. [build_examples=$enableval],
  174. [build_examples='no'])
  175. AM_CONDITIONAL([BUILD_EXAMPLES], [test "x$build_examples" != "xno"])
  176. # check for -fvisibility=hidden compiler support (GCC >= 3.4)
  177. saved_cflags="$CFLAGS"
  178. # -Werror required for cygwin
  179. CFLAGS="$CFLAGS -Werror -fvisibility=hidden"
  180. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
  181. [VISIBILITY_CFLAGS="-fvisibility=hidden"
  182. AC_DEFINE([DEFAULT_VISIBILITY], [__attribute__((visibility("default")))], [Default visibility]) ],
  183. [ VISIBILITY_CFLAGS=""
  184. AC_DEFINE([DEFAULT_VISIBILITY], [], [Default visibility]) ],
  185. ])
  186. CFLAGS="$saved_cflags"
  187. # check for -Wno-pointer-sign compiler support (GCC >= 4)
  188. saved_cflags="$CFLAGS"
  189. CFLAGS="$CFLAGS -Wno-pointer-sign"
  190. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
  191. nopointersign_cflags="-Wno-pointer-sign", nopointersign_cflags="")
  192. CFLAGS="$saved_cflags"
  193. # sigaction not available on MinGW
  194. AC_CHECK_FUNC([sigaction], [have_sigaction=yes], [have_sigaction=no])
  195. AM_CONDITIONAL([HAVE_SIGACTION], [test "x$have_sigaction" = "xyes"])
  196. # headers not available on all platforms but required on others
  197. AC_CHECK_HEADERS([sys/time.h])
  198. AC_CHECK_FUNCS(gettimeofday)
  199. AM_CFLAGS="-std=gnu99 -Wall -Wundef -Wunused -Wstrict-prototypes -Werror-implicit-function-declaration $nopointersign_cflags -Wshadow ${THREAD_CFLAGS} ${VISIBILITY_CFLAGS}"
  200. AC_SUBST(AM_CFLAGS)
  201. AC_SUBST(LTLDFLAGS)
  202. AC_CONFIG_FILES([libusb-1.0.pc])
  203. AC_CONFIG_FILES([Makefile])
  204. AC_CONFIG_FILES([libusb/Makefile])
  205. AC_OUTPUT