1 # iconv.m4 serial AM6 (gettext-0.17)
2 dnl Copyright (C) 2000, 2001, 2002, 2007, 2009 Free Software Foundation,
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.
10 AC_DEFUN([AM_ICONV_LINKFLAGS_BODY],
12 dnl Prerequisites of AC_LIB_LINKFLAGS_BODY.
13 AC_REQUIRE([AC_LIB_PREPARE_PREFIX])
14 AC_REQUIRE([AC_LIB_RPATH])
16 dnl Search for libiconv and define LIBICONV, LTLIBICONV and INCICONV
18 AC_LIB_LINKFLAGS_BODY([iconv])
21 AC_DEFUN([AM_ICONV_LINK],
23 dnl Some systems have iconv in libc, some have it in libiconv (OSF/1 and
24 dnl those with the standalone portable GNU libiconv installed).
25 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
27 dnl Search for libiconv and define LIBICONV, LTLIBICONV and INCICONV
29 AC_REQUIRE([AM_ICONV_LINKFLAGS_BODY])
31 dnl Add $INCICONV to CPPFLAGS before performing the following checks,
32 dnl because if the user has installed libiconv and not disabled its use
33 dnl via --without-libiconv-prefix, he wants to use it. The first
34 dnl AC_TRY_LINK will then fail, the second AC_TRY_LINK will succeed.
35 am_save_CPPFLAGS="$CPPFLAGS"
36 AC_LIB_APPENDTOVAR([CPPFLAGS], [$INCICONV])
38 AC_CACHE_CHECK([for iconv], am_cv_func_iconv, [
39 am_cv_func_iconv="no, consider installing GNU libiconv"
41 AC_TRY_LINK([#include <stdlib.h>
43 [iconv_t cd = iconv_open("","");
44 iconv(cd,NULL,NULL,NULL,NULL);
47 if test "$am_cv_func_iconv" != yes; then
49 LIBS="$LIBS $LIBICONV"
50 AC_TRY_LINK([#include <stdlib.h>
52 [iconv_t cd = iconv_open("","");
53 iconv(cd,NULL,NULL,NULL,NULL);
60 if test "$am_cv_func_iconv" = yes; then
61 AC_CACHE_CHECK([for working iconv], am_cv_func_iconv_works, [
62 dnl This tests against bugs in AIX 5.1 and HP-UX 11.11.
64 if test $am_cv_lib_iconv = yes; then
65 LIBS="$LIBS $LIBICONV"
72 /* Test against AIX 5.1 bug: Failures are not distinguishable from successful
75 iconv_t cd_utf8_to_88591 = iconv_open ("ISO8859-1", "UTF-8");
76 if (cd_utf8_to_88591 != (iconv_t)(-1))
78 static const char input[] = "\342\202\254"; /* EURO SIGN */
80 const char *inptr = input;
81 size_t inbytesleft = strlen (input);
83 size_t outbytesleft = sizeof (buf);
84 size_t res = iconv (cd_utf8_to_88591,
85 (char **) &inptr, &inbytesleft,
86 &outptr, &outbytesleft);
91 #if 0 /* This bug could be worked around by the caller. */
92 /* Test against HP-UX 11.11 bug: Positive return value instead of 0. */
94 iconv_t cd_88591_to_utf8 = iconv_open ("utf8", "iso88591");
95 if (cd_88591_to_utf8 != (iconv_t)(-1))
97 static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
99 const char *inptr = input;
100 size_t inbytesleft = strlen (input);
102 size_t outbytesleft = sizeof (buf);
103 size_t res = iconv (cd_88591_to_utf8,
104 (char **) &inptr, &inbytesleft,
105 &outptr, &outbytesleft);
111 /* Test against HP-UX 11.11 bug: No converter from EUC-JP to UTF-8 is
113 if (/* Try standardized names. */
114 iconv_open ("UTF-8", "EUC-JP") == (iconv_t)(-1)
115 /* Try IRIX, OSF/1 names. */
116 && iconv_open ("UTF-8", "eucJP") == (iconv_t)(-1)
118 && iconv_open ("UTF-8", "IBM-eucJP") == (iconv_t)(-1)
119 /* Try HP-UX names. */
120 && iconv_open ("utf8", "eucJP") == (iconv_t)(-1))
123 }], [am_cv_func_iconv_works=yes], [am_cv_func_iconv_works=no],
125 aix* | hpux*) am_cv_func_iconv_works="guessing no" ;;
126 *) am_cv_func_iconv_works="guessing yes" ;;
130 case "$am_cv_func_iconv_works" in
131 *no) am_func_iconv=no am_cv_lib_iconv=no ;;
132 *) am_func_iconv=yes ;;
135 am_func_iconv=no am_cv_lib_iconv=no
137 if test "$am_func_iconv" = yes; then
138 AC_DEFINE(HAVE_ICONV, 1,
139 [Define if you have the iconv() function and it works.])
141 if test "$am_cv_lib_iconv" = yes; then
142 AC_MSG_CHECKING([how to link with libiconv])
143 AC_MSG_RESULT([$LIBICONV])
145 dnl If $LIBICONV didn't lead to a usable library, we don't need $INCICONV
147 CPPFLAGS="$am_save_CPPFLAGS"
158 if test "$am_cv_func_iconv" = yes; then
159 AC_MSG_CHECKING([for iconv declaration])
160 AC_CACHE_VAL(am_cv_proto_iconv, [
168 #if defined(__STDC__) || defined(__cplusplus)
169 size_t iconv (iconv_t cd, char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);
173 ], [], am_cv_proto_iconv_arg1="", am_cv_proto_iconv_arg1="const")
174 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);"])
175 am_cv_proto_iconv=`echo "[$]am_cv_proto_iconv" | tr -s ' ' | sed -e 's/( /(/'`
176 AC_MSG_RESULT([$]{ac_t:-
177 }[$]am_cv_proto_iconv)
178 AC_DEFINE_UNQUOTED(ICONV_CONST, $am_cv_proto_iconv_arg1,
179 [Define as const if the declaration of iconv() needs const.])