autoupdate
[gnulib.git] / m4 / wchar.m4
1 dnl A placeholder for ISO C99 <wchar.h>, for platforms that have issues.
2
3 dnl Copyright (C) 2007-2009 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.m4 serial 28
11
12 AC_DEFUN([gl_WCHAR_H],
13 [
14   AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
15   AC_REQUIRE([gl_WCHAR_H_INLINE_OK])
16   AC_CACHE_CHECK([whether <wchar.h> is standalone],
17     [gl_cv_header_wchar_h_standalone],
18     [AC_COMPILE_IFELSE([[#include <wchar.h>
19 wchar_t w;]],
20       [gl_cv_header_wchar_h_standalone=yes],
21       [gl_cv_header_wchar_h_standalone=no])])
22
23   AC_REQUIRE([gt_TYPE_WINT_T])
24   if test $gt_cv_c_wint_t = yes; then
25     HAVE_WINT_T=1
26   else
27     HAVE_WINT_T=0
28   fi
29   AC_SUBST([HAVE_WINT_T])
30
31   dnl If <stddef.h> is replaced, then <wchar.h> must also be replaced.
32   AC_REQUIRE([gl_STDDEF_H])
33
34   dnl Prepare for creating substitute <wchar.h>.
35   dnl Do it always: WCHAR_H may be empty here but can be set later.
36   dnl Check for <wchar.h> (missing in Linux uClibc when built without wide
37   dnl character support).
38   AC_CHECK_HEADERS_ONCE([wchar.h])
39   if test $ac_cv_header_wchar_h = yes; then
40     HAVE_WCHAR_H=1
41   else
42     HAVE_WCHAR_H=0
43   fi
44   AC_SUBST([HAVE_WCHAR_H])
45   dnl Execute this unconditionally, because WCHAR_H may be set by other
46   dnl modules, after this code is executed.
47   gl_CHECK_NEXT_HEADERS([wchar.h])
48 ])
49
50 dnl Check whether <wchar.h> is usable at all.
51 AC_DEFUN([gl_WCHAR_H_INLINE_OK],
52 [
53   dnl Test whether <wchar.h> suffers due to the transition from '__inline' to
54   dnl 'gnu_inline'. See <http://sourceware.org/bugzilla/show_bug.cgi?id=4022>
55   dnl and <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42440>. In summary,
56   dnl glibc version 2.5 or older, together with gcc version 4.3 or newer and
57   dnl the option -std=c99 or -std=gnu99, leads to a broken <wchar.h>.
58   AC_CACHE_CHECK([whether <wchar.h> uses 'inline' correctly],
59     [gl_cv_header_wchar_h_correct_inline],
60     [gl_cv_header_wchar_h_correct_inline=yes
61      AC_LANG_CONFTEST([
62        AC_LANG_SOURCE([[#define wcstod renamed_wcstod
63 #include <wchar.h>
64 extern int zero (void);
65 int main () { return zero(); }
66 ]])])
67      if AC_TRY_EVAL([ac_compile]); then
68        mv conftest.$ac_objext conftest1.$ac_objext
69        AC_LANG_CONFTEST([
70          AC_LANG_SOURCE([[#define wcstod renamed_wcstod
71 #include <wchar.h>
72 int zero (void) { return 0; }
73 ]])])
74        if AC_TRY_EVAL([ac_compile]); then
75          mv conftest.$ac_objext conftest2.$ac_objext
76          if $CC -o conftest$ac_exeext $CFLAGS $LDFLAGS conftest1.$ac_objext conftest2.$ac_objext $LIBS >&AS_MESSAGE_LOG_FD 2>&1; then
77            :
78          else
79            gl_cv_header_wchar_h_correct_inline=no
80          fi
81        fi
82      fi
83      rm -f conftest1.$ac_objext conftest2.$ac_objext conftest$ac_exeext
84     ])
85   if test $gl_cv_header_wchar_h_correct_inline = no; then
86     AC_MSG_ERROR([<wchar.h> cannot be used with this compiler ($CC $CFLAGS $CPPFLAGS).
87 This is a known interoperability problem of glibc <= 2.5 with gcc >= 4.3 in
88 C99 mode. You have four options:
89   - Add the flag -fgnu89-inline to CC and reconfigure, or
90   - Fix your include files, using parts of
91     <http://sourceware.org/git/?p=glibc.git;a=commitdiff;h=b037a293a48718af30d706c2e18c929d0e69a621>, or
92   - Use a gcc version older than 4.3, or
93   - Don't use the flags -std=c99 or -std=gnu99.
94 Configuration aborted.])
95   fi
96 ])
97
98 dnl Unconditionally enables the replacement of <wchar.h>.
99 AC_DEFUN([gl_REPLACE_WCHAR_H],
100 [
101   AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
102   :
103 ])
104
105 AC_DEFUN([gl_WCHAR_MODULE_INDICATOR],
106 [
107   dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
108   AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
109   GNULIB_[]m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./-],[ABCDEFGHIJKLMNOPQRSTUVWXYZ___])=1
110 ])
111
112 AC_DEFUN([gl_WCHAR_H_DEFAULTS],
113 [
114   GNULIB_BTOWC=0;      AC_SUBST([GNULIB_BTOWC])
115   GNULIB_WCTOB=0;      AC_SUBST([GNULIB_WCTOB])
116   GNULIB_MBSINIT=0;    AC_SUBST([GNULIB_MBSINIT])
117   GNULIB_MBRTOWC=0;    AC_SUBST([GNULIB_MBRTOWC])
118   GNULIB_MBRLEN=0;     AC_SUBST([GNULIB_MBRLEN])
119   GNULIB_MBSRTOWCS=0;  AC_SUBST([GNULIB_MBSRTOWCS])
120   GNULIB_MBSNRTOWCS=0; AC_SUBST([GNULIB_MBSNRTOWCS])
121   GNULIB_WCRTOMB=0;    AC_SUBST([GNULIB_WCRTOMB])
122   GNULIB_WCSRTOMBS=0;  AC_SUBST([GNULIB_WCSRTOMBS])
123   GNULIB_WCSNRTOMBS=0; AC_SUBST([GNULIB_WCSNRTOMBS])
124   GNULIB_WCWIDTH=0;    AC_SUBST([GNULIB_WCWIDTH])
125   dnl Assume proper GNU behavior unless another module says otherwise.
126   HAVE_BTOWC=1;         AC_SUBST([HAVE_BTOWC])
127   HAVE_MBSINIT=1;       AC_SUBST([HAVE_MBSINIT])
128   HAVE_MBRTOWC=1;       AC_SUBST([HAVE_MBRTOWC])
129   HAVE_MBRLEN=1;        AC_SUBST([HAVE_MBRLEN])
130   HAVE_MBSRTOWCS=1;     AC_SUBST([HAVE_MBSRTOWCS])
131   HAVE_MBSNRTOWCS=1;    AC_SUBST([HAVE_MBSNRTOWCS])
132   HAVE_WCRTOMB=1;       AC_SUBST([HAVE_WCRTOMB])
133   HAVE_WCSRTOMBS=1;     AC_SUBST([HAVE_WCSRTOMBS])
134   HAVE_WCSNRTOMBS=1;    AC_SUBST([HAVE_WCSNRTOMBS])
135   HAVE_DECL_WCTOB=1;    AC_SUBST([HAVE_DECL_WCTOB])
136   HAVE_DECL_WCWIDTH=1;  AC_SUBST([HAVE_DECL_WCWIDTH])
137   REPLACE_MBSTATE_T=0;  AC_SUBST([REPLACE_MBSTATE_T])
138   REPLACE_BTOWC=0;      AC_SUBST([REPLACE_BTOWC])
139   REPLACE_WCTOB=0;      AC_SUBST([REPLACE_WCTOB])
140   REPLACE_MBSINIT=0;    AC_SUBST([REPLACE_MBSINIT])
141   REPLACE_MBRTOWC=0;    AC_SUBST([REPLACE_MBRTOWC])
142   REPLACE_MBRLEN=0;     AC_SUBST([REPLACE_MBRLEN])
143   REPLACE_MBSRTOWCS=0;  AC_SUBST([REPLACE_MBSRTOWCS])
144   REPLACE_MBSNRTOWCS=0; AC_SUBST([REPLACE_MBSNRTOWCS])
145   REPLACE_WCRTOMB=0;    AC_SUBST([REPLACE_WCRTOMB])
146   REPLACE_WCSRTOMBS=0;  AC_SUBST([REPLACE_WCSRTOMBS])
147   REPLACE_WCSNRTOMBS=0; AC_SUBST([REPLACE_WCSNRTOMBS])
148   REPLACE_WCWIDTH=0;    AC_SUBST([REPLACE_WCWIDTH])
149 ])