iconv.m4 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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.
  6. dnl From Bruno Haible.
  7. AC_DEFUN([AM_ICONV_LINK],
  8. [
  9. dnl Some systems have iconv in libc, some have it in libiconv (OSF/1 and
  10. dnl those with the standalone portable GNU libiconv installed).
  11. AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
  12. dnl Add $INCICONV to CPPFLAGS before performing the following checks,
  13. dnl because if the user has installed libiconv and not disabled its use
  14. dnl via --without-libiconv-prefix, he wants to use it. The first
  15. dnl AC_TRY_LINK will then fail, the second AC_TRY_LINK will succeed.
  16. am_save_CPPFLAGS="$CPPFLAGS"
  17. dnl AC_LIB_APPENDTOVAR([CPPFLAGS], [$INCICONV])
  18. AC_CACHE_CHECK([for iconv], [am_cv_func_iconv], [
  19. am_cv_func_iconv="no, consider installing GNU libiconv"
  20. am_cv_lib_iconv=no
  21. AC_TRY_LINK([#include <stdlib.h>
  22. #include <iconv.h>],
  23. [iconv_t cd = iconv_open("","");
  24. iconv(cd,NULL,NULL,NULL,NULL);
  25. iconv_close(cd);],
  26. [am_cv_func_iconv=yes])
  27. if test "$am_cv_func_iconv" != yes; then
  28. am_save_LIBS="$LIBS"
  29. LIBS="$LIBS $LIBICONV"
  30. AC_TRY_LINK([#include <stdlib.h>
  31. #include <iconv.h>],
  32. [iconv_t cd = iconv_open("","");
  33. iconv(cd,NULL,NULL,NULL,NULL);
  34. iconv_close(cd);],
  35. [am_cv_lib_iconv=yes]
  36. [am_cv_func_iconv=yes])
  37. LIBS="$am_save_LIBS"
  38. fi
  39. ])
  40. if test "$am_cv_func_iconv" = yes; then
  41. AC_CACHE_CHECK([for working iconv], [am_cv_func_iconv_works], [
  42. dnl This tests against bugs in AIX 5.1, HP-UX 11.11, Solaris 10.
  43. am_save_LIBS="$LIBS"
  44. if test $am_cv_lib_iconv = yes; then
  45. LIBS="$LIBS $LIBICONV"
  46. fi
  47. AC_TRY_RUN([
  48. #include <iconv.h>
  49. #include <string.h>
  50. int main ()
  51. {
  52. /* Test against AIX 5.1 bug: Failures are not distinguishable from successful
  53. returns. */
  54. {
  55. iconv_t cd_utf8_to_88591 = iconv_open ("ISO8859-1", "UTF-8");
  56. if (cd_utf8_to_88591 != (iconv_t)(-1))
  57. {
  58. static const char input[] = "\342\202\254"; /* EURO SIGN */
  59. char buf[10];
  60. const char *inptr = input;
  61. size_t inbytesleft = strlen (input);
  62. char *outptr = buf;
  63. size_t outbytesleft = sizeof (buf);
  64. size_t res = iconv (cd_utf8_to_88591,
  65. (char **) &inptr, &inbytesleft,
  66. &outptr, &outbytesleft);
  67. if (res == 0)
  68. return 1;
  69. }
  70. }
  71. /* Test against Solaris 10 bug: Failures are not distinguishable from
  72. successful returns. */
  73. {
  74. iconv_t cd_ascii_to_88591 = iconv_open ("ISO8859-1", "646");
  75. if (cd_ascii_to_88591 != (iconv_t)(-1))
  76. {
  77. static const char input[] = "\263";
  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_ascii_to_88591,
  84. (char **) &inptr, &inbytesleft,
  85. &outptr, &outbytesleft);
  86. if (res == 0)
  87. return 1;
  88. }
  89. }
  90. #if 0 /* This bug could be worked around by the caller. */
  91. /* Test against HP-UX 11.11 bug: Positive return value instead of 0. */
  92. {
  93. iconv_t cd_88591_to_utf8 = iconv_open ("utf8", "iso88591");
  94. if (cd_88591_to_utf8 != (iconv_t)(-1))
  95. {
  96. static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
  97. char buf[50];
  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_88591_to_utf8,
  103. (char **) &inptr, &inbytesleft,
  104. &outptr, &outbytesleft);
  105. if ((int)res > 0)
  106. return 1;
  107. }
  108. }
  109. #endif
  110. /* Test against HP-UX 11.11 bug: No converter from EUC-JP to UTF-8 is
  111. provided. */
  112. if (/* Try standardized names. */
  113. iconv_open ("UTF-8", "EUC-JP") == (iconv_t)(-1)
  114. /* Try IRIX, OSF/1 names. */
  115. && iconv_open ("UTF-8", "eucJP") == (iconv_t)(-1)
  116. /* Try AIX names. */
  117. && iconv_open ("UTF-8", "IBM-eucJP") == (iconv_t)(-1)
  118. /* Try HP-UX names. */
  119. && iconv_open ("utf8", "eucJP") == (iconv_t)(-1))
  120. return 1;
  121. return 0;
  122. }], [am_cv_func_iconv_works=yes], [am_cv_func_iconv_works=no],
  123. [case "$host_os" in
  124. aix* | hpux*) am_cv_func_iconv_works="guessing no" ;;
  125. *) am_cv_func_iconv_works="guessing yes" ;;
  126. esac])
  127. LIBS="$am_save_LIBS"
  128. ])
  129. case "$am_cv_func_iconv_works" in
  130. *no) am_func_iconv=no am_cv_lib_iconv=no ;;
  131. *) am_func_iconv=yes ;;
  132. esac
  133. else
  134. am_func_iconv=no am_cv_lib_iconv=no
  135. fi
  136. if test "$am_func_iconv" = yes; then
  137. AC_DEFINE([HAVE_ICONV], [1],
  138. [Define if you have the iconv() function and it works.])
  139. fi
  140. if test "$am_cv_lib_iconv" = yes; then
  141. AC_MSG_CHECKING([how to link with libiconv])
  142. AC_MSG_RESULT([$LIBICONV])
  143. else
  144. dnl If $LIBICONV didn't lead to a usable library, we don't need $INCICONV
  145. dnl either.
  146. CPPFLAGS="$am_save_CPPFLAGS"
  147. LIBICONV=
  148. LTLIBICONV=
  149. fi
  150. AC_SUBST([LIBICONV])
  151. AC_SUBST([LTLIBICONV])
  152. ])
  153. dnl Define AM_ICONV using AC_DEFUN_ONCE for Autoconf >= 2.64, in order to
  154. dnl avoid warnings like
  155. dnl "warning: AC_REQUIRE: `AM_ICONV' was expanded before it was required".
  156. dnl This is tricky because of the way 'aclocal' is implemented:
  157. dnl - It requires defining an auxiliary macro whose name ends in AC_DEFUN.
  158. dnl Otherwise aclocal's initial scan pass would miss the macro definition.
  159. dnl - It requires a line break inside the AC_DEFUN_ONCE and AC_DEFUN expansions.
  160. dnl Otherwise aclocal would emit many "Use of uninitialized value $1"
  161. dnl warnings.
  162. m4_define([gl_iconv_AC_DEFUN],
  163. m4_version_prereq([2.64],
  164. [[AC_DEFUN_ONCE(
  165. [$1], [$2])]],
  166. [[AC_DEFUN(
  167. [$1], [$2])]]))
  168. gl_iconv_AC_DEFUN([AM_ICONV],
  169. [
  170. AM_ICONV_LINK
  171. if test "$am_cv_func_iconv" = yes; then
  172. AC_MSG_CHECKING([for iconv declaration])
  173. AC_CACHE_VAL([am_cv_proto_iconv], [
  174. AC_TRY_COMPILE([
  175. #include <stdlib.h>
  176. #include <iconv.h>
  177. extern
  178. #ifdef __cplusplus
  179. "C"
  180. #endif
  181. #if defined(__STDC__) || defined(__cplusplus)
  182. size_t iconv (iconv_t cd, char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);
  183. #else
  184. size_t iconv();
  185. #endif
  186. ], [], [am_cv_proto_iconv_arg1=""], [am_cv_proto_iconv_arg1="const"])
  187. 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);"])
  188. am_cv_proto_iconv=`echo "[$]am_cv_proto_iconv" | tr -s ' ' | sed -e 's/( /(/'`
  189. AC_MSG_RESULT([
  190. $am_cv_proto_iconv])
  191. AC_DEFINE_UNQUOTED([ICONV_CONST], [$am_cv_proto_iconv_arg1],
  192. [Define as const if the declaration of iconv() needs const.])
  193. fi
  194. ])