Support cross-compilation of <wctype.h>.
[gnulib.git] / m4 / wctype.m4
1 dnl A placeholder for ISO C99 <wctype.h>, for platforms that lack it.
2
3 dnl Copyright (C) 2006-2008 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 Paul Eggert.
9
10 #serial 2
11 AC_DEFUN([gl_WCTYPE_H],
12 [
13   AC_REQUIRE([AC_PROG_CC])
14   AC_CHECK_FUNCS_ONCE([iswcntrl])
15   if test $ac_cv_func_iswcntrl = yes; then
16     HAVE_ISWCNTRL=1
17   else
18     HAVE_ISWCNTRL=0
19   fi
20   AC_SUBST([HAVE_ISWCNTRL])
21   AC_CHECK_HEADERS_ONCE([wctype.h])
22   AC_REQUIRE([AC_C_INLINE])
23
24   AC_REQUIRE([gt_TYPE_WINT_T])
25   if test $gt_cv_c_wint_t = yes; then
26     HAVE_WINT_T=1
27   else
28     HAVE_WINT_T=0
29   fi
30   AC_SUBST([HAVE_WINT_T])
31
32   WCTYPE_H=wctype.h
33   if test $ac_cv_header_wctype_h = yes; then
34     if test $ac_cv_func_iswcntrl = yes; then
35       dnl Linux libc5 has an iswprint function that returns 0 for all arguments.
36       dnl The other functions are likely broken in the same way.
37       AC_CACHE_CHECK([whether iswcntrl works], [gl_cv_func_iswcntrl_works],
38         [
39           AC_TRY_RUN([#include <stddef.h>
40                       #include <stdio.h>
41                       #include <time.h>
42                       #include <wchar.h>
43                       #include <wctype.h>
44                       int main () { return iswprint ('x') == 0; }],
45             [gl_cv_func_iswcntrl_works=yes], [gl_cv_func_iswcntrl_works=no],
46             [AC_TRY_COMPILE([#include <stdlib.h>
47                           #if __GNU_LIBRARY__ == 1
48                           Linux libc5 i18n is broken.
49                           #endif], [],
50               [gl_cv_func_iswcntrl_works=yes], [gl_cv_func_iswcntrl_works=no])
51         ])])
52       if test $gl_cv_func_iswcntrl_works = yes; then
53         WCTYPE_H=
54       fi
55     fi
56     dnl Compute NEXT_WCTYPE_H even if WCTYPE_H is empty,
57     dnl for the benefit of builds from non-distclean directories.
58     gl_CHECK_NEXT_HEADERS([wctype.h])
59     HAVE_WCTYPE_H=1
60   else
61     HAVE_WCTYPE_H=0
62   fi
63   AC_SUBST([HAVE_WCTYPE_H])
64   AC_SUBST([WCTYPE_H])
65
66   if test "$gl_cv_func_iswcntrl_works" = no; then
67     REPLACE_ISWCNTRL=1
68   else
69     REPLACE_ISWCNTRL=0
70   fi
71   AC_SUBST([REPLACE_ISWCNTRL])
72 ])