Bring the manual organisation section a little closer to reality
[bpt/guile.git] / acinclude.m4
1 dnl -*- Autoconf -*-
2
3 dnl On the NeXT, #including <utime.h> doesn't give you a definition for
4 dnl struct utime, unless you #define _POSIX_SOURCE.
5
6 AC_DEFUN([GUILE_STRUCT_UTIMBUF], [
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
15 struct 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
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.])
23 fi])
24
25
26
27
28 dnl
29 dnl Apparently, at CMU they have a weird version of libc.h that is
30 dnl installed in /usr/local/include and conflicts with unistd.h.
31 dnl In these situations, we should not #include libc.h.
32 dnl This test arranges to #define LIBC_H_WITH_UNISTD_H iff libc.h is
33 dnl present on the system, and is safe to #include.
34 dnl
35 AC_DEFUN([GUILE_HEADER_LIBC_WITH_UNISTD],
36 [
37 AC_CHECK_HEADERS(libc.h unistd.h)
38 AC_CACHE_CHECK(
39 [whether libc.h and unistd.h can be included together],
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"
44 elif test "$ac_cv_header_unistd_h" = "no"; then
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
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.])
65 fi
66 ]
67 )
68
69
70
71 dnl This is needed when we want to check for the same function repeatedly
72 dnl with other parameters, such as libraries, varying.
73 dnl
74 dnl GUILE_NAMED_CHECK_FUNC(FUNCTION, TESTNAME,
75 dnl [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]])
76 AC_DEFUN([GUILE_NAMED_CHECK_FUNC],
77 [AC_MSG_CHECKING([for $1])
78 AC_CACHE_VAL(ac_cv_func_$1_$2,
79 [AC_TRY_LINK(
80 dnl Don't include <ctype.h> because on OSF/1 3.0 it includes <sys/types.h>
81 dnl which includes <sys/select.h> which contains a prototype for
82 dnl 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. */
87 #ifdef __cplusplus
88 extern "C"
89 #endif
90 /* We use char because int might match the return type of a gcc2
91 builtin and then its argument prototype would still apply. */
92 char $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)
98 choke me
99 #else
100 $1();
101 #endif
102 ], eval "ac_cv_func_$1_$2=yes", eval "ac_cv_func_$1_$2=no")])
103 if eval "test \"`echo '$ac_cv_func_'$1'_'$2`\" = yes"; then
104 AC_MSG_RESULT(yes)
105 ifelse([$3], , :, [$3])
106 else
107 AC_MSG_RESULT(no)
108 ifelse([$4], , , [$4
109 ])dnl
110 fi
111 ])
112
113
114
115
116 dnl Available from the Autoconf Macro Archive at:
117 dnl http://autoconf-archive.cryp.to/acx_pthread.html
118 dnl
119 AC_DEFUN([ACX_PTHREAD], [
120 AC_REQUIRE([AC_CANONICAL_HOST])
121 AC_LANG_SAVE
122 AC_LANG_C
123 acx_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:
132 if 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"
146 fi
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
158 acx_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)
175 # ... -mt is also the pthreads flag for HP/aCC
176 # pthread: Linux, etcetera
177 # --thread-safe: KAI C++
178 # pthread-config: use pthread-config program (for GNU Pth library)
179
180 case "${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
185 # tests will erroneously succeed. (We need to link with -pthreads/-mt/
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
191 acx_pthread_flags="-pthreads pthread -mt -pthread $acx_pthread_flags"
192 ;;
193 esac
194
195 if test x"$acx_pthread_ok" = xno; then
196 for 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
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 ;;
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=""
251 done
252 fi
253
254 # Various other checks:
255 if 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
261 # Detect AIX lossage: JOINABLE attribute is called UNDETACHED.
262 AC_MSG_CHECKING([for joinable pthread attribute])
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.])
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
278 *-aix* | *-freebsd* | *-darwin*) flag="-D_THREAD_SAFE";;
279 *solaris* | *-osf* | *-hpux*) flag="-D_REENTRANT";;
280 esac
281 AC_MSG_RESULT(${flag})
282 if test "x$flag" != xno; then
283 PTHREAD_CFLAGS="$flag $PTHREAD_CFLAGS"
284 fi
285
286 LIBS="$save_LIBS"
287 CFLAGS="$save_CFLAGS"
288
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
295 else
296 PTHREAD_CC="$CC"
297 fi
298
299 AC_SUBST(PTHREAD_LIBS)
300 AC_SUBST(PTHREAD_CFLAGS)
301 AC_SUBST(PTHREAD_CC)
302
303 # Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND:
304 if 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 :
307 else
308 acx_pthread_ok=no
309 $2
310 fi
311 AC_LANG_RESTORE
312 ])dnl ACX_PTHREAD
313
314 dnl GUILE_GNU_LD_RELRO
315 dnl
316 dnl Check whether GNU ld's read-only relocations (the `PT_GNU_RELRO'
317 dnl ELF segment header) are supported. This allows things like
318 dnl statically allocated cells (1) to eventually be remapped read-only
319 dnl by the loader, and (2) to be identified as pointerless by the
320 dnl garbage collector. Substitute `GNU_LD_FLAGS' with the relevant
321 dnl flags.
322 AC_DEFUN([GUILE_GNU_LD_RELRO], [
323 AC_MSG_CHECKING([whether the linker understands `-z relro'])
324
325 GNU_LD_FLAGS="-Wl,-z -Wl,relro"
326
327 save_LDFLAGS="$LDFLAGS"
328 LDFLAGS="$LDFLAGS $GNU_LD_FLAGS"
329 AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])],
330 [AC_MSG_RESULT([yes])],
331 [AC_MSG_RESULT([no])
332 GNU_LD_FLAGS=""])
333 LDFLAGS="$save_LDFLAGS"
334
335 AC_SUBST([GNU_LD_FLAGS])
336 ])
337
338 dnl GUILE_THREAD_LOCAL_STORAGE
339 dnl
340 dnl Check for compiler thread-local storage (TLS) support.
341 AC_DEFUN([GUILE_THREAD_LOCAL_STORAGE], [
342 AC_CACHE_CHECK([whether the `__thread' storage class is available],
343 [ac_cv_have_thread_storage_class],
344 [dnl On some systems, e.g., NetBSD 5.0 with GCC 4.1, `__thread' is
345 dnl properly compiled but fails to link due to the lack of TLS
346 dnl support in the C library. Thus we try to link, not just
347 dnl compile. Unfortunately, this test is not enough, so we
348 dnl explicitly check for known-broken systems. See
349 dnl http://lists.gnu.org/archive/html/guile-devel/2009-10/msg00138.html
350 dnl for details.
351 dnl
352 dnl Known broken systems includes:
353 dnl - x86_64-unknown-netbsd5.0.
354 dnl - sparc-sun-solaris2.8
355 case "x$enable_shared--$host" in
356 xyes--*netbsd[0-5].[0-9].|xyes--*solaris2.8)
357 ac_cv_have_thread_storage_class="no"
358 ;;
359 *)
360 AC_LINK_IFELSE([AC_LANG_PROGRAM([__thread int tls_integer;],
361 [tls_integer = 123;])],
362 [ac_cv_have_thread_storage_class="yes"],
363 [ac_cv_have_thread_storage_class="no"])
364 ;;
365 esac])
366
367 if test "x$ac_cv_have_thread_storage_class" = "xyes"; then
368 SCM_I_GSC_HAVE_THREAD_STORAGE_CLASS=1
369 else
370 SCM_I_GSC_HAVE_THREAD_STORAGE_CLASS=0
371 fi
372
373 AC_SUBST([SCM_I_GSC_HAVE_THREAD_STORAGE_CLASS])
374 ])
375
376 dnl GUILE_READLINE
377 dnl
378 dnl Check all the things needed by `guile-readline', the Readline
379 dnl bindings.
380 AC_DEFUN([GUILE_READLINE], [
381 for termlib in ncurses curses termcap terminfo termlib ; do
382 AC_CHECK_LIB(${termlib}, [tgoto],
383 [READLINE_LIBS="-l${termlib} $READLINE_LIBS"; break])
384 done
385
386 AC_LIB_LINKFLAGS([readline])
387
388 if test "x$LTLIBREADLINE" = "x"; then
389 AC_MSG_WARN([GNU Readline was not found on your system.])
390 else
391 rl_save_LIBS="$LIBS"
392 LIBS="$LIBREADLINE $READLINE_LIBS $LIBS"
393
394 AC_CHECK_FUNCS([siginterrupt rl_clear_signals rl_cleanup_after_signal])
395
396 dnl Check for modern readline naming
397 AC_CHECK_FUNCS([rl_filename_completion_function])
398
399 dnl Check for rl_get_keymap. We only use this for deciding whether to
400 dnl install paren matching on the Guile command line (when using
401 dnl readline for input), so it's completely optional.
402 AC_CHECK_FUNCS([rl_get_keymap])
403
404 AC_CACHE_CHECK([for rl_getc_function pointer in readline],
405 ac_cv_var_rl_getc_function,
406 [AC_TRY_LINK([
407 #include <stdio.h>
408 #include <readline/readline.h>],
409 [printf ("%ld", (long) rl_getc_function)],
410 [ac_cv_var_rl_getc_function=yes],
411 [ac_cv_var_rl_getc_function=no])])
412 if test "${ac_cv_var_rl_getc_function}" = "yes"; then
413 AC_DEFINE([HAVE_RL_GETC_FUNCTION], 1,
414 [Define if your readline library has the rl_getc_function variable.])
415 fi
416
417 if test $ac_cv_var_rl_getc_function = no; then
418 AC_MSG_WARN([*** GNU Readline is too old on your system.])
419 AC_MSG_WARN([*** You need readline version 2.1 or later.])
420 LTLIBREADLINE=""
421 LIBREADLINE=""
422 fi
423
424 LIBS="$rl_save_LIBS"
425
426 READLINE_LIBS="$LTLIBREADLINE $READLINE_LIBS"
427 fi
428
429 AM_CONDITIONAL([HAVE_READLINE], [test "x$LTLIBREADLINE" != "x"])
430
431 AC_CHECK_FUNCS([strdup])
432
433 AC_SUBST([READLINE_LIBS])
434
435 . $srcdir/guile-readline/LIBGUILEREADLINE-VERSION
436 AC_SUBST(LIBGUILEREADLINE_MAJOR)
437 AC_SUBST(LIBGUILEREADLINE_INTERFACE_CURRENT)
438 AC_SUBST(LIBGUILEREADLINE_INTERFACE_REVISION)
439 AC_SUBST(LIBGUILEREADLINE_INTERFACE_AGE)
440 AC_SUBST(LIBGUILEREADLINE_INTERFACE)
441 ])