Merge branch 'upstream' into stable
[gnulib.git] / m4 / wctype_h.m4
1 # wctype_h.m4 serial 12
2
3 dnl A placeholder for ISO C99 <wctype.h>, for platforms that lack it.
4
5 dnl Copyright (C) 2006-2011 Free Software Foundation, Inc.
6 dnl This file is free software; the Free Software Foundation
7 dnl gives unlimited permission to copy and/or distribute it,
8 dnl with or without modifications, as long as this notice is preserved.
9
10 dnl Written by Paul Eggert.
11
12 AC_DEFUN([gl_WCTYPE_H],
13 [
14   AC_REQUIRE([AC_PROG_CC])
15   AC_REQUIRE([AC_CANONICAL_HOST])
16   AC_CHECK_FUNCS_ONCE([iswcntrl])
17   if test $ac_cv_func_iswcntrl = yes; then
18     HAVE_ISWCNTRL=1
19   else
20     HAVE_ISWCNTRL=0
21   fi
22   AC_SUBST([HAVE_ISWCNTRL])
23   AC_CHECK_FUNCS_ONCE([iswblank])
24   AC_CHECK_DECLS_ONCE([iswblank])
25   if test $ac_cv_func_iswblank = yes; then
26     HAVE_ISWBLANK=1
27     REPLACE_ISWBLANK=0
28   else
29     HAVE_ISWBLANK=0
30     if test $ac_cv_have_decl_iswblank = yes; then
31       REPLACE_ISWBLANK=1
32     else
33       REPLACE_ISWBLANK=0
34     fi
35   fi
36   AC_SUBST([HAVE_ISWBLANK])
37   AC_SUBST([REPLACE_ISWBLANK])
38
39   AC_REQUIRE([AC_C_INLINE])
40
41   AC_REQUIRE([gt_TYPE_WINT_T])
42   if test $gt_cv_c_wint_t = yes; then
43     HAVE_WINT_T=1
44   else
45     HAVE_WINT_T=0
46   fi
47   AC_SUBST([HAVE_WINT_T])
48
49   gl_CHECK_NEXT_HEADERS([wctype.h])
50   if test $ac_cv_header_wctype_h = yes; then
51     if test $ac_cv_func_iswcntrl = yes; then
52       dnl Linux libc5 has an iswprint function that returns 0 for all arguments.
53       dnl The other functions are likely broken in the same way.
54       AC_CACHE_CHECK([whether iswcntrl works], [gl_cv_func_iswcntrl_works],
55         [
56           AC_RUN_IFELSE(
57             [AC_LANG_SOURCE([[
58                /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be
59                   included before <wchar.h>.
60                   BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h>
61                   must be included before <wchar.h>.  */
62                #include <stddef.h>
63                #include <stdio.h>
64                #include <time.h>
65                #include <wchar.h>
66                #include <wctype.h>
67                int main () { return iswprint ('x') == 0; }
68             ]])],
69             [gl_cv_func_iswcntrl_works=yes], [gl_cv_func_iswcntrl_works=no],
70             [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <stdlib.h>
71                           #if __GNU_LIBRARY__ == 1
72                           Linux libc5 i18n is broken.
73                           #endif]], [])],
74               [gl_cv_func_iswcntrl_works=yes], [gl_cv_func_iswcntrl_works=no])
75             ])
76         ])
77     fi
78     HAVE_WCTYPE_H=1
79   else
80     HAVE_WCTYPE_H=0
81   fi
82   AC_SUBST([HAVE_WCTYPE_H])
83
84   if test "$gl_cv_func_iswcntrl_works" = no; then
85     REPLACE_ISWCNTRL=1
86   else
87     REPLACE_ISWCNTRL=0
88   fi
89   AC_SUBST([REPLACE_ISWCNTRL])
90
91   if test $HAVE_ISWCNTRL = 0 || test $REPLACE_ISWCNTRL = 1; then
92     dnl Redefine all of iswcntrl, ..., towupper in <wctype.h>.
93     :
94   else
95     if test $HAVE_ISWBLANK = 0 || test $REPLACE_ISWBLANK = 1; then
96       dnl Redefine only iswblank.
97       AC_LIBOBJ([iswblank])
98     fi
99   fi
100 ])