1 dnl On the NeXT, #including <utime.h> doesn't give you a definition for
2 dnl struct utime, unless you #define _POSIX_SOURCE.
4 AC_DEFUN([GUILE_STRUCT_UTIMBUF], [
5 AC_CACHE_CHECK([whether we need POSIX to get struct utimbuf],
6 guile_cv_struct_utimbuf_needs_posix,
15 guile_cv_struct_utimbuf_needs_posix=no,
16 guile_cv_struct_utimbuf_needs_posix=yes)])
17 if test "$guile_cv_struct_utimbuf_needs_posix" = yes; then
18 AC_DEFINE([UTIMBUF_NEEDS_POSIX], 1,
19 [Define this if <utime.h> doesn't define struct utimbuf unless
20 _POSIX_SOURCE is defined. See GUILE_STRUCT_UTIMBUF in aclocal.m4.])
27 dnl Apparently, at CMU they have a weird version of libc.h that is
28 dnl installed in /usr/local/include and conflicts with unistd.h.
29 dnl In these situations, we should not #include libc.h.
30 dnl This test arranges to #define LIBC_H_WITH_UNISTD_H iff libc.h is
31 dnl present on the system, and is safe to #include.
33 AC_DEFUN([GUILE_HEADER_LIBC_WITH_UNISTD],
35 AC_CHECK_HEADERS(libc.h unistd.h)
37 [whether libc.h and unistd.h can be included together],
38 guile_cv_header_libc_with_unistd,
40 if test "$ac_cv_header_libc_h" = "no"; then
41 guile_cv_header_libc_with_unistd="no"
42 elif test "$ac_cv_header_unistd_h" = "no"; then
43 guile_cv_header_libc_with_unistd="yes"
51 [guile_cv_header_libc_with_unistd=yes],
52 [guile_cv_header_libc_with_unistd=no]
57 if test "$guile_cv_header_libc_with_unistd" = yes; then
58 AC_DEFINE(LIBC_H_WITH_UNISTD_H, 1,
59 [Define this if we should include <libc.h> when we've already
60 included <unistd.h>. On some systems, they conflict, and libc.h
61 should be omitted. See GUILE_HEADER_LIBC_WITH_UNISTD in
69 dnl This is needed when we want to check for the same function repeatedly
70 dnl with other parameters, such as libraries, varying.
72 dnl GUILE_NAMED_CHECK_FUNC(FUNCTION, TESTNAME,
73 dnl [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]])
74 AC_DEFUN([GUILE_NAMED_CHECK_FUNC],
75 [AC_MSG_CHECKING([for $1])
76 AC_CACHE_VAL(ac_cv_func_$1_$2,
78 dnl Don't include <ctype.h> because on OSF/1 3.0 it includes <sys/types.h>
79 dnl which includes <sys/select.h> which contains a prototype for
80 dnl select. Similarly for bzero.
81 [/* System header to define __stub macros and hopefully few prototypes,
82 which can conflict with char $1(); below. */
84 /* Override any gcc2 internal prototype to avoid an error. */
88 /* We use char because int might match the return type of a gcc2
89 builtin and then its argument prototype would still apply. */
92 /* The GNU C library defines this for functions which it implements
93 to always fail with ENOSYS. Some functions are actually named
94 something starting with __ and the normal name is an alias. */
95 #if defined (__stub_$1) || defined (__stub___$1)
100 ], eval "ac_cv_func_$1_$2=yes", eval "ac_cv_func_$1_$2=no")])
101 if eval "test \"`echo '$ac_cv_func_'$1'_'$2`\" = yes"; then
103 ifelse([$3], , :, [$3])
114 dnl Available from the Autoconf Macro Archive at:
115 dnl http://autoconf-archive.cryp.to/acx_pthread.html
117 AC_DEFUN([ACX_PTHREAD], [
118 AC_REQUIRE([AC_CANONICAL_HOST])
123 # We used to check for pthread.h first, but this fails if pthread.h
124 # requires special compiler flags (e.g. on True64 or Sequent).
125 # It gets checked for in the link test anyway.
127 # First of all, check if the user has set any of the PTHREAD_LIBS,
128 # etcetera environment variables, and if threads linking works using
130 if test x"$PTHREAD_LIBS$PTHREAD_CFLAGS" != x; then
131 save_CFLAGS="$CFLAGS"
132 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
134 LIBS="$PTHREAD_LIBS $LIBS"
135 AC_MSG_CHECKING([for pthread_join in LIBS=$PTHREAD_LIBS with CFLAGS=$PTHREAD_CFLAGS])
136 AC_TRY_LINK_FUNC(pthread_join, acx_pthread_ok=yes)
137 AC_MSG_RESULT($acx_pthread_ok)
138 if test x"$acx_pthread_ok" = xno; then
143 CFLAGS="$save_CFLAGS"
146 # We must check for the threads library under a number of different
147 # names; the ordering is very important because some systems
148 # (e.g. DEC) have both -lpthread and -lpthreads, where one of the
149 # libraries is broken (non-POSIX).
151 # Create a list of thread flags to try. Items starting with a "-" are
152 # C compiler flags, and other items are library names, except for "none"
153 # which indicates that we try without any flags at all, and "pthread-config"
154 # which is a program returning the flags for the Pth emulation library.
156 acx_pthread_flags="pthreads none -Kthread -kthread lthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config"
158 # The ordering *is* (sometimes) important. Some notes on the
159 # individual items follow:
161 # pthreads: AIX (must check this before -lpthread)
162 # none: in case threads are in libc; should be tried before -Kthread and
163 # other compiler flags to prevent continual compiler warnings
164 # -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h)
165 # -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able)
166 # lthread: LinuxThreads port on FreeBSD (also preferred to -pthread)
167 # -pthread: Linux/gcc (kernel threads), BSD/gcc (userland threads)
168 # -pthreads: Solaris/gcc
169 # -mthreads: Mingw32/gcc, Lynx/gcc
170 # -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it
171 # doesn't hurt to check since this sometimes defines pthreads too;
172 # also defines -D_REENTRANT)
173 # ... -mt is also the pthreads flag for HP/aCC
174 # pthread: Linux, etcetera
175 # --thread-safe: KAI C++
176 # pthread-config: use pthread-config program (for GNU Pth library)
178 case "${host_cpu}-${host_os}" in
181 # On Solaris (at least, for some versions), libc contains stubbed
182 # (non-functional) versions of the pthreads routines, so link-based
183 # tests will erroneously succeed. (We need to link with -pthreads/-mt/
184 # -lpthread.) (The stubs are missing pthread_cleanup_push, or rather
185 # a function called by this macro, so we could check for that, but
186 # who knows whether they'll stub that too in a future libc.) So,
187 # we'll just look for -pthreads and -lpthread first:
189 acx_pthread_flags="-pthreads pthread -mt -pthread $acx_pthread_flags"
193 if test x"$acx_pthread_ok" = xno; then
194 for flag in $acx_pthread_flags; do
198 AC_MSG_CHECKING([whether pthreads work without any flags])
202 AC_MSG_CHECKING([whether pthreads work with $flag])
203 PTHREAD_CFLAGS="$flag"
207 AC_CHECK_PROG(acx_pthread_config, pthread-config, yes, no)
208 if test x"$acx_pthread_config" = xno; then continue; fi
209 PTHREAD_CFLAGS="`pthread-config --cflags`"
210 PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`"
214 AC_MSG_CHECKING([for the pthreads library -l$flag])
215 PTHREAD_LIBS="-l$flag"
220 save_CFLAGS="$CFLAGS"
221 LIBS="$PTHREAD_LIBS $LIBS"
222 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
224 # Check for various functions. We must include pthread.h,
225 # since some functions may be macros. (On the Sequent, we
226 # need a special flag -Kthread to make this header compile.)
227 # We check for pthread_join because it is in -lpthread on IRIX
228 # while pthread_create is in libc. We check for pthread_attr_init
229 # due to DEC craziness with -lpthreads. We check for
230 # pthread_cleanup_push because it is one of the few pthread
231 # functions on Solaris that doesn't have a non-functional libc stub.
232 # We try pthread_create on general principles.
233 AC_TRY_LINK([#include <pthread.h>],
234 [pthread_t th; pthread_join(th, 0);
235 pthread_attr_init(0); pthread_cleanup_push(0, 0);
236 pthread_create(0,0,0,0); pthread_cleanup_pop(0); ],
237 [acx_pthread_ok=yes])
240 CFLAGS="$save_CFLAGS"
242 AC_MSG_RESULT($acx_pthread_ok)
243 if test "x$acx_pthread_ok" = xyes; then
252 # Various other checks:
253 if test "x$acx_pthread_ok" = xyes; then
255 LIBS="$PTHREAD_LIBS $LIBS"
256 save_CFLAGS="$CFLAGS"
257 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
259 # Detect AIX lossage: JOINABLE attribute is called UNDETACHED.
260 AC_MSG_CHECKING([for joinable pthread attribute])
262 for attr in PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_UNDETACHED; do
263 AC_TRY_LINK([#include <pthread.h>], [int attr=$attr; return attr;],
264 [attr_name=$attr; break])
266 AC_MSG_RESULT($attr_name)
267 if test "$attr_name" != PTHREAD_CREATE_JOINABLE; then
268 AC_DEFINE_UNQUOTED(PTHREAD_CREATE_JOINABLE, $attr_name,
269 [Define to necessary symbol if this constant
270 uses a non-standard name on your system.])
273 AC_MSG_CHECKING([if more special flags are required for pthreads])
275 case "${host_cpu}-${host_os}" in
276 *-aix* | *-freebsd* | *-darwin*) flag="-D_THREAD_SAFE";;
277 *solaris* | *-osf* | *-hpux*) flag="-D_REENTRANT";;
279 AC_MSG_RESULT(${flag})
280 if test "x$flag" != xno; then
281 PTHREAD_CFLAGS="$flag $PTHREAD_CFLAGS"
285 CFLAGS="$save_CFLAGS"
287 # More AIX lossage: must compile with xlc_r or cc_r
288 if test x"$GCC" != xyes; then
289 AC_CHECK_PROGS(PTHREAD_CC, xlc_r cc_r, ${CC})
297 AC_SUBST(PTHREAD_LIBS)
298 AC_SUBST(PTHREAD_CFLAGS)
301 # Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND:
302 if test x"$acx_pthread_ok" = xyes; then
303 ifelse([$1],,AC_DEFINE(HAVE_PTHREAD,1,[Define if you have POSIX threads libraries and header files.]),[$1])