~ubuntu-branches/ubuntu/natty/diffutils/natty

« back to all changes in this revision

Viewing changes to m4/iconv.m4

  • Committer: Bazaar Package Importer
  • Author(s): Santiago Vila
  • Date: 2010-05-04 20:38:00 UTC
  • mfrom: (2.1.7 sid)
  • Revision ID: james.westby@ubuntu.com-20100504203800-f67xd9rsa9xl9qqj
Tags: 1:3.0-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# iconv.m4 serial AM3 (gettext-0.11)
2
 
dnl Copyright (C) 2000-2002 Free Software Foundation, Inc.
3
 
dnl This file is free software, distributed under the terms of the GNU
4
 
dnl General Public License.  As a special exception to the GNU General
5
 
dnl Public License, this file may be distributed as part of a program
6
 
dnl that contains a configuration script generated by Autoconf, under
7
 
dnl the same distribution terms as the rest of that program.
 
1
# iconv.m4 serial 9 (gettext-0.18)
 
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.
8
6
 
9
7
dnl From Bruno Haible.
10
8
 
11
 
AC_DEFUN([AM_ICONV_LINK],
 
9
AC_DEFUN([AM_ICONV_LINKFLAGS_BODY],
12
10
[
13
 
  dnl Some systems have iconv in libc, some have it in libiconv (OSF/1 and
14
 
  dnl those with the standalone portable GNU libiconv installed).
15
 
 
16
11
  dnl Prerequisites of AC_LIB_LINKFLAGS_BODY.
17
12
  AC_REQUIRE([AC_LIB_PREPARE_PREFIX])
18
13
  AC_REQUIRE([AC_LIB_RPATH])
20
15
  dnl Search for libiconv and define LIBICONV, LTLIBICONV and INCICONV
21
16
  dnl accordingly.
22
17
  AC_LIB_LINKFLAGS_BODY([iconv])
 
18
])
 
19
 
 
20
AC_DEFUN([AM_ICONV_LINK],
 
21
[
 
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
 
25
 
 
26
  dnl Search for libiconv and define LIBICONV, LTLIBICONV and INCICONV
 
27
  dnl accordingly.
 
28
  AC_REQUIRE([AM_ICONV_LINKFLAGS_BODY])
23
29
 
24
30
  dnl Add $INCICONV to CPPFLAGS before performing the following checks,
25
31
  dnl because if the user has installed libiconv and not disabled its use
28
34
  am_save_CPPFLAGS="$CPPFLAGS"
29
35
  AC_LIB_APPENDTOVAR([CPPFLAGS], [$INCICONV])
30
36
 
31
 
  AC_CACHE_CHECK(for iconv, am_cv_func_iconv, [
 
37
  AC_CACHE_CHECK([for iconv], [am_cv_func_iconv], [
32
38
    am_cv_func_iconv="no, consider installing GNU libiconv"
33
39
    am_cv_lib_iconv=no
34
40
    AC_TRY_LINK([#include <stdlib.h>
36
42
      [iconv_t cd = iconv_open("","");
37
43
       iconv(cd,NULL,NULL,NULL,NULL);
38
44
       iconv_close(cd);],
39
 
      am_cv_func_iconv=yes)
 
45
      [am_cv_func_iconv=yes])
40
46
    if test "$am_cv_func_iconv" != yes; then
41
47
      am_save_LIBS="$LIBS"
42
48
      LIBS="$LIBS $LIBICONV"
45
51
        [iconv_t cd = iconv_open("","");
46
52
         iconv(cd,NULL,NULL,NULL,NULL);
47
53
         iconv_close(cd);],
48
 
        am_cv_lib_iconv=yes
49
 
        am_cv_func_iconv=yes)
 
54
        [am_cv_lib_iconv=yes]
 
55
        [am_cv_func_iconv=yes])
50
56
      LIBS="$am_save_LIBS"
51
57
    fi
52
58
  ])
53
59
  if test "$am_cv_func_iconv" = yes; then
54
 
    AC_DEFINE(HAVE_ICONV, 1, [Define if you have the iconv() function.])
 
60
    AC_CACHE_CHECK([for working iconv], [am_cv_func_iconv_works], [
 
61
      dnl This tests against bugs in AIX 5.1, HP-UX 11.11, Solaris 10.
 
62
      am_save_LIBS="$LIBS"
 
63
      if test $am_cv_lib_iconv = yes; then
 
64
        LIBS="$LIBS $LIBICONV"
 
65
      fi
 
66
      AC_TRY_RUN([
 
67
#include <iconv.h>
 
68
#include <string.h>
 
69
int main ()
 
70
{
 
71
  /* Test against AIX 5.1 bug: Failures are not distinguishable from successful
 
72
     returns.  */
 
73
  {
 
74
    iconv_t cd_utf8_to_88591 = iconv_open ("ISO8859-1", "UTF-8");
 
75
    if (cd_utf8_to_88591 != (iconv_t)(-1))
 
76
      {
 
77
        static const char input[] = "\342\202\254"; /* EURO SIGN */
 
78
        char buf[10];
 
79
        const char *inptr = input;
 
80
        size_t inbytesleft = strlen (input);
 
81
        char *outptr = buf;
 
82
        size_t outbytesleft = sizeof (buf);
 
83
        size_t res = iconv (cd_utf8_to_88591,
 
84
                            (char **) &inptr, &inbytesleft,
 
85
                            &outptr, &outbytesleft);
 
86
        if (res == 0)
 
87
          return 1;
 
88
      }
 
89
  }
 
90
  /* Test against Solaris 10 bug: Failures are not distinguishable from
 
91
     successful returns.  */
 
92
  {
 
93
    iconv_t cd_ascii_to_88591 = iconv_open ("ISO8859-1", "646");
 
94
    if (cd_ascii_to_88591 != (iconv_t)(-1))
 
95
      {
 
96
        static const char input[] = "\263";
 
97
        char buf[10];
 
98
        const char *inptr = input;
 
99
        size_t inbytesleft = strlen (input);
 
100
        char *outptr = buf;
 
101
        size_t outbytesleft = sizeof (buf);
 
102
        size_t res = iconv (cd_ascii_to_88591,
 
103
                            (char **) &inptr, &inbytesleft,
 
104
                            &outptr, &outbytesleft);
 
105
        if (res == 0)
 
106
          return 1;
 
107
      }
 
108
  }
 
109
#if 0 /* This bug could be worked around by the caller.  */
 
110
  /* Test against HP-UX 11.11 bug: Positive return value instead of 0.  */
 
111
  {
 
112
    iconv_t cd_88591_to_utf8 = iconv_open ("utf8", "iso88591");
 
113
    if (cd_88591_to_utf8 != (iconv_t)(-1))
 
114
      {
 
115
        static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
 
116
        char buf[50];
 
117
        const char *inptr = input;
 
118
        size_t inbytesleft = strlen (input);
 
119
        char *outptr = buf;
 
120
        size_t outbytesleft = sizeof (buf);
 
121
        size_t res = iconv (cd_88591_to_utf8,
 
122
                            (char **) &inptr, &inbytesleft,
 
123
                            &outptr, &outbytesleft);
 
124
        if ((int)res > 0)
 
125
          return 1;
 
126
      }
 
127
  }
 
128
#endif
 
129
  /* Test against HP-UX 11.11 bug: No converter from EUC-JP to UTF-8 is
 
130
     provided.  */
 
131
  if (/* Try standardized names.  */
 
132
      iconv_open ("UTF-8", "EUC-JP") == (iconv_t)(-1)
 
133
      /* Try IRIX, OSF/1 names.  */
 
134
      && iconv_open ("UTF-8", "eucJP") == (iconv_t)(-1)
 
135
      /* Try AIX names.  */
 
136
      && iconv_open ("UTF-8", "IBM-eucJP") == (iconv_t)(-1)
 
137
      /* Try HP-UX names.  */
 
138
      && iconv_open ("utf8", "eucJP") == (iconv_t)(-1))
 
139
    return 1;
 
140
  return 0;
 
141
}], [am_cv_func_iconv_works=yes], [am_cv_func_iconv_works=no],
 
142
        [case "$host_os" in
 
143
           aix* | hpux*) am_cv_func_iconv_works="guessing no" ;;
 
144
           *)            am_cv_func_iconv_works="guessing yes" ;;
 
145
         esac])
 
146
      LIBS="$am_save_LIBS"
 
147
    ])
 
148
    case "$am_cv_func_iconv_works" in
 
149
      *no) am_func_iconv=no am_cv_lib_iconv=no ;;
 
150
      *)   am_func_iconv=yes ;;
 
151
    esac
 
152
  else
 
153
    am_func_iconv=no am_cv_lib_iconv=no
 
154
  fi
 
155
  if test "$am_func_iconv" = yes; then
 
156
    AC_DEFINE([HAVE_ICONV], [1],
 
157
      [Define if you have the iconv() function and it works.])
55
158
  fi
56
159
  if test "$am_cv_lib_iconv" = yes; then
57
160
    AC_MSG_CHECKING([how to link with libiconv])
63
166
    LIBICONV=
64
167
    LTLIBICONV=
65
168
  fi
66
 
  AC_SUBST(LIBICONV)
67
 
  AC_SUBST(LTLIBICONV)
 
169
  AC_SUBST([LIBICONV])
 
170
  AC_SUBST([LTLIBICONV])
68
171
])
69
172
 
70
173
AC_DEFUN([AM_ICONV],
71
174
[
72
 
  AC_REQUIRE([AM_ICONV_LINK])
 
175
  AM_ICONV_LINK
73
176
  if test "$am_cv_func_iconv" = yes; then
74
177
    AC_MSG_CHECKING([for iconv declaration])
75
 
    AC_CACHE_VAL(am_cv_proto_iconv, [
 
178
    AC_CACHE_VAL([am_cv_proto_iconv], [
76
179
      AC_TRY_COMPILE([
77
180
#include <stdlib.h>
78
181
#include <iconv.h>
85
188
#else
86
189
size_t iconv();
87
190
#endif
88
 
], [], am_cv_proto_iconv_arg1="", am_cv_proto_iconv_arg1="const")
 
191
], [], [am_cv_proto_iconv_arg1=""], [am_cv_proto_iconv_arg1="const"])
89
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);"])
90
193
    am_cv_proto_iconv=`echo "[$]am_cv_proto_iconv" | tr -s ' ' | sed -e 's/( /(/'`
91
 
    AC_MSG_RESULT([$]{ac_t:-
92
 
         }[$]am_cv_proto_iconv)
93
 
    AC_DEFINE_UNQUOTED(ICONV_CONST, $am_cv_proto_iconv_arg1,
 
194
    AC_MSG_RESULT([
 
195
         $am_cv_proto_iconv])
 
196
    AC_DEFINE_UNQUOTED([ICONV_CONST], [$am_cv_proto_iconv_arg1],
94
197
      [Define as const if the declaration of iconv() needs const.])
95
198
  fi
96
199
])