(SCM_ARRAY_DIMS): Rename scm_i_attay_dims -->
[bpt/guile.git] / acinclude.m4
CommitLineData
3a629497
JB
1dnl On the NeXT, #including <utime.h> doesn't give you a definition for
2dnl struct utime, unless you #define _POSIX_SOURCE.
3
d70e0619 4AC_DEFUN([GUILE_STRUCT_UTIMBUF], [
3a629497
JB
5 AC_CACHE_CHECK([whether we need POSIX to get struct utimbuf],
6 guile_cv_struct_utimbuf_needs_posix,
7 [AC_TRY_CPP([
8#ifdef __EMX__
9#include <sys/utime.h>
10#else
11#include <utime.h>
12#endif
13struct utime blah;
14],
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
e103c6b4
RB
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.])
3a629497
JB
21 fi])
22
23
24
25
26dnl
27dnl Apparently, at CMU they have a weird version of libc.h that is
28dnl installed in /usr/local/include and conflicts with unistd.h.
29dnl In these situations, we should not #include libc.h.
30dnl This test arranges to #define LIBC_H_WITH_UNISTD_H iff libc.h is
31dnl present on the system, and is safe to #include.
32dnl
33AC_DEFUN([GUILE_HEADER_LIBC_WITH_UNISTD],
34 [
35 AC_CHECK_HEADERS(libc.h unistd.h)
36 AC_CACHE_CHECK(
3d77146f 37 [whether libc.h and unistd.h can be included together],
3a629497
JB
38 guile_cv_header_libc_with_unistd,
39 [
40 if test "$ac_cv_header_libc_h" = "no"; then
41 guile_cv_header_libc_with_unistd="no"
42d0ffc9 42 elif test "$ac_cv_header_unistd_h" = "no"; then
3a629497
JB
43 guile_cv_header_libc_with_unistd="yes"
44 else
45 AC_TRY_COMPILE(
46 [
47# include <libc.h>
48# include <unistd.h>
49 ],
50 [],
51 [guile_cv_header_libc_with_unistd=yes],
52 [guile_cv_header_libc_with_unistd=no]
53 )
54 fi
55 ]
56 )
57 if test "$guile_cv_header_libc_with_unistd" = yes; then
e103c6b4
RB
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
62 aclocal.m4.])
3a629497
JB
63 fi
64 ]
65)
0b89e78e
MD
66
67
68
69dnl This is needed when we want to check for the same function repeatedly
70dnl with other parameters, such as libraries, varying.
71dnl
72dnl GUILE_NAMED_CHECK_FUNC(FUNCTION, TESTNAME,
73dnl [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]])
d70e0619 74AC_DEFUN([GUILE_NAMED_CHECK_FUNC],
0b89e78e
MD
75[AC_MSG_CHECKING([for $1])
76AC_CACHE_VAL(ac_cv_func_$1_$2,
77[AC_TRY_LINK(
78dnl Don't include <ctype.h> because on OSF/1 3.0 it includes <sys/types.h>
79dnl which includes <sys/select.h> which contains a prototype for
80dnl select. Similarly for bzero.
81[/* System header to define __stub macros and hopefully few prototypes,
82 which can conflict with char $1(); below. */
83#include <assert.h>
84/* Override any gcc2 internal prototype to avoid an error. */
ee79b9ff 85#ifdef __cplusplus
0b89e78e
MD
86extern "C"
87#endif
ee79b9ff 88/* We use char because int might match the return type of a gcc2
0b89e78e
MD
89 builtin and then its argument prototype would still apply. */
90char $1();
91], [
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)
96choke me
97#else
98$1();
99#endif
100], eval "ac_cv_func_$1_$2=yes", eval "ac_cv_func_$1_$2=no")])
101if eval "test \"`echo '$ac_cv_func_'$1'_'$2`\" = yes"; then
102 AC_MSG_RESULT(yes)
103 ifelse([$3], , :, [$3])
104else
105 AC_MSG_RESULT(no)
106ifelse([$4], , , [$4
107])dnl
108fi
109])
75bfae86
MV
110
111
112
113
114dnl Available from the GNU Autoconf Macro Archive at:
115dnl http://www.gnu.org/software/ac-archive/htmldoc/acx_pthread.html
116dnl
117AC_DEFUN([ACX_PTHREAD], [
118AC_REQUIRE([AC_CANONICAL_HOST])
119AC_LANG_SAVE
120AC_LANG_C
121acx_pthread_ok=no
122
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.
126
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
129# them:
130if test x"$PTHREAD_LIBS$PTHREAD_CFLAGS" != x; then
131 save_CFLAGS="$CFLAGS"
132 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
133 save_LIBS="$LIBS"
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
139 PTHREAD_LIBS=""
140 PTHREAD_CFLAGS=""
141 fi
142 LIBS="$save_LIBS"
143 CFLAGS="$save_CFLAGS"
144fi
145
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).
150
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.
155
156acx_pthread_flags="pthreads none -Kthread -kthread lthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config"
157
158# The ordering *is* (sometimes) important. Some notes on the
159# individual items follow:
160
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# pthread: Linux, etcetera
174# --thread-safe: KAI C++
175# pthread-config: use pthread-config program (for GNU Pth library)
176
177case "${host_cpu}-${host_os}" in
178 *solaris*)
179
180 # On Solaris (at least, for some versions), libc contains stubbed
181 # (non-functional) versions of the pthreads routines, so link-based
182 # tests will erroneously succeed. (We need to link with -pthread or
183 # -lpthread.) (The stubs are missing pthread_cleanup_push, or rather
184 # a function called by this macro, so we could check for that, but
185 # who knows whether they'll stub that too in a future libc.) So,
186 # we'll just look for -pthreads and -lpthread first:
187
188 acx_pthread_flags="-pthread -pthreads pthread -mt $acx_pthread_flags"
189 ;;
190esac
191
192if test x"$acx_pthread_ok" = xno; then
193for flag in $acx_pthread_flags; do
194
195 case $flag in
196 none)
197 AC_MSG_CHECKING([whether pthreads work without any flags])
198 ;;
199
200 -*)
201 AC_MSG_CHECKING([whether pthreads work with $flag])
202 PTHREAD_CFLAGS="$flag"
203 ;;
204
205 pthread-config)
206 AC_CHECK_PROG(acx_pthread_config, pthread-config, yes, no)
207 if test x"$acx_pthread_config" = xno; then continue; fi
208 PTHREAD_CFLAGS="`pthread-config --cflags`"
209 PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`"
210 ;;
211
212 *)
213 AC_MSG_CHECKING([for the pthreads library -l$flag])
214 PTHREAD_LIBS="-l$flag"
215 ;;
216 esac
217
218 save_LIBS="$LIBS"
219 save_CFLAGS="$CFLAGS"
220 LIBS="$PTHREAD_LIBS $LIBS"
221 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
222
223 # Check for various functions. We must include pthread.h,
224 # since some functions may be macros. (On the Sequent, we
225 # need a special flag -Kthread to make this header compile.)
226 # We check for pthread_join because it is in -lpthread on IRIX
227 # while pthread_create is in libc. We check for pthread_attr_init
228 # due to DEC craziness with -lpthreads. We check for
229 # pthread_cleanup_push because it is one of the few pthread
230 # functions on Solaris that doesn't have a non-functional libc stub.
231 # We try pthread_create on general principles.
232 AC_TRY_LINK([#include <pthread.h>],
233 [pthread_t th; pthread_join(th, 0);
234 pthread_attr_init(0); pthread_cleanup_push(0, 0);
235 pthread_create(0,0,0,0); pthread_cleanup_pop(0); ],
236 [acx_pthread_ok=yes])
237
238 LIBS="$save_LIBS"
239 CFLAGS="$save_CFLAGS"
240
241 AC_MSG_RESULT($acx_pthread_ok)
242 if test "x$acx_pthread_ok" = xyes; then
243 break;
244 fi
245
246 PTHREAD_LIBS=""
247 PTHREAD_CFLAGS=""
248done
249fi
250
251# Various other checks:
252if test "x$acx_pthread_ok" = xyes; then
253 save_LIBS="$LIBS"
254 LIBS="$PTHREAD_LIBS $LIBS"
255 save_CFLAGS="$CFLAGS"
256 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
257
258 # Detect AIX lossage: threads are created detached by default
259 # and the JOINABLE attribute has a nonstandard name (UNDETACHED).
260 AC_MSG_CHECKING([for joinable pthread attribute])
261 AC_TRY_LINK([#include <pthread.h>],
262 [int attr=PTHREAD_CREATE_JOINABLE;],
263 ok=PTHREAD_CREATE_JOINABLE, ok=unknown)
264 if test x"$ok" = xunknown; then
265 AC_TRY_LINK([#include <pthread.h>],
266 [int attr=PTHREAD_CREATE_UNDETACHED;],
267 ok=PTHREAD_CREATE_UNDETACHED, ok=unknown)
268 fi
269 if test x"$ok" != xPTHREAD_CREATE_JOINABLE; then
270 AC_DEFINE(PTHREAD_CREATE_JOINABLE, $ok,
271 [Define to the necessary symbol if this constant
272 uses a non-standard name on your system.])
273 fi
274 AC_MSG_RESULT(${ok})
275 if test x"$ok" = xunknown; then
276 AC_MSG_WARN([we do not know how to create joinable pthreads])
277 fi
278
279 AC_MSG_CHECKING([if more special flags are required for pthreads])
280 flag=no
281 case "${host_cpu}-${host_os}" in
282 *-aix* | *-freebsd* | *-darwin*) flag="-D_THREAD_SAFE";;
283 *solaris* | *-osf* | *-hpux*) flag="-D_REENTRANT";;
284 esac
285 AC_MSG_RESULT(${flag})
286 if test "x$flag" != xno; then
287 PTHREAD_CFLAGS="$flag $PTHREAD_CFLAGS"
288 fi
289
290 LIBS="$save_LIBS"
291 CFLAGS="$save_CFLAGS"
292
293 # More AIX lossage: must compile with cc_r
294 AC_CHECK_PROG(PTHREAD_CC, cc_r, cc_r, ${CC})
295else
296 PTHREAD_CC="$CC"
297fi
298
299AC_SUBST(PTHREAD_LIBS)
300AC_SUBST(PTHREAD_CFLAGS)
301AC_SUBST(PTHREAD_CC)
302
303# Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND:
304if test x"$acx_pthread_ok" = xyes; then
305 ifelse([$1],,AC_DEFINE(HAVE_PTHREAD,1,[Define if you have POSIX threads libraries and header files.]),[$1])
306 :
307else
308 acx_pthread_ok=no
309 $2
310fi
311AC_LANG_RESTORE
312])dnl ACX_PTHREAD