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