A clone of btpd with my configuration changes.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

191 lignes
7.1 KiB

  1. AC_DEFUN([ACX_PTHREAD], [
  2. AC_REQUIRE([AC_CANONICAL_HOST])
  3. AC_LANG_SAVE
  4. AC_LANG_C
  5. acx_pthread_ok=no
  6. # We used to check for pthread.h first, but this fails if pthread.h
  7. # requires special compiler flags (e.g. on True64 or Sequent).
  8. # It gets checked for in the link test anyway.
  9. # First of all, check if the user has set any of the PTHREAD_LIBS,
  10. # etcetera environment variables, and if threads linking works using
  11. # them:
  12. if test x"$PTHREAD_LIBS$PTHREAD_CFLAGS" != x; then
  13. save_CFLAGS="$CFLAGS"
  14. CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
  15. save_LIBS="$LIBS"
  16. LIBS="$PTHREAD_LIBS $LIBS"
  17. AC_MSG_CHECKING([for pthread_join in LIBS=$PTHREAD_LIBS with CFLAGS=$PTHREAD_CFLAGS])
  18. AC_TRY_LINK_FUNC(pthread_join, acx_pthread_ok=yes)
  19. AC_MSG_RESULT($acx_pthread_ok)
  20. if test x"$acx_pthread_ok" = xno; then
  21. PTHREAD_LIBS=""
  22. PTHREAD_CFLAGS=""
  23. fi
  24. LIBS="$save_LIBS"
  25. CFLAGS="$save_CFLAGS"
  26. fi
  27. # We must check for the threads library under a number of different
  28. # names; the ordering is very important because some systems
  29. # (e.g. DEC) have both -lpthread and -lpthreads, where one of the
  30. # libraries is broken (non-POSIX).
  31. # Create a list of thread flags to try. Items starting with a "-" are
  32. # C compiler flags, and other items are library names, except for "none"
  33. # which indicates that we try without any flags at all, and "pthread-config"
  34. # which is a program returning the flags for the Pth emulation library.
  35. acx_pthread_flags="pthreads none -Kthread -kthread lthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config"
  36. # The ordering *is* (sometimes) important. Some notes on the
  37. # individual items follow:
  38. # pthreads: AIX (must check this before -lpthread)
  39. # none: in case threads are in libc; should be tried before -Kthread and
  40. # other compiler flags to prevent continual compiler warnings
  41. # -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h)
  42. # -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able)
  43. # lthread: LinuxThreads port on FreeBSD (also preferred to -pthread)
  44. # -pthread: Linux/gcc (kernel threads), BSD/gcc (userland threads)
  45. # -pthreads: Solaris/gcc
  46. # -mthreads: Mingw32/gcc, Lynx/gcc
  47. # -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it
  48. # doesn't hurt to check since this sometimes defines pthreads too;
  49. # also defines -D_REENTRANT)
  50. # ... -mt is also the pthreads flag for HP/aCC
  51. # pthread: Linux, etcetera
  52. # --thread-safe: KAI C++
  53. # pthread-config: use pthread-config program (for GNU Pth library)
  54. case "${host_cpu}-${host_os}" in
  55. *solaris*)
  56. # On Solaris (at least, for some versions), libc contains stubbed
  57. # (non-functional) versions of the pthreads routines, so link-based
  58. # tests will erroneously succeed. (We need to link with -pthreads/-mt/
  59. # -lpthread.) (The stubs are missing pthread_cleanup_push, or rather
  60. # a function called by this macro, so we could check for that, but
  61. # who knows whether they'll stub that too in a future libc.) So,
  62. # we'll just look for -pthreads and -lpthread first:
  63. acx_pthread_flags="-pthreads pthread -mt -pthread $acx_pthread_flags"
  64. ;;
  65. esac
  66. if test x"$acx_pthread_ok" = xno; then
  67. for flag in $acx_pthread_flags; do
  68. case $flag in
  69. none)
  70. AC_MSG_CHECKING([whether pthreads work without any flags])
  71. ;;
  72. -*)
  73. AC_MSG_CHECKING([whether pthreads work with $flag])
  74. PTHREAD_CFLAGS="$flag"
  75. ;;
  76. pthread-config)
  77. AC_CHECK_PROG(acx_pthread_config, pthread-config, yes, no)
  78. if test x"$acx_pthread_config" = xno; then continue; fi
  79. PTHREAD_CFLAGS="`pthread-config --cflags`"
  80. PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`"
  81. ;;
  82. *)
  83. AC_MSG_CHECKING([for the pthreads library -l$flag])
  84. PTHREAD_LIBS="-l$flag"
  85. ;;
  86. esac
  87. save_LIBS="$LIBS"
  88. save_CFLAGS="$CFLAGS"
  89. LIBS="$PTHREAD_LIBS $LIBS"
  90. CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
  91. # Check for various functions. We must include pthread.h,
  92. # since some functions may be macros. (On the Sequent, we
  93. # need a special flag -Kthread to make this header compile.)
  94. # We check for pthread_join because it is in -lpthread on IRIX
  95. # while pthread_create is in libc. We check for pthread_attr_init
  96. # due to DEC craziness with -lpthreads. We check for
  97. # pthread_cleanup_push because it is one of the few pthread
  98. # functions on Solaris that doesn't have a non-functional libc stub.
  99. # We try pthread_create on general principles.
  100. AC_TRY_LINK([#include <pthread.h>],
  101. [pthread_t th; pthread_join(th, 0);
  102. pthread_attr_init(0); pthread_cleanup_push(0, 0);
  103. pthread_create(0,0,0,0); pthread_cleanup_pop(0); ],
  104. [acx_pthread_ok=yes])
  105. LIBS="$save_LIBS"
  106. CFLAGS="$save_CFLAGS"
  107. AC_MSG_RESULT($acx_pthread_ok)
  108. if test "x$acx_pthread_ok" = xyes; then
  109. break;
  110. fi
  111. PTHREAD_LIBS=""
  112. PTHREAD_CFLAGS=""
  113. done
  114. fi
  115. # Various other checks:
  116. if test "x$acx_pthread_ok" = xyes; then
  117. save_LIBS="$LIBS"
  118. LIBS="$PTHREAD_LIBS $LIBS"
  119. save_CFLAGS="$CFLAGS"
  120. CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
  121. # Detect AIX lossage: JOINABLE attribute is called UNDETACHED.
  122. AC_MSG_CHECKING([for joinable pthread attribute])
  123. attr_name=unknown
  124. for attr in PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_UNDETACHED; do
  125. AC_TRY_LINK([#include <pthread.h>], [int attr=$attr; return attr;],
  126. [attr_name=$attr; break])
  127. done
  128. AC_MSG_RESULT($attr_name)
  129. if test "$attr_name" != PTHREAD_CREATE_JOINABLE; then
  130. AC_DEFINE_UNQUOTED(PTHREAD_CREATE_JOINABLE, $attr_name,
  131. [Define to necessary symbol if this constant
  132. uses a non-standard name on your system.])
  133. fi
  134. AC_MSG_CHECKING([if more special flags are required for pthreads])
  135. flag=no
  136. case "${host_cpu}-${host_os}" in
  137. *-aix* | *-freebsd* | *-darwin*) flag="-D_THREAD_SAFE";;
  138. *solaris* | *-osf* | *-hpux*) flag="-D_REENTRANT";;
  139. esac
  140. AC_MSG_RESULT(${flag})
  141. if test "x$flag" != xno; then
  142. PTHREAD_CFLAGS="$flag $PTHREAD_CFLAGS"
  143. fi
  144. LIBS="$save_LIBS"
  145. CFLAGS="$save_CFLAGS"
  146. # More AIX lossage: must compile with cc_r
  147. AC_CHECK_PROG(PTHREAD_CC, cc_r, cc_r, ${CC})
  148. else
  149. PTHREAD_CC="$CC"
  150. fi
  151. AC_SUBST(PTHREAD_LIBS)
  152. AC_SUBST(PTHREAD_CFLAGS)
  153. AC_SUBST(PTHREAD_CC)
  154. # Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND:
  155. if test x"$acx_pthread_ok" = xyes; then
  156. ifelse([$1],,AC_DEFINE(HAVE_PTHREAD,1,[Define if you have POSIX threads libraries and header files.]),[$1])
  157. :
  158. else
  159. acx_pthread_ok=no
  160. $2
  161. fi
  162. AC_LANG_RESTORE
  163. ])dnl ACX_PTHREAD