maint: update almost all copyright ranges to include 2011
[gnulib.git] / m4 / wchar_h.m4
1 dnl A placeholder for ISO C99 <wchar.h>, for platforms that have issues.
2
3 dnl Copyright (C) 2007-2011 Free Software Foundation, Inc.
4 dnl This file is free software; the Free Software Foundation
5 dnl gives unlimited permission to copy and/or distribute it,
6 dnl with or without modifications, as long as this notice is preserved.
7
8 dnl Written by Eric Blake.
9
10 # wchar_h.m4 serial 36
11
12 AC_DEFUN([gl_WCHAR_H],
13 [
14   AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
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])
28
29   AC_REQUIRE([gl_FEATURES_H])
30
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
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 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
43    <wchar.h>.
44    BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
45    included before <wchar.h>.  */
46 #if !(defined __GLIBC__ && !defined __UCLIBC__)
47 # include <stddef.h>
48 # include <stdio.h>
49 # include <time.h>
50 #endif
51 #include <wchar.h>
52     ]], [btowc wctob mbsinit mbrtowc mbrlen mbsrtowcs mbsnrtowcs wcrtomb
53     wcsrtombs wcsnrtombs wcwidth])
54 ])
55
56 dnl Check whether <wchar.h> is usable at all.
57 AC_DEFUN([gl_WCHAR_H_INLINE_OK],
58 [
59   dnl Test whether <wchar.h> suffers due to the transition from '__inline' to
60   dnl 'gnu_inline'. See <http://sourceware.org/bugzilla/show_bug.cgi?id=4022>
61   dnl and <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42440>. In summary,
62   dnl glibc version 2.5 or older, together with gcc version 4.3 or newer and
63   dnl the option -std=c99 or -std=gnu99, leads to a broken <wchar.h>.
64   AC_CACHE_CHECK([whether <wchar.h> uses 'inline' correctly],
65     [gl_cv_header_wchar_h_correct_inline],
66     [gl_cv_header_wchar_h_correct_inline=yes
67      AC_LANG_CONFTEST([
68        AC_LANG_SOURCE([[#define wcstod renamed_wcstod
69 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
70    <wchar.h>.
71    BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
72    included before <wchar.h>.  */
73 #include <stddef.h>
74 #include <stdio.h>
75 #include <time.h>
76 #include <wchar.h>
77 extern int zero (void);
78 int main () { return zero(); }
79 ]])])
80      if AC_TRY_EVAL([ac_compile]); then
81        mv conftest.$ac_objext conftest1.$ac_objext
82        AC_LANG_CONFTEST([
83          AC_LANG_SOURCE([[#define wcstod renamed_wcstod
84 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
85    <wchar.h>.
86    BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
87    included before <wchar.h>.  */
88 #include <stddef.h>
89 #include <stdio.h>
90 #include <time.h>
91 #include <wchar.h>
92 int zero (void) { return 0; }
93 ]])])
94        if AC_TRY_EVAL([ac_compile]); then
95          mv conftest.$ac_objext conftest2.$ac_objext
96          if $CC -o conftest$ac_exeext $CFLAGS $LDFLAGS conftest1.$ac_objext conftest2.$ac_objext $LIBS >&AS_MESSAGE_LOG_FD 2>&1; then
97            :
98          else
99            gl_cv_header_wchar_h_correct_inline=no
100          fi
101        fi
102      fi
103      rm -f conftest1.$ac_objext conftest2.$ac_objext conftest$ac_exeext
104     ])
105   if test $gl_cv_header_wchar_h_correct_inline = no; then
106     AC_MSG_ERROR([<wchar.h> cannot be used with this compiler ($CC $CFLAGS $CPPFLAGS).
107 This is a known interoperability problem of glibc <= 2.5 with gcc >= 4.3 in
108 C99 mode. You have four options:
109   - Add the flag -fgnu89-inline to CC and reconfigure, or
110   - Fix your include files, using parts of
111     <http://sourceware.org/git/?p=glibc.git;a=commitdiff;h=b037a293a48718af30d706c2e18c929d0e69a621>, or
112   - Use a gcc version older than 4.3, or
113   - Don't use the flags -std=c99 or -std=gnu99.
114 Configuration aborted.])
115   fi
116 ])
117
118 dnl Unconditionally enables the replacement of <wchar.h>.
119 AC_DEFUN([gl_REPLACE_WCHAR_H],
120 [
121   dnl This is a no-op, because <wchar.h> is always overridden.
122   :
123 ])
124
125 AC_DEFUN([gl_WCHAR_MODULE_INDICATOR],
126 [
127   dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
128   AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
129   gl_MODULE_INDICATOR_SET_VARIABLE([$1])
130   dnl Define it also as a C macro, for the benefit of the unit tests.
131   gl_MODULE_INDICATOR_FOR_TESTS([$1])
132 ])
133
134 AC_DEFUN([gl_WCHAR_H_DEFAULTS],
135 [
136   GNULIB_BTOWC=0;      AC_SUBST([GNULIB_BTOWC])
137   GNULIB_WCTOB=0;      AC_SUBST([GNULIB_WCTOB])
138   GNULIB_MBSINIT=0;    AC_SUBST([GNULIB_MBSINIT])
139   GNULIB_MBRTOWC=0;    AC_SUBST([GNULIB_MBRTOWC])
140   GNULIB_MBRLEN=0;     AC_SUBST([GNULIB_MBRLEN])
141   GNULIB_MBSRTOWCS=0;  AC_SUBST([GNULIB_MBSRTOWCS])
142   GNULIB_MBSNRTOWCS=0; AC_SUBST([GNULIB_MBSNRTOWCS])
143   GNULIB_WCRTOMB=0;    AC_SUBST([GNULIB_WCRTOMB])
144   GNULIB_WCSRTOMBS=0;  AC_SUBST([GNULIB_WCSRTOMBS])
145   GNULIB_WCSNRTOMBS=0; AC_SUBST([GNULIB_WCSNRTOMBS])
146   GNULIB_WCWIDTH=0;    AC_SUBST([GNULIB_WCWIDTH])
147   dnl Assume proper GNU behavior unless another module says otherwise.
148   HAVE_BTOWC=1;         AC_SUBST([HAVE_BTOWC])
149   HAVE_MBSINIT=1;       AC_SUBST([HAVE_MBSINIT])
150   HAVE_MBRTOWC=1;       AC_SUBST([HAVE_MBRTOWC])
151   HAVE_MBRLEN=1;        AC_SUBST([HAVE_MBRLEN])
152   HAVE_MBSRTOWCS=1;     AC_SUBST([HAVE_MBSRTOWCS])
153   HAVE_MBSNRTOWCS=1;    AC_SUBST([HAVE_MBSNRTOWCS])
154   HAVE_WCRTOMB=1;       AC_SUBST([HAVE_WCRTOMB])
155   HAVE_WCSRTOMBS=1;     AC_SUBST([HAVE_WCSRTOMBS])
156   HAVE_WCSNRTOMBS=1;    AC_SUBST([HAVE_WCSNRTOMBS])
157   HAVE_DECL_WCTOB=1;    AC_SUBST([HAVE_DECL_WCTOB])
158   HAVE_DECL_WCWIDTH=1;  AC_SUBST([HAVE_DECL_WCWIDTH])
159   REPLACE_MBSTATE_T=0;  AC_SUBST([REPLACE_MBSTATE_T])
160   REPLACE_BTOWC=0;      AC_SUBST([REPLACE_BTOWC])
161   REPLACE_WCTOB=0;      AC_SUBST([REPLACE_WCTOB])
162   REPLACE_MBSINIT=0;    AC_SUBST([REPLACE_MBSINIT])
163   REPLACE_MBRTOWC=0;    AC_SUBST([REPLACE_MBRTOWC])
164   REPLACE_MBRLEN=0;     AC_SUBST([REPLACE_MBRLEN])
165   REPLACE_MBSRTOWCS=0;  AC_SUBST([REPLACE_MBSRTOWCS])
166   REPLACE_MBSNRTOWCS=0; AC_SUBST([REPLACE_MBSNRTOWCS])
167   REPLACE_WCRTOMB=0;    AC_SUBST([REPLACE_WCRTOMB])
168   REPLACE_WCSRTOMBS=0;  AC_SUBST([REPLACE_WCSRTOMBS])
169   REPLACE_WCSNRTOMBS=0; AC_SUBST([REPLACE_WCSNRTOMBS])
170   REPLACE_WCWIDTH=0;    AC_SUBST([REPLACE_WCWIDTH])
171 ])