]> sjero.net Git - wget/blob - m4/iconv.m4
Check for idna.h in /usr/include/idn.
[wget] / m4 / iconv.m4
1 # iconv.m4 serial AM6 (gettext-0.17)
2 dnl Copyright (C) 2000, 2001, 2002, 2007, 2009 Free Software Foundation,
3 dnl Inc.
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.
7
8 dnl From Bruno Haible.
9
10 AC_DEFUN([AM_ICONV_LINKFLAGS_BODY],
11 [
12   dnl Prerequisites of AC_LIB_LINKFLAGS_BODY.
13   AC_REQUIRE([AC_LIB_PREPARE_PREFIX])
14   AC_REQUIRE([AC_LIB_RPATH])
15
16   dnl Search for libiconv and define LIBICONV, LTLIBICONV and INCICONV
17   dnl accordingly.
18   AC_LIB_LINKFLAGS_BODY([iconv])
19 ])
20
21 AC_DEFUN([AM_ICONV_LINK],
22 [
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
26
27   dnl Search for libiconv and define LIBICONV, LTLIBICONV and INCICONV
28   dnl accordingly.
29   AC_REQUIRE([AM_ICONV_LINKFLAGS_BODY])
30
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])
37
38   AC_CACHE_CHECK([for iconv], am_cv_func_iconv, [
39     am_cv_func_iconv="no, consider installing GNU libiconv"
40     am_cv_lib_iconv=no
41     AC_TRY_LINK([#include <stdlib.h>
42 #include <iconv.h>],
43       [iconv_t cd = iconv_open("","");
44        iconv(cd,NULL,NULL,NULL,NULL);
45        iconv_close(cd);],
46       am_cv_func_iconv=yes)
47     if test "$am_cv_func_iconv" != yes; then
48       am_save_LIBS="$LIBS"
49       LIBS="$LIBS $LIBICONV"
50       AC_TRY_LINK([#include <stdlib.h>
51 #include <iconv.h>],
52         [iconv_t cd = iconv_open("","");
53          iconv(cd,NULL,NULL,NULL,NULL);
54          iconv_close(cd);],
55         am_cv_lib_iconv=yes
56         am_cv_func_iconv=yes)
57       LIBS="$am_save_LIBS"
58     fi
59   ])
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.
63       am_save_LIBS="$LIBS"
64       if test $am_cv_lib_iconv = yes; then
65         LIBS="$LIBS $LIBICONV"
66       fi
67       AC_TRY_RUN([
68 #include <iconv.h>
69 #include <string.h>
70 int main ()
71 {
72   /* Test against AIX 5.1 bug: Failures are not distinguishable from successful
73      returns.  */
74   {
75     iconv_t cd_utf8_to_88591 = iconv_open ("ISO8859-1", "UTF-8");
76     if (cd_utf8_to_88591 != (iconv_t)(-1))
77       {
78         static const char input[] = "\342\202\254"; /* EURO SIGN */
79         char buf[10];
80         const char *inptr = input;
81         size_t inbytesleft = strlen (input);
82         char *outptr = buf;
83         size_t outbytesleft = sizeof (buf);
84         size_t res = iconv (cd_utf8_to_88591,
85                             (char **) &inptr, &inbytesleft,
86                             &outptr, &outbytesleft);
87         if (res == 0)
88           return 1;
89       }
90   }
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.  */
93   {
94     iconv_t cd_88591_to_utf8 = iconv_open ("utf8", "iso88591");
95     if (cd_88591_to_utf8 != (iconv_t)(-1))
96       {
97         static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
98         char buf[50];
99         const char *inptr = input;
100         size_t inbytesleft = strlen (input);
101         char *outptr = buf;
102         size_t outbytesleft = sizeof (buf);
103         size_t res = iconv (cd_88591_to_utf8,
104                             (char **) &inptr, &inbytesleft,
105                             &outptr, &outbytesleft);
106         if ((int)res > 0)
107           return 1;
108       }
109   }
110 #endif
111   /* Test against HP-UX 11.11 bug: No converter from EUC-JP to UTF-8 is
112      provided.  */
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)
117       /* Try AIX names.  */
118       && iconv_open ("UTF-8", "IBM-eucJP") == (iconv_t)(-1)
119       /* Try HP-UX names.  */
120       && iconv_open ("utf8", "eucJP") == (iconv_t)(-1))
121     return 1;
122   return 0;
123 }], [am_cv_func_iconv_works=yes], [am_cv_func_iconv_works=no],
124         [case "$host_os" in
125            aix* | hpux*) am_cv_func_iconv_works="guessing no" ;;
126            *)            am_cv_func_iconv_works="guessing yes" ;;
127          esac])
128       LIBS="$am_save_LIBS"
129     ])
130     case "$am_cv_func_iconv_works" in
131       *no) am_func_iconv=no am_cv_lib_iconv=no ;;
132       *)   am_func_iconv=yes ;;
133     esac
134   else
135     am_func_iconv=no am_cv_lib_iconv=no
136   fi
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.])
140   fi
141   if test "$am_cv_lib_iconv" = yes; then
142     AC_MSG_CHECKING([how to link with libiconv])
143     AC_MSG_RESULT([$LIBICONV])
144   else
145     dnl If $LIBICONV didn't lead to a usable library, we don't need $INCICONV
146     dnl either.
147     CPPFLAGS="$am_save_CPPFLAGS"
148     LIBICONV=
149     LTLIBICONV=
150   fi
151   AC_SUBST(LIBICONV)
152   AC_SUBST(LTLIBICONV)
153 ])
154
155 AC_DEFUN([AM_ICONV],
156 [
157   AM_ICONV_LINK
158   if test "$am_cv_func_iconv" = yes; then
159     AC_MSG_CHECKING([for iconv declaration])
160     AC_CACHE_VAL(am_cv_proto_iconv, [
161       AC_TRY_COMPILE([
162 #include <stdlib.h>
163 #include <iconv.h>
164 extern
165 #ifdef __cplusplus
166 "C"
167 #endif
168 #if defined(__STDC__) || defined(__cplusplus)
169 size_t iconv (iconv_t cd, char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);
170 #else
171 size_t iconv();
172 #endif
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.])
180   fi
181 ])