xref: /PHP-7.0/Zend/acinclude.m4 (revision 854ccf50)
1dnl $Id$
2dnl
3dnl This file contains local autoconf functions.
4
5AC_DEFUN([LIBZEND_BISON_CHECK],[
6  # we only support certain bison versions;
7  # min: 2.4 (i.e. 204, major * 100 + minor for easier comparison)
8  bison_version_min="204"
9  # non-working versions, e.g. "3.0 3.2";
10  # remove "none" when introducing the first incompatible bison version an
11  # separate any following additions by spaces
12  bison_version_exclude=""
13
14  # for standalone build of Zend Engine
15  test -z "$SED" && SED=sed
16
17  bison_version=none
18  if test "$YACC"; then
19    AC_CACHE_CHECK([for bison version], php_cv_bison_version, [
20      bison_version_vars=`$YACC --version 2> /dev/null | grep 'GNU Bison' | cut -d ' ' -f 4 | $SED -e 's/\./ /g' | tr -d a-z`
21      php_cv_bison_version=invalid
22      if test -n "$bison_version_vars"; then
23        set $bison_version_vars
24        bison_version="${1}.${2}"
25        bison_version_num="`expr ${1} \* 100 + ${2}`"
26        if test $bison_version_num -ge $bison_version_min; then
27          php_cv_bison_version="$bison_version (ok)"
28          for bison_check_version in $bison_version_exclude; do
29            if test "$bison_version" = "$bison_check_version"; then
30              php_cv_bison_version=invalid
31              break
32            fi
33          done
34        fi
35      fi
36    ])
37  fi
38  case $php_cv_bison_version in
39    ""|invalid[)]
40      bison_msg="This bison version is not supported for regeneration of the Zend/PHP parsers (found: $bison_version, min: $bison_version_min, excluded: $bison_version_exclude)."
41      AC_MSG_WARN([$bison_msg])
42      YACC="exit 0;"
43      ;;
44  esac
45])
46
47AC_DEFUN([ZEND_FP_EXCEPT],[
48  AC_CACHE_CHECK(whether fp_except is defined, ac_cv_type_fp_except,[
49    AC_TRY_COMPILE([
50#include <floatingpoint.h>
51],[
52fp_except x = (fp_except) 0;
53],[
54     ac_cv_type_fp_except=yes
55],[
56     ac_cv_type_fp_except=no
57],[
58     ac_cv_type_fp_except=no
59])])
60  if test "$ac_cv_type_fp_except" = "yes"; then
61    AC_DEFINE(HAVE_FP_EXCEPT, 1, [whether floatingpoint.h defines fp_except])
62  fi
63])
64
65dnl
66dnl Check for broken sprintf()
67dnl
68AC_DEFUN([AC_ZEND_BROKEN_SPRINTF],[
69  AC_CACHE_CHECK(whether sprintf is broken, ac_cv_broken_sprintf,[
70    AC_TRY_RUN([main() {char buf[20];exit(sprintf(buf,"testing 123")!=11); }],[
71      ac_cv_broken_sprintf=no
72    ],[
73      ac_cv_broken_sprintf=yes
74    ],[
75      ac_cv_broken_sprintf=no
76    ])
77  ])
78  if test "$ac_cv_broken_sprintf" = "yes"; then
79    ac_result=1
80  else
81    ac_result=0
82  fi
83  AC_DEFINE_UNQUOTED(ZEND_BROKEN_SPRINTF, $ac_result, [Whether sprintf is broken])
84])
85
86dnl
87dnl AC_ZEND_C_BIGENDIAN
88dnl Replacement macro for AC_C_BIGENDIAN
89dnl
90AC_DEFUN([AC_ZEND_C_BIGENDIAN],
91[AC_CACHE_CHECK([whether byte ordering is bigendian], ac_cv_c_bigendian_php,
92 [
93  ac_cv_c_bigendian_php=unknown
94  AC_TRY_RUN(
95  [
96int main(void)
97{
98        short one = 1;
99        char *cp = (char *)&one;
100
101        if (*cp == 0) {
102                return(0);
103        } else {
104                return(1);
105        }
106}
107  ], [ac_cv_c_bigendian_php=yes], [ac_cv_c_bigendian_php=no], [ac_cv_c_bigendian_php=unknown])
108 ])
109 if test $ac_cv_c_bigendian_php = yes; then
110   AC_DEFINE(WORDS_BIGENDIAN, [], [Define if processor uses big-endian word])
111 fi
112])
113
114AC_DEFUN([AM_SET_LIBTOOL_VARIABLE],[
115  LIBTOOL='$(SHELL) $(top_builddir)/libtool $1'
116])
117
118dnl x87 floating point internal precision control checks
119dnl See: http://wiki.php.net/rfc/rounding
120AC_DEFUN([ZEND_CHECK_FLOAT_PRECISION],[
121  AC_MSG_CHECKING([for usable _FPU_SETCW])
122  AC_TRY_LINK([
123    #include <fpu_control.h>
124  ],[
125    fpu_control_t fpu_oldcw, fpu_cw;
126    volatile double result;
127    double a = 2877.0;
128    volatile double b = 1000000.0;
129
130    _FPU_GETCW(fpu_oldcw);
131    fpu_cw = (fpu_oldcw & ~_FPU_EXTENDED & ~_FPU_SINGLE) | _FPU_DOUBLE;
132    _FPU_SETCW(fpu_cw);
133    result = a / b;
134    _FPU_SETCW(fpu_oldcw);
135  ], [ac_cfp_have__fpu_setcw=yes], [ac_cfp_have__fpu_setcw=no])
136  if test "$ac_cfp_have__fpu_setcw" = "yes" ; then
137    AC_DEFINE(HAVE__FPU_SETCW, 1, [whether _FPU_SETCW is present and usable])
138    AC_MSG_RESULT(yes)
139  else
140    AC_MSG_RESULT(no)
141  fi
142
143  AC_MSG_CHECKING([for usable fpsetprec])
144  AC_TRY_LINK([
145    #include <machine/ieeefp.h>
146  ],[
147    fp_prec_t fpu_oldprec;
148    volatile double result;
149    double a = 2877.0;
150    volatile double b = 1000000.0;
151
152    fpu_oldprec = fpgetprec();
153    fpsetprec(FP_PD);
154    result = a / b;
155    fpsetprec(fpu_oldprec);
156  ], [ac_cfp_have_fpsetprec=yes], [ac_cfp_have_fpsetprec=no])
157  if test "$ac_cfp_have_fpsetprec" = "yes" ; then
158    AC_DEFINE(HAVE_FPSETPREC, 1, [whether fpsetprec is present and usable])
159    AC_MSG_RESULT(yes)
160  else
161    AC_MSG_RESULT(no)
162  fi
163
164  AC_MSG_CHECKING([for usable _controlfp])
165  AC_TRY_LINK([
166    #include <float.h>
167  ],[
168    unsigned int fpu_oldcw;
169    volatile double result;
170    double a = 2877.0;
171    volatile double b = 1000000.0;
172
173    fpu_oldcw = _controlfp(0, 0);
174    _controlfp(_PC_53, _MCW_PC);
175    result = a / b;
176    _controlfp(fpu_oldcw, _MCW_PC);
177  ], [ac_cfp_have__controlfp=yes], [ac_cfp_have__controlfp=no])
178  if test "$ac_cfp_have__controlfp" = "yes" ; then
179    AC_DEFINE(HAVE__CONTROLFP, 1, [whether _controlfp is present usable])
180    AC_MSG_RESULT(yes)
181  else
182    AC_MSG_RESULT(no)
183  fi
184
185  AC_MSG_CHECKING([for usable _controlfp_s])
186  AC_TRY_LINK([
187   #include <float.h>
188  ],[
189    unsigned int fpu_oldcw, fpu_cw;
190    volatile double result;
191    double a = 2877.0;
192    volatile double b = 1000000.0;
193
194    _controlfp_s(&fpu_cw, 0, 0);
195    fpu_oldcw = fpu_cw;
196    _controlfp_s(&fpu_cw, _PC_53, _MCW_PC);
197    result = a / b;
198    _controlfp_s(&fpu_cw, fpu_oldcw, _MCW_PC);
199  ], [ac_cfp_have__controlfp_s=yes], [ac_cfp_have__controlfp_s=no])
200  if test "$ac_cfp_have__controlfp_s" = "yes" ; then
201    AC_DEFINE(HAVE__CONTROLFP_S, 1, [whether _controlfp_s is present and usable])
202    AC_MSG_RESULT(yes)
203  else
204    AC_MSG_RESULT(no)
205  fi
206
207  AC_MSG_CHECKING([whether FPU control word can be manipulated by inline assembler])
208  AC_TRY_LINK([
209    /* nothing */
210  ],[
211    unsigned int oldcw, cw;
212    volatile double result;
213    double a = 2877.0;
214    volatile double b = 1000000.0;
215
216    __asm__ __volatile__ ("fnstcw %0" : "=m" (*&oldcw));
217    cw = (oldcw & ~0x0 & ~0x300) | 0x200;
218    __asm__ __volatile__ ("fldcw %0" : : "m" (*&cw));
219
220    result = a / b;
221
222    __asm__ __volatile__ ("fldcw %0" : : "m" (*&oldcw));
223  ], [ac_cfp_have_fpu_inline_asm_x86=yes], [ac_cfp_have_fpu_inline_asm_x86=no])
224  if test "$ac_cfp_have_fpu_inline_asm_x86" = "yes" ; then
225    AC_DEFINE(HAVE_FPU_INLINE_ASM_X86, 1, [whether FPU control word can be manipulated by inline assembler])
226    AC_MSG_RESULT(yes)
227  else
228    AC_MSG_RESULT(no)
229  fi
230])
231