1dnl 2dnl $Id$ 3dnl 4dnl This file contains Zend specific autoconf functions. 5dnl 6 7AC_DEFUN([LIBZEND_CHECK_INT_TYPE],[ 8AC_MSG_CHECKING(for $1) 9AC_TRY_COMPILE([ 10#if HAVE_SYS_TYPES_H 11#include <sys/types.h> 12#endif 13#if HAVE_INTTYPES_H 14#include <inttypes.h> 15#elif HAVE_STDINT_H 16#include <stdint.h> 17#endif], 18[if (($1 *) 0) 19 return 0; 20if (sizeof ($1)) 21 return 0; 22],[ 23 AC_DEFINE_UNQUOTED([HAVE_]translit($1,a-z_-,A-Z__), 1,[Define if $1 type is present. ]) 24 AC_MSG_RESULT(yes) 25], AC_MSG_RESULT(no) 26)dnl 27]) 28 29AC_DEFUN([LIBZEND_BASIC_CHECKS],[ 30 31AC_REQUIRE([AC_PROG_YACC]) 32AC_REQUIRE([AC_PROG_CC]) 33AC_REQUIRE([AC_PROG_CC_C_O]) 34AC_REQUIRE([AC_HEADER_STDC]) 35 36LIBZEND_BISON_CHECK 37 38dnl Ugly hack to get around a problem with gcc on AIX. 39if test "$CC" = "gcc" -a "$ac_cv_prog_cc_g" = "yes" -a \ 40 "`uname -sv`" = "AIX 4"; then 41 CFLAGS=`echo $CFLAGS | sed -e 's/-g//'` 42fi 43 44dnl Hack to work around a Mac OS X cpp problem 45dnl Known versions needing this workaround are 5.3 and 5.4 46if test "$ac_cv_prog_gcc" = "yes" -a "`uname -s`" = "Rhapsody"; then 47 CPPFLAGS="$CPPFLAGS -traditional-cpp" 48fi 49 50AC_CHECK_HEADERS( 51inttypes.h \ 52stdint.h \ 53limits.h \ 54malloc.h \ 55string.h \ 56unistd.h \ 57stdarg.h \ 58sys/types.h \ 59sys/time.h \ 60signal.h \ 61unix.h \ 62stdlib.h \ 63dlfcn.h) 64 65AC_TYPE_SIZE_T 66AC_TYPE_SIGNAL 67 68AC_DEFUN([LIBZEND_LIBDL_CHECKS],[ 69AC_CHECK_LIB(dl, dlopen, [LIBS="-ldl $LIBS"]) 70AC_CHECK_FUNC(dlopen,[AC_DEFINE(HAVE_LIBDL, 1,[ ])]) 71]) 72 73AC_DEFUN([LIBZEND_DLSYM_CHECK],[ 74dnl 75dnl Ugly hack to check if dlsym() requires a leading underscore in symbol name. 76dnl 77AC_MSG_CHECKING([whether dlsym() requires a leading underscore in symbol names]) 78_LT_AC_TRY_DLOPEN_SELF([ 79 AC_MSG_RESULT(no) 80], [ 81 AC_MSG_RESULT(yes) 82 AC_DEFINE(DLSYM_NEEDS_UNDERSCORE, 1, [Define if dlsym() requires a leading underscore in symbol names. ]) 83], [ 84 AC_MSG_RESULT(no) 85], []) 86]) 87 88dnl This is required for QNX and may be some BSD derived systems 89AC_CHECK_TYPE( uint, unsigned int ) 90AC_CHECK_TYPE( ulong, unsigned long ) 91 92dnl Check if int32_t and uint32_t are defined 93LIBZEND_CHECK_INT_TYPE(int32_t) 94LIBZEND_CHECK_INT_TYPE(uint32_t) 95 96dnl Checks for library functions. 97AC_FUNC_VPRINTF 98AC_FUNC_MEMCMP 99AC_FUNC_ALLOCA 100AC_CHECK_FUNCS(memcpy strdup getpid kill strtod strtol finite fpclass sigsetjmp) 101AC_ZEND_BROKEN_SPRINTF 102 103AC_CHECK_FUNCS(finite isfinite isinf isnan) 104 105ZEND_FP_EXCEPT 106 107ZEND_CHECK_FLOAT_PRECISION 108 109dnl test whether double cast to long preserves least significant bits 110AC_MSG_CHECKING(whether double cast to long preserves least significant bits) 111 112AC_TRY_RUN([ 113#include <limits.h> 114 115int main() 116{ 117 if (sizeof(long) == 4) { 118 double d = (double) LONG_MIN * LONG_MIN + 2e9; 119 120 if ((long) d == 2e9 && (long) -d == -2e9) { 121 exit(0); 122 } 123 } else if (sizeof(long) == 8) { 124 double correct = 18e18 - ((double) LONG_MIN * -2); /* Subtract ULONG_MAX + 1 */ 125 126 if ((long) 18e18 == correct) { /* On 64-bit, only check between LONG_MAX and ULONG_MAX */ 127 exit(0); 128 } 129 } 130 exit(1); 131} 132], [ 133 AC_DEFINE([ZEND_DVAL_TO_LVAL_CAST_OK], 1, [Define if double cast to long preserves least significant bits]) 134 AC_MSG_RESULT(yes) 135], [ 136 AC_MSG_RESULT(no) 137], [ 138 AC_MSG_RESULT(no) 139]) 140 141]) 142 143AC_DEFUN([LIBZEND_ENABLE_DEBUG],[ 144 145AC_ARG_ENABLE(debug, 146[ --enable-debug Compile with debugging symbols],[ 147 ZEND_DEBUG=$enableval 148],[ 149 ZEND_DEBUG=no 150]) 151 152]) 153 154AC_DEFUN([LIBZEND_OTHER_CHECKS],[ 155 156AC_ARG_WITH(zend-vm, 157[ --with-zend-vm=TYPE Set virtual machine dispatch method. Type is 158 one of "CALL", "SWITCH" or "GOTO" [TYPE=CALL]],[ 159 PHP_ZEND_VM=$withval 160],[ 161 PHP_ZEND_VM=CALL 162]) 163 164AC_ARG_ENABLE(maintainer-zts, 165[ --enable-maintainer-zts Enable thread safety - for code maintainers only!!],[ 166 ZEND_MAINTAINER_ZTS=$enableval 167],[ 168 ZEND_MAINTAINER_ZTS=no 169]) 170 171AC_ARG_ENABLE(inline-optimization, 172[ --disable-inline-optimization 173 If building zend_execute.lo fails, try this switch],[ 174 ZEND_INLINE_OPTIMIZATION=$enableval 175],[ 176 ZEND_INLINE_OPTIMIZATION=yes 177]) 178 179AC_ARG_ENABLE(zend-multibyte, 180[ --enable-zend-multibyte Compile with zend multibyte support], [ 181 ZEND_MULTIBYTE=$enableval 182],[ 183 ZEND_MULTIBYTE=no 184]) 185 186AC_MSG_CHECKING([virtual machine dispatch method]) 187AC_MSG_RESULT($PHP_ZEND_VM) 188 189AC_MSG_CHECKING(whether to enable thread-safety) 190AC_MSG_RESULT($ZEND_MAINTAINER_ZTS) 191 192AC_MSG_CHECKING(whether to enable inline optimization for GCC) 193AC_MSG_RESULT($ZEND_INLINE_OPTIMIZATION) 194 195AC_MSG_CHECKING(whether to enable Zend debugging) 196AC_MSG_RESULT($ZEND_DEBUG) 197 198AC_MSG_CHECKING(whether to enable Zend multibyte) 199AC_MSG_RESULT($ZEND_MULTIBYTE) 200 201case $PHP_ZEND_VM in 202 SWITCH) 203 AC_DEFINE(ZEND_VM_KIND,ZEND_VM_KIND_SWITCH,[virtual machine dispatch method]) 204 ;; 205 GOTO) 206 AC_DEFINE(ZEND_VM_KIND,ZEND_VM_KIND_GOTO,[virtual machine dispatch method]) 207 ;; 208 *) 209 PHP_ZEND_VM=CALL 210 AC_DEFINE(ZEND_VM_KIND,ZEND_VM_KIND_CALL,[virtual machine dispatch method]) 211 ;; 212esac 213 214if test "$ZEND_DEBUG" = "yes"; then 215 AC_DEFINE(ZEND_DEBUG,1,[ ]) 216 echo " $CFLAGS" | grep ' -g' >/dev/null || DEBUG_CFLAGS="-g" 217 if test "$CFLAGS" = "-g -O2"; then 218 CFLAGS=-g 219 fi 220 test -n "$GCC" && DEBUG_CFLAGS="$DEBUG_CFLAGS -Wall" 221 test -n "$GCC" && test "$USE_MAINTAINER_MODE" = "yes" && \ 222 DEBUG_CFLAGS="$DEBUG_CFLAGS -Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations" 223else 224 AC_DEFINE(ZEND_DEBUG,0,[ ]) 225fi 226 227test -n "$DEBUG_CFLAGS" && CFLAGS="$CFLAGS $DEBUG_CFLAGS" 228 229if test "$ZEND_MAINTAINER_ZTS" = "yes"; then 230 AC_DEFINE(ZTS,1,[ ]) 231 CFLAGS="$CFLAGS -DZTS" 232 LIBZEND_CPLUSPLUS_CHECKS 233fi 234 235if test "$ZEND_MULTIBYTE" = "yes"; then 236 AC_DEFINE(ZEND_MULTIBYTE, 1, [ ]) 237fi 238 239changequote({,}) 240if test -n "$GCC" && test "$ZEND_INLINE_OPTIMIZATION" != "yes"; then 241 INLINE_CFLAGS=`echo $ac_n "$CFLAGS $ac_c" | sed s/-O[0-9s]*//` 242else 243 INLINE_CFLAGS="$CFLAGS" 244fi 245changequote([,]) 246 247AC_C_INLINE 248 249AC_SUBST(INLINE_CFLAGS) 250 251AC_MSG_CHECKING(target system is Darwin) 252if echo "$target" | grep "darwin" > /dev/null; then 253 AC_DEFINE([DARWIN], 1, [Define if the target system is darwin]) 254 AC_MSG_RESULT(yes) 255else 256 AC_MSG_RESULT(no) 257fi 258 259dnl test and set the alignment define for ZEND_MM 260dnl this also does the logarithmic test for ZEND_MM. 261AC_MSG_CHECKING(for MM alignment and log values) 262 263AC_TRY_RUN([ 264#include <stdio.h> 265 266typedef union _mm_align_test { 267 void *ptr; 268 double dbl; 269 long lng; 270} mm_align_test; 271 272#if (defined (__GNUC__) && __GNUC__ >= 2) 273#define ZEND_MM_ALIGNMENT (__alignof__ (mm_align_test)) 274#else 275#define ZEND_MM_ALIGNMENT (sizeof(mm_align_test)) 276#endif 277 278int main() 279{ 280 int i = ZEND_MM_ALIGNMENT; 281 int zeros = 0; 282 FILE *fp; 283 284 while (i & ~0x1) { 285 zeros++; 286 i = i >> 1; 287 } 288 289 fp = fopen("conftest.zend", "w"); 290 fprintf(fp, "%d %d\n", ZEND_MM_ALIGNMENT, zeros); 291 fclose(fp); 292 293 exit(0); 294} 295], [ 296 LIBZEND_MM_ALIGN=`cat conftest.zend | cut -d ' ' -f 1` 297 LIBZEND_MM_ALIGN_LOG2=`cat conftest.zend | cut -d ' ' -f 2` 298 AC_DEFINE_UNQUOTED(ZEND_MM_ALIGNMENT, $LIBZEND_MM_ALIGN, [ ]) 299 AC_DEFINE_UNQUOTED(ZEND_MM_ALIGNMENT_LOG2, $LIBZEND_MM_ALIGN_LOG2, [ ]) 300], [], [ 301 dnl cross-compile needs something here 302 LIBZEND_MM_ALIGN=8 303]) 304 305AC_MSG_RESULT(done) 306 307dnl test for memory allocation using mmap(MAP_ANON) 308AC_MSG_CHECKING(for memory allocation using mmap(MAP_ANON)) 309 310AC_TRY_RUN([ 311#include <sys/types.h> 312#include <sys/stat.h> 313#include <fcntl.h> 314#include <sys/mman.h> 315#include <stdlib.h> 316#include <stdio.h> 317#ifndef MAP_ANON 318# ifdef MAP_ANONYMOUS 319# define MAP_ANON MAP_ANONYMOUS 320# endif 321#endif 322#ifndef MREMAP_MAYMOVE 323# define MREMAP_MAYMOVE 0 324#endif 325#ifndef MAP_FAILED 326# define MAP_FAILED ((void*)-1) 327#endif 328 329#define SEG_SIZE (256*1024) 330 331int main() 332{ 333 void *seg = mmap(NULL, SEG_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0); 334 if (seg == MAP_FAILED) { 335 return 1; 336 } 337 if (munmap(seg, SEG_SIZE) != 0) { 338 return 2; 339 } 340 return 0; 341} 342], [ 343 AC_DEFINE([HAVE_MEM_MMAP_ANON], 1, [Define if the target system has support for memory allocation using mmap(MAP_ANON)]) 344 AC_MSG_RESULT(yes) 345], [ 346 AC_MSG_RESULT(no) 347], [ 348 dnl cross-compile needs something here 349 AC_MSG_RESULT(no) 350]) 351 352dnl test for memory allocation using mmap("/dev/zero") 353AC_MSG_CHECKING(for memory allocation using mmap("/dev/zero")) 354 355AC_TRY_RUN([ 356#include <sys/types.h> 357#include <sys/stat.h> 358#include <fcntl.h> 359#include <sys/mman.h> 360#include <stdlib.h> 361#include <stdio.h> 362#ifndef MAP_ANON 363# ifdef MAP_ANONYMOUS 364# define MAP_ANON MAP_ANONYMOUS 365# endif 366#endif 367#ifndef MREMAP_MAYMOVE 368# define MREMAP_MAYMOVE 0 369#endif 370#ifndef MAP_FAILED 371# define MAP_FAILED ((void*)-1) 372#endif 373 374#define SEG_SIZE (256*1024) 375 376int main() 377{ 378 int fd; 379 void *seg; 380 381 fd = open("/dev/zero", O_RDWR, S_IRUSR | S_IWUSR); 382 if (fd < 0) { 383 return 1; 384 } 385 seg = mmap(NULL, SEG_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0); 386 if (seg == MAP_FAILED) { 387 return 2; 388 } 389 if (munmap(seg, SEG_SIZE) != 0) { 390 return 3; 391 } 392 if (close(fd) != 0) { 393 return 4; 394 } 395 return 0; 396} 397], [ 398 AC_DEFINE([HAVE_MEM_MMAP_ZERO], 1, [Define if the target system has support for memory allocation using mmap("/dev/zero")]) 399 AC_MSG_RESULT(yes) 400], [ 401 AC_MSG_RESULT(no) 402], [ 403 dnl cross-compile needs something here 404 AC_MSG_RESULT(no) 405]) 406 407AC_CHECK_FUNCS(mremap) 408 409]) 410 411 412AC_DEFUN([LIBZEND_CPLUSPLUS_CHECKS],[ 413 414]) 415 416AC_MSG_CHECKING(whether /dev/urandom exists) 417if test -r "/dev/urandom" && test -c "/dev/urandom"; then 418 AC_DEFINE([HAVE_DEV_URANDOM], 1, [Define if the target system has /dev/urandom device]) 419 AC_MSG_RESULT(yes) 420else 421 AC_MSG_RESULT(no) 422fi 423