3 dnl Copyright (C) 1997, 1999, 2000, 2001, 2002, 2004, 2006,
4 dnl 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
6 dnl This file is part of GUILE
8 dnl GUILE is free software; you can redistribute it and/or modify it under
9 dnl the terms of the GNU Lesser General Public License as published by the
10 dnl Free Software Foundation; either version 3, or (at your option) any
13 dnl GUILE is distributed in the hope that it will be useful, but WITHOUT
14 dnl ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 dnl FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
16 dnl License for more details.
18 dnl You should have received a copy of the GNU Lesser General Public
19 dnl License along with GUILE; see the file COPYING.LESSER. If not, write
20 dnl to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 dnl Floor, Boston, MA 02110-1301, USA.
24 dnl On the NeXT, #including <utime.h> doesn't give you a definition for
25 dnl struct utime, unless you #define _POSIX_SOURCE.
27 AC_DEFUN([GUILE_STRUCT_UTIMBUF], [
28 AC_CACHE_CHECK([whether we need POSIX to get struct utimbuf],
29 guile_cv_struct_utimbuf_needs_posix,
32 #include <sys/utime.h>
38 guile_cv_struct_utimbuf_needs_posix=no,
39 guile_cv_struct_utimbuf_needs_posix=yes)])
40 if test "$guile_cv_struct_utimbuf_needs_posix" = yes; then
41 AC_DEFINE([UTIMBUF_NEEDS_POSIX], 1,
42 [Define this if <utime.h> doesn't define struct utimbuf unless
43 _POSIX_SOURCE is defined. See GUILE_STRUCT_UTIMBUF in aclocal.m4.])
50 dnl Apparently, at CMU they have a weird version of libc.h that is
51 dnl installed in /usr/local/include and conflicts with unistd.h.
52 dnl In these situations, we should not #include libc.h.
53 dnl This test arranges to #define LIBC_H_WITH_UNISTD_H iff libc.h is
54 dnl present on the system, and is safe to #include.
56 AC_DEFUN([GUILE_HEADER_LIBC_WITH_UNISTD],
58 AC_CHECK_HEADERS(libc.h unistd.h)
60 [whether libc.h and unistd.h can be included together],
61 guile_cv_header_libc_with_unistd,
63 if test "$ac_cv_header_libc_h" = "no"; then
64 guile_cv_header_libc_with_unistd="no"
65 elif test "$ac_cv_header_unistd_h" = "no"; then
66 guile_cv_header_libc_with_unistd="yes"
74 [guile_cv_header_libc_with_unistd=yes],
75 [guile_cv_header_libc_with_unistd=no]
80 if test "$guile_cv_header_libc_with_unistd" = yes; then
81 AC_DEFINE([LIBC_H_WITH_UNISTD_H], 1,
82 [Define this if we should include <libc.h> when we've already
83 included <unistd.h>. On some systems, they conflict, and libc.h
84 should be omitted. See GUILE_HEADER_LIBC_WITH_UNISTD in
92 dnl This is needed when we want to check for the same function repeatedly
93 dnl with other parameters, such as libraries, varying.
95 dnl GUILE_NAMED_CHECK_FUNC(FUNCTION, TESTNAME,
96 dnl [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]])
97 AC_DEFUN([GUILE_NAMED_CHECK_FUNC],
98 [AC_MSG_CHECKING([for $1])
99 AC_CACHE_VAL(ac_cv_func_$1_$2,
101 dnl Don't include <ctype.h> because on OSF/1 3.0 it includes <sys/types.h>
102 dnl which includes <sys/select.h> which contains a prototype for
103 dnl select. Similarly for bzero.
104 [/* System header to define __stub macros and hopefully few prototypes,
105 which can conflict with char $1(); below. */
107 /* Override any gcc2 internal prototype to avoid an error. */
111 /* We use char because int might match the return type of a gcc2
112 builtin and then its argument prototype would still apply. */
115 /* The GNU C library defines this for functions which it implements
116 to always fail with ENOSYS. Some functions are actually named
117 something starting with __ and the normal name is an alias. */
118 #if defined (__stub_$1) || defined (__stub___$1)
123 ], eval "ac_cv_func_$1_$2=yes", eval "ac_cv_func_$1_$2=no")])
124 if eval "test \"`echo '$ac_cv_func_'$1'_'$2`\" = yes"; then
126 ifelse([$3], , :, [$3])
137 dnl Available from the Autoconf Macro Archive at:
138 dnl http://autoconf-archive.cryp.to/acx_pthread.html
140 AC_DEFUN([ACX_PTHREAD], [
141 AC_REQUIRE([AC_CANONICAL_HOST])
146 # We used to check for pthread.h first, but this fails if pthread.h
147 # requires special compiler flags (e.g. on True64 or Sequent).
148 # It gets checked for in the link test anyway.
150 # First of all, check if the user has set any of the PTHREAD_LIBS,
151 # etcetera environment variables, and if threads linking works using
153 if test x"$PTHREAD_LIBS$PTHREAD_CFLAGS" != x; then
154 save_CFLAGS="$CFLAGS"
155 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
157 LIBS="$PTHREAD_LIBS $LIBS"
158 AC_MSG_CHECKING([for pthread_join in LIBS=$PTHREAD_LIBS with CFLAGS=$PTHREAD_CFLAGS])
159 AC_TRY_LINK_FUNC(pthread_join, acx_pthread_ok=yes)
160 AC_MSG_RESULT($acx_pthread_ok)
161 if test x"$acx_pthread_ok" = xno; then
166 CFLAGS="$save_CFLAGS"
169 # We must check for the threads library under a number of different
170 # names; the ordering is very important because some systems
171 # (e.g. DEC) have both -lpthread and -lpthreads, where one of the
172 # libraries is broken (non-POSIX).
174 # Create a list of thread flags to try. Items starting with a "-" are
175 # C compiler flags, and other items are library names, except for "none"
176 # which indicates that we try without any flags at all, and "pthread-config"
177 # which is a program returning the flags for the Pth emulation library.
179 acx_pthread_flags="pthreads none -Kthread -kthread lthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config"
181 # The ordering *is* (sometimes) important. Some notes on the
182 # individual items follow:
184 # pthreads: AIX (must check this before -lpthread)
185 # none: in case threads are in libc; should be tried before -Kthread and
186 # other compiler flags to prevent continual compiler warnings
187 # -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h)
188 # -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able)
189 # lthread: LinuxThreads port on FreeBSD (also preferred to -pthread)
190 # -pthread: Linux/gcc (kernel threads), BSD/gcc (userland threads)
191 # -pthreads: Solaris/gcc
192 # -mthreads: Mingw32/gcc, Lynx/gcc
193 # -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it
194 # doesn't hurt to check since this sometimes defines pthreads too;
195 # also defines -D_REENTRANT)
196 # ... -mt is also the pthreads flag for HP/aCC
197 # pthread: Linux, etcetera
198 # --thread-safe: KAI C++
199 # pthread-config: use pthread-config program (for GNU Pth library)
201 case "${host_cpu}-${host_os}" in
204 # On Solaris (at least, for some versions), libc contains stubbed
205 # (non-functional) versions of the pthreads routines, so link-based
206 # tests will erroneously succeed. (We need to link with -pthreads/-mt/
207 # -lpthread.) (The stubs are missing pthread_cleanup_push, or rather
208 # a function called by this macro, so we could check for that, but
209 # who knows whether they'll stub that too in a future libc.) So,
210 # we'll just look for -pthreads and -lpthread first:
212 acx_pthread_flags="-pthreads pthread -mt -pthread $acx_pthread_flags"
216 if test x"$acx_pthread_ok" = xno; then
217 for flag in $acx_pthread_flags; do
221 AC_MSG_CHECKING([whether pthreads work without any flags])
225 AC_MSG_CHECKING([whether pthreads work with $flag])
226 PTHREAD_CFLAGS="$flag"
230 AC_CHECK_PROG(acx_pthread_config, pthread-config, yes, no)
231 if test x"$acx_pthread_config" = xno; then continue; fi
232 PTHREAD_CFLAGS="`pthread-config --cflags`"
233 PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`"
237 AC_MSG_CHECKING([for the pthreads library -l$flag])
238 PTHREAD_LIBS="-l$flag"
243 save_CFLAGS="$CFLAGS"
244 LIBS="$PTHREAD_LIBS $LIBS"
245 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
247 # Check for various functions. We must include pthread.h,
248 # since some functions may be macros. (On the Sequent, we
249 # need a special flag -Kthread to make this header compile.)
250 # We check for pthread_join because it is in -lpthread on IRIX
251 # while pthread_create is in libc. We check for pthread_attr_init
252 # due to DEC craziness with -lpthreads. We check for
253 # pthread_cleanup_push because it is one of the few pthread
254 # functions on Solaris that doesn't have a non-functional libc stub.
255 # We try pthread_create on general principles.
256 AC_TRY_LINK([#include <pthread.h>],
257 [pthread_t th; pthread_join(th, 0);
258 pthread_attr_init(0); pthread_cleanup_push(0, 0);
259 pthread_create(0,0,0,0); pthread_cleanup_pop(0); ],
260 [acx_pthread_ok=yes])
263 CFLAGS="$save_CFLAGS"
265 AC_MSG_RESULT($acx_pthread_ok)
266 if test "x$acx_pthread_ok" = xyes; then
275 # Various other checks:
276 if test "x$acx_pthread_ok" = xyes; then
278 LIBS="$PTHREAD_LIBS $LIBS"
279 save_CFLAGS="$CFLAGS"
280 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
282 # Detect AIX lossage: JOINABLE attribute is called UNDETACHED.
283 AC_MSG_CHECKING([for joinable pthread attribute])
285 for attr in PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_UNDETACHED; do
286 AC_TRY_LINK([#include <pthread.h>], [int attr=$attr; return attr;],
287 [attr_name=$attr; break])
289 AC_MSG_RESULT($attr_name)
290 if test "$attr_name" != PTHREAD_CREATE_JOINABLE; then
291 AC_DEFINE_UNQUOTED([PTHREAD_CREATE_JOINABLE], $attr_name,
292 [Define to necessary symbol if this constant
293 uses a non-standard name on your system.])
296 AC_MSG_CHECKING([if more special flags are required for pthreads])
298 case "${host_cpu}-${host_os}" in
299 *-aix* | *-freebsd* | *-darwin*) flag="-D_THREAD_SAFE";;
300 *solaris* | *-osf* | *-hpux*) flag="-D_REENTRANT";;
302 AC_MSG_RESULT(${flag})
303 if test "x$flag" != xno; then
304 PTHREAD_CFLAGS="$flag $PTHREAD_CFLAGS"
308 CFLAGS="$save_CFLAGS"
310 # More AIX lossage: must compile with xlc_r or cc_r
311 if test x"$GCC" != xyes; then
312 AC_CHECK_PROGS(PTHREAD_CC, xlc_r cc_r, ${CC})
320 AC_SUBST(PTHREAD_LIBS)
321 AC_SUBST(PTHREAD_CFLAGS)
324 # Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND:
325 if test x"$acx_pthread_ok" = xyes; then
326 ifelse([$1],,AC_DEFINE([HAVE_PTHREAD],1,[Define if you have POSIX threads libraries and header files.]),[$1])
335 dnl GUILE_GNU_LD_RELRO
337 dnl Check whether GNU ld's read-only relocations (the `PT_GNU_RELRO'
338 dnl ELF segment header) are supported. This allows things like
339 dnl statically allocated cells (1) to eventually be remapped read-only
340 dnl by the loader, and (2) to be identified as pointerless by the
341 dnl garbage collector. Substitute `GNU_LD_FLAGS' with the relevant
343 AC_DEFUN([GUILE_GNU_LD_RELRO], [
344 AC_MSG_CHECKING([whether the linker understands `-z relro'])
346 GNU_LD_FLAGS="-Wl,-z -Wl,relro"
348 save_LDFLAGS="$LDFLAGS"
349 LDFLAGS="$LDFLAGS $GNU_LD_FLAGS"
350 AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])],
351 [AC_MSG_RESULT([yes])],
354 LDFLAGS="$save_LDFLAGS"
356 AC_SUBST([GNU_LD_FLAGS])
359 dnl GUILE_THREAD_LOCAL_STORAGE
361 dnl Check for compiler thread-local storage (TLS) support.
362 AC_DEFUN([GUILE_THREAD_LOCAL_STORAGE], [
363 AC_REQUIRE([AC_CANONICAL_HOST])
365 AC_CACHE_CHECK([whether the `__thread' storage class is available],
366 [ac_cv_have_thread_storage_class],
367 [dnl On some systems, e.g., NetBSD 5.0 with GCC 4.1, `__thread' is
368 dnl properly compiled but fails to link due to the lack of TLS
369 dnl support in the C library. Thus we try to link, not just
370 dnl compile. Unfortunately, this test is not enough, so we
371 dnl explicitly check for known-broken systems. See
372 dnl http://lists.gnu.org/archive/html/guile-devel/2009-10/msg00138.html
375 dnl Known broken systems includes:
376 dnl - x86_64-unknown-netbsd5.0.
377 dnl - sparc-sun-solaris2.8
379 dnl On `x86_64-unknown-freebsd8.0', thread-local storage appears to
380 dnl be reclaimed at the wrong time, leading to a segfault when
381 dnl running `threads.test'. So disable it.
382 case "$enable_shared--$host_os" in
383 [yes--netbsd[0-5].[0-9].|yes--solaris2.8|yes--freebsd[0-8]*])
384 ac_cv_have_thread_storage_class="no"
387 AC_LINK_IFELSE([AC_LANG_PROGRAM([__thread int tls_integer;],
388 [tls_integer = 123;])],
389 [ac_cv_have_thread_storage_class="yes"],
390 [ac_cv_have_thread_storage_class="no"])
394 if test "x$ac_cv_have_thread_storage_class" = "xyes"; then
395 SCM_I_GSC_HAVE_THREAD_STORAGE_CLASS=1
397 SCM_I_GSC_HAVE_THREAD_STORAGE_CLASS=0
400 AC_SUBST([SCM_I_GSC_HAVE_THREAD_STORAGE_CLASS])
405 dnl Check all the things needed by `guile-readline', the Readline
407 AC_DEFUN([GUILE_READLINE], [
408 for termlib in ncurses curses termcap terminfo termlib pdcurses ; do
409 AC_CHECK_LIB(${termlib}, [tgoto],
410 [READLINE_LIBS="-l${termlib} $READLINE_LIBS"; break])
413 AC_LIB_LINKFLAGS([readline])
415 if test "x$LTLIBREADLINE" = "x"; then
416 AC_MSG_WARN([GNU Readline was not found on your system.])
419 LIBS="$LIBREADLINE $READLINE_LIBS $LIBS"
421 AC_CHECK_FUNCS([siginterrupt rl_clear_signals rl_cleanup_after_signal])
423 dnl Check for modern readline naming
424 AC_CHECK_FUNCS([rl_filename_completion_function])
425 AC_CHECK_DECLS([rl_catch_signals, rl_catch_sigwinch], [], [],
426 [[#include <stdio.h>]
427 [#include <readline/readline.h>]])
429 dnl Check for rl_get_keymap. We only use this for deciding whether to
430 dnl install paren matching on the Guile command line (when using
431 dnl readline for input), so it's completely optional.
432 AC_CHECK_FUNCS([rl_get_keymap])
434 AC_CACHE_CHECK([for rl_getc_function pointer in readline],
435 ac_cv_var_rl_getc_function,
438 #include <readline/readline.h>],
439 [printf ("%ld", (long) rl_getc_function)],
440 [ac_cv_var_rl_getc_function=yes],
441 [ac_cv_var_rl_getc_function=no])])
442 if test "${ac_cv_var_rl_getc_function}" = "yes"; then
443 AC_DEFINE([HAVE_RL_GETC_FUNCTION], 1,
444 [Define if your readline library has the rl_getc_function variable.])
447 if test $ac_cv_var_rl_getc_function = no; then
448 AC_MSG_WARN([*** GNU Readline is too old on your system.])
449 AC_MSG_WARN([*** You need readline version 2.1 or later.])
456 READLINE_LIBS="$LTLIBREADLINE $READLINE_LIBS"
459 AM_CONDITIONAL([HAVE_READLINE], [test "x$LTLIBREADLINE" != "x"])
461 AC_CHECK_FUNCS([strdup])
463 AC_SUBST([READLINE_LIBS])
465 . $srcdir/guile-readline/LIBGUILEREADLINE-VERSION
466 AC_SUBST(LIBGUILEREADLINE_MAJOR)
467 AC_SUBST(LIBGUILEREADLINE_INTERFACE_CURRENT)
468 AC_SUBST(LIBGUILEREADLINE_INTERFACE_REVISION)
469 AC_SUBST(LIBGUILEREADLINE_INTERFACE_AGE)
470 AC_SUBST(LIBGUILEREADLINE_INTERFACE)
473 dnl Declare file $1 to be a script that needs configuring,
474 dnl and arrange to make it executable in the process.
475 AC_DEFUN([GUILE_CONFIG_SCRIPT],[AC_CONFIG_FILES([$1],[chmod +x $1])])