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.
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"
25 AC_TRY_LINK([#include <stdlib.h>
27 [iconv_t cd = iconv_open("","");
28 iconv(cd,NULL,NULL,NULL,NULL);
30 [am_cv_func_iconv=yes])
31 if test "$am_cv_func_iconv" != yes; then
33 LIBS="$LIBS $LIBICONV"
34 AC_TRY_LINK([#include <stdlib.h>
36 [iconv_t cd = iconv_open("","");
37 iconv(cd,NULL,NULL,NULL,NULL);
40 [am_cv_func_iconv=yes])
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.
48 if test $am_cv_lib_iconv = yes; then
49 LIBS="$LIBS $LIBICONV"
56 /* Test against AIX 5.1 bug: Failures are not distinguishable from successful
59 iconv_t cd_utf8_to_88591 = iconv_open ("ISO8859-1", "UTF-8");
60 if (cd_utf8_to_88591 != (iconv_t)(-1))
62 static const char input[] = "\342\202\254"; /* EURO SIGN */
64 const char *inptr = input;
65 size_t inbytesleft = strlen (input);
67 size_t outbytesleft = sizeof (buf);
68 size_t res = iconv (cd_utf8_to_88591,
69 (char **) &inptr, &inbytesleft,
70 &outptr, &outbytesleft);
75 /* Test against Solaris 10 bug: Failures are not distinguishable from
76 successful returns. */
78 iconv_t cd_ascii_to_88591 = iconv_open ("ISO8859-1", "646");
79 if (cd_ascii_to_88591 != (iconv_t)(-1))
81 static const char input[] = "\263";
83 const char *inptr = input;
84 size_t inbytesleft = strlen (input);
86 size_t outbytesleft = sizeof (buf);
87 size_t res = iconv (cd_ascii_to_88591,
88 (char **) &inptr, &inbytesleft,
89 &outptr, &outbytesleft);
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. */
97 iconv_t cd_88591_to_utf8 = iconv_open ("utf8", "iso88591");
98 if (cd_88591_to_utf8 != (iconv_t)(-1))
100 static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
102 const char *inptr = input;
103 size_t inbytesleft = strlen (input);
105 size_t outbytesleft = sizeof (buf);
106 size_t res = iconv (cd_88591_to_utf8,
107 (char **) &inptr, &inbytesleft,
108 &outptr, &outbytesleft);
114 /* Test against HP-UX 11.11 bug: No converter from EUC-JP to UTF-8 is
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)
121 && iconv_open ("UTF-8", "IBM-eucJP") == (iconv_t)(-1)
122 /* Try HP-UX names. */
123 && iconv_open ("utf8", "eucJP") == (iconv_t)(-1))
126 }], [am_cv_func_iconv_works=yes], [am_cv_func_iconv_works=no],
128 aix* | hpux*) am_cv_func_iconv_works="guessing no" ;;
129 *) am_cv_func_iconv_works="guessing yes" ;;
133 case "$am_cv_func_iconv_works" in
134 *no) am_func_iconv=no am_cv_lib_iconv=no ;;
135 *) am_func_iconv=yes ;;
138 am_func_iconv=no am_cv_lib_iconv=no
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.])
144 if test "$am_cv_lib_iconv" = yes; then
145 AC_MSG_CHECKING([how to link with libiconv])
146 AC_MSG_RESULT([$LIBICONV])
148 dnl If $LIBICONV didn't lead to a usable library, we don't need $INCICONV
150 CPPFLAGS="$am_save_CPPFLAGS"
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"
167 m4_define([gl_iconv_AC_DEFUN],
168 m4_version_prereq([2.64],
173 gl_iconv_AC_DEFUN([AM_ICONV],
176 if test "$am_cv_func_iconv" = yes; then
177 AC_MSG_CHECKING([for iconv declaration])
178 AC_CACHE_VAL([am_cv_proto_iconv], [
186 #if defined(__STDC__) || defined(__cplusplus)
187 size_t iconv (iconv_t cd, char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);
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/( /(/'`
196 AC_DEFINE_UNQUOTED([ICONV_CONST], [$am_cv_proto_iconv_arg1],
197 [Define as const if the declaration of iconv() needs const.])