Turn the libunistring/iconv configure check into a macro.
[bpt/guile.git] / acinclude.m4
1 dnl -*- Autoconf -*-
2
3 dnl Copyright (C) 1997, 1999, 2000, 2001, 2002, 2004, 2006,
4 dnl 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
5 dnl
6 dnl This file is part of GUILE
7 dnl
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
11 dnl later version.
12 dnl
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.
17 dnl
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.
22
23
24 dnl On the NeXT, #including <utime.h> doesn't give you a definition for
25 dnl struct utime, unless you #define _POSIX_SOURCE.
26
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,
30 [AC_TRY_CPP([
31 #ifdef __EMX__
32 #include <sys/utime.h>
33 #else
34 #include <utime.h>
35 #endif
36 struct utime blah;
37 ],
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.])
44 fi])
45
46
47
48
49 dnl
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.
55 dnl
56 AC_DEFUN([GUILE_HEADER_LIBC_WITH_UNISTD],
57 [
58 AC_CHECK_HEADERS(libc.h unistd.h)
59 AC_CACHE_CHECK(
60 [whether libc.h and unistd.h can be included together],
61 guile_cv_header_libc_with_unistd,
62 [
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"
67 else
68 AC_TRY_COMPILE(
69 [
70 # include <libc.h>
71 # include <unistd.h>
72 ],
73 [],
74 [guile_cv_header_libc_with_unistd=yes],
75 [guile_cv_header_libc_with_unistd=no]
76 )
77 fi
78 ]
79 )
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
85 aclocal.m4.])
86 fi
87 ]
88 )
89
90
91
92 dnl This is needed when we want to check for the same function repeatedly
93 dnl with other parameters, such as libraries, varying.
94 dnl
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,
100 [AC_TRY_LINK(
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. */
106 #include <assert.h>
107 /* Override any gcc2 internal prototype to avoid an error. */
108 #ifdef __cplusplus
109 extern "C"
110 #endif
111 /* We use char because int might match the return type of a gcc2
112 builtin and then its argument prototype would still apply. */
113 char $1();
114 ], [
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)
119 choke me
120 #else
121 $1();
122 #endif
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
125 AC_MSG_RESULT(yes)
126 ifelse([$3], , :, [$3])
127 else
128 AC_MSG_RESULT(no)
129 ifelse([$4], , , [$4
130 ])dnl
131 fi
132 ])
133
134
135
136
137 dnl Available from the Autoconf Macro Archive at:
138 dnl http://autoconf-archive.cryp.to/acx_pthread.html
139 dnl
140 AC_DEFUN([ACX_PTHREAD], [
141 AC_REQUIRE([AC_CANONICAL_HOST])
142 AC_LANG_SAVE
143 AC_LANG_C
144 acx_pthread_ok=no
145
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.
149
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
152 # them:
153 if test x"$PTHREAD_LIBS$PTHREAD_CFLAGS" != x; then
154 save_CFLAGS="$CFLAGS"
155 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
156 save_LIBS="$LIBS"
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
162 PTHREAD_LIBS=""
163 PTHREAD_CFLAGS=""
164 fi
165 LIBS="$save_LIBS"
166 CFLAGS="$save_CFLAGS"
167 fi
168
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).
173
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.
178
179 acx_pthread_flags="pthreads none -Kthread -kthread lthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config"
180
181 # The ordering *is* (sometimes) important. Some notes on the
182 # individual items follow:
183
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)
200
201 case "${host_cpu}-${host_os}" in
202 *solaris*)
203
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:
211
212 acx_pthread_flags="-pthreads pthread -mt -pthread $acx_pthread_flags"
213 ;;
214 esac
215
216 if test x"$acx_pthread_ok" = xno; then
217 for flag in $acx_pthread_flags; do
218
219 case $flag in
220 none)
221 AC_MSG_CHECKING([whether pthreads work without any flags])
222 ;;
223
224 -*)
225 AC_MSG_CHECKING([whether pthreads work with $flag])
226 PTHREAD_CFLAGS="$flag"
227 ;;
228
229 pthread-config)
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`"
234 ;;
235
236 *)
237 AC_MSG_CHECKING([for the pthreads library -l$flag])
238 PTHREAD_LIBS="-l$flag"
239 ;;
240 esac
241
242 save_LIBS="$LIBS"
243 save_CFLAGS="$CFLAGS"
244 LIBS="$PTHREAD_LIBS $LIBS"
245 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
246
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])
261
262 LIBS="$save_LIBS"
263 CFLAGS="$save_CFLAGS"
264
265 AC_MSG_RESULT($acx_pthread_ok)
266 if test "x$acx_pthread_ok" = xyes; then
267 break;
268 fi
269
270 PTHREAD_LIBS=""
271 PTHREAD_CFLAGS=""
272 done
273 fi
274
275 # Various other checks:
276 if test "x$acx_pthread_ok" = xyes; then
277 save_LIBS="$LIBS"
278 LIBS="$PTHREAD_LIBS $LIBS"
279 save_CFLAGS="$CFLAGS"
280 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
281
282 # Detect AIX lossage: JOINABLE attribute is called UNDETACHED.
283 AC_MSG_CHECKING([for joinable pthread attribute])
284 attr_name=unknown
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])
288 done
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.])
294 fi
295
296 AC_MSG_CHECKING([if more special flags are required for pthreads])
297 flag=no
298 case "${host_cpu}-${host_os}" in
299 *-aix* | *-freebsd* | *-darwin*) flag="-D_THREAD_SAFE";;
300 *solaris* | *-osf* | *-hpux*) flag="-D_REENTRANT";;
301 esac
302 AC_MSG_RESULT(${flag})
303 if test "x$flag" != xno; then
304 PTHREAD_CFLAGS="$flag $PTHREAD_CFLAGS"
305 fi
306
307 LIBS="$save_LIBS"
308 CFLAGS="$save_CFLAGS"
309
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})
313 else
314 PTHREAD_CC=$CC
315 fi
316 else
317 PTHREAD_CC="$CC"
318 fi
319
320 AC_SUBST(PTHREAD_LIBS)
321 AC_SUBST(PTHREAD_CFLAGS)
322 AC_SUBST(PTHREAD_CC)
323
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])
327 :
328 else
329 acx_pthread_ok=no
330 $2
331 fi
332 AC_LANG_RESTORE
333 ])dnl ACX_PTHREAD
334
335 dnl GUILE_GNU_LD_RELRO
336 dnl
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
342 dnl flags.
343 AC_DEFUN([GUILE_GNU_LD_RELRO], [
344 AC_MSG_CHECKING([whether the linker understands `-z relro'])
345
346 GNU_LD_FLAGS="-Wl,-z -Wl,relro"
347
348 save_LDFLAGS="$LDFLAGS"
349 LDFLAGS="$LDFLAGS $GNU_LD_FLAGS"
350 AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])],
351 [AC_MSG_RESULT([yes])],
352 [AC_MSG_RESULT([no])
353 GNU_LD_FLAGS=""])
354 LDFLAGS="$save_LDFLAGS"
355
356 AC_SUBST([GNU_LD_FLAGS])
357 ])
358
359 dnl GUILE_THREAD_LOCAL_STORAGE
360 dnl
361 dnl Check for compiler thread-local storage (TLS) support.
362 AC_DEFUN([GUILE_THREAD_LOCAL_STORAGE], [
363 AC_REQUIRE([AC_CANONICAL_HOST])
364
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
373 dnl for details.
374 dnl
375 dnl Known broken systems includes:
376 dnl - x86_64-unknown-netbsd5.0.
377 dnl - sparc-sun-solaris2.8
378 dnl
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"
385 ;;
386 *)
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"])
391 ;;
392 esac])
393
394 if test "x$ac_cv_have_thread_storage_class" = "xyes"; then
395 SCM_I_GSC_HAVE_THREAD_STORAGE_CLASS=1
396 else
397 SCM_I_GSC_HAVE_THREAD_STORAGE_CLASS=0
398 fi
399
400 AC_SUBST([SCM_I_GSC_HAVE_THREAD_STORAGE_CLASS])
401 ])
402
403 dnl GUILE_READLINE
404 dnl
405 dnl Check all the things needed by `guile-readline', the Readline
406 dnl bindings.
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])
411 done
412
413 AC_LIB_LINKFLAGS([readline])
414
415 if test "x$LTLIBREADLINE" = "x"; then
416 AC_MSG_WARN([GNU Readline was not found on your system.])
417 else
418 rl_save_LIBS="$LIBS"
419 LIBS="$LIBREADLINE $READLINE_LIBS $LIBS"
420
421 AC_CHECK_FUNCS([siginterrupt rl_clear_signals rl_cleanup_after_signal])
422
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>]])
428
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])
433
434 AC_CACHE_CHECK([for rl_getc_function pointer in readline],
435 ac_cv_var_rl_getc_function,
436 [AC_TRY_LINK([
437 #include <stdio.h>
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.])
445 fi
446
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.])
450 LTLIBREADLINE=""
451 LIBREADLINE=""
452 fi
453
454 LIBS="$rl_save_LIBS"
455
456 READLINE_LIBS="$LTLIBREADLINE $READLINE_LIBS"
457 fi
458
459 AM_CONDITIONAL([HAVE_READLINE], [test "x$LTLIBREADLINE" != "x"])
460
461 AC_CHECK_FUNCS([strdup])
462
463 AC_SUBST([READLINE_LIBS])
464
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)
471 ])
472
473 dnl GUILE_LIBUNISTRING_WITH_ICONV_SUPPORT
474 dnl
475 dnl Check whether libunistring has iconv support. When it lacks iconv
476 dnl support, `mem_iconveh' returns -1 (ENOSYS) and conversions from one
477 dnl codeset to another do not work.
478 AC_DEFUN([GUILE_LIBUNISTRING_WITH_ICONV_SUPPORT], [
479 AC_CACHE_CHECK([whether libunistring was built with iconv support],
480 [ac_cv_libunistring_with_iconv_support], [
481 save_LIBS=$LIBS
482 LIBS="$LIBS $LIBUNISTRING"
483 AC_RUN_IFELSE([AC_LANG_SOURCE([[
484 #include <uniconv.h>
485 #include <unistring/iconveh.h>
486 int
487 main (int argc, char *argv[])
488 {
489 size_t result_size;
490 return (NULL == u32_conv_from_encoding ("ASCII", iconveh_question_mark,
491 "a", 1,
492 NULL, NULL, &result_size));
493 }
494 ]])],
495 [ac_cv_libunistring_with_iconv_support=yes],
496 [ac_cv_libunistring_with_iconv_support=no],
497 [ac_cv_libunistring_with_iconv_support=yes])
498 LIBS=$save_LIBS
499 ])
500 ])
501
502 dnl Declare file $1 to be a script that needs configuring,
503 dnl and arrange to make it executable in the process.
504 AC_DEFUN([GUILE_CONFIG_SCRIPT],[AC_CONFIG_FILES([$1],[chmod +x $1])])