iconv.m4 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. # iconv.m4 serial AM4 (gettext-0.11.3)
  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.
  8. dnl From Bruno Haible.
  9. dnl with modifications to support building with in-tree libiconv
  10. AC_DEFUN([AM_ICONV_LINKFLAGS_BODY],
  11. [
  12. dnl Prerequisites of AC_LIB_LINKFLAGS_BODY.
  13. AC_REQUIRE([AC_LIB_PREPARE_PREFIX])
  14. AC_REQUIRE([AC_LIB_RPATH])
  15. dnl Search for libiconv and define LIBICONV, LTLIBICONV and INCICONV
  16. dnl accordingly.
  17. AC_LIB_LINKFLAGS_BODY([iconv])
  18. ])
  19. AC_DEFUN([AM_ICONV_LINK],
  20. [
  21. dnl Some systems have iconv in libc, some have it in libiconv (OSF/1 and
  22. dnl those with the standalone portable GNU libiconv installed).
  23. dnl Search for libiconv and define LIBICONV, LTLIBICONV and INCICONV
  24. dnl accordingly.
  25. AC_REQUIRE([AM_ICONV_LINKFLAGS_BODY])
  26. AC_CACHE_CHECK(for iconv, am_cv_func_iconv, [
  27. am_cv_func_iconv="no, consider installing GNU libiconv"
  28. am_cv_lib_iconv=no
  29. dnl Add $INCICONV to CPPFLAGS before performing the first check,
  30. dnl because if the user has installed libiconv and not disabled its use
  31. dnl via --without-libiconv-prefix, he wants to use it. This first
  32. dnl AC_TRY_LINK will then fail, the second AC_TRY_LINK will succeed.
  33. am_save_CPPFLAGS="$CPPFLAGS"
  34. CPPFLAGS="$CPPFLAGS $INCICONV"
  35. AC_TRY_LINK([#include <stdlib.h>
  36. #include <iconv.h>],
  37. [iconv_t cd = iconv_open("","");
  38. iconv(cd,NULL,NULL,NULL,NULL);
  39. iconv_close(cd);],
  40. am_cv_func_iconv=yes)
  41. CPPFLAGS="$am_save_CPPFLAGS"
  42. if test "$am_cv_func_iconv" != yes && test -d ../libiconv; then
  43. for _libs in .libs _libs; do
  44. am_save_CPPFLAGS="$CPPFLAGS"
  45. am_save_LIBS="$LIBS"
  46. CPPFLAGS="$CPPFLAGS -I../libiconv/include"
  47. LIBS="$LIBS ../libiconv/lib/$_libs/libiconv.a"
  48. AC_TRY_LINK([#include <stdlib.h>
  49. #include <iconv.h>],
  50. [iconv_t cd = iconv_open("","");
  51. iconv(cd,NULL,NULL,NULL,NULL);
  52. iconv_close(cd);],
  53. INCICONV="-I../libiconv/include"
  54. LIBICONV='${top_builddir}'/../libiconv/lib/$_libs/libiconv.a
  55. LTLIBICONV='${top_builddir}'/../libiconv/lib/libiconv.la
  56. am_cv_lib_iconv=yes
  57. am_cv_func_iconv=yes)
  58. CPPFLAGS="$am_save_CPPFLAGS"
  59. LIBS="$am_save_LIBS"
  60. if test "$am_cv_func_iconv" = "yes"; then
  61. break
  62. fi
  63. done
  64. fi
  65. if test "$am_cv_func_iconv" != yes; then
  66. am_save_CPPFLAGS="$CPPFLAGS"
  67. am_save_LIBS="$LIBS"
  68. CPPFLAGS="$CPPFLAGS $INCICONV"
  69. LIBS="$LIBS $LIBICONV"
  70. AC_TRY_LINK([#include <stdlib.h>
  71. #include <iconv.h>],
  72. [iconv_t cd = iconv_open("","");
  73. iconv(cd,NULL,NULL,NULL,NULL);
  74. iconv_close(cd);],
  75. am_cv_lib_iconv=yes
  76. am_cv_func_iconv=yes)
  77. CPPFLAGS="$am_save_CPPFLAGS"
  78. LIBS="$am_save_LIBS"
  79. fi
  80. ])
  81. if test "$am_cv_func_iconv" = yes; then
  82. AC_DEFINE(HAVE_ICONV, 1, [Define if you have the iconv() function.])
  83. fi
  84. if test "$am_cv_lib_iconv" = yes; then
  85. AC_LIB_APPENDTOVAR([CPPFLAGS], [$INCICONV])
  86. AC_MSG_CHECKING([how to link with libiconv])
  87. AC_MSG_RESULT([$LIBICONV])
  88. else
  89. LIBICONV=
  90. LTLIBICONV=
  91. fi
  92. AC_SUBST(LIBICONV)
  93. AC_SUBST(LTLIBICONV)
  94. ])
  95. AC_DEFUN([AM_ICONV],
  96. [
  97. AM_ICONV_LINK
  98. if test "$am_cv_func_iconv" = yes; then
  99. AC_MSG_CHECKING([for iconv declaration])
  100. AC_CACHE_VAL(am_cv_proto_iconv, [
  101. AC_TRY_COMPILE([
  102. #include <stdlib.h>
  103. #include <iconv.h>
  104. extern
  105. #ifdef __cplusplus
  106. "C"
  107. #endif
  108. #if defined(__STDC__) || defined(__cplusplus)
  109. size_t iconv (iconv_t cd, char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);
  110. #else
  111. size_t iconv();
  112. #endif
  113. ], [], am_cv_proto_iconv_arg1="", am_cv_proto_iconv_arg1="const")
  114. 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);"])
  115. am_cv_proto_iconv=`echo "[$]am_cv_proto_iconv" | tr -s ' ' | sed -e 's/( /(/'`
  116. AC_MSG_RESULT([$]{ac_t:-
  117. }[$]am_cv_proto_iconv)
  118. AC_DEFINE_UNQUOTED(ICONV_CONST, $am_cv_proto_iconv_arg1,
  119. [Define as const if the declaration of iconv() needs const.])
  120. fi
  121. ])