Arrange so that `SCM_I_CURRENT_THREAD' is not accessed outside of libguile.
[bpt/guile.git] / acinclude.m4
CommitLineData
7a5ab369
LC
1dnl -*- Autoconf -*-
2
3a629497
JB
3dnl On the NeXT, #including <utime.h> doesn't give you a definition for
4dnl struct utime, unless you #define _POSIX_SOURCE.
5
d70e0619 6AC_DEFUN([GUILE_STRUCT_UTIMBUF], [
3a629497
JB
7 AC_CACHE_CHECK([whether we need POSIX to get struct utimbuf],
8 guile_cv_struct_utimbuf_needs_posix,
9 [AC_TRY_CPP([
10#ifdef __EMX__
11#include <sys/utime.h>
12#else
13#include <utime.h>
14#endif
15struct utime blah;
16],
17 guile_cv_struct_utimbuf_needs_posix=no,
18 guile_cv_struct_utimbuf_needs_posix=yes)])
19 if test "$guile_cv_struct_utimbuf_needs_posix" = yes; then
e103c6b4
RB
20 AC_DEFINE([UTIMBUF_NEEDS_POSIX], 1,
21 [Define this if <utime.h> doesn't define struct utimbuf unless
22 _POSIX_SOURCE is defined. See GUILE_STRUCT_UTIMBUF in aclocal.m4.])
3a629497
JB
23 fi])
24
25
26
27
28dnl
29dnl Apparently, at CMU they have a weird version of libc.h that is
30dnl installed in /usr/local/include and conflicts with unistd.h.
31dnl In these situations, we should not #include libc.h.
32dnl This test arranges to #define LIBC_H_WITH_UNISTD_H iff libc.h is
33dnl present on the system, and is safe to #include.
34dnl
35AC_DEFUN([GUILE_HEADER_LIBC_WITH_UNISTD],
36 [
37 AC_CHECK_HEADERS(libc.h unistd.h)
38 AC_CACHE_CHECK(
3d77146f 39 [whether libc.h and unistd.h can be included together],
3a629497
JB
40 guile_cv_header_libc_with_unistd,
41 [
42 if test "$ac_cv_header_libc_h" = "no"; then
43 guile_cv_header_libc_with_unistd="no"
42d0ffc9 44 elif test "$ac_cv_header_unistd_h" = "no"; then
3a629497
JB
45 guile_cv_header_libc_with_unistd="yes"
46 else
47 AC_TRY_COMPILE(
48 [
49# include <libc.h>
50# include <unistd.h>
51 ],
52 [],
53 [guile_cv_header_libc_with_unistd=yes],
54 [guile_cv_header_libc_with_unistd=no]
55 )
56 fi
57 ]
58 )
59 if test "$guile_cv_header_libc_with_unistd" = yes; then
e103c6b4
RB
60 AC_DEFINE(LIBC_H_WITH_UNISTD_H, 1,
61 [Define this if we should include <libc.h> when we've already
62 included <unistd.h>. On some systems, they conflict, and libc.h
63 should be omitted. See GUILE_HEADER_LIBC_WITH_UNISTD in
64 aclocal.m4.])
3a629497
JB
65 fi
66 ]
67)
0b89e78e
MD
68
69
70
71dnl This is needed when we want to check for the same function repeatedly
72dnl with other parameters, such as libraries, varying.
73dnl
74dnl GUILE_NAMED_CHECK_FUNC(FUNCTION, TESTNAME,
75dnl [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]])
d70e0619 76AC_DEFUN([GUILE_NAMED_CHECK_FUNC],
0b89e78e
MD
77[AC_MSG_CHECKING([for $1])
78AC_CACHE_VAL(ac_cv_func_$1_$2,
79[AC_TRY_LINK(
80dnl Don't include <ctype.h> because on OSF/1 3.0 it includes <sys/types.h>
81dnl which includes <sys/select.h> which contains a prototype for
82dnl select. Similarly for bzero.
83[/* System header to define __stub macros and hopefully few prototypes,
84 which can conflict with char $1(); below. */
85#include <assert.h>
86/* Override any gcc2 internal prototype to avoid an error. */
ee79b9ff 87#ifdef __cplusplus
0b89e78e
MD
88extern "C"
89#endif
ee79b9ff 90/* We use char because int might match the return type of a gcc2
0b89e78e
MD
91 builtin and then its argument prototype would still apply. */
92char $1();
93], [
94/* The GNU C library defines this for functions which it implements
95 to always fail with ENOSYS. Some functions are actually named
96 something starting with __ and the normal name is an alias. */
97#if defined (__stub_$1) || defined (__stub___$1)
98choke me
99#else
100$1();
101#endif
102], eval "ac_cv_func_$1_$2=yes", eval "ac_cv_func_$1_$2=no")])
103if eval "test \"`echo '$ac_cv_func_'$1'_'$2`\" = yes"; then
104 AC_MSG_RESULT(yes)
105 ifelse([$3], , :, [$3])
106else
107 AC_MSG_RESULT(no)
108ifelse([$4], , , [$4
109])dnl
110fi
111])
75bfae86
MV
112
113
114
115
d79a62db
NJ
116dnl Available from the Autoconf Macro Archive at:
117dnl http://autoconf-archive.cryp.to/acx_pthread.html
75bfae86
MV
118dnl
119AC_DEFUN([ACX_PTHREAD], [
120AC_REQUIRE([AC_CANONICAL_HOST])
121AC_LANG_SAVE
122AC_LANG_C
123acx_pthread_ok=no
124
125# We used to check for pthread.h first, but this fails if pthread.h
126# requires special compiler flags (e.g. on True64 or Sequent).
127# It gets checked for in the link test anyway.
128
129# First of all, check if the user has set any of the PTHREAD_LIBS,
130# etcetera environment variables, and if threads linking works using
131# them:
132if test x"$PTHREAD_LIBS$PTHREAD_CFLAGS" != x; then
133 save_CFLAGS="$CFLAGS"
134 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
135 save_LIBS="$LIBS"
136 LIBS="$PTHREAD_LIBS $LIBS"
137 AC_MSG_CHECKING([for pthread_join in LIBS=$PTHREAD_LIBS with CFLAGS=$PTHREAD_CFLAGS])
138 AC_TRY_LINK_FUNC(pthread_join, acx_pthread_ok=yes)
139 AC_MSG_RESULT($acx_pthread_ok)
140 if test x"$acx_pthread_ok" = xno; then
141 PTHREAD_LIBS=""
142 PTHREAD_CFLAGS=""
143 fi
144 LIBS="$save_LIBS"
145 CFLAGS="$save_CFLAGS"
146fi
147
148# We must check for the threads library under a number of different
149# names; the ordering is very important because some systems
150# (e.g. DEC) have both -lpthread and -lpthreads, where one of the
151# libraries is broken (non-POSIX).
152
153# Create a list of thread flags to try. Items starting with a "-" are
154# C compiler flags, and other items are library names, except for "none"
155# which indicates that we try without any flags at all, and "pthread-config"
156# which is a program returning the flags for the Pth emulation library.
157
158acx_pthread_flags="pthreads none -Kthread -kthread lthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config"
159
160# The ordering *is* (sometimes) important. Some notes on the
161# individual items follow:
162
163# pthreads: AIX (must check this before -lpthread)
164# none: in case threads are in libc; should be tried before -Kthread and
165# other compiler flags to prevent continual compiler warnings
166# -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h)
167# -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able)
168# lthread: LinuxThreads port on FreeBSD (also preferred to -pthread)
169# -pthread: Linux/gcc (kernel threads), BSD/gcc (userland threads)
170# -pthreads: Solaris/gcc
171# -mthreads: Mingw32/gcc, Lynx/gcc
172# -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it
173# doesn't hurt to check since this sometimes defines pthreads too;
174# also defines -D_REENTRANT)
d79a62db 175# ... -mt is also the pthreads flag for HP/aCC
75bfae86
MV
176# pthread: Linux, etcetera
177# --thread-safe: KAI C++
178# pthread-config: use pthread-config program (for GNU Pth library)
179
180case "${host_cpu}-${host_os}" in
181 *solaris*)
182
183 # On Solaris (at least, for some versions), libc contains stubbed
184 # (non-functional) versions of the pthreads routines, so link-based
d79a62db 185 # tests will erroneously succeed. (We need to link with -pthreads/-mt/
75bfae86
MV
186 # -lpthread.) (The stubs are missing pthread_cleanup_push, or rather
187 # a function called by this macro, so we could check for that, but
188 # who knows whether they'll stub that too in a future libc.) So,
189 # we'll just look for -pthreads and -lpthread first:
190
d79a62db 191 acx_pthread_flags="-pthreads pthread -mt -pthread $acx_pthread_flags"
75bfae86
MV
192 ;;
193esac
194
195if test x"$acx_pthread_ok" = xno; then
196for flag in $acx_pthread_flags; do
197
198 case $flag in
199 none)
200 AC_MSG_CHECKING([whether pthreads work without any flags])
201 ;;
202
203 -*)
204 AC_MSG_CHECKING([whether pthreads work with $flag])
205 PTHREAD_CFLAGS="$flag"
206 ;;
207
d79a62db
NJ
208 pthread-config)
209 AC_CHECK_PROG(acx_pthread_config, pthread-config, yes, no)
210 if test x"$acx_pthread_config" = xno; then continue; fi
211 PTHREAD_CFLAGS="`pthread-config --cflags`"
212 PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`"
213 ;;
75bfae86
MV
214
215 *)
216 AC_MSG_CHECKING([for the pthreads library -l$flag])
217 PTHREAD_LIBS="-l$flag"
218 ;;
219 esac
220
221 save_LIBS="$LIBS"
222 save_CFLAGS="$CFLAGS"
223 LIBS="$PTHREAD_LIBS $LIBS"
224 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
225
226 # Check for various functions. We must include pthread.h,
227 # since some functions may be macros. (On the Sequent, we
228 # need a special flag -Kthread to make this header compile.)
229 # We check for pthread_join because it is in -lpthread on IRIX
230 # while pthread_create is in libc. We check for pthread_attr_init
231 # due to DEC craziness with -lpthreads. We check for
232 # pthread_cleanup_push because it is one of the few pthread
233 # functions on Solaris that doesn't have a non-functional libc stub.
234 # We try pthread_create on general principles.
235 AC_TRY_LINK([#include <pthread.h>],
236 [pthread_t th; pthread_join(th, 0);
237 pthread_attr_init(0); pthread_cleanup_push(0, 0);
238 pthread_create(0,0,0,0); pthread_cleanup_pop(0); ],
239 [acx_pthread_ok=yes])
240
241 LIBS="$save_LIBS"
242 CFLAGS="$save_CFLAGS"
243
244 AC_MSG_RESULT($acx_pthread_ok)
245 if test "x$acx_pthread_ok" = xyes; then
246 break;
247 fi
248
249 PTHREAD_LIBS=""
250 PTHREAD_CFLAGS=""
251done
252fi
253
254# Various other checks:
255if test "x$acx_pthread_ok" = xyes; then
256 save_LIBS="$LIBS"
257 LIBS="$PTHREAD_LIBS $LIBS"
258 save_CFLAGS="$CFLAGS"
259 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
260
d79a62db 261 # Detect AIX lossage: JOINABLE attribute is called UNDETACHED.
75bfae86 262 AC_MSG_CHECKING([for joinable pthread attribute])
d79a62db
NJ
263 attr_name=unknown
264 for attr in PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_UNDETACHED; do
265 AC_TRY_LINK([#include <pthread.h>], [int attr=$attr; return attr;],
266 [attr_name=$attr; break])
267 done
268 AC_MSG_RESULT($attr_name)
269 if test "$attr_name" != PTHREAD_CREATE_JOINABLE; then
270 AC_DEFINE_UNQUOTED(PTHREAD_CREATE_JOINABLE, $attr_name,
271 [Define to necessary symbol if this constant
272 uses a non-standard name on your system.])
75bfae86
MV
273 fi
274
275 AC_MSG_CHECKING([if more special flags are required for pthreads])
276 flag=no
277 case "${host_cpu}-${host_os}" in
d79a62db
NJ
278 *-aix* | *-freebsd* | *-darwin*) flag="-D_THREAD_SAFE";;
279 *solaris* | *-osf* | *-hpux*) flag="-D_REENTRANT";;
75bfae86
MV
280 esac
281 AC_MSG_RESULT(${flag})
282 if test "x$flag" != xno; then
d79a62db 283 PTHREAD_CFLAGS="$flag $PTHREAD_CFLAGS"
75bfae86
MV
284 fi
285
286 LIBS="$save_LIBS"
287 CFLAGS="$save_CFLAGS"
288
d79a62db
NJ
289 # More AIX lossage: must compile with xlc_r or cc_r
290 if test x"$GCC" != xyes; then
291 AC_CHECK_PROGS(PTHREAD_CC, xlc_r cc_r, ${CC})
292 else
293 PTHREAD_CC=$CC
294 fi
75bfae86
MV
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
7a5ab369 313
9d19a9d6
LC
314dnl GUILE_GNU_LD_RELRO
315dnl
316dnl Check whether GNU ld's read-only relocations (the `PT_GNU_RELRO'
317dnl ELF segment header) are supported. This allows things like
318dnl statically allocated cells (1) to eventually be remapped read-only
319dnl by the loader, and (2) to be identified as pointerless by the
76e8a758
LC
320dnl garbage collector. Substitute `GNU_LD_FLAGS' with the relevant
321dnl flags.
9d19a9d6
LC
322AC_DEFUN([GUILE_GNU_LD_RELRO], [
323 AC_MSG_CHECKING([whether the linker understands `-z relro'])
324
76e8a758
LC
325 GNU_LD_FLAGS="-Wl,-z -Wl,relro"
326
9d19a9d6 327 save_LDFLAGS="$LDFLAGS"
76e8a758 328 LDFLAGS="$LDFLAGS $GNU_LD_FLAGS"
9d19a9d6
LC
329 AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])],
330 [AC_MSG_RESULT([yes])],
331 [AC_MSG_RESULT([no])
76e8a758
LC
332 GNU_LD_FLAGS=""])
333 LDFLAGS="$save_LDFLAGS"
334
335 AC_SUBST([GNU_LD_FLAGS])
9d19a9d6
LC
336])
337
7a5ab369
LC
338dnl GUILE_READLINE
339dnl
340dnl Check all the things needed by `guile-readline', the Readline
341dnl bindings.
342AC_DEFUN([GUILE_READLINE], [
343 for termlib in ncurses curses termcap terminfo termlib ; do
344 AC_CHECK_LIB(${termlib}, [tgoto],
345 [READLINE_LIBS="-l${termlib} $READLINE_LIBS"; break])
346 done
347
348 AC_LIB_LINKFLAGS([readline])
349
350 if test "x$LTLIBREADLINE" = "x"; then
351 AC_MSG_WARN([GNU Readline was not found on your system.])
352 else
353 rl_save_LIBS="$LIBS"
354 LIBS="$LIBREADLINE $READLINE_LIBS $LIBS"
355
356 AC_CHECK_FUNCS([siginterrupt rl_clear_signals rl_cleanup_after_signal])
357
358 dnl Check for modern readline naming
359 AC_CHECK_FUNCS([rl_filename_completion_function])
360
361 dnl Check for rl_get_keymap. We only use this for deciding whether to
362 dnl install paren matching on the Guile command line (when using
363 dnl readline for input), so it's completely optional.
364 AC_CHECK_FUNCS([rl_get_keymap])
365
366 AC_CACHE_CHECK([for rl_getc_function pointer in readline],
367 ac_cv_var_rl_getc_function,
368 [AC_TRY_LINK([
369 #include <stdio.h>
370 #include <readline/readline.h>],
371 [printf ("%ld", (long) rl_getc_function)],
372 [ac_cv_var_rl_getc_function=yes],
373 [ac_cv_var_rl_getc_function=no])])
374 if test "${ac_cv_var_rl_getc_function}" = "yes"; then
375 AC_DEFINE([HAVE_RL_GETC_FUNCTION], 1,
376 [Define if your readline library has the rl_getc_function variable.])
377 fi
378
379 if test $ac_cv_var_rl_getc_function = no; then
380 AC_MSG_WARN([*** GNU Readline is too old on your system.])
381 AC_MSG_WARN([*** You need readline version 2.1 or later.])
382 LTLIBREADLINE=""
383 LIBREADLINE=""
384 fi
385
386 LIBS="$rl_save_LIBS"
387
023cd5ba 388 READLINE_LIBS="$LTLIBREADLINE $READLINE_LIBS"
7a5ab369
LC
389 fi
390
391 AM_CONDITIONAL([HAVE_READLINE], [test "x$LTLIBREADLINE" != "x"])
392
393 AC_CHECK_FUNCS([strdup])
394
395 AC_SUBST([READLINE_LIBS])
396
397 . $srcdir/guile-readline/LIBGUILEREADLINE-VERSION
398 AC_SUBST(LIBGUILEREADLINE_MAJOR)
399 AC_SUBST(LIBGUILEREADLINE_INTERFACE_CURRENT)
400 AC_SUBST(LIBGUILEREADLINE_INTERFACE_REVISION)
401 AC_SUBST(LIBGUILEREADLINE_INTERFACE_AGE)
402 AC_SUBST(LIBGUILEREADLINE_INTERFACE)
403])