mention Tile architecture
[uclibc-ng.git] / libiconv / m4 / iconv.m4
blob0be3a1f5bb19fbd7a0493ff2cd42ae58d877eb70
1 # iconv.m4 serial 11 (gettext-0.18.1)
2 dnl Copyright (C) 2000-2002, 2007-2010 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.
7 dnl From Bruno Haible.
9 AC_DEFUN([AM_ICONV_LINK],
11   dnl Some systems have iconv in libc, some have it in libiconv (OSF/1 and
12   dnl those with the standalone portable GNU libiconv installed).
13   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
15   dnl Add $INCICONV to CPPFLAGS before performing the following checks,
16   dnl because if the user has installed libiconv and not disabled its use
17   dnl via --without-libiconv-prefix, he wants to use it. The first
18   dnl AC_TRY_LINK will then fail, the second AC_TRY_LINK will succeed.
19   am_save_CPPFLAGS="$CPPFLAGS"
20   dnl AC_LIB_APPENDTOVAR([CPPFLAGS], [$INCICONV])
22   AC_CACHE_CHECK([for iconv], [am_cv_func_iconv], [
23     am_cv_func_iconv="no, consider installing GNU libiconv"
24     am_cv_lib_iconv=no
25     AC_TRY_LINK([#include <stdlib.h>
26 #include <iconv.h>],
27       [iconv_t cd = iconv_open("","");
28        iconv(cd,NULL,NULL,NULL,NULL);
29        iconv_close(cd);],
30       [am_cv_func_iconv=yes])
31     if test "$am_cv_func_iconv" != yes; then
32       am_save_LIBS="$LIBS"
33       LIBS="$LIBS $LIBICONV"
34       AC_TRY_LINK([#include <stdlib.h>
35 #include <iconv.h>],
36         [iconv_t cd = iconv_open("","");
37          iconv(cd,NULL,NULL,NULL,NULL);
38          iconv_close(cd);],
39         [am_cv_lib_iconv=yes]
40         [am_cv_func_iconv=yes])
41       LIBS="$am_save_LIBS"
42     fi
43   ])
44   if test "$am_cv_func_iconv" = yes; then
45     AC_CACHE_CHECK([for working iconv], [am_cv_func_iconv_works], [
46       dnl This tests against bugs in AIX 5.1, HP-UX 11.11, Solaris 10.
47       am_save_LIBS="$LIBS"
48       if test $am_cv_lib_iconv = yes; then
49         LIBS="$LIBS $LIBICONV"
50       fi
51       AC_TRY_RUN([
52 #include <iconv.h>
53 #include <string.h>
54 int main ()
56   /* Test against AIX 5.1 bug: Failures are not distinguishable from successful
57      returns.  */
58   {
59     iconv_t cd_utf8_to_88591 = iconv_open ("ISO8859-1", "UTF-8");
60     if (cd_utf8_to_88591 != (iconv_t)(-1))
61       {
62         static const char input[] = "\342\202\254"; /* EURO SIGN */
63         char buf[10];
64         const char *inptr = input;
65         size_t inbytesleft = strlen (input);
66         char *outptr = buf;
67         size_t outbytesleft = sizeof (buf);
68         size_t res = iconv (cd_utf8_to_88591,
69                             (char **) &inptr, &inbytesleft,
70                             &outptr, &outbytesleft);
71         if (res == 0)
72           return 1;
73       }
74   }
75   /* Test against Solaris 10 bug: Failures are not distinguishable from
76      successful returns.  */
77   {
78     iconv_t cd_ascii_to_88591 = iconv_open ("ISO8859-1", "646");
79     if (cd_ascii_to_88591 != (iconv_t)(-1))
80       {
81         static const char input[] = "\263";
82         char buf[10];
83         const char *inptr = input;
84         size_t inbytesleft = strlen (input);
85         char *outptr = buf;
86         size_t outbytesleft = sizeof (buf);
87         size_t res = iconv (cd_ascii_to_88591,
88                             (char **) &inptr, &inbytesleft,
89                             &outptr, &outbytesleft);
90         if (res == 0)
91           return 1;
92       }
93   }
94 #if 0 /* This bug could be worked around by the caller.  */
95   /* Test against HP-UX 11.11 bug: Positive return value instead of 0.  */
96   {
97     iconv_t cd_88591_to_utf8 = iconv_open ("utf8", "iso88591");
98     if (cd_88591_to_utf8 != (iconv_t)(-1))
99       {
100         static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
101         char buf[50];
102         const char *inptr = input;
103         size_t inbytesleft = strlen (input);
104         char *outptr = buf;
105         size_t outbytesleft = sizeof (buf);
106         size_t res = iconv (cd_88591_to_utf8,
107                             (char **) &inptr, &inbytesleft,
108                             &outptr, &outbytesleft);
109         if ((int)res > 0)
110           return 1;
111       }
112   }
113 #endif
114   /* Test against HP-UX 11.11 bug: No converter from EUC-JP to UTF-8 is
115      provided.  */
116   if (/* Try standardized names.  */
117       iconv_open ("UTF-8", "EUC-JP") == (iconv_t)(-1)
118       /* Try IRIX, OSF/1 names.  */
119       && iconv_open ("UTF-8", "eucJP") == (iconv_t)(-1)
120       /* Try AIX names.  */
121       && iconv_open ("UTF-8", "IBM-eucJP") == (iconv_t)(-1)
122       /* Try HP-UX names.  */
123       && iconv_open ("utf8", "eucJP") == (iconv_t)(-1))
124     return 1;
125   return 0;
126 }], [am_cv_func_iconv_works=yes], [am_cv_func_iconv_works=no],
127         [case "$host_os" in
128            aix* | hpux*) am_cv_func_iconv_works="guessing no" ;;
129            *)            am_cv_func_iconv_works="guessing yes" ;;
130          esac])
131       LIBS="$am_save_LIBS"
132     ])
133     case "$am_cv_func_iconv_works" in
134       *no) am_func_iconv=no am_cv_lib_iconv=no ;;
135       *)   am_func_iconv=yes ;;
136     esac
137   else
138     am_func_iconv=no am_cv_lib_iconv=no
139   fi
140   if test "$am_func_iconv" = yes; then
141     AC_DEFINE([HAVE_ICONV], [1],
142       [Define if you have the iconv() function and it works.])
143   fi
144   if test "$am_cv_lib_iconv" = yes; then
145     AC_MSG_CHECKING([how to link with libiconv])
146     AC_MSG_RESULT([$LIBICONV])
147   else
148     dnl If $LIBICONV didn't lead to a usable library, we don't need $INCICONV
149     dnl either.
150     CPPFLAGS="$am_save_CPPFLAGS"
151     LIBICONV=
152     LTLIBICONV=
153   fi
154   AC_SUBST([LIBICONV])
155   AC_SUBST([LTLIBICONV])
158 dnl Define AM_ICONV using AC_DEFUN_ONCE for Autoconf >= 2.64, in order to
159 dnl avoid warnings like
160 dnl "warning: AC_REQUIRE: `AM_ICONV' was expanded before it was required".
161 dnl This is tricky because of the way 'aclocal' is implemented:
162 dnl - It requires defining an auxiliary macro whose name ends in AC_DEFUN.
163 dnl   Otherwise aclocal's initial scan pass would miss the macro definition.
164 dnl - It requires a line break inside the AC_DEFUN_ONCE and AC_DEFUN expansions.
165 dnl   Otherwise aclocal would emit many "Use of uninitialized value $1"
166 dnl   warnings.
167 m4_define([gl_iconv_AC_DEFUN],
168   m4_version_prereq([2.64],
169     [[AC_DEFUN_ONCE(
170         [$1], [$2])]],
171     [[AC_DEFUN(
172         [$1], [$2])]]))
173 gl_iconv_AC_DEFUN([AM_ICONV],
175   AM_ICONV_LINK
176   if test "$am_cv_func_iconv" = yes; then
177     AC_MSG_CHECKING([for iconv declaration])
178     AC_CACHE_VAL([am_cv_proto_iconv], [
179       AC_TRY_COMPILE([
180 #include <stdlib.h>
181 #include <iconv.h>
182 extern
183 #ifdef __cplusplus
185 #endif
186 #if defined(__STDC__) || defined(__cplusplus)
187 size_t iconv (iconv_t cd, char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);
188 #else
189 size_t iconv();
190 #endif
191 ], [], [am_cv_proto_iconv_arg1=""], [am_cv_proto_iconv_arg1="const"])
192       am_cv_proto_iconv="extern size_t iconv (iconv_t cd, $am_cv_proto_iconv_arg1 char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);"])
193     am_cv_proto_iconv=`echo "[$]am_cv_proto_iconv" | tr -s ' ' | sed -e 's/( /(/'`
194     AC_MSG_RESULT([
195          $am_cv_proto_iconv])
196     AC_DEFINE_UNQUOTED([ICONV_CONST], [$am_cv_proto_iconv_arg1],
197       [Define as const if the declaration of iconv() needs const.])
198   fi