iconv.m4 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. # iconv.m4 serial AM7 (gettext-0.18)
  2. dnl Copyright (C) 2000-2002, 2007-2009 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_LINKFLAGS_BODY],
  8. [
  9. dnl Prerequisites of AC_LIB_LINKFLAGS_BODY.
  10. AC_REQUIRE([AC_LIB_PREPARE_PREFIX])
  11. AC_REQUIRE([AC_LIB_RPATH])
  12. dnl Search for libiconv and define LIBICONV, LTLIBICONV and INCICONV
  13. dnl accordingly.
  14. AC_LIB_LINKFLAGS_BODY([iconv])
  15. ])
  16. AC_DEFUN([AM_ICONV_LINK],
  17. [
  18. dnl Some systems have iconv in libc, some have it in libiconv (OSF/1 and
  19. dnl those with the standalone portable GNU libiconv installed).
  20. AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
  21. dnl Search for libiconv and define LIBICONV, LTLIBICONV and INCICONV
  22. dnl accordingly.
  23. AC_REQUIRE([AM_ICONV_LINKFLAGS_BODY])
  24. dnl Add $INCICONV to CPPFLAGS before performing the following checks,
  25. dnl because if the user has installed libiconv and not disabled its use
  26. dnl via --without-libiconv-prefix, he wants to use it. The first
  27. dnl AC_TRY_LINK will then fail, the second AC_TRY_LINK will succeed.
  28. am_save_CPPFLAGS="$CPPFLAGS"
  29. AC_LIB_APPENDTOVAR([CPPFLAGS], [$INCICONV])
  30. AC_CACHE_CHECK([for iconv], [am_cv_func_iconv], [
  31. am_cv_func_iconv="no, consider installing GNU libiconv"
  32. am_cv_lib_iconv=no
  33. AC_TRY_LINK([#include <stdlib.h>
  34. #include <iconv.h>],
  35. [iconv_t cd = iconv_open("","");
  36. iconv(cd,NULL,NULL,NULL,NULL);
  37. iconv_close(cd);],
  38. [am_cv_func_iconv=yes])
  39. if test "$am_cv_func_iconv" != yes; then
  40. am_save_LIBS="$LIBS"
  41. LIBS="$LIBS $LIBICONV"
  42. AC_TRY_LINK([#include <stdlib.h>
  43. #include <iconv.h>],
  44. [iconv_t cd = iconv_open("","");
  45. iconv(cd,NULL,NULL,NULL,NULL);
  46. iconv_close(cd);],
  47. [am_cv_lib_iconv=yes]
  48. [am_cv_func_iconv=yes])
  49. LIBS="$am_save_LIBS"
  50. fi
  51. ])
  52. if test "$am_cv_func_iconv" = yes; then
  53. AC_CACHE_CHECK([for working iconv], [am_cv_func_iconv_works], [
  54. dnl This tests against bugs in AIX 5.1 and HP-UX 11.11.
  55. am_save_LIBS="$LIBS"
  56. if test $am_cv_lib_iconv = yes; then
  57. LIBS="$LIBS $LIBICONV"
  58. fi
  59. AC_TRY_RUN([
  60. #include <iconv.h>
  61. #include <string.h>
  62. int main ()
  63. {
  64. /* Test against AIX 5.1 bug: Failures are not distinguishable from successful
  65. returns. */
  66. {
  67. iconv_t cd_utf8_to_88591 = iconv_open ("ISO8859-1", "UTF-8");
  68. if (cd_utf8_to_88591 != (iconv_t)(-1))
  69. {
  70. static const char input[] = "\342\202\254"; /* EURO SIGN */
  71. char buf[10];
  72. const char *inptr = input;
  73. size_t inbytesleft = strlen (input);
  74. char *outptr = buf;
  75. size_t outbytesleft = sizeof (buf);
  76. size_t res = iconv (cd_utf8_to_88591,
  77. (char **) &inptr, &inbytesleft,
  78. &outptr, &outbytesleft);
  79. if (res == 0)
  80. return 1;
  81. }
  82. }
  83. #if 0 /* This bug could be worked around by the caller. */
  84. /* Test against HP-UX 11.11 bug: Positive return value instead of 0. */
  85. {
  86. iconv_t cd_88591_to_utf8 = iconv_open ("utf8", "iso88591");
  87. if (cd_88591_to_utf8 != (iconv_t)(-1))
  88. {
  89. static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
  90. char buf[50];
  91. const char *inptr = input;
  92. size_t inbytesleft = strlen (input);
  93. char *outptr = buf;
  94. size_t outbytesleft = sizeof (buf);
  95. size_t res = iconv (cd_88591_to_utf8,
  96. (char **) &inptr, &inbytesleft,
  97. &outptr, &outbytesleft);
  98. if ((int)res > 0)
  99. return 1;
  100. }
  101. }
  102. #endif
  103. /* Test against HP-UX 11.11 bug: No converter from EUC-JP to UTF-8 is
  104. provided. */
  105. if (/* Try standardized names. */
  106. iconv_open ("UTF-8", "EUC-JP") == (iconv_t)(-1)
  107. /* Try IRIX, OSF/1 names. */
  108. && iconv_open ("UTF-8", "eucJP") == (iconv_t)(-1)
  109. /* Try AIX names. */
  110. && iconv_open ("UTF-8", "IBM-eucJP") == (iconv_t)(-1)
  111. /* Try HP-UX names. */
  112. && iconv_open ("utf8", "eucJP") == (iconv_t)(-1))
  113. return 1;
  114. return 0;
  115. }], [am_cv_func_iconv_works=yes], [am_cv_func_iconv_works=no],
  116. [case "$host_os" in
  117. aix* | hpux*) am_cv_func_iconv_works="guessing no" ;;
  118. *) am_cv_func_iconv_works="guessing yes" ;;
  119. esac])
  120. LIBS="$am_save_LIBS"
  121. ])
  122. case "$am_cv_func_iconv_works" in
  123. *no) am_func_iconv=no am_cv_lib_iconv=no ;;
  124. *) am_func_iconv=yes ;;
  125. esac
  126. else
  127. am_func_iconv=no am_cv_lib_iconv=no
  128. fi
  129. if test "$am_func_iconv" = yes; then
  130. AC_DEFINE([HAVE_ICONV], [1],
  131. [Define if you have the iconv() function and it works.])
  132. fi
  133. if test "$am_cv_lib_iconv" = yes; then
  134. AC_MSG_CHECKING([how to link with libiconv])
  135. AC_MSG_RESULT([$LIBICONV])
  136. else
  137. dnl If $LIBICONV didn't lead to a usable library, we don't need $INCICONV
  138. dnl either.
  139. CPPFLAGS="$am_save_CPPFLAGS"
  140. LIBICONV=
  141. LTLIBICONV=
  142. fi
  143. AC_SUBST([LIBICONV])
  144. AC_SUBST([LTLIBICONV])
  145. ])
  146. AC_DEFUN([AM_ICONV],
  147. [
  148. AM_ICONV_LINK
  149. if test "$am_cv_func_iconv" = yes; then
  150. AC_MSG_CHECKING([for iconv declaration])
  151. AC_CACHE_VAL([am_cv_proto_iconv], [
  152. AC_TRY_COMPILE([
  153. #include <stdlib.h>
  154. #include <iconv.h>
  155. extern
  156. #ifdef __cplusplus
  157. "C"
  158. #endif
  159. #if defined(__STDC__) || defined(__cplusplus)
  160. size_t iconv (iconv_t cd, char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);
  161. #else
  162. size_t iconv();
  163. #endif
  164. ], [], [am_cv_proto_iconv_arg1=""], [am_cv_proto_iconv_arg1="const"])
  165. 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);"])
  166. am_cv_proto_iconv=`echo "[$]am_cv_proto_iconv" | tr -s ' ' | sed -e 's/( /(/'`
  167. AC_MSG_RESULT([${ac_t:-
  168. }$am_cv_proto_iconv])
  169. AC_DEFINE_UNQUOTED([ICONV_CONST], [$am_cv_proto_iconv_arg1],
  170. [Define as const if the declaration of iconv() needs const.])
  171. fi
  172. ])