config.m4 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. dnl
  2. dnl $Id$
  3. dnl
  4. PHP_ARG_WITH(iconv, for iconv support,
  5. [ --without-iconv[=DIR] Exclude iconv support], yes)
  6. if test "$PHP_ICONV" != "no"; then
  7. PHP_SETUP_ICONV(ICONV_SHARED_LIBADD, [
  8. iconv_avail="yes";
  9. ],[
  10. iconv_avail="no";
  11. ])
  12. if test "$iconv_avail" != "no"; then
  13. if test -z "$ICONV_DIR"; then
  14. for i in /usr/local /usr; do
  15. if test -f "$i/include/iconv.h" || test -f "$i/include/giconv.h"; then
  16. PHP_ICONV_PREFIX="$i"
  17. break
  18. fi
  19. done
  20. if test -z "$PHP_ICONV_PREFIX"; then
  21. PHP_ICONV_PREFIX="/usr"
  22. fi
  23. else
  24. PHP_ICONV_PREFIX="$ICONV_DIR"
  25. fi
  26. CFLAGS="-I$PHP_ICONV_PREFIX/include $CFLAGS"
  27. LDFLAGS="-L$PHP_ICONV_PREFIX/$PHP_LIBDIR $LDFLAGS"
  28. if test -r "$PHP_ICONV_PREFIX/include/giconv.h"; then
  29. PHP_ICONV_H_PATH="$PHP_ICONV_PREFIX/include/giconv.h"
  30. else
  31. PHP_ICONV_H_PATH="$PHP_ICONV_PREFIX/include/iconv.h"
  32. fi
  33. AC_MSG_CHECKING([if iconv is glibc's])
  34. AC_TRY_LINK([#include <gnu/libc-version.h>],[gnu_get_libc_version();],
  35. [
  36. AC_MSG_RESULT(yes)
  37. iconv_impl_name="glibc"
  38. ],[
  39. AC_MSG_RESULT(no)
  40. ])
  41. if test -z "$iconv_impl_name"; then
  42. AC_MSG_CHECKING([if using GNU libiconv])
  43. php_iconv_old_ld="$LDFLAGS"
  44. LDFLAGS="-liconv $LDFLAGS"
  45. AC_TRY_RUN([
  46. #include <$PHP_ICONV_H_PATH>
  47. int main() {
  48. printf("%d", _libiconv_version);
  49. return 0;
  50. }
  51. ],[
  52. AC_MSG_RESULT(yes)
  53. iconv_impl_name="gnu_libiconv"
  54. ],[
  55. AC_MSG_RESULT(no)
  56. LDFLAGS="$php_iconv_old_ld"
  57. ],[
  58. AC_MSG_RESULT(no, cross-compiling)
  59. LDFLAGS="$php_iconv_old_ld"
  60. ])
  61. fi
  62. if test -z "$iconv_impl_name"; then
  63. AC_MSG_CHECKING([if iconv is Konstantin Chuguev's])
  64. AC_TRY_LINK([#include <iconv.h>],[iconv_ccs_init(NULL, NULL);],
  65. [
  66. AC_MSG_RESULT(yes)
  67. iconv_impl_name="bsd"
  68. ],[
  69. AC_MSG_RESULT(no)
  70. ])
  71. fi
  72. if test -z "$iconv_impl_name"; then
  73. AC_MSG_CHECKING([if using IBM iconv])
  74. php_iconv_old_ld="$LDFLAGS"
  75. LDFLAGS="-liconv $LDFLAGS"
  76. AC_TRY_LINK([#include <iconv.h>],[cstoccsid("");],
  77. [
  78. AC_MSG_RESULT(yes)
  79. iconv_impl_name="ibm"
  80. ],[
  81. AC_MSG_RESULT(no)
  82. LDFLAGS="$php_iconv_old_ld"
  83. ])
  84. fi
  85. echo > ext/iconv/php_have_bsd_iconv.h
  86. echo > ext/iconv/php_have_glibc_iconv.h
  87. echo > ext/iconv/php_have_libiconv.h
  88. echo > ext/iconv/php_have_ibm_iconv.h
  89. case "$iconv_impl_name" in
  90. gnu_libiconv [)]
  91. PHP_DEFINE([PHP_ICONV_IMPL],[\"libiconv\"],[ext/iconv])
  92. AC_DEFINE([PHP_ICONV_IMPL],["libiconv"],[Which iconv implementation to use])
  93. PHP_DEFINE([HAVE_LIBICONV],1,[ext/iconv])
  94. PHP_ADD_LIBRARY_WITH_PATH(iconv, "$PHP_ICONV_PREFIX/$PHP_LIBDIR", ICONV_SHARED_LIBADD)
  95. ;;
  96. bsd [)]
  97. PHP_DEFINE([HAVE_BSD_ICONV],1,[ext/iconv])
  98. AC_DEFINE([HAVE_BSD_ICONV],1,[Konstantin Chuguev's iconv implementation])
  99. PHP_DEFINE([PHP_ICONV_IMPL],[\"BSD iconv\"],[ext/iconv])
  100. AC_DEFINE([PHP_ICONV_IMPL],["BSD iconv"],[Which iconv implementation to use])
  101. ;;
  102. glibc [)]
  103. PHP_DEFINE([HAVE_GLIBC_ICONV],1,[ext/iconv])
  104. AC_DEFINE([HAVE_GLIBC_ICONV],1,[glibc's iconv implementation])
  105. PHP_DEFINE([PHP_ICONV_IMPL],[\"glibc\"],[ext/iconv])
  106. AC_DEFINE([PHP_ICONV_IMPL],["glibc"],[Which iconv implementation to use])
  107. ;;
  108. ibm [)]
  109. PHP_DEFINE([HAVE_IBM_ICONV],1,[ext/iconv])
  110. AC_DEFINE([HAVE_IBM_ICONV],1,[IBM iconv implementation])
  111. PHP_DEFINE([PHP_ICONV_IMPL],[\"IBM iconv\"],[ext/iconv])
  112. AC_DEFINE([PHP_ICONV_IMPL],["IBM iconv"],[Which iconv implementation to use])
  113. ;;
  114. esac
  115. AC_MSG_CHECKING([if iconv supports errno])
  116. AC_TRY_RUN([
  117. #include <$PHP_ICONV_H_PATH>
  118. #include <errno.h>
  119. int main() {
  120. iconv_t cd;
  121. cd = iconv_open( "*blahblah*", "*blahblah*" );
  122. if (cd == (iconv_t)(-1)) {
  123. if (errno == EINVAL) {
  124. return 0;
  125. } else {
  126. return 1;
  127. }
  128. }
  129. iconv_close( cd );
  130. return 2;
  131. }
  132. ],[
  133. AC_MSG_RESULT(yes)
  134. PHP_DEFINE([ICONV_SUPPORTS_ERRNO],1,[ext/iconv])
  135. AC_DEFINE([ICONV_SUPPORTS_ERRNO],1,[Whether iconv supports error no or not])
  136. ],[
  137. AC_MSG_RESULT(no)
  138. PHP_DEFINE([ICONV_SUPPORTS_ERRNO],0,[ext/iconv])
  139. AC_DEFINE([ICONV_SUPPORTS_ERRNO],0,[Whether iconv supports error no or not])
  140. ],[
  141. AC_MSG_RESULT(no, cross-compiling)
  142. PHP_DEFINE([ICONV_SUPPORTS_ERRNO],0,[ext/iconv])
  143. AC_DEFINE([ICONV_SUPPORTS_ERRNO],0,[Whether iconv supports error no or not])
  144. ])
  145. AC_MSG_CHECKING([if iconv supports //IGNORE])
  146. AC_TRY_RUN([
  147. #include <$PHP_ICONV_H_PATH>
  148. #include <stdlib.h>
  149. int main() {
  150. iconv_t cd = iconv_open( "UTF-8//IGNORE", "UTF-8" );
  151. char *in_p = "\xC3\xC3\xC3\xB8";
  152. size_t in_left = 4, out_left = 4096;
  153. char *out = malloc(out_left);
  154. char *out_p = out;
  155. size_t result = iconv(cd, (char **) &in_p, &in_left, (char **) &out_p, &out_left);
  156. if(result == (size_t)-1) {
  157. return 1;
  158. }
  159. return 0;
  160. }
  161. ],[
  162. AC_MSG_RESULT(yes)
  163. PHP_DEFINE([ICONV_BROKEN_IGNORE],0,[ext/iconv])
  164. AC_DEFINE([ICONV_BROKEN_IGNORE],0,[Whether iconv supports IGNORE])
  165. ],[
  166. AC_MSG_RESULT(no)
  167. PHP_DEFINE([ICONV_BROKEN_IGNORE],1,[ext/iconv])
  168. AC_DEFINE([ICONV_BROKEN_IGNORE],1,[Whether iconv supports IGNORE])
  169. ],[
  170. AC_MSG_RESULT(no, cross-compiling)
  171. PHP_DEFINE([ICONV_BROKEN_IGNORE],0,[ext/iconv])
  172. AC_DEFINE([ICONV_BROKEN_IGNORE],0,[Whether iconv supports IGNORE])
  173. ])
  174. AC_MSG_CHECKING([if your cpp allows macro usage in include lines])
  175. AC_TRY_COMPILE([
  176. #define FOO <$PHP_ICONV_H_PATH>
  177. #include FOO
  178. ], [], [
  179. AC_MSG_RESULT([yes])
  180. PHP_DEFINE([PHP_ICONV_H_PATH], [<$PHP_ICONV_H_PATH>],[ext/iconv])
  181. AC_DEFINE_UNQUOTED([PHP_ICONV_H_PATH], [<$PHP_ICONV_H_PATH>], [Path to iconv.h])
  182. ], [
  183. AC_MSG_RESULT([no])
  184. ])
  185. PHP_NEW_EXTENSION(iconv, iconv.c, $ext_shared,, [-I\"$PHP_ICONV_PREFIX/include\"])
  186. PHP_SUBST(ICONV_SHARED_LIBADD)
  187. PHP_INSTALL_HEADERS([ext/iconv/])
  188. else
  189. AC_MSG_ERROR(Please reinstall the iconv library.)
  190. fi
  191. fi