1dnl This file contains Zend specific autoconf macros. 2 3dnl 4dnl ZEND_CHECK_FLOAT_PRECISION 5dnl 6dnl x87 floating point internal precision control checks 7dnl See: http://wiki.php.net/rfc/rounding 8dnl 9AC_DEFUN([ZEND_CHECK_FLOAT_PRECISION],[ 10 AC_MSG_CHECKING([for usable _FPU_SETCW]) 11 AC_LINK_IFELSE([AC_LANG_PROGRAM([[ 12 #include <fpu_control.h> 13 ]],[[ 14 fpu_control_t fpu_oldcw, fpu_cw; 15 volatile double result; 16 double a = 2877.0; 17 volatile double b = 1000000.0; 18 19 _FPU_GETCW(fpu_oldcw); 20 fpu_cw = (fpu_oldcw & ~_FPU_EXTENDED & ~_FPU_SINGLE) | _FPU_DOUBLE; 21 _FPU_SETCW(fpu_cw); 22 result = a / b; 23 _FPU_SETCW(fpu_oldcw); 24 ]])],[ac_cfp_have__fpu_setcw=yes],[ac_cfp_have__fpu_setcw=no]) 25 if test "$ac_cfp_have__fpu_setcw" = "yes" ; then 26 AC_DEFINE(HAVE__FPU_SETCW, 1, [whether _FPU_SETCW is present and usable]) 27 AC_MSG_RESULT(yes) 28 else 29 AC_MSG_RESULT(no) 30 fi 31 32 AC_MSG_CHECKING([for usable fpsetprec]) 33 AC_LINK_IFELSE([AC_LANG_PROGRAM([[ 34 #include <machine/ieeefp.h> 35 ]],[[ 36 fp_prec_t fpu_oldprec; 37 volatile double result; 38 double a = 2877.0; 39 volatile double b = 1000000.0; 40 41 fpu_oldprec = fpgetprec(); 42 fpsetprec(FP_PD); 43 result = a / b; 44 fpsetprec(fpu_oldprec); 45 ]])], [ac_cfp_have_fpsetprec=yes], [ac_cfp_have_fpsetprec=no]) 46 if test "$ac_cfp_have_fpsetprec" = "yes" ; then 47 AC_DEFINE(HAVE_FPSETPREC, 1, [whether fpsetprec is present and usable]) 48 AC_MSG_RESULT(yes) 49 else 50 AC_MSG_RESULT(no) 51 fi 52 53 AC_MSG_CHECKING([for usable _controlfp]) 54 AC_LINK_IFELSE([AC_LANG_PROGRAM([[ 55 #include <float.h> 56 ]],[[ 57 unsigned int fpu_oldcw; 58 volatile double result; 59 double a = 2877.0; 60 volatile double b = 1000000.0; 61 62 fpu_oldcw = _controlfp(0, 0); 63 _controlfp(_PC_53, _MCW_PC); 64 result = a / b; 65 _controlfp(fpu_oldcw, _MCW_PC); 66 ]])], [ac_cfp_have__controlfp=yes], [ac_cfp_have__controlfp=no]) 67 if test "$ac_cfp_have__controlfp" = "yes" ; then 68 AC_DEFINE(HAVE__CONTROLFP, 1, [whether _controlfp is present usable]) 69 AC_MSG_RESULT(yes) 70 else 71 AC_MSG_RESULT(no) 72 fi 73 74 AC_MSG_CHECKING([for usable _controlfp_s]) 75 AC_LINK_IFELSE([AC_LANG_PROGRAM([[ 76 #include <float.h> 77 ]],[[ 78 unsigned int fpu_oldcw, fpu_cw; 79 volatile double result; 80 double a = 2877.0; 81 volatile double b = 1000000.0; 82 83 _controlfp_s(&fpu_cw, 0, 0); 84 fpu_oldcw = fpu_cw; 85 _controlfp_s(&fpu_cw, _PC_53, _MCW_PC); 86 result = a / b; 87 _controlfp_s(&fpu_cw, fpu_oldcw, _MCW_PC); 88 ]])], [ac_cfp_have__controlfp_s=yes], [ac_cfp_have__controlfp_s=no]) 89 if test "$ac_cfp_have__controlfp_s" = "yes" ; then 90 AC_DEFINE(HAVE__CONTROLFP_S, 1, [whether _controlfp_s is present and usable]) 91 AC_MSG_RESULT(yes) 92 else 93 AC_MSG_RESULT(no) 94 fi 95 96 AC_MSG_CHECKING([whether FPU control word can be manipulated by inline assembler]) 97 AC_LINK_IFELSE([AC_LANG_PROGRAM([[ 98 /* nothing */ 99 ]],[[ 100 unsigned int oldcw, cw; 101 volatile double result; 102 double a = 2877.0; 103 volatile double b = 1000000.0; 104 105 __asm__ __volatile__ ("fnstcw %0" : "=m" (*&oldcw)); 106 cw = (oldcw & ~0x0 & ~0x300) | 0x200; 107 __asm__ __volatile__ ("fldcw %0" : : "m" (*&cw)); 108 109 result = a / b; 110 111 __asm__ __volatile__ ("fldcw %0" : : "m" (*&oldcw)); 112 ]])], [ac_cfp_have_fpu_inline_asm_x86=yes], [ac_cfp_have_fpu_inline_asm_x86=no]) 113 if test "$ac_cfp_have_fpu_inline_asm_x86" = "yes" ; then 114 AC_DEFINE(HAVE_FPU_INLINE_ASM_X86, 1, [whether FPU control word can be manipulated by inline assembler]) 115 AC_MSG_RESULT(yes) 116 else 117 AC_MSG_RESULT(no) 118 fi 119]) 120 121dnl 122dnl LIBZEND_BASIC_CHECKS 123dnl 124dnl Basic checks specific for the Zend engine library. 125dnl 126AC_DEFUN([LIBZEND_BASIC_CHECKS],[ 127AC_REQUIRE([AC_PROG_CC]) 128 129AC_CHECK_HEADERS([cpuid.h]) 130 131dnl 132dnl LIBZEND_DLSYM_CHECK 133dnl 134dnl Ugly hack to check if dlsym() requires a leading underscore in symbol name. 135dnl 136AC_DEFUN([LIBZEND_DLSYM_CHECK],[ 137AC_MSG_CHECKING([whether dlsym() requires a leading underscore in symbol names]) 138_LT_AC_TRY_DLOPEN_SELF([ 139 AC_MSG_RESULT(no) 140], [ 141 AC_MSG_RESULT(yes) 142 AC_DEFINE(DLSYM_NEEDS_UNDERSCORE, 1, [Define if dlsym() requires a leading underscore in symbol names. ]) 143], [ 144 AC_MSG_RESULT(no) 145], []) 146]) 147 148dnl Checks for library functions. 149AC_CHECK_FUNCS(getpid kill finite sigsetjmp) 150 151AC_CHECK_DECLS([isfinite, isnan, isinf], [], [], [[#include <math.h>]]) 152 153ZEND_CHECK_FLOAT_PRECISION 154 155dnl Test whether double cast to long preserves least significant bits. 156AC_MSG_CHECKING(whether double cast to long preserves least significant bits) 157 158AC_RUN_IFELSE([AC_LANG_SOURCE([[ 159#include <limits.h> 160 161int main() 162{ 163 if (sizeof(long) == 4) { 164 double d = (double) LONG_MIN * LONG_MIN + 2e9; 165 166 if ((long) d == 2e9 && (long) -d == -2e9) { 167 return 0; 168 } 169 } else if (sizeof(long) == 8) { 170 double correct = 18e18 - ((double) LONG_MIN * -2); /* Subtract ULONG_MAX + 1 */ 171 172 if ((long) 18e18 == correct) { /* On 64-bit, only check between LONG_MAX and ULONG_MAX */ 173 return 0; 174 } 175 } 176 return 1; 177} 178]])], [ 179 AC_DEFINE([ZEND_DVAL_TO_LVAL_CAST_OK], 1, [Define if double cast to long preserves least significant bits]) 180 AC_MSG_RESULT(yes) 181], [ 182 AC_MSG_RESULT(no) 183], [ 184 AC_MSG_RESULT(no) 185]) 186 187]) 188 189dnl 190dnl LIBZEND_OTHER_CHECKS 191dnl 192AC_DEFUN([LIBZEND_OTHER_CHECKS],[ 193 194AC_ARG_ENABLE([maintainer-zts], 195 [AS_HELP_STRING([--enable-maintainer-zts], 196 [Enable thread safety - for code maintainers only!!])], 197 [ZEND_MAINTAINER_ZTS=$enableval], 198 [ZEND_MAINTAINER_ZTS=no]) 199 200AC_ARG_ENABLE([inline-optimization], 201 [AS_HELP_STRING([--disable-inline-optimization], 202 [If building zend_execute.lo fails, try this switch])], 203 [ZEND_INLINE_OPTIMIZATION=$enableval], 204 [ZEND_INLINE_OPTIMIZATION=yes]) 205 206AC_MSG_CHECKING(whether to enable thread-safety) 207AC_MSG_RESULT($ZEND_MAINTAINER_ZTS) 208 209AC_MSG_CHECKING(whether to enable inline optimization for GCC) 210AC_MSG_RESULT($ZEND_INLINE_OPTIMIZATION) 211 212AC_MSG_CHECKING(whether to enable Zend debugging) 213AC_MSG_RESULT($ZEND_DEBUG) 214 215if test "$ZEND_DEBUG" = "yes"; then 216 AC_DEFINE(ZEND_DEBUG,1,[ ]) 217 echo " $CFLAGS" | grep ' -g' >/dev/null || DEBUG_CFLAGS="-g" 218 if test "$CFLAGS" = "-g -O2"; then 219 CFLAGS=-g 220 fi 221else 222 AC_DEFINE(ZEND_DEBUG,0,[ ]) 223fi 224 225test -n "$GCC" && CFLAGS="$CFLAGS -Wall -Wno-strict-aliasing" 226test -n "$DEBUG_CFLAGS" && CFLAGS="$CFLAGS $DEBUG_CFLAGS" 227 228if test "$ZEND_MAINTAINER_ZTS" = "yes"; then 229 AC_DEFINE(ZTS,1,[ ]) 230 CFLAGS="$CFLAGS -DZTS" 231fi 232 233changequote({,}) 234if test -n "$GCC" && test "$ZEND_INLINE_OPTIMIZATION" != "yes"; then 235 INLINE_CFLAGS=`echo $ac_n "$CFLAGS $ac_c" | sed s/-O[0-9s]*//` 236else 237 INLINE_CFLAGS="$CFLAGS" 238fi 239changequote([,]) 240 241AC_C_INLINE 242 243AC_SUBST(INLINE_CFLAGS) 244 245AC_MSG_CHECKING(target system is Darwin) 246if echo "$target" | grep "darwin" > /dev/null; then 247 AC_DEFINE([DARWIN], 1, [Define if the target system is darwin]) 248 AC_MSG_RESULT(yes) 249else 250 AC_MSG_RESULT(no) 251fi 252 253dnl Test and set the alignment define for ZEND_MM. This also does the 254dnl logarithmic test for ZEND_MM. 255AC_MSG_CHECKING(for MM alignment and log values) 256 257AC_RUN_IFELSE([AC_LANG_SOURCE([[ 258#include <stdio.h> 259 260typedef union _mm_align_test { 261 void *ptr; 262 double dbl; 263 long lng; 264} mm_align_test; 265 266#if (defined (__GNUC__) && __GNUC__ >= 2) 267#define ZEND_MM_ALIGNMENT (__alignof__ (mm_align_test)) 268#else 269#define ZEND_MM_ALIGNMENT (sizeof(mm_align_test)) 270#endif 271 272int main() 273{ 274 int i = ZEND_MM_ALIGNMENT; 275 int zeros = 0; 276 FILE *fp; 277 278 while (i & ~0x1) { 279 zeros++; 280 i = i >> 1; 281 } 282 283 fp = fopen("conftest.zend", "w"); 284 fprintf(fp, "%d %d\n", ZEND_MM_ALIGNMENT, zeros); 285 fclose(fp); 286 287 return 0; 288} 289]])], [ 290 LIBZEND_MM_ALIGN=`cat conftest.zend | cut -d ' ' -f 1` 291 LIBZEND_MM_ALIGN_LOG2=`cat conftest.zend | cut -d ' ' -f 2` 292 AC_DEFINE_UNQUOTED(ZEND_MM_ALIGNMENT, $LIBZEND_MM_ALIGN, [ ]) 293 AC_DEFINE_UNQUOTED(ZEND_MM_ALIGNMENT_LOG2, $LIBZEND_MM_ALIGN_LOG2, [ ]) 294], [], [ 295 dnl Cross compilation needs something here. 296 LIBZEND_MM_ALIGN=8 297]) 298 299AC_MSG_RESULT(done) 300 301AC_CHECK_FUNCS(mremap) 302 303AC_ARG_ENABLE([zend-signals], 304 [AS_HELP_STRING([--disable-zend-signals], 305 [whether to enable zend signal handling])], 306 [ZEND_SIGNALS=$enableval], 307 [ZEND_SIGNALS=yes]) 308 309AC_CHECK_FUNCS([sigaction], [], [ 310 ZEND_SIGNALS=no 311]) 312if test "$ZEND_SIGNALS" = "yes"; then 313 AC_DEFINE(ZEND_SIGNALS, 1, [Use zend signal handling]) 314 CFLAGS="$CFLAGS -DZEND_SIGNALS" 315fi 316 317AC_MSG_CHECKING(whether to enable zend signal handling) 318AC_MSG_RESULT($ZEND_SIGNALS) 319 320]) 321 322AC_MSG_CHECKING(whether /dev/urandom exists) 323if test -r "/dev/urandom" && test -c "/dev/urandom"; then 324 AC_DEFINE([HAVE_DEV_URANDOM], 1, [Define if the target system has /dev/urandom device]) 325 AC_MSG_RESULT(yes) 326else 327 AC_MSG_RESULT(no) 328fi 329 330AC_ARG_ENABLE([gcc-global-regs], 331 [AS_HELP_STRING([--disable-gcc-global-regs], 332 [whether to enable GCC global register variables])], 333 [ZEND_GCC_GLOBAL_REGS=$enableval], 334 [ZEND_GCC_GLOBAL_REGS=yes]) 335 336AC_MSG_CHECKING(for global register variables support) 337if test "$ZEND_GCC_GLOBAL_REGS" != "no"; then 338 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ 339#if defined(__GNUC__) 340# define ZEND_GCC_VERSION (__GNUC__ * 1000 + __GNUC_MINOR__) 341#else 342# define ZEND_GCC_VERSION 0 343#endif 344#if defined(__GNUC__) && ZEND_GCC_VERSION >= 4008 && defined(i386) 345# define ZEND_VM_FP_GLOBAL_REG "%esi" 346# define ZEND_VM_IP_GLOBAL_REG "%edi" 347#elif defined(__GNUC__) && ZEND_GCC_VERSION >= 4008 && defined(__x86_64__) 348# define ZEND_VM_FP_GLOBAL_REG "%r14" 349# define ZEND_VM_IP_GLOBAL_REG "%r15" 350#elif defined(__GNUC__) && ZEND_GCC_VERSION >= 4008 && defined(__powerpc64__) 351# define ZEND_VM_FP_GLOBAL_REG "r28" 352# define ZEND_VM_IP_GLOBAL_REG "r29" 353#elif defined(__IBMC__) && ZEND_GCC_VERSION >= 4002 && defined(__powerpc64__) 354# define ZEND_VM_FP_GLOBAL_REG "r28" 355# define ZEND_VM_IP_GLOBAL_REG "r29" 356#elif defined(__GNUC__) && ZEND_GCC_VERSION >= 4008 && defined(__aarch64__) 357# define ZEND_VM_FP_GLOBAL_REG "x27" 358# define ZEND_VM_IP_GLOBAL_REG "x28" 359#else 360# error "global register variables are not supported" 361#endif 362typedef int (*opcode_handler_t)(void); 363register void *FP __asm__(ZEND_VM_FP_GLOBAL_REG); 364register const opcode_handler_t *IP __asm__(ZEND_VM_IP_GLOBAL_REG); 365int emu(const opcode_handler_t *ip, void *fp) { 366 const opcode_handler_t *orig_ip = IP; 367 void *orig_fp = FP; 368 IP = ip; 369 FP = fp; 370 while ((*ip)()); 371 FP = orig_fp; 372 IP = orig_ip; 373} 374 ]], [[ 375 ]])], [ 376 ZEND_GCC_GLOBAL_REGS=yes 377 ], [ 378 ZEND_GCC_GLOBAL_REGS=no 379 ]) 380fi 381if test "$ZEND_GCC_GLOBAL_REGS" = "yes"; then 382 AC_DEFINE([HAVE_GCC_GLOBAL_REGS], 1, [Define if the target system has support for global register variables]) 383else 384 HAVE_GCC_GLOBAL_REGS=no 385fi 386AC_MSG_RESULT($ZEND_GCC_GLOBAL_REGS) 387 388dnl Check if atof() accepts NAN. 389AC_CACHE_CHECK(whether atof() accepts NAN, ac_cv_atof_accept_nan,[ 390AC_RUN_IFELSE([AC_LANG_SOURCE([[ 391#include <math.h> 392#include <stdlib.h> 393 394#ifdef HAVE_ISNAN 395#define zend_isnan(a) isnan(a) 396#elif defined(HAVE_FPCLASS) 397#define zend_isnan(a) ((fpclass(a) == FP_SNAN) || (fpclass(a) == FP_QNAN)) 398#else 399#define zend_isnan(a) 0 400#endif 401 402int main(int argc, char** argv) 403{ 404 return zend_isnan(atof("NAN")) ? 0 : 1; 405} 406]])],[ 407 ac_cv_atof_accept_nan=yes 408],[ 409 ac_cv_atof_accept_nan=no 410],[ 411 ac_cv_atof_accept_nan=no 412])]) 413if test "$ac_cv_atof_accept_nan" = "yes"; then 414 AC_DEFINE([HAVE_ATOF_ACCEPTS_NAN], 1, [whether atof() accepts NAN]) 415fi 416 417dnl Check if atof() accepts INF. 418AC_CACHE_CHECK(whether atof() accepts INF, ac_cv_atof_accept_inf,[ 419AC_RUN_IFELSE([AC_LANG_SOURCE([[ 420#include <math.h> 421#include <stdlib.h> 422 423#ifdef HAVE_ISINF 424#define zend_isinf(a) isinf(a) 425#elif defined(INFINITY) 426/* Might not work, but is required by ISO C99 */ 427#define zend_isinf(a) (((a)==INFINITY)?1:0) 428#elif defined(HAVE_FPCLASS) 429#define zend_isinf(a) ((fpclass(a) == FP_PINF) || (fpclass(a) == FP_NINF)) 430#else 431#define zend_isinf(a) 0 432#endif 433 434int main(int argc, char** argv) 435{ 436 return zend_isinf(atof("INF")) && zend_isinf(atof("-INF")) ? 0 : 1; 437} 438]])],[ 439 ac_cv_atof_accept_inf=yes 440],[ 441 ac_cv_atof_accept_inf=no 442],[ 443 ac_cv_atof_accept_inf=no 444])]) 445if test "$ac_cv_atof_accept_inf" = "yes"; then 446 AC_DEFINE([HAVE_ATOF_ACCEPTS_INF], 1, [whether atof() accepts INF]) 447fi 448 449dnl Check if HUGE_VAL == INF. 450AC_CACHE_CHECK(whether HUGE_VAL == INF, ac_cv_huge_val_inf,[ 451AC_RUN_IFELSE([AC_LANG_SOURCE([[ 452#include <math.h> 453#include <stdlib.h> 454 455#ifdef HAVE_ISINF 456#define zend_isinf(a) isinf(a) 457#elif defined(INFINITY) 458/* Might not work, but is required by ISO C99 */ 459#define zend_isinf(a) (((a)==INFINITY)?1:0) 460#elif defined(HAVE_FPCLASS) 461#define zend_isinf(a) ((fpclass(a) == FP_PINF) || (fpclass(a) == FP_NINF)) 462#else 463#define zend_isinf(a) 0 464#endif 465 466int main(int argc, char** argv) 467{ 468 return zend_isinf(HUGE_VAL) ? 0 : 1; 469} 470]])],[ 471 ac_cv_huge_val_inf=yes 472],[ 473 ac_cv_huge_val_inf=no 474],[ 475 ac_cv_huge_val_inf=yes 476])]) 477dnl This is the most probable fallback so we assume yes in case of cross compile. 478if test "$ac_cv_huge_val_inf" = "yes"; then 479 AC_DEFINE([HAVE_HUGE_VAL_INF], 1, [whether HUGE_VAL == INF]) 480fi 481 482dnl Check if HUGE_VAL + -HUGEVAL == NAN. 483AC_CACHE_CHECK(whether HUGE_VAL + -HUGEVAL == NAN, ac_cv_huge_val_nan,[ 484AC_RUN_IFELSE([AC_LANG_SOURCE([[ 485#include <math.h> 486#include <stdlib.h> 487 488#ifdef HAVE_ISNAN 489#define zend_isnan(a) isnan(a) 490#elif defined(HAVE_FPCLASS) 491#define zend_isnan(a) ((fpclass(a) == FP_SNAN) || (fpclass(a) == FP_QNAN)) 492#else 493#define zend_isnan(a) 0 494#endif 495 496int main(int argc, char** argv) 497{ 498#if defined(__sparc__) && !(__GNUC__ >= 3) 499 /* prevent bug #27830 */ 500 return 1; 501#else 502 return zend_isnan(HUGE_VAL + -HUGE_VAL) ? 0 : 1; 503#endif 504} 505]])],[ 506 ac_cv_huge_val_nan=yes 507],[ 508 ac_cv_huge_val_nan=no 509],[ 510 ac_cv_huge_val_nan=yes 511])]) 512dnl This is the most probable fallback so we assume yes in case of cross compile. 513if test "$ac_cv_huge_val_nan" = "yes"; then 514 AC_DEFINE([HAVE_HUGE_VAL_NAN], 1, [whether HUGE_VAL + -HUGEVAL == NAN]) 515fi 516 517dnl Check whether __cpuid_count is available. 518AC_CACHE_CHECK(whether __cpuid_count is available, ac_cv_cpuid_count_available, [ 519AC_LINK_IFELSE([AC_LANG_PROGRAM([[ 520 #include <cpuid.h> 521]], [[ 522 unsigned eax, ebx, ecx, edx; 523 __cpuid_count(0, 0, eax, ebx, ecx, edx); 524]])], [ 525 ac_cv_cpuid_count_available=yes 526], [ 527 ac_cv_cpuid_count_available=no 528])]) 529if test "$ac_cv_cpuid_count_available" = "yes"; then 530 AC_DEFINE([HAVE_CPUID_COUNT], 1, [whether __cpuid_count is available]) 531fi 532