aboutsummaryrefslogtreecommitdiff
path: root/m4/iconv.m4
diff options
context:
space:
mode:
Diffstat (limited to 'm4/iconv.m4')
-rw-r--r--m4/iconv.m4223
1 files changed, 195 insertions, 28 deletions
diff --git a/m4/iconv.m4 b/m4/iconv.m4
index 654c41589..4b29c5f2c 100644
--- a/m4/iconv.m4
+++ b/m4/iconv.m4
@@ -1,5 +1,5 @@
1# iconv.m4 serial AM4 (gettext-0.11.3) 1# iconv.m4 serial 18 (gettext-0.18.2)
2dnl Copyright (C) 2000-2002 Free Software Foundation, Inc. 2dnl Copyright (C) 2000-2002, 2007-2014 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 5dnl with or without modifications, as long as this notice is preserved.
@@ -21,6 +21,7 @@ AC_DEFUN([AM_ICONV_LINK],
21[ 21[
22 dnl Some systems have iconv in libc, some have it in libiconv (OSF/1 and 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). 23 dnl those with the standalone portable GNU libiconv installed).
24 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
24 25
25 dnl Search for libiconv and define LIBICONV, LTLIBICONV and INCICONV 26 dnl Search for libiconv and define LIBICONV, LTLIBICONV and INCICONV
26 dnl accordingly. 27 dnl accordingly.
@@ -29,34 +30,170 @@ AC_DEFUN([AM_ICONV_LINK],
29 dnl Add $INCICONV to CPPFLAGS before performing the following checks, 30 dnl Add $INCICONV to CPPFLAGS before performing the following checks,
30 dnl because if the user has installed libiconv and not disabled its use 31 dnl because if the user has installed libiconv and not disabled its use
31 dnl via --without-libiconv-prefix, he wants to use it. The first 32 dnl via --without-libiconv-prefix, he wants to use it. The first
32 dnl AC_TRY_LINK will then fail, the second AC_TRY_LINK will succeed. 33 dnl AC_LINK_IFELSE will then fail, the second AC_LINK_IFELSE will succeed.
33 am_save_CPPFLAGS="$CPPFLAGS" 34 am_save_CPPFLAGS="$CPPFLAGS"
34 AC_LIB_APPENDTOVAR([CPPFLAGS], [$INCICONV]) 35 AC_LIB_APPENDTOVAR([CPPFLAGS], [$INCICONV])
35 36
36 AC_CACHE_CHECK(for iconv, am_cv_func_iconv, [ 37 AC_CACHE_CHECK([for iconv], [am_cv_func_iconv], [
37 am_cv_func_iconv="no, consider installing GNU libiconv" 38 am_cv_func_iconv="no, consider installing GNU libiconv"
38 am_cv_lib_iconv=no 39 am_cv_lib_iconv=no
39 AC_TRY_LINK([#include <stdlib.h> 40 AC_LINK_IFELSE(
40#include <iconv.h>], 41 [AC_LANG_PROGRAM(
41 [iconv_t cd = iconv_open("",""); 42 [[
42 iconv(cd,NULL,NULL,NULL,NULL); 43#include <stdlib.h>
43 iconv_close(cd);], 44#include <iconv.h>
44 am_cv_func_iconv=yes) 45 ]],
46 [[iconv_t cd = iconv_open("","");
47 iconv(cd,NULL,NULL,NULL,NULL);
48 iconv_close(cd);]])],
49 [am_cv_func_iconv=yes])
45 if test "$am_cv_func_iconv" != yes; then 50 if test "$am_cv_func_iconv" != yes; then
46 am_save_LIBS="$LIBS" 51 am_save_LIBS="$LIBS"
47 LIBS="$LIBS $LIBICONV" 52 LIBS="$LIBS $LIBICONV"
48 AC_TRY_LINK([#include <stdlib.h> 53 AC_LINK_IFELSE(
49#include <iconv.h>], 54 [AC_LANG_PROGRAM(
50 [iconv_t cd = iconv_open("",""); 55 [[
51 iconv(cd,NULL,NULL,NULL,NULL); 56#include <stdlib.h>
52 iconv_close(cd);], 57#include <iconv.h>
53 am_cv_lib_iconv=yes 58 ]],
54 am_cv_func_iconv=yes) 59 [[iconv_t cd = iconv_open("","");
60 iconv(cd,NULL,NULL,NULL,NULL);
61 iconv_close(cd);]])],
62 [am_cv_lib_iconv=yes]
63 [am_cv_func_iconv=yes])
55 LIBS="$am_save_LIBS" 64 LIBS="$am_save_LIBS"
56 fi 65 fi
57 ]) 66 ])
58 if test "$am_cv_func_iconv" = yes; then 67 if test "$am_cv_func_iconv" = yes; then
59 AC_DEFINE(HAVE_ICONV, 1, [Define if you have the iconv() function.]) 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,
70 dnl Solaris 10.
71 am_save_LIBS="$LIBS"
72 if test $am_cv_lib_iconv = yes; then
73 LIBS="$LIBS $LIBICONV"
74 fi
75 AC_RUN_IFELSE(
76 [AC_LANG_SOURCE([[
77#include <iconv.h>
78#include <string.h>
79int main ()
80{
81 int result = 0;
82 /* Test against AIX 5.1 bug: Failures are not distinguishable from successful
83 returns. */
84 {
85 iconv_t cd_utf8_to_88591 = iconv_open ("ISO8859-1", "UTF-8");
86 if (cd_utf8_to_88591 != (iconv_t)(-1))
87 {
88 static const char input[] = "\342\202\254"; /* EURO SIGN */
89 char buf[10];
90 const char *inptr = input;
91 size_t inbytesleft = strlen (input);
92 char *outptr = buf;
93 size_t outbytesleft = sizeof (buf);
94 size_t res = iconv (cd_utf8_to_88591,
95 (char **) &inptr, &inbytesleft,
96 &outptr, &outbytesleft);
97 if (res == 0)
98 result |= 1;
99 iconv_close (cd_utf8_to_88591);
100 }
101 }
102 /* Test against Solaris 10 bug: Failures are not distinguishable from
103 successful returns. */
104 {
105 iconv_t cd_ascii_to_88591 = iconv_open ("ISO8859-1", "646");
106 if (cd_ascii_to_88591 != (iconv_t)(-1))
107 {
108 static const char input[] = "\263";
109 char buf[10];
110 const char *inptr = input;
111 size_t inbytesleft = strlen (input);
112 char *outptr = buf;
113 size_t outbytesleft = sizeof (buf);
114 size_t res = iconv (cd_ascii_to_88591,
115 (char **) &inptr, &inbytesleft,
116 &outptr, &outbytesleft);
117 if (res == 0)
118 result |= 2;
119 iconv_close (cd_ascii_to_88591);
120 }
121 }
122 /* Test against AIX 6.1..7.1 bug: Buffer overrun. */
123 {
124 iconv_t cd_88591_to_utf8 = iconv_open ("UTF-8", "ISO-8859-1");
125 if (cd_88591_to_utf8 != (iconv_t)(-1))
126 {
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;
131 char *outptr = buf;
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)
137 result |= 4;
138 iconv_close (cd_88591_to_utf8);
139 }
140 }
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. */
143 {
144 iconv_t cd_88591_to_utf8 = iconv_open ("utf8", "iso88591");
145 if (cd_88591_to_utf8 != (iconv_t)(-1))
146 {
147 static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
148 char buf[50];
149 const char *inptr = input;
150 size_t inbytesleft = strlen (input);
151 char *outptr = buf;
152 size_t outbytesleft = sizeof (buf);
153 size_t res = iconv (cd_88591_to_utf8,
154 (char **) &inptr, &inbytesleft,
155 &outptr, &outbytesleft);
156 if ((int)res > 0)
157 result |= 8;
158 iconv_close (cd_88591_to_utf8);
159 }
160 }
161#endif
162 /* Test against HP-UX 11.11 bug: No converter from EUC-JP to UTF-8 is
163 provided. */
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)
168 /* Try AIX names. */
169 && iconv_open ("UTF-8", "IBM-eucJP") == (iconv_t)(-1)
170 /* Try HP-UX names. */
171 && iconv_open ("utf8", "eucJP") == (iconv_t)(-1))
172 result |= 16;
173 return result;
174}]])],
175 [am_cv_func_iconv_works=yes],
176 [am_cv_func_iconv_works=no],
177 [
178changequote(,)dnl
179 case "$host_os" in
180 aix* | hpux*) am_cv_func_iconv_works="guessing no" ;;
181 *) am_cv_func_iconv_works="guessing yes" ;;
182 esac
183changequote([,])dnl
184 ])
185 LIBS="$am_save_LIBS"
186 ])
187 case "$am_cv_func_iconv_works" in
188 *no) am_func_iconv=no am_cv_lib_iconv=no ;;
189 *) am_func_iconv=yes ;;
190 esac
191 else
192 am_func_iconv=no am_cv_lib_iconv=no
193 fi
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.])
60 fi 197 fi
61 if test "$am_cv_lib_iconv" = yes; then 198 if test "$am_cv_lib_iconv" = yes; then
62 AC_MSG_CHECKING([how to link with libiconv]) 199 AC_MSG_CHECKING([how to link with libiconv])
@@ -68,34 +205,64 @@ AC_DEFUN([AM_ICONV_LINK],
68 LIBICONV= 205 LIBICONV=
69 LTLIBICONV= 206 LTLIBICONV=
70 fi 207 fi
71 AC_SUBST(LIBICONV) 208 AC_SUBST([LIBICONV])
72 AC_SUBST(LTLIBICONV) 209 AC_SUBST([LTLIBICONV])
73]) 210])
74 211
75AC_DEFUN([AM_ICONV], 212dnl Define AM_ICONV using AC_DEFUN_ONCE for Autoconf >= 2.64, in order to
213dnl avoid warnings like
214dnl "warning: AC_REQUIRE: `AM_ICONV' was expanded before it was required".
215dnl This is tricky because of the way 'aclocal' is implemented:
216dnl - It requires defining an auxiliary macro whose name ends in AC_DEFUN.
217dnl Otherwise aclocal's initial scan pass would miss the macro definition.
218dnl - It requires a line break inside the AC_DEFUN_ONCE and AC_DEFUN expansions.
219dnl Otherwise aclocal would emit many "Use of uninitialized value $1"
220dnl warnings.
221m4_define([gl_iconv_AC_DEFUN],
222 m4_version_prereq([2.64],
223 [[AC_DEFUN_ONCE(
224 [$1], [$2])]],
225 [m4_ifdef([gl_00GNULIB],
226 [[AC_DEFUN_ONCE(
227 [$1], [$2])]],
228 [[AC_DEFUN(
229 [$1], [$2])]])]))
230gl_iconv_AC_DEFUN([AM_ICONV],
76[ 231[
77 AM_ICONV_LINK 232 AM_ICONV_LINK
78 if test "$am_cv_func_iconv" = yes; then 233 if test "$am_cv_func_iconv" = yes; then
79 AC_MSG_CHECKING([for iconv declaration]) 234 AC_MSG_CHECKING([for iconv declaration])
80 AC_CACHE_VAL(am_cv_proto_iconv, [ 235 AC_CACHE_VAL([am_cv_proto_iconv], [
81 AC_TRY_COMPILE([ 236 AC_COMPILE_IFELSE(
237 [AC_LANG_PROGRAM(
238 [[
82#include <stdlib.h> 239#include <stdlib.h>
83#include <iconv.h> 240#include <iconv.h>
84extern 241extern
85#ifdef __cplusplus 242#ifdef __cplusplus
86"C" 243"C"
87#endif 244#endif
88#if defined(__STDC__) || defined(__cplusplus) 245#if defined(__STDC__) || defined(_MSC_VER) || defined(__cplusplus)
89size_t iconv (iconv_t cd, char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft); 246size_t iconv (iconv_t cd, char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);
90#else 247#else
91size_t iconv(); 248size_t iconv();
92#endif 249#endif
93], [], am_cv_proto_iconv_arg1="", am_cv_proto_iconv_arg1="const") 250 ]],
251 [[]])],
252 [am_cv_proto_iconv_arg1=""],
253 [am_cv_proto_iconv_arg1="const"])
94 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);"]) 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);"])
95 am_cv_proto_iconv=`echo "[$]am_cv_proto_iconv" | tr -s ' ' | sed -e 's/( /(/'` 255 am_cv_proto_iconv=`echo "[$]am_cv_proto_iconv" | tr -s ' ' | sed -e 's/( /(/'`
96 AC_MSG_RESULT([$]{ac_t:- 256 AC_MSG_RESULT([
97 }[$]am_cv_proto_iconv) 257 $am_cv_proto_iconv])
98 AC_DEFINE_UNQUOTED(ICONV_CONST, $am_cv_proto_iconv_arg1, 258 AC_DEFINE_UNQUOTED([ICONV_CONST], [$am_cv_proto_iconv_arg1],
99 [Define as const if the declaration of iconv() needs const.]) 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
264 ICONV_CONST="const"
265 fi
266 ])
100 fi 267 fi
101]) 268])