2
0

iconv.m4 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. # iconv.m4 serial 18 (gettext-0.18.2)
  2. dnl Copyright (C) 2000-2002, 2007-2013 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, they want to use it. The first
  27. dnl AC_LINK_IFELSE will then fail, the second AC_LINK_IFELSE 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_LINK_IFELSE(
  34. [AC_LANG_PROGRAM(
  35. [[
  36. #include <stdlib.h>
  37. #include <iconv.h>
  38. ]],
  39. [[iconv_t cd = iconv_open("","");
  40. iconv(cd,NULL,NULL,NULL,NULL);
  41. iconv_close(cd);]])],
  42. [am_cv_func_iconv=yes])
  43. if test "$am_cv_func_iconv" != yes; then
  44. am_save_LIBS="$LIBS"
  45. LIBS="$LIBS $LIBICONV"
  46. AC_LINK_IFELSE(
  47. [AC_LANG_PROGRAM(
  48. [[
  49. #include <stdlib.h>
  50. #include <iconv.h>
  51. ]],
  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, AIX 6.1..7.1, HP-UX 11.11,
  63. dnl Solaris 10.
  64. am_save_LIBS="$LIBS"
  65. if test $am_cv_lib_iconv = yes; then
  66. LIBS="$LIBS $LIBICONV"
  67. fi
  68. AC_RUN_IFELSE(
  69. [AC_LANG_SOURCE([[
  70. #include <iconv.h>
  71. #include <string.h>
  72. int main ()
  73. {
  74. int result = 0;
  75. /* Test against AIX 5.1 bug: Failures are not distinguishable from successful
  76. returns. */
  77. {
  78. iconv_t cd_utf8_to_88591 = iconv_open ("ISO8859-1", "UTF-8");
  79. if (cd_utf8_to_88591 != (iconv_t)(-1))
  80. {
  81. static const char input[] = "\342\202\254"; /* EURO SIGN */
  82. char buf[10];
  83. const char *inptr = input;
  84. size_t inbytesleft = strlen (input);
  85. char *outptr = buf;
  86. size_t outbytesleft = sizeof (buf);
  87. size_t res = iconv (cd_utf8_to_88591,
  88. (char **) &inptr, &inbytesleft,
  89. &outptr, &outbytesleft);
  90. if (res == 0)
  91. result |= 1;
  92. iconv_close (cd_utf8_to_88591);
  93. }
  94. }
  95. /* Test against Solaris 10 bug: Failures are not distinguishable from
  96. successful returns. */
  97. {
  98. iconv_t cd_ascii_to_88591 = iconv_open ("ISO8859-1", "646");
  99. if (cd_ascii_to_88591 != (iconv_t)(-1))
  100. {
  101. static const char input[] = "\263";
  102. char buf[10];
  103. const char *inptr = input;
  104. size_t inbytesleft = strlen (input);
  105. char *outptr = buf;
  106. size_t outbytesleft = sizeof (buf);
  107. size_t res = iconv (cd_ascii_to_88591,
  108. (char **) &inptr, &inbytesleft,
  109. &outptr, &outbytesleft);
  110. if (res == 0)
  111. result |= 2;
  112. iconv_close (cd_ascii_to_88591);
  113. }
  114. }
  115. /* Test against AIX 6.1..7.1 bug: Buffer overrun. */
  116. {
  117. iconv_t cd_88591_to_utf8 = iconv_open ("UTF-8", "ISO-8859-1");
  118. if (cd_88591_to_utf8 != (iconv_t)(-1))
  119. {
  120. static const char input[] = "\304";
  121. static char buf[2] = { (char)0xDE, (char)0xAD };
  122. const char *inptr = input;
  123. size_t inbytesleft = 1;
  124. char *outptr = buf;
  125. size_t outbytesleft = 1;
  126. size_t res = iconv (cd_88591_to_utf8,
  127. (char **) &inptr, &inbytesleft,
  128. &outptr, &outbytesleft);
  129. if (res != (size_t)(-1) || outptr - buf > 1 || buf[1] != (char)0xAD)
  130. result |= 4;
  131. iconv_close (cd_88591_to_utf8);
  132. }
  133. }
  134. #if 0 /* This bug could be worked around by the caller. */
  135. /* Test against HP-UX 11.11 bug: Positive return value instead of 0. */
  136. {
  137. iconv_t cd_88591_to_utf8 = iconv_open ("utf8", "iso88591");
  138. if (cd_88591_to_utf8 != (iconv_t)(-1))
  139. {
  140. static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
  141. char buf[50];
  142. const char *inptr = input;
  143. size_t inbytesleft = strlen (input);
  144. char *outptr = buf;
  145. size_t outbytesleft = sizeof (buf);
  146. size_t res = iconv (cd_88591_to_utf8,
  147. (char **) &inptr, &inbytesleft,
  148. &outptr, &outbytesleft);
  149. if ((int)res > 0)
  150. result |= 8;
  151. iconv_close (cd_88591_to_utf8);
  152. }
  153. }
  154. #endif
  155. /* Test against HP-UX 11.11 bug: No converter from EUC-JP to UTF-8 is
  156. provided. */
  157. if (/* Try standardized names. */
  158. iconv_open ("UTF-8", "EUC-JP") == (iconv_t)(-1)
  159. /* Try IRIX, OSF/1 names. */
  160. && iconv_open ("UTF-8", "eucJP") == (iconv_t)(-1)
  161. /* Try AIX names. */
  162. && iconv_open ("UTF-8", "IBM-eucJP") == (iconv_t)(-1)
  163. /* Try HP-UX names. */
  164. && iconv_open ("utf8", "eucJP") == (iconv_t)(-1))
  165. result |= 16;
  166. return result;
  167. }]])],
  168. [am_cv_func_iconv_works=yes],
  169. [am_cv_func_iconv_works=no],
  170. [
  171. changequote(,)dnl
  172. case "$host_os" in
  173. aix* | hpux*) am_cv_func_iconv_works="guessing no" ;;
  174. *) am_cv_func_iconv_works="guessing yes" ;;
  175. esac
  176. changequote([,])dnl
  177. ])
  178. LIBS="$am_save_LIBS"
  179. ])
  180. case "$am_cv_func_iconv_works" in
  181. *no) am_func_iconv=no am_cv_lib_iconv=no ;;
  182. *) am_func_iconv=yes ;;
  183. esac
  184. else
  185. am_func_iconv=no am_cv_lib_iconv=no
  186. fi
  187. if test "$am_func_iconv" = yes; then
  188. AC_DEFINE([HAVE_ICONV], [1],
  189. [Define if you have the iconv() function and it works.])
  190. fi
  191. if test "$am_cv_lib_iconv" = yes; then
  192. AC_MSG_CHECKING([how to link with libiconv])
  193. AC_MSG_RESULT([$LIBICONV])
  194. else
  195. dnl If $LIBICONV didn't lead to a usable library, we don't need $INCICONV
  196. dnl either.
  197. CPPFLAGS="$am_save_CPPFLAGS"
  198. LIBICONV=
  199. LTLIBICONV=
  200. fi
  201. AC_SUBST([LIBICONV])
  202. AC_SUBST([LTLIBICONV])
  203. ])
  204. dnl Define AM_ICONV using AC_DEFUN_ONCE for Autoconf >= 2.64, in order to
  205. dnl avoid warnings like
  206. dnl "warning: AC_REQUIRE: `AM_ICONV' was expanded before it was required".
  207. dnl This is tricky because of the way 'aclocal' is implemented:
  208. dnl - It requires defining an auxiliary macro whose name ends in AC_DEFUN.
  209. dnl Otherwise aclocal's initial scan pass would miss the macro definition.
  210. dnl - It requires a line break inside the AC_DEFUN_ONCE and AC_DEFUN expansions.
  211. dnl Otherwise aclocal would emit many "Use of uninitialized value $1"
  212. dnl warnings.
  213. m4_define([gl_iconv_AC_DEFUN],
  214. m4_version_prereq([2.64],
  215. [[AC_DEFUN_ONCE(
  216. [$1], [$2])]],
  217. [m4_ifdef([gl_00GNULIB],
  218. [[AC_DEFUN_ONCE(
  219. [$1], [$2])]],
  220. [[AC_DEFUN(
  221. [$1], [$2])]])]))
  222. gl_iconv_AC_DEFUN([AM_ICONV],
  223. [
  224. AM_ICONV_LINK
  225. if test "$am_cv_func_iconv" = yes; then
  226. AC_MSG_CHECKING([for iconv declaration])
  227. AC_CACHE_VAL([am_cv_proto_iconv], [
  228. AC_COMPILE_IFELSE(
  229. [AC_LANG_PROGRAM(
  230. [[
  231. #include <stdlib.h>
  232. #include <iconv.h>
  233. extern
  234. #ifdef __cplusplus
  235. "C"
  236. #endif
  237. #if defined(__STDC__) || defined(_MSC_VER) || defined(__cplusplus)
  238. size_t iconv (iconv_t cd, char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);
  239. #else
  240. size_t iconv();
  241. #endif
  242. ]],
  243. [[]])],
  244. [am_cv_proto_iconv_arg1=""],
  245. [am_cv_proto_iconv_arg1="const"])
  246. 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);"])
  247. am_cv_proto_iconv=`echo "[$]am_cv_proto_iconv" | tr -s ' ' | sed -e 's/( /(/'`
  248. AC_MSG_RESULT([
  249. $am_cv_proto_iconv])
  250. AC_DEFINE_UNQUOTED([ICONV_CONST], [$am_cv_proto_iconv_arg1],
  251. [Define as const if the declaration of iconv() needs const.])
  252. dnl Also substitute ICONV_CONST in the gnulib generated <iconv.h>.
  253. m4_ifdef([gl_ICONV_H_DEFAULTS],
  254. [AC_REQUIRE([gl_ICONV_H_DEFAULTS])
  255. if test -n "$am_cv_proto_iconv_arg1"; then
  256. ICONV_CONST="const"
  257. fi
  258. ])
  259. fi
  260. ])