Imported Upstream version 1.4.16
[platform/upstream/m4.git] / m4 / wctob.m4
1 # wctob.m4 serial 7
2 dnl Copyright (C) 2008-2011 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
6
7 AC_DEFUN([gl_FUNC_WCTOB],
8 [
9   AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
10
11   AC_CHECK_FUNCS_ONCE([wctob])
12   if test $ac_cv_func_wctob = no; then
13     HAVE_DECL_WCTOB=0
14     gl_REPLACE_WCHAR_H
15     AC_LIBOBJ([wctob])
16     gl_PREREQ_WCTOB
17   else
18
19     dnl Solaris 9 has the wctob() function but it does not work.
20     dnl Cygwin 1.7.2 has the wctob() function but it clobbers caller-owned
21     dnl registers, see <http://cygwin.com/ml/cygwin/2010-05/msg00015.html>.
22     AC_REQUIRE([AC_PROG_CC])
23     AC_REQUIRE([gt_LOCALE_FR])
24     AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
25     AC_CACHE_CHECK([whether wctob works],
26       [gl_cv_func_wctob_works],
27       [
28         dnl Initial guess, used when cross-compiling or when no suitable locale
29         dnl is present.
30 changequote(,)dnl
31         case "$host_os" in
32             # Guess no on Solaris <= 9 and Cygwin.
33           solaris2.[1-9] | solaris2.[1-9].* | cygwin*)
34             gl_cv_func_wctob_works="guessing no" ;;
35             # Guess yes otherwise.
36           *) gl_cv_func_wctob_works="guessing yes" ;;
37         esac
38 changequote([,])dnl
39         case "$host_os" in
40           cygwin*)
41             AC_RUN_IFELSE(
42               [AC_LANG_SOURCE([[
43 #include <locale.h>
44 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
45    <wchar.h>.
46    BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
47    included before <wchar.h>.  */
48 #include <stddef.h>
49 #include <stdio.h>
50 #include <time.h>
51 #include <wchar.h>
52
53 register long global __asm__ ("%ebx");
54
55 int main ()
56 {
57   setlocale (LC_ALL, "en_US.UTF-8");
58
59   global = 0x12345678;
60   if (wctob (0x00FC) != -1)
61     return 1;
62   if (global != 0x12345678)
63     return 2;
64   return 0;
65 }]])],
66               [:],
67               [gl_cv_func_wctob_works=no],
68               [:])
69             ;;
70         esac
71         if test "$gl_cv_func_wctob_works" != no && test $LOCALE_FR != none; then
72           AC_RUN_IFELSE(
73             [AC_LANG_SOURCE([[
74 #include <locale.h>
75 #include <string.h>
76 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
77    <wchar.h>.
78    BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
79    included before <wchar.h>.  */
80 #include <stddef.h>
81 #include <stdio.h>
82 #include <time.h>
83 #include <wchar.h>
84 int main ()
85 {
86   if (setlocale (LC_ALL, "$LOCALE_FR") != NULL)
87     {
88       wchar_t wc;
89
90       if (mbtowc (&wc, "\374", 1) == 1)
91         if (wctob (wc) != (unsigned char) '\374')
92           return 1;
93     }
94   return 0;
95 }]])],
96             [gl_cv_func_wctob_works=yes],
97             [gl_cv_func_wctob_works=no],
98             [:])
99         fi
100       ])
101     case "$gl_cv_func_wctob_works" in
102       *yes) ;;
103       *) REPLACE_WCTOB=1 ;;
104     esac
105     if test $REPLACE_WCTOB = 1; then
106       gl_REPLACE_WCHAR_H
107       AC_LIBOBJ([wctob])
108       gl_PREREQ_WCTOB
109     else
110
111       dnl IRIX 6.5 has the wctob() function but does not declare it.
112       AC_CHECK_DECLS([wctob], [], [], [
113 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
114    <wchar.h>.
115    BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be included
116    before <wchar.h>.  */
117 #include <stddef.h>
118 #include <stdio.h>
119 #include <time.h>
120 #include <wchar.h>
121 ])
122       if test $ac_cv_have_decl_wctob != yes; then
123         HAVE_DECL_WCTOB=0
124         gl_REPLACE_WCHAR_H
125       fi
126     fi
127   fi
128 ])
129
130 # Prerequisites of lib/wctob.c.
131 AC_DEFUN([gl_PREREQ_WCTOB], [
132   :
133 ])