acinclude.m4 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. dnl On the NeXT, #including <utime.h> doesn't give you a definition for
  2. dnl struct utime, unless you #define _POSIX_SOURCE.
  3. AC_DEFUN([GUILE_STRUCT_UTIMBUF], [
  4. AC_CACHE_CHECK([whether we need POSIX to get struct utimbuf],
  5. guile_cv_struct_utimbuf_needs_posix,
  6. [AC_TRY_CPP([
  7. #ifdef __EMX__
  8. #include <sys/utime.h>
  9. #else
  10. #include <utime.h>
  11. #endif
  12. struct utime blah;
  13. ],
  14. guile_cv_struct_utimbuf_needs_posix=no,
  15. guile_cv_struct_utimbuf_needs_posix=yes)])
  16. if test "$guile_cv_struct_utimbuf_needs_posix" = yes; then
  17. AC_DEFINE([UTIMBUF_NEEDS_POSIX], 1,
  18. [Define this if <utime.h> doesn't define struct utimbuf unless
  19. _POSIX_SOURCE is defined. See GUILE_STRUCT_UTIMBUF in aclocal.m4.])
  20. fi])
  21. dnl
  22. dnl Apparently, at CMU they have a weird version of libc.h that is
  23. dnl installed in /usr/local/include and conflicts with unistd.h.
  24. dnl In these situations, we should not #include libc.h.
  25. dnl This test arranges to #define LIBC_H_WITH_UNISTD_H iff libc.h is
  26. dnl present on the system, and is safe to #include.
  27. dnl
  28. AC_DEFUN([GUILE_HEADER_LIBC_WITH_UNISTD],
  29. [
  30. AC_CHECK_HEADERS(libc.h unistd.h)
  31. AC_CACHE_CHECK(
  32. [whether libc.h and unistd.h can be included together],
  33. guile_cv_header_libc_with_unistd,
  34. [
  35. if test "$ac_cv_header_libc_h" = "no"; then
  36. guile_cv_header_libc_with_unistd="no"
  37. elif test "$ac_cv_header_unistd_h" = "no"; then
  38. guile_cv_header_libc_with_unistd="yes"
  39. else
  40. AC_TRY_COMPILE(
  41. [
  42. # include <libc.h>
  43. # include <unistd.h>
  44. ],
  45. [],
  46. [guile_cv_header_libc_with_unistd=yes],
  47. [guile_cv_header_libc_with_unistd=no]
  48. )
  49. fi
  50. ]
  51. )
  52. if test "$guile_cv_header_libc_with_unistd" = yes; then
  53. AC_DEFINE(LIBC_H_WITH_UNISTD_H, 1,
  54. [Define this if we should include <libc.h> when we've already
  55. included <unistd.h>. On some systems, they conflict, and libc.h
  56. should be omitted. See GUILE_HEADER_LIBC_WITH_UNISTD in
  57. aclocal.m4.])
  58. fi
  59. ]
  60. )
  61. dnl This is needed when we want to check for the same function repeatedly
  62. dnl with other parameters, such as libraries, varying.
  63. dnl
  64. dnl GUILE_NAMED_CHECK_FUNC(FUNCTION, TESTNAME,
  65. dnl [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]])
  66. AC_DEFUN([GUILE_NAMED_CHECK_FUNC],
  67. [AC_MSG_CHECKING([for $1])
  68. AC_CACHE_VAL(ac_cv_func_$1_$2,
  69. [AC_TRY_LINK(
  70. dnl Don't include <ctype.h> because on OSF/1 3.0 it includes <sys/types.h>
  71. dnl which includes <sys/select.h> which contains a prototype for
  72. dnl select. Similarly for bzero.
  73. [/* System header to define __stub macros and hopefully few prototypes,
  74. which can conflict with char $1(); below. */
  75. #include <assert.h>
  76. /* Override any gcc2 internal prototype to avoid an error. */
  77. #ifdef __cplusplus
  78. extern "C"
  79. #endif
  80. /* We use char because int might match the return type of a gcc2
  81. builtin and then its argument prototype would still apply. */
  82. char $1();
  83. ], [
  84. /* The GNU C library defines this for functions which it implements
  85. to always fail with ENOSYS. Some functions are actually named
  86. something starting with __ and the normal name is an alias. */
  87. #if defined (__stub_$1) || defined (__stub___$1)
  88. choke me
  89. #else
  90. $1();
  91. #endif
  92. ], eval "ac_cv_func_$1_$2=yes", eval "ac_cv_func_$1_$2=no")])
  93. if eval "test \"`echo '$ac_cv_func_'$1'_'$2`\" = yes"; then
  94. AC_MSG_RESULT(yes)
  95. ifelse([$3], , :, [$3])
  96. else
  97. AC_MSG_RESULT(no)
  98. ifelse([$4], , , [$4
  99. ])dnl
  100. fi
  101. ])
  102. dnl Available from the Autoconf Macro Archive at:
  103. dnl http://autoconf-archive.cryp.to/acx_pthread.html
  104. dnl
  105. AC_DEFUN([ACX_PTHREAD], [
  106. AC_REQUIRE([AC_CANONICAL_HOST])
  107. AC_LANG_SAVE
  108. AC_LANG_C
  109. acx_pthread_ok=no
  110. # We used to check for pthread.h first, but this fails if pthread.h
  111. # requires special compiler flags (e.g. on True64 or Sequent).
  112. # It gets checked for in the link test anyway.
  113. # First of all, check if the user has set any of the PTHREAD_LIBS,
  114. # etcetera environment variables, and if threads linking works using
  115. # them:
  116. if test x"$PTHREAD_LIBS$PTHREAD_CFLAGS" != x; then
  117. save_CFLAGS="$CFLAGS"
  118. CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
  119. save_LIBS="$LIBS"
  120. LIBS="$PTHREAD_LIBS $LIBS"
  121. AC_MSG_CHECKING([for pthread_join in LIBS=$PTHREAD_LIBS with CFLAGS=$PTHREAD_CFLAGS])
  122. AC_TRY_LINK_FUNC(pthread_join, acx_pthread_ok=yes)
  123. AC_MSG_RESULT($acx_pthread_ok)
  124. if test x"$acx_pthread_ok" = xno; then
  125. PTHREAD_LIBS=""
  126. PTHREAD_CFLAGS=""
  127. fi
  128. LIBS="$save_LIBS"
  129. CFLAGS="$save_CFLAGS"
  130. fi
  131. # We must check for the threads library under a number of different
  132. # names; the ordering is very important because some systems
  133. # (e.g. DEC) have both -lpthread and -lpthreads, where one of the
  134. # libraries is broken (non-POSIX).
  135. # Create a list of thread flags to try. Items starting with a "-" are
  136. # C compiler flags, and other items are library names, except for "none"
  137. # which indicates that we try without any flags at all, and "pthread-config"
  138. # which is a program returning the flags for the Pth emulation library.
  139. acx_pthread_flags="pthreads none -Kthread -kthread lthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config"
  140. # The ordering *is* (sometimes) important. Some notes on the
  141. # individual items follow:
  142. # pthreads: AIX (must check this before -lpthread)
  143. # none: in case threads are in libc; should be tried before -Kthread and
  144. # other compiler flags to prevent continual compiler warnings
  145. # -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h)
  146. # -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able)
  147. # lthread: LinuxThreads port on FreeBSD (also preferred to -pthread)
  148. # -pthread: Linux/gcc (kernel threads), BSD/gcc (userland threads)
  149. # -pthreads: Solaris/gcc
  150. # -mthreads: Mingw32/gcc, Lynx/gcc
  151. # -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it
  152. # doesn't hurt to check since this sometimes defines pthreads too;
  153. # also defines -D_REENTRANT)
  154. # ... -mt is also the pthreads flag for HP/aCC
  155. # pthread: Linux, etcetera
  156. # --thread-safe: KAI C++
  157. # pthread-config: use pthread-config program (for GNU Pth library)
  158. case "${host_cpu}-${host_os}" in
  159. *solaris*)
  160. # On Solaris (at least, for some versions), libc contains stubbed
  161. # (non-functional) versions of the pthreads routines, so link-based
  162. # tests will erroneously succeed. (We need to link with -pthreads/-mt/
  163. # -lpthread.) (The stubs are missing pthread_cleanup_push, or rather
  164. # a function called by this macro, so we could check for that, but
  165. # who knows whether they'll stub that too in a future libc.) So,
  166. # we'll just look for -pthreads and -lpthread first:
  167. acx_pthread_flags="-pthreads pthread -mt -pthread $acx_pthread_flags"
  168. ;;
  169. esac
  170. if test x"$acx_pthread_ok" = xno; then
  171. for flag in $acx_pthread_flags; do
  172. case $flag in
  173. none)
  174. AC_MSG_CHECKING([whether pthreads work without any flags])
  175. ;;
  176. -*)
  177. AC_MSG_CHECKING([whether pthreads work with $flag])
  178. PTHREAD_CFLAGS="$flag"
  179. ;;
  180. pthread-config)
  181. AC_CHECK_PROG(acx_pthread_config, pthread-config, yes, no)
  182. if test x"$acx_pthread_config" = xno; then continue; fi
  183. PTHREAD_CFLAGS="`pthread-config --cflags`"
  184. PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`"
  185. ;;
  186. *)
  187. AC_MSG_CHECKING([for the pthreads library -l$flag])
  188. PTHREAD_LIBS="-l$flag"
  189. ;;
  190. esac
  191. save_LIBS="$LIBS"
  192. save_CFLAGS="$CFLAGS"
  193. LIBS="$PTHREAD_LIBS $LIBS"
  194. CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
  195. # Check for various functions. We must include pthread.h,
  196. # since some functions may be macros. (On the Sequent, we
  197. # need a special flag -Kthread to make this header compile.)
  198. # We check for pthread_join because it is in -lpthread on IRIX
  199. # while pthread_create is in libc. We check for pthread_attr_init
  200. # due to DEC craziness with -lpthreads. We check for
  201. # pthread_cleanup_push because it is one of the few pthread
  202. # functions on Solaris that doesn't have a non-functional libc stub.
  203. # We try pthread_create on general principles.
  204. AC_TRY_LINK([#include <pthread.h>],
  205. [pthread_t th; pthread_join(th, 0);
  206. pthread_attr_init(0); pthread_cleanup_push(0, 0);
  207. pthread_create(0,0,0,0); pthread_cleanup_pop(0); ],
  208. [acx_pthread_ok=yes])
  209. LIBS="$save_LIBS"
  210. CFLAGS="$save_CFLAGS"
  211. AC_MSG_RESULT($acx_pthread_ok)
  212. if test "x$acx_pthread_ok" = xyes; then
  213. break;
  214. fi
  215. PTHREAD_LIBS=""
  216. PTHREAD_CFLAGS=""
  217. done
  218. fi
  219. # Various other checks:
  220. if test "x$acx_pthread_ok" = xyes; then
  221. save_LIBS="$LIBS"
  222. LIBS="$PTHREAD_LIBS $LIBS"
  223. save_CFLAGS="$CFLAGS"
  224. CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
  225. # Detect AIX lossage: JOINABLE attribute is called UNDETACHED.
  226. AC_MSG_CHECKING([for joinable pthread attribute])
  227. attr_name=unknown
  228. for attr in PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_UNDETACHED; do
  229. AC_TRY_LINK([#include <pthread.h>], [int attr=$attr; return attr;],
  230. [attr_name=$attr; break])
  231. done
  232. AC_MSG_RESULT($attr_name)
  233. if test "$attr_name" != PTHREAD_CREATE_JOINABLE; then
  234. AC_DEFINE_UNQUOTED(PTHREAD_CREATE_JOINABLE, $attr_name,
  235. [Define to necessary symbol if this constant
  236. uses a non-standard name on your system.])
  237. fi
  238. AC_MSG_CHECKING([if more special flags are required for pthreads])
  239. flag=no
  240. case "${host_cpu}-${host_os}" in
  241. *-aix* | *-freebsd* | *-darwin*) flag="-D_THREAD_SAFE";;
  242. *solaris* | *-osf* | *-hpux*) flag="-D_REENTRANT";;
  243. esac
  244. AC_MSG_RESULT(${flag})
  245. if test "x$flag" != xno; then
  246. PTHREAD_CFLAGS="$flag $PTHREAD_CFLAGS"
  247. fi
  248. LIBS="$save_LIBS"
  249. CFLAGS="$save_CFLAGS"
  250. # More AIX lossage: must compile with xlc_r or cc_r
  251. if test x"$GCC" != xyes; then
  252. AC_CHECK_PROGS(PTHREAD_CC, xlc_r cc_r, ${CC})
  253. else
  254. PTHREAD_CC=$CC
  255. fi
  256. else
  257. PTHREAD_CC="$CC"
  258. fi
  259. AC_SUBST(PTHREAD_LIBS)
  260. AC_SUBST(PTHREAD_CFLAGS)
  261. AC_SUBST(PTHREAD_CC)
  262. # Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND:
  263. if test x"$acx_pthread_ok" = xyes; then
  264. ifelse([$1],,AC_DEFINE(HAVE_PTHREAD,1,[Define if you have POSIX threads libraries and header files.]),[$1])
  265. :
  266. else
  267. acx_pthread_ok=no
  268. $2
  269. fi
  270. AC_LANG_RESTORE
  271. ])dnl ACX_PTHREAD