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