1 # iconv.m4 serial 18 (gettext-0.18.2)
2 dnl Copyright (C) 2000-2002, 2007-2014 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.
9 AC_DEFUN([AM_ICONV_LINKFLAGS_BODY],
11 dnl Prerequisites of AC_LIB_LINKFLAGS_BODY.
12 AC_REQUIRE([AC_LIB_PREPARE_PREFIX])
13 AC_REQUIRE([AC_LIB_RPATH])
15 dnl Search for libiconv and define LIBICONV, LTLIBICONV and INCICONV
17 AC_LIB_LINKFLAGS_BODY([iconv])
20 AC_DEFUN([AM_ICONV_LINK],
22 dnl Some systems have iconv in libc, some have it in libiconv (OSF/1 and
23 dnl those with the standalone portable GNU libiconv installed).
24 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
26 dnl Search for libiconv and define LIBICONV, LTLIBICONV and INCICONV
28 AC_REQUIRE([AM_ICONV_LINKFLAGS_BODY])
30 dnl Add $INCICONV to CPPFLAGS before performing the following checks,
31 dnl because if the user has installed libiconv and not disabled its use
32 dnl via --without-libiconv-prefix, he wants to use it. The first
33 dnl AC_LINK_IFELSE will then fail, the second AC_LINK_IFELSE will succeed.
34 am_save_CPPFLAGS="$CPPFLAGS"
35 AC_LIB_APPENDTOVAR([CPPFLAGS], [$INCICONV])
37 AC_CACHE_CHECK([for iconv], [am_cv_func_iconv], [
38 am_cv_func_iconv="no, consider installing GNU libiconv"
46 [[iconv_t cd = iconv_open("","");
47 iconv(cd,NULL,NULL,NULL,NULL);
49 [am_cv_func_iconv=yes])
50 if test "$am_cv_func_iconv" != yes; then
52 LIBS="$LIBS $LIBICONV"
59 [[iconv_t cd = iconv_open("","");
60 iconv(cd,NULL,NULL,NULL,NULL);
63 [am_cv_func_iconv=yes])
67 if test "$am_cv_func_iconv" = yes; then
68 AC_CACHE_CHECK([for working iconv], [am_cv_func_iconv_works], [
69 dnl This tests against bugs in AIX 5.1, AIX 6.1..7.1, HP-UX 11.11,
72 if test $am_cv_lib_iconv = yes; then
73 LIBS="$LIBS $LIBICONV"
82 /* Test against AIX 5.1 bug: Failures are not distinguishable from successful
85 iconv_t cd_utf8_to_88591 = iconv_open ("ISO8859-1", "UTF-8");
86 if (cd_utf8_to_88591 != (iconv_t)(-1))
88 static const char input[] = "\342\202\254"; /* EURO SIGN */
90 const char *inptr = input;
91 size_t inbytesleft = strlen (input);
93 size_t outbytesleft = sizeof (buf);
94 size_t res = iconv (cd_utf8_to_88591,
95 (char **) &inptr, &inbytesleft,
96 &outptr, &outbytesleft);
99 iconv_close (cd_utf8_to_88591);
102 /* Test against Solaris 10 bug: Failures are not distinguishable from
103 successful returns. */
105 iconv_t cd_ascii_to_88591 = iconv_open ("ISO8859-1", "646");
106 if (cd_ascii_to_88591 != (iconv_t)(-1))
108 static const char input[] = "\263";
110 const char *inptr = input;
111 size_t inbytesleft = strlen (input);
113 size_t outbytesleft = sizeof (buf);
114 size_t res = iconv (cd_ascii_to_88591,
115 (char **) &inptr, &inbytesleft,
116 &outptr, &outbytesleft);
119 iconv_close (cd_ascii_to_88591);
122 /* Test against AIX 6.1..7.1 bug: Buffer overrun. */
124 iconv_t cd_88591_to_utf8 = iconv_open ("UTF-8", "ISO-8859-1");
125 if (cd_88591_to_utf8 != (iconv_t)(-1))
127 static const char input[] = "\304";
128 static char buf[2] = { (char)0xDE, (char)0xAD };
129 const char *inptr = input;
130 size_t inbytesleft = 1;
132 size_t outbytesleft = 1;
133 size_t res = iconv (cd_88591_to_utf8,
134 (char **) &inptr, &inbytesleft,
135 &outptr, &outbytesleft);
136 if (res != (size_t)(-1) || outptr - buf > 1 || buf[1] != (char)0xAD)
138 iconv_close (cd_88591_to_utf8);
141 #if 0 /* This bug could be worked around by the caller. */
142 /* Test against HP-UX 11.11 bug: Positive return value instead of 0. */
144 iconv_t cd_88591_to_utf8 = iconv_open ("utf8", "iso88591");
145 if (cd_88591_to_utf8 != (iconv_t)(-1))
147 static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
149 const char *inptr = input;
150 size_t inbytesleft = strlen (input);
152 size_t outbytesleft = sizeof (buf);
153 size_t res = iconv (cd_88591_to_utf8,
154 (char **) &inptr, &inbytesleft,
155 &outptr, &outbytesleft);
158 iconv_close (cd_88591_to_utf8);
162 /* Test against HP-UX 11.11 bug: No converter from EUC-JP to UTF-8 is
164 if (/* Try standardized names. */
165 iconv_open ("UTF-8", "EUC-JP") == (iconv_t)(-1)
166 /* Try IRIX, OSF/1 names. */
167 && iconv_open ("UTF-8", "eucJP") == (iconv_t)(-1)
169 && iconv_open ("UTF-8", "IBM-eucJP") == (iconv_t)(-1)
170 /* Try HP-UX names. */
171 && iconv_open ("utf8", "eucJP") == (iconv_t)(-1))
175 [am_cv_func_iconv_works=yes],
176 [am_cv_func_iconv_works=no],
180 aix* | hpux*) am_cv_func_iconv_works="guessing no" ;;
181 *) am_cv_func_iconv_works="guessing yes" ;;
187 case "$am_cv_func_iconv_works" in
188 *no) am_func_iconv=no am_cv_lib_iconv=no ;;
189 *) am_func_iconv=yes ;;
192 am_func_iconv=no am_cv_lib_iconv=no
194 if test "$am_func_iconv" = yes; then
195 AC_DEFINE([HAVE_ICONV], [1],
196 [Define if you have the iconv() function and it works.])
198 if test "$am_cv_lib_iconv" = yes; then
199 AC_MSG_CHECKING([how to link with libiconv])
200 AC_MSG_RESULT([$LIBICONV])
202 dnl If $LIBICONV didn't lead to a usable library, we don't need $INCICONV
204 CPPFLAGS="$am_save_CPPFLAGS"
209 AC_SUBST([LTLIBICONV])
212 dnl Define AM_ICONV using AC_DEFUN_ONCE for Autoconf >= 2.64, in order to
213 dnl avoid warnings like
214 dnl "warning: AC_REQUIRE: `AM_ICONV' was expanded before it was required".
215 dnl This is tricky because of the way 'aclocal' is implemented:
216 dnl - It requires defining an auxiliary macro whose name ends in AC_DEFUN.
217 dnl Otherwise aclocal's initial scan pass would miss the macro definition.
218 dnl - It requires a line break inside the AC_DEFUN_ONCE and AC_DEFUN expansions.
219 dnl Otherwise aclocal would emit many "Use of uninitialized value $1"
221 m4_define([gl_iconv_AC_DEFUN],
222 m4_version_prereq([2.64],
225 [m4_ifdef([gl_00GNULIB],
230 gl_iconv_AC_DEFUN([AM_ICONV],
233 if test "$am_cv_func_iconv" = yes; then
234 AC_MSG_CHECKING([for iconv declaration])
235 AC_CACHE_VAL([am_cv_proto_iconv], [
245 #if defined(__STDC__) || defined(_MSC_VER) || defined(__cplusplus)
246 size_t iconv (iconv_t cd, char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);
252 [am_cv_proto_iconv_arg1=""],
253 [am_cv_proto_iconv_arg1="const"])
254 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);"])
255 am_cv_proto_iconv=`echo "[$]am_cv_proto_iconv" | tr -s ' ' | sed -e 's/( /(/'`
258 AC_DEFINE_UNQUOTED([ICONV_CONST], [$am_cv_proto_iconv_arg1],
259 [Define as const if the declaration of iconv() needs const.])
260 dnl Also substitute ICONV_CONST in the gnulib generated <iconv.h>.
261 m4_ifdef([gl_ICONV_H_DEFAULTS],
262 [AC_REQUIRE([gl_ICONV_H_DEFAULTS])
263 if test -n "$am_cv_proto_iconv_arg1"; then