Thank Ralf
[bpt/guile.git] / m4 / wchar_h.m4
CommitLineData
e65fc94b
LC
1dnl A placeholder for ISO C99 <wchar.h>, for platforms that have issues.
2
61cd9dc9 3dnl Copyright (C) 2007-2010 Free Software Foundation, Inc.
e65fc94b
LC
4dnl This file is free software; the Free Software Foundation
5dnl gives unlimited permission to copy and/or distribute it,
6dnl with or without modifications, as long as this notice is preserved.
7
8dnl Written by Eric Blake.
9
0f00f2c3 10# wchar_h.m4 serial 35
e65fc94b
LC
11
12AC_DEFUN([gl_WCHAR_H],
13[
14 AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
61cd9dc9
LC
15 AC_REQUIRE([gl_WCHAR_H_INLINE_OK])
16 dnl Prepare for creating substitute <wchar.h>.
17 dnl Check for <wchar.h> (missing in Linux uClibc when built without wide
18 dnl character support).
19 dnl <wchar.h> is always overridden, because of GNULIB_POSIXCHECK.
20 AC_CHECK_HEADERS_ONCE([wchar.h])
21 gl_CHECK_NEXT_HEADERS([wchar.h])
22 if test $ac_cv_header_wchar_h = yes; then
23 HAVE_WCHAR_H=1
24 else
25 HAVE_WCHAR_H=0
26 fi
27 AC_SUBST([HAVE_WCHAR_H])
aa7a939c 28
0f00f2c3
LC
29 AC_REQUIRE([gl_FEATURES_H])
30
aa7a939c
LC
31 AC_REQUIRE([gt_TYPE_WINT_T])
32 if test $gt_cv_c_wint_t = yes; then
33 HAVE_WINT_T=1
34 else
35 HAVE_WINT_T=0
36 fi
37 AC_SUBST([HAVE_WINT_T])
38
61cd9dc9
LC
39 dnl Check for declarations of anything we want to poison if the
40 dnl corresponding gnulib module is not in use.
41 gl_WARN_ON_USE_PREPARE([[
42/* Some systems require additional headers. */
0f00f2c3 43#if !(defined __GLIBC__ && !defined __UCLIBC__)
61cd9dc9
LC
44# include <stddef.h>
45# include <stdio.h>
46# include <time.h>
47#endif
48#include <wchar.h>
49 ]], [btowc wctob mbsinit mbrtowc mbrlen mbsrtowcs mbsnrtowcs wcrtomb
50 wcsrtombs wcsnrtombs wcwidth])
51])
e65fc94b 52
61cd9dc9
LC
53dnl Check whether <wchar.h> is usable at all.
54AC_DEFUN([gl_WCHAR_H_INLINE_OK],
55[
56 dnl Test whether <wchar.h> suffers due to the transition from '__inline' to
57 dnl 'gnu_inline'. See <http://sourceware.org/bugzilla/show_bug.cgi?id=4022>
58 dnl and <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42440>. In summary,
59 dnl glibc version 2.5 or older, together with gcc version 4.3 or newer and
60 dnl the option -std=c99 or -std=gnu99, leads to a broken <wchar.h>.
61 AC_CACHE_CHECK([whether <wchar.h> uses 'inline' correctly],
62 [gl_cv_header_wchar_h_correct_inline],
63 [gl_cv_header_wchar_h_correct_inline=yes
64 AC_LANG_CONFTEST([
65 AC_LANG_SOURCE([[#define wcstod renamed_wcstod
66#include <wchar.h>
67extern int zero (void);
68int main () { return zero(); }
69]])])
70 if AC_TRY_EVAL([ac_compile]); then
71 mv conftest.$ac_objext conftest1.$ac_objext
72 AC_LANG_CONFTEST([
73 AC_LANG_SOURCE([[#define wcstod renamed_wcstod
74#include <wchar.h>
75int zero (void) { return 0; }
76]])])
77 if AC_TRY_EVAL([ac_compile]); then
78 mv conftest.$ac_objext conftest2.$ac_objext
79 if $CC -o conftest$ac_exeext $CFLAGS $LDFLAGS conftest1.$ac_objext conftest2.$ac_objext $LIBS >&AS_MESSAGE_LOG_FD 2>&1; then
80 :
81 else
82 gl_cv_header_wchar_h_correct_inline=no
83 fi
84 fi
85 fi
86 rm -f conftest1.$ac_objext conftest2.$ac_objext conftest$ac_exeext
87 ])
88 if test $gl_cv_header_wchar_h_correct_inline = no; then
89 AC_MSG_ERROR([<wchar.h> cannot be used with this compiler ($CC $CFLAGS $CPPFLAGS).
90This is a known interoperability problem of glibc <= 2.5 with gcc >= 4.3 in
91C99 mode. You have four options:
92 - Add the flag -fgnu89-inline to CC and reconfigure, or
93 - Fix your include files, using parts of
94 <http://sourceware.org/git/?p=glibc.git;a=commitdiff;h=b037a293a48718af30d706c2e18c929d0e69a621>, or
95 - Use a gcc version older than 4.3, or
96 - Don't use the flags -std=c99 or -std=gnu99.
97Configuration aborted.])
e65fc94b 98 fi
e65fc94b
LC
99])
100
aa7a939c
LC
101dnl Unconditionally enables the replacement of <wchar.h>.
102AC_DEFUN([gl_REPLACE_WCHAR_H],
103[
61cd9dc9
LC
104 dnl This is a no-op, because <wchar.h> is always overridden.
105 :
aa7a939c
LC
106])
107
e65fc94b
LC
108AC_DEFUN([gl_WCHAR_MODULE_INDICATOR],
109[
110 dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
111 AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
a927b6c1 112 gl_MODULE_INDICATOR_SET_VARIABLE([$1])
f4c79b3c 113 dnl Define it also as a C macro, for the benefit of the unit tests.
a927b6c1 114 gl_MODULE_INDICATOR_FOR_TESTS([$1])
e65fc94b
LC
115])
116
117AC_DEFUN([gl_WCHAR_H_DEFAULTS],
118[
4a462e35
NJ
119 GNULIB_BTOWC=0; AC_SUBST([GNULIB_BTOWC])
120 GNULIB_WCTOB=0; AC_SUBST([GNULIB_WCTOB])
121 GNULIB_MBSINIT=0; AC_SUBST([GNULIB_MBSINIT])
122 GNULIB_MBRTOWC=0; AC_SUBST([GNULIB_MBRTOWC])
123 GNULIB_MBRLEN=0; AC_SUBST([GNULIB_MBRLEN])
124 GNULIB_MBSRTOWCS=0; AC_SUBST([GNULIB_MBSRTOWCS])
125 GNULIB_MBSNRTOWCS=0; AC_SUBST([GNULIB_MBSNRTOWCS])
126 GNULIB_WCRTOMB=0; AC_SUBST([GNULIB_WCRTOMB])
127 GNULIB_WCSRTOMBS=0; AC_SUBST([GNULIB_WCSRTOMBS])
128 GNULIB_WCSNRTOMBS=0; AC_SUBST([GNULIB_WCSNRTOMBS])
129 GNULIB_WCWIDTH=0; AC_SUBST([GNULIB_WCWIDTH])
e65fc94b 130 dnl Assume proper GNU behavior unless another module says otherwise.
f240aacb
LC
131 HAVE_BTOWC=1; AC_SUBST([HAVE_BTOWC])
132 HAVE_MBSINIT=1; AC_SUBST([HAVE_MBSINIT])
133 HAVE_MBRTOWC=1; AC_SUBST([HAVE_MBRTOWC])
134 HAVE_MBRLEN=1; AC_SUBST([HAVE_MBRLEN])
135 HAVE_MBSRTOWCS=1; AC_SUBST([HAVE_MBSRTOWCS])
136 HAVE_MBSNRTOWCS=1; AC_SUBST([HAVE_MBSNRTOWCS])
137 HAVE_WCRTOMB=1; AC_SUBST([HAVE_WCRTOMB])
138 HAVE_WCSRTOMBS=1; AC_SUBST([HAVE_WCSRTOMBS])
139 HAVE_WCSNRTOMBS=1; AC_SUBST([HAVE_WCSNRTOMBS])
140 HAVE_DECL_WCTOB=1; AC_SUBST([HAVE_DECL_WCTOB])
141 HAVE_DECL_WCWIDTH=1; AC_SUBST([HAVE_DECL_WCWIDTH])
142 REPLACE_MBSTATE_T=0; AC_SUBST([REPLACE_MBSTATE_T])
143 REPLACE_BTOWC=0; AC_SUBST([REPLACE_BTOWC])
144 REPLACE_WCTOB=0; AC_SUBST([REPLACE_WCTOB])
145 REPLACE_MBSINIT=0; AC_SUBST([REPLACE_MBSINIT])
146 REPLACE_MBRTOWC=0; AC_SUBST([REPLACE_MBRTOWC])
147 REPLACE_MBRLEN=0; AC_SUBST([REPLACE_MBRLEN])
148 REPLACE_MBSRTOWCS=0; AC_SUBST([REPLACE_MBSRTOWCS])
149 REPLACE_MBSNRTOWCS=0; AC_SUBST([REPLACE_MBSNRTOWCS])
150 REPLACE_WCRTOMB=0; AC_SUBST([REPLACE_WCRTOMB])
151 REPLACE_WCSRTOMBS=0; AC_SUBST([REPLACE_WCSRTOMBS])
152 REPLACE_WCSNRTOMBS=0; AC_SUBST([REPLACE_WCSNRTOMBS])
153 REPLACE_WCWIDTH=0; AC_SUBST([REPLACE_WCWIDTH])
e65fc94b 154])