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