configure.ac 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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([libusbx],[LIBUSB_MAJOR[.]LIBUSB_MINOR[.]LIBUSB_MICRO[]LIBUSB_RC],[libusbx-devel@lists.sourceforge.net],[libusbx],[http://libusbx.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="1"
  22. lt_revision="0"
  23. lt_age="1"
  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. LT_INIT
  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. threads="posix"
  45. ;;
  46. *-darwin*)
  47. AC_MSG_RESULT([Darwin/Mac OS X])
  48. backend="darwin"
  49. threads="posix"
  50. ;;
  51. *-openbsd*)
  52. AC_MSG_RESULT([OpenBSD])
  53. backend="openbsd"
  54. threads="posix"
  55. ;;
  56. *-netbsd*)
  57. AC_MSG_RESULT([NetBSD])
  58. backend="netbsd"
  59. threads="posix"
  60. ;;
  61. *-mingw*)
  62. AC_MSG_RESULT([Windows])
  63. backend="windows"
  64. threads="windows"
  65. create_import_lib="yes"
  66. AM_CFLAGS="${AM_CFLAGS} -fno-omit-frame-pointer"
  67. ;;
  68. *-cygwin*)
  69. AC_MSG_RESULT([Cygwin (using Windows backend)])
  70. backend="windows"
  71. threads="posix"
  72. ;;
  73. *)
  74. AC_MSG_ERROR([unsupported operating system])
  75. esac
  76. case $backend in
  77. linux)
  78. AC_DEFINE(OS_LINUX, 1, [Linux backend])
  79. AC_SUBST(OS_LINUX)
  80. AC_SEARCH_LIBS(clock_gettime, rt, [], [], -pthread)
  81. AC_ARG_ENABLE([udev],
  82. [AC_HELP_STRING([--enable-udev], [use udev for device enumeration and hotplug support (recommended) [default=yes]])],
  83. [], [enable_udev="yes"])
  84. if test "x$enable_udev" = "xyes" ; then
  85. # system has udev. use it or fail!
  86. AC_CHECK_HEADERS([libudev.h],[],[AC_ERROR(["udev support requested but libudev not installed"])])
  87. AC_CHECK_LIB([udev], [udev_new], [], [AC_ERROR(["udev support requested but libudev not installed"])])
  88. AC_DEFINE(USE_UDEV, 1, [Use udev for device enumeration/hotplug])
  89. else
  90. AC_CHECK_HEADERS([asm/types.h sys/socket.h], [], [])
  91. AC_CHECK_HEADERS([linux/netlink.h linux/filter.h], [], [AC_ERROR(["Linux netlink headers not found"])], [
  92. #ifdef HAVE_ASM_TYPES_H
  93. #include <asm/types.h>
  94. #endif
  95. #ifdef HAVE_SYS_SOCKET_H
  96. #include <sys/socket.h>
  97. #endif
  98. ])
  99. fi
  100. AC_SUBST(USE_UDEV)
  101. THREAD_CFLAGS="-pthread"
  102. LIBS="${LIBS} -pthread"
  103. AC_CHECK_HEADERS([poll.h])
  104. AC_DEFINE([POLL_NFDS_TYPE],[nfds_t],[type of second poll() argument])
  105. ;;
  106. darwin)
  107. AC_DEFINE(OS_DARWIN, 1, [Darwin backend])
  108. AC_SUBST(OS_DARWIN)
  109. LIBS="-lobjc -Wl,-framework,IOKit -Wl,-framework,CoreFoundation"
  110. LTLDFLAGS="${LTLDFLAGS} -Wl,-prebind"
  111. AC_CHECK_HEADERS([poll.h])
  112. AC_CHECK_TYPE([nfds_t],
  113. [AC_DEFINE([POLL_NFDS_TYPE],[nfds_t],[type of second poll() argument])],
  114. [AC_DEFINE([POLL_NFDS_TYPE],[unsigned int],[type of second poll() argument])],
  115. [#include <poll.h>])
  116. ;;
  117. openbsd)
  118. AC_DEFINE(OS_OPENBSD, 1, [OpenBSD backend])
  119. AC_SUBST(OS_OPENBSD)
  120. THREAD_CFLAGS="-pthread"
  121. LIBS="-pthread"
  122. AC_CHECK_HEADERS([poll.h])
  123. AC_DEFINE([POLL_NFDS_TYPE],[nfds_t],[type of second poll() argument])
  124. ;;
  125. netbsd)
  126. AC_DEFINE(OS_NETBSD, 1, [NetBSD backend])
  127. AC_SUBST(OS_NETBSD)
  128. THREAD_CFLAGS="-pthread"
  129. LIBS="-pthread"
  130. AC_CHECK_HEADERS([poll.h])
  131. AC_DEFINE([POLL_NFDS_TYPE],[nfds_t],[type of second poll() argument])
  132. ;;
  133. windows)
  134. AC_DEFINE(OS_WINDOWS, 1, [Windows backend])
  135. AC_SUBST(OS_WINDOWS)
  136. LIBS=""
  137. LTLDFLAGS="${LTLDFLAGS} -avoid-version -Wl,--add-stdcall-alias"
  138. AC_DEFINE([POLL_NFDS_TYPE],[unsigned int],[type of second poll() argument])
  139. ;;
  140. esac
  141. AC_SUBST(LIBS)
  142. AM_CONDITIONAL(OS_LINUX, test "x$backend" = xlinux)
  143. AM_CONDITIONAL(OS_DARWIN, test "x$backend" = xdarwin)
  144. AM_CONDITIONAL(OS_OPENBSD, test "x$backend" = xopenbsd)
  145. AM_CONDITIONAL(OS_NETBSD, test "x$backend" = xnetbsd)
  146. AM_CONDITIONAL(OS_WINDOWS, test "x$backend" = xwindows)
  147. AM_CONDITIONAL(THREADS_POSIX, test "x$threads" = xposix)
  148. AM_CONDITIONAL(CREATE_IMPORT_LIB, test "x$create_import_lib" = "xyes")
  149. AM_CONDITIONAL(USE_UDEV, test "x$enable_udev" = xyes)
  150. if test "$threads" = posix; then
  151. AC_DEFINE(THREADS_POSIX, 1, [Use POSIX Threads])
  152. fi
  153. # timerfd
  154. AC_CHECK_HEADER([sys/timerfd.h], [timerfd_h=1], [timerfd_h=0])
  155. AC_ARG_ENABLE([timerfd],
  156. [AS_HELP_STRING([--enable-timerfd],
  157. [use timerfd for timing [default=auto]])],
  158. [use_timerfd=$enableval], [use_timerfd='auto'])
  159. if test "x$use_timerfd" = "xyes" -a "x$timerfd_h" = "x0"; then
  160. AC_MSG_ERROR([timerfd header not available; glibc 2.9+ required])
  161. fi
  162. AC_CHECK_DECL([TFD_NONBLOCK], [tfd_hdr_ok=yes], [tfd_hdr_ok=no], [#include <sys/timerfd.h>])
  163. if test "x$use_timerfd" = "xyes" -a "x$tfd_hdr_ok" = "xno"; then
  164. AC_MSG_ERROR([timerfd header not usable; glibc 2.9+ required])
  165. fi
  166. AC_MSG_CHECKING([whether to use timerfd for timing])
  167. if test "x$use_timerfd" = "xno"; then
  168. AC_MSG_RESULT([no (disabled by user)])
  169. else
  170. if test "x$timerfd_h" = "x1" -a "x$tfd_hdr_ok" = "xyes"; then
  171. AC_MSG_RESULT([yes])
  172. AC_DEFINE(USBI_TIMERFD_AVAILABLE, 1, [timerfd headers available])
  173. else
  174. AC_MSG_RESULT([no (header not available)])
  175. fi
  176. fi
  177. AC_CHECK_TYPES(struct timespec)
  178. # Message logging
  179. AC_ARG_ENABLE([log], [AS_HELP_STRING([--disable-log], [disable all logging])],
  180. [log_enabled=$enableval],
  181. [log_enabled='yes'])
  182. if test "x$log_enabled" != "xno"; then
  183. AC_DEFINE([ENABLE_LOGGING], 1, [Message logging])
  184. fi
  185. AC_ARG_ENABLE([debug-log], [AS_HELP_STRING([--enable-debug-log],
  186. [start with debug message logging enabled [default=no]])],
  187. [debug_log_enabled=$enableval],
  188. [debug_log_enabled='no'])
  189. if test "x$debug_log_enabled" != "xno"; then
  190. AC_DEFINE([ENABLE_DEBUG_LOGGING], 1, [Start with debug message logging enabled])
  191. fi
  192. AC_ARG_ENABLE([system-log], [AS_HELP_STRING([--enable-system-log],
  193. [output logging messages to system wide log, if supported by the OS [default=no]])],
  194. [system_log_enabled=$enableval],
  195. [system_log_enabled='no'])
  196. if test "x$system_log_enabled" != "xno"; then
  197. AC_DEFINE([USE_SYSTEM_LOGGING_FACILITY], 1, [Enable output to system log])
  198. fi
  199. # Check if syslog is available in standard C library
  200. AC_CHECK_HEADERS(syslog.h)
  201. AC_CHECK_FUNC([syslog], [have_syslog=yes], [have_syslog=no])
  202. if test "x$have_syslog" != "xno"; then
  203. AC_DEFINE([HAVE_SYSLOG_FUNC], 1, [syslog() function available])
  204. fi
  205. # check for -fvisibility=hidden compiler support (GCC >= 3.4)
  206. saved_cflags="$CFLAGS"
  207. # -Werror required for cygwin
  208. CFLAGS="$CFLAGS -Werror -fvisibility=hidden"
  209. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
  210. [VISIBILITY_CFLAGS="-fvisibility=hidden"
  211. AC_DEFINE([DEFAULT_VISIBILITY], [__attribute__((visibility("default")))], [Default visibility]) ],
  212. [ VISIBILITY_CFLAGS=""
  213. AC_DEFINE([DEFAULT_VISIBILITY], [], [Default visibility]) ],
  214. ])
  215. CFLAGS="$saved_cflags"
  216. # check for -Wno-pointer-sign compiler support (GCC >= 4)
  217. saved_cflags="$CFLAGS"
  218. CFLAGS="$CFLAGS -Wno-pointer-sign"
  219. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
  220. nopointersign_cflags="-Wno-pointer-sign", nopointersign_cflags="")
  221. CFLAGS="$saved_cflags"
  222. # sigaction not available on MinGW
  223. AC_CHECK_FUNC([sigaction], [have_sigaction=yes], [have_sigaction=no])
  224. AM_CONDITIONAL([HAVE_SIGACTION], [test "x$have_sigaction" = "xyes"])
  225. # headers not available on all platforms but required on others
  226. AC_CHECK_HEADERS([sys/time.h])
  227. AC_CHECK_FUNCS(gettimeofday)
  228. AC_CHECK_HEADERS([signal.h])
  229. AM_CFLAGS="${AM_CFLAGS} -std=gnu99 -Wall -Wundef -Wunused -Wstrict-prototypes -Werror-implicit-function-declaration $nopointersign_cflags -Wshadow ${THREAD_CFLAGS} ${VISIBILITY_CFLAGS}"
  230. AC_SUBST(AM_CFLAGS)
  231. AC_SUBST(LTLDFLAGS)
  232. AC_CONFIG_FILES([libusb-1.0.pc])
  233. AC_CONFIG_FILES([Makefile])
  234. AC_CONFIG_FILES([libusb/Makefile])
  235. AC_OUTPUT