iconv.m4 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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_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, HP-UX 11.11, Solaris 10.
  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. /* Test against Solaris 10 bug: Failures are not distinguishable from
  84. successful returns. */
  85. {
  86. iconv_t cd_ascii_to_88591 = iconv_open ("ISO8859-1", "646");
  87. if (cd_ascii_to_88591 != (iconv_t)(-1))
  88. {
  89. static const char input[] = "\263";
  90. char buf[10];
  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_ascii_to_88591,
  96. (char **) &inptr, &inbytesleft,
  97. &outptr, &outbytesleft);
  98. if (res == 0)
  99. return 1;
  100. }
  101. }
  102. #if 0 /* This bug could be worked around by the caller. */
  103. /* Test against HP-UX 11.11 bug: Positive return value instead of 0. */
  104. {
  105. iconv_t cd_88591_to_utf8 = iconv_open ("utf8", "iso88591");
  106. if (cd_88591_to_utf8 != (iconv_t)(-1))
  107. {
  108. static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
  109. char buf[50];
  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_88591_to_utf8,
  115. (char **) &inptr, &inbytesleft,
  116. &outptr, &outbytesleft);
  117. if ((int)res > 0)
  118. return 1;
  119. }
  120. }
  121. #endif
  122. /* Test against HP-UX 11.11 bug: No converter from EUC-JP to UTF-8 is
  123. provided. */
  124. if (/* Try standardized names. */
  125. iconv_open ("UTF-8", "EUC-JP") == (iconv_t)(-1)
  126. /* Try IRIX, OSF/1 names. */
  127. && iconv_open ("UTF-8", "eucJP") == (iconv_t)(-1)
  128. /* Try AIX names. */
  129. && iconv_open ("UTF-8", "IBM-eucJP") == (iconv_t)(-1)
  130. /* Try HP-UX names. */
  131. && iconv_open ("utf8", "eucJP") == (iconv_t)(-1))
  132. return 1;
  133. return 0;
  134. }], [am_cv_func_iconv_works=yes], [am_cv_func_iconv_works=no],
  135. [case "$host_os" in
  136. aix* | hpux*) am_cv_func_iconv_works="guessing no" ;;
  137. *) am_cv_func_iconv_works="guessing yes" ;;
  138. esac])
  139. LIBS="$am_save_LIBS"
  140. ])
  141. case "$am_cv_func_iconv_works" in
  142. *no) am_func_iconv=no am_cv_lib_iconv=no ;;
  143. *) am_func_iconv=yes ;;
  144. esac
  145. else
  146. am_func_iconv=no am_cv_lib_iconv=no
  147. fi
  148. if test "$am_func_iconv" = yes; then
  149. AC_DEFINE([HAVE_ICONV], [1],
  150. [Define if you have the iconv() function and it works.])
  151. fi
  152. if test "$am_cv_lib_iconv" = yes; then
  153. AC_MSG_CHECKING([how to link with libiconv])
  154. AC_MSG_RESULT([$LIBICONV])
  155. else
  156. dnl If $LIBICONV didn't lead to a usable library, we don't need $INCICONV
  157. dnl either.
  158. CPPFLAGS="$am_save_CPPFLAGS"
  159. LIBICONV=
  160. LTLIBICONV=
  161. fi
  162. AC_SUBST([LIBICONV])
  163. AC_SUBST([LTLIBICONV])
  164. ])
  165. dnl Define AM_ICONV using AC_DEFUN_ONCE for Autoconf >= 2.64, in order to
  166. dnl avoid warnings like
  167. dnl "warning: AC_REQUIRE: `AM_ICONV' was expanded before it was required".
  168. dnl This is tricky because of the way 'aclocal' is implemented:
  169. dnl - It requires defining an auxiliary macro whose name ends in AC_DEFUN.
  170. dnl Otherwise aclocal's initial scan pass would miss the macro definition.
  171. dnl - It requires a line break inside the AC_DEFUN_ONCE and AC_DEFUN expansions.
  172. dnl Otherwise aclocal would emit many "Use of uninitialized value $1"
  173. dnl warnings.
  174. m4_define([gl_iconv_AC_DEFUN],
  175. m4_version_prereq([2.64],
  176. [[AC_DEFUN_ONCE(
  177. [$1], [$2])]],
  178. [[AC_DEFUN(
  179. [$1], [$2])]]))
  180. gl_iconv_AC_DEFUN([AM_ICONV],
  181. [
  182. AM_ICONV_LINK
  183. if test "$am_cv_func_iconv" = yes; then
  184. AC_MSG_CHECKING([for iconv declaration])
  185. AC_CACHE_VAL([am_cv_proto_iconv], [
  186. AC_TRY_COMPILE([
  187. #include <stdlib.h>
  188. #include <iconv.h>
  189. extern
  190. #ifdef __cplusplus
  191. "C"
  192. #endif
  193. #if defined(__STDC__) || defined(__cplusplus)
  194. size_t iconv (iconv_t cd, char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);
  195. #else
  196. size_t iconv();
  197. #endif
  198. ], [], [am_cv_proto_iconv_arg1=""], [am_cv_proto_iconv_arg1="const"])
  199. 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);"])
  200. am_cv_proto_iconv=`echo "[$]am_cv_proto_iconv" | tr -s ' ' | sed -e 's/( /(/'`
  201. AC_MSG_RESULT([
  202. $am_cv_proto_iconv])
  203. AC_DEFINE_UNQUOTED([ICONV_CONST], [$am_cv_proto_iconv_arg1],
  204. [Define as const if the declaration of iconv() needs const.])
  205. fi
  206. ])