xref: /PHP-7.3/Zend/Zend.m4 (revision aa405b7d)
1dnl
2dnl This file contains Zend specific autoconf functions.
3dnl
4
5AC_DEFUN([LIBZEND_CHECK_INT_TYPE],[
6AC_MSG_CHECKING(for $1)
7AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
8#if HAVE_SYS_TYPES_H
9#include <sys/types.h>
10#endif
11#if HAVE_INTTYPES_H
12#include <inttypes.h>
13#elif HAVE_STDINT_H
14#include <stdint.h>
15#endif]],
16[[if (($1 *) 0)
17  return 0;
18if (sizeof ($1))
19  return 0;
20]])],[
21  AC_DEFINE_UNQUOTED([HAVE_]translit($1,a-z_-,A-Z__), 1,[Define if $1 type is present. ])
22  AC_MSG_RESULT(yes)
23], [AC_MSG_RESULT(no)
24])dnl
25])
26
27AC_DEFUN([LIBZEND_BASIC_CHECKS],[
28
29AC_REQUIRE([AC_PROG_YACC])
30AC_REQUIRE([AC_PROG_CC])
31AC_REQUIRE([AC_PROG_CC_C_O])
32AC_REQUIRE([AC_HEADER_STDC])
33
34LIBZEND_BISON_CHECK
35
36dnl Ugly hack to get around a problem with gcc on AIX.
37if test "$CC" = "gcc" -a "$ac_cv_prog_cc_g" = "yes" -a \
38   "`uname -sv`" = "AIX 4"; then
39	CFLAGS=`echo $CFLAGS | sed -e 's/-g//'`
40fi
41
42dnl Hack to work around a Mac OS X cpp problem
43dnl Known versions needing this workaround are 5.3 and 5.4
44if test "$ac_cv_prog_gcc" = "yes" -a "`uname -s`" = "Rhapsody"; then
45        CPPFLAGS="$CPPFLAGS -traditional-cpp"
46fi
47
48AC_CHECK_HEADERS(
49inttypes.h \
50stdint.h \
51limits.h \
52malloc.h \
53string.h \
54unistd.h \
55stdarg.h \
56sys/types.h \
57sys/time.h \
58signal.h \
59unix.h \
60stdlib.h \
61cpuid.h \
62dlfcn.h)
63
64AC_TYPE_SIZE_T
65
66AC_DEFUN([LIBZEND_LIBDL_CHECKS],[
67AC_CHECK_LIB(dl, dlopen, [LIBS="-ldl $LIBS"])
68AC_CHECK_FUNC(dlopen,[AC_DEFINE(HAVE_LIBDL, 1,[ ])])
69])
70
71AC_DEFUN([LIBZEND_DLSYM_CHECK],[
72dnl
73dnl Ugly hack to check if dlsym() requires a leading underscore in symbol name.
74dnl
75AC_MSG_CHECKING([whether dlsym() requires a leading underscore in symbol names])
76_LT_AC_TRY_DLOPEN_SELF([
77  AC_MSG_RESULT(no)
78], [
79  AC_MSG_RESULT(yes)
80  AC_DEFINE(DLSYM_NEEDS_UNDERSCORE, 1, [Define if dlsym() requires a leading underscore in symbol names. ])
81], [
82  AC_MSG_RESULT(no)
83], [])
84])
85
86dnl This is required for QNX and may be some BSD derived systems
87AC_CHECK_TYPE( uint, unsigned int )
88AC_CHECK_TYPE( ulong, unsigned long )
89
90dnl Check if int32_t and uint32_t are defined
91LIBZEND_CHECK_INT_TYPE(int32_t)
92LIBZEND_CHECK_INT_TYPE(uint32_t)
93
94dnl Checks for library functions.
95AC_FUNC_VPRINTF
96AC_FUNC_MEMCMP
97AC_FUNC_ALLOCA
98AC_CHECK_FUNCS(memcpy strdup getpid kill strtod strtol finite fpclass sigsetjmp)
99AC_ZEND_BROKEN_SPRINTF
100
101AC_CHECK_DECLS([isfinite, isnan, isinf], [], [], [[#include <math.h>]])
102
103ZEND_FP_EXCEPT
104
105ZEND_CHECK_FLOAT_PRECISION
106
107dnl test whether double cast to long preserves least significant bits
108AC_MSG_CHECKING(whether double cast to long preserves least significant bits)
109
110AC_RUN_IFELSE([AC_LANG_SOURCE([[
111#include <limits.h>
112
113int main()
114{
115	if (sizeof(long) == 4) {
116		double d = (double) LONG_MIN * LONG_MIN + 2e9;
117
118		if ((long) d == 2e9 && (long) -d == -2e9) {
119			return 0;
120		}
121	} else if (sizeof(long) == 8) {
122		double correct = 18e18 - ((double) LONG_MIN * -2); /* Subtract ULONG_MAX + 1 */
123
124		if ((long) 18e18 == correct) { /* On 64-bit, only check between LONG_MAX and ULONG_MAX */
125			return 0;
126		}
127	}
128	return 1;
129}
130]])], [
131  AC_DEFINE([ZEND_DVAL_TO_LVAL_CAST_OK], 1, [Define if double cast to long preserves least significant bits])
132  AC_MSG_RESULT(yes)
133], [
134  AC_MSG_RESULT(no)
135], [
136  AC_MSG_RESULT(no)
137])
138
139])
140
141AC_DEFUN([LIBZEND_ENABLE_DEBUG],[
142
143AC_ARG_ENABLE(debug,
144[  --enable-debug          Compile with debugging symbols],[
145  ZEND_DEBUG=$enableval
146],[
147  ZEND_DEBUG=no
148])
149
150])
151
152AC_DEFUN([LIBZEND_OTHER_CHECKS],[
153
154AC_ARG_ENABLE(maintainer-zts,
155[  --enable-maintainer-zts Enable thread safety - for code maintainers only!!],[
156  ZEND_MAINTAINER_ZTS=$enableval
157],[
158  ZEND_MAINTAINER_ZTS=no
159])
160
161AC_ARG_ENABLE(inline-optimization,
162[  --disable-inline-optimization
163                          If building zend_execute.lo fails, try this switch],[
164  ZEND_INLINE_OPTIMIZATION=$enableval
165],[
166  ZEND_INLINE_OPTIMIZATION=yes
167])
168
169AC_MSG_CHECKING(whether to enable thread-safety)
170AC_MSG_RESULT($ZEND_MAINTAINER_ZTS)
171
172AC_MSG_CHECKING(whether to enable inline optimization for GCC)
173AC_MSG_RESULT($ZEND_INLINE_OPTIMIZATION)
174
175AC_MSG_CHECKING(whether to enable Zend debugging)
176AC_MSG_RESULT($ZEND_DEBUG)
177
178if test "$ZEND_DEBUG" = "yes"; then
179  AC_DEFINE(ZEND_DEBUG,1,[ ])
180  echo " $CFLAGS" | grep ' -g' >/dev/null || DEBUG_CFLAGS="-g"
181  if test "$CFLAGS" = "-g -O2"; then
182  	CFLAGS=-g
183  fi
184  test -n "$GCC" && DEBUG_CFLAGS="$DEBUG_CFLAGS -Wall"
185  test -n "$GCC" && test "$USE_MAINTAINER_MODE" = "yes" && \
186    DEBUG_CFLAGS="$DEBUG_CFLAGS -Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations"
187else
188  AC_DEFINE(ZEND_DEBUG,0,[ ])
189fi
190
191test -n "$DEBUG_CFLAGS" && CFLAGS="$CFLAGS $DEBUG_CFLAGS"
192
193if test "$ZEND_MAINTAINER_ZTS" = "yes"; then
194  AC_DEFINE(ZTS,1,[ ])
195  CFLAGS="$CFLAGS -DZTS"
196fi
197
198changequote({,})
199if test -n "$GCC" && test "$ZEND_INLINE_OPTIMIZATION" != "yes"; then
200  INLINE_CFLAGS=`echo $ac_n "$CFLAGS $ac_c" | sed s/-O[0-9s]*//`
201else
202  INLINE_CFLAGS="$CFLAGS"
203fi
204changequote([,])
205
206AC_C_INLINE
207
208AC_SUBST(INLINE_CFLAGS)
209
210AC_MSG_CHECKING(target system is Darwin)
211if echo "$target" | grep "darwin" > /dev/null; then
212  AC_DEFINE([DARWIN], 1, [Define if the target system is darwin])
213  AC_MSG_RESULT(yes)
214else
215  AC_MSG_RESULT(no)
216fi
217
218dnl test and set the alignment define for ZEND_MM
219dnl this also does the logarithmic test for ZEND_MM.
220AC_MSG_CHECKING(for MM alignment and log values)
221
222AC_RUN_IFELSE([AC_LANG_SOURCE([[
223#include <stdio.h>
224
225typedef union _mm_align_test {
226  void *ptr;
227  double dbl;
228  long lng;
229} mm_align_test;
230
231#if (defined (__GNUC__) && __GNUC__ >= 2)
232#define ZEND_MM_ALIGNMENT (__alignof__ (mm_align_test))
233#else
234#define ZEND_MM_ALIGNMENT (sizeof(mm_align_test))
235#endif
236
237int main()
238{
239  int i = ZEND_MM_ALIGNMENT;
240  int zeros = 0;
241  FILE *fp;
242
243  while (i & ~0x1) {
244    zeros++;
245    i = i >> 1;
246  }
247
248  fp = fopen("conftest.zend", "w");
249  fprintf(fp, "%d %d\n", ZEND_MM_ALIGNMENT, zeros);
250  fclose(fp);
251
252  return 0;
253}
254]])], [
255  LIBZEND_MM_ALIGN=`cat conftest.zend | cut -d ' ' -f 1`
256  LIBZEND_MM_ALIGN_LOG2=`cat conftest.zend | cut -d ' ' -f 2`
257  AC_DEFINE_UNQUOTED(ZEND_MM_ALIGNMENT, $LIBZEND_MM_ALIGN, [ ])
258  AC_DEFINE_UNQUOTED(ZEND_MM_ALIGNMENT_LOG2, $LIBZEND_MM_ALIGN_LOG2, [ ])
259], [], [
260  dnl cross-compile needs something here
261  LIBZEND_MM_ALIGN=8
262])
263
264AC_MSG_RESULT(done)
265
266dnl test for memory allocation using mmap(MAP_ANON)
267AC_MSG_CHECKING(for memory allocation using mmap(MAP_ANON))
268
269AC_RUN_IFELSE([AC_LANG_SOURCE([[
270#include <sys/types.h>
271#include <sys/stat.h>
272#include <fcntl.h>
273#include <sys/mman.h>
274#include <stdlib.h>
275#include <stdio.h>
276#ifndef MAP_ANON
277# ifdef MAP_ANONYMOUS
278#  define MAP_ANON MAP_ANONYMOUS
279# endif
280#endif
281#ifndef MREMAP_MAYMOVE
282# define MREMAP_MAYMOVE 0
283#endif
284#ifndef MAP_FAILED
285# define MAP_FAILED ((void*)-1)
286#endif
287
288#define SEG_SIZE (256*1024)
289
290int main()
291{
292	void *seg = mmap(NULL, SEG_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0);
293	if (seg == MAP_FAILED) {
294		return 1;
295	}
296	if (munmap(seg, SEG_SIZE) != 0) {
297		return 2;
298	}
299	return 0;
300}
301]])], [
302  AC_DEFINE([HAVE_MEM_MMAP_ANON], 1, [Define if the target system has support for memory allocation using mmap(MAP_ANON)])
303  AC_MSG_RESULT(yes)
304], [
305  AC_MSG_RESULT(no)
306], [
307  dnl cross-compile needs something here
308  AC_MSG_RESULT(no)
309])
310
311dnl test for memory allocation using mmap("/dev/zero")
312AC_MSG_CHECKING(for memory allocation using mmap("/dev/zero"))
313
314AC_RUN_IFELSE([AC_LANG_SOURCE([[
315#include <sys/types.h>
316#include <sys/stat.h>
317#include <fcntl.h>
318#include <sys/mman.h>
319#include <stdlib.h>
320#include <stdio.h>
321#include <unistd.h>
322#ifndef MAP_ANON
323# ifdef MAP_ANONYMOUS
324#  define MAP_ANON MAP_ANONYMOUS
325# endif
326#endif
327#ifndef MREMAP_MAYMOVE
328# define MREMAP_MAYMOVE 0
329#endif
330#ifndef MAP_FAILED
331# define MAP_FAILED ((void*)-1)
332#endif
333
334#define SEG_SIZE (256*1024)
335
336int main()
337{
338	int fd;
339	void *seg;
340
341	fd = open("/dev/zero", O_RDWR, S_IRUSR | S_IWUSR);
342	if (fd < 0) {
343		return 1;
344	}
345	seg = mmap(NULL, SEG_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
346	if (seg == MAP_FAILED) {
347		return 2;
348	}
349	if (munmap(seg, SEG_SIZE) != 0) {
350		return 3;
351	}
352	if (close(fd) != 0) {
353		return 4;
354	}
355	return 0;
356}
357]])], [
358  AC_DEFINE([HAVE_MEM_MMAP_ZERO], 1, [Define if the target system has support for memory allocation using mmap("/dev/zero")])
359  AC_MSG_RESULT(yes)
360], [
361  AC_MSG_RESULT(no)
362], [
363  dnl cross-compile needs something here
364  AC_MSG_RESULT(no)
365])
366
367AC_CHECK_FUNCS(mremap)
368
369
370AC_ARG_ENABLE(zend-signals,
371[  --disable-zend-signals  whether to enable zend signal handling],[
372  ZEND_SIGNALS=$enableval
373],[
374  ZEND_SIGNALS=yes
375])
376
377AC_CHECK_FUNC(sigaction, [
378	AC_DEFINE(HAVE_SIGACTION, 1, [Whether sigaction() is available])
379], [
380	ZEND_SIGNALS=no
381])
382if test "$ZEND_SIGNALS" = "yes"; then
383	AC_DEFINE(ZEND_SIGNALS, 1, [Use zend signal handling])
384	CFLAGS="$CFLAGS -DZEND_SIGNALS"
385fi
386
387AC_MSG_CHECKING(whether to enable zend signal handling)
388AC_MSG_RESULT($ZEND_SIGNALS)
389
390])
391
392AC_MSG_CHECKING(whether /dev/urandom exists)
393if test -r "/dev/urandom" && test -c "/dev/urandom"; then
394  AC_DEFINE([HAVE_DEV_URANDOM], 1, [Define if the target system has /dev/urandom device])
395  AC_MSG_RESULT(yes)
396else
397  AC_MSG_RESULT(no)
398fi
399
400AC_MSG_CHECKING(whether /dev/arandom exists)
401if test -r "/dev/arandom" && test -c "/dev/arandom"; then
402  AC_DEFINE([HAVE_DEV_ARANDOM], 1, [Define if the target system has /dev/arandom device])
403  AC_MSG_RESULT(yes)
404else
405  AC_MSG_RESULT(no)
406fi
407
408AC_ARG_ENABLE(gcc-global-regs,
409[  --disable-gcc-global-regs
410                          whether to enable GCC global register variables],[
411  ZEND_GCC_GLOBAL_REGS=$enableval
412],[
413  ZEND_GCC_GLOBAL_REGS=yes
414])
415AC_MSG_CHECKING(for global register variables support)
416if test "$ZEND_GCC_GLOBAL_REGS" != "no"; then
417  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
418#if defined(__GNUC__)
419# define ZEND_GCC_VERSION (__GNUC__ * 1000 + __GNUC_MINOR__)
420#else
421# define ZEND_GCC_VERSION 0
422#endif
423#if defined(__GNUC__) && ZEND_GCC_VERSION >= 4008 && defined(i386)
424# define ZEND_VM_FP_GLOBAL_REG "%esi"
425# define ZEND_VM_IP_GLOBAL_REG "%edi"
426#elif defined(__GNUC__) && ZEND_GCC_VERSION >= 4008 && defined(__x86_64__)
427# define ZEND_VM_FP_GLOBAL_REG "%r14"
428# define ZEND_VM_IP_GLOBAL_REG "%r15"
429#elif defined(__GNUC__) && ZEND_GCC_VERSION >= 4008 && defined(__powerpc64__)
430# define ZEND_VM_FP_GLOBAL_REG "r28"
431# define ZEND_VM_IP_GLOBAL_REG "r29"
432#elif defined(__IBMC__) && ZEND_GCC_VERSION >= 4002 && defined(__powerpc64__)
433# define ZEND_VM_FP_GLOBAL_REG "r28"
434# define ZEND_VM_IP_GLOBAL_REG "r29"
435#else
436# error "global register variables are not supported"
437#endif
438typedef int (*opcode_handler_t)(void);
439register void *FP  __asm__(ZEND_VM_FP_GLOBAL_REG);
440register const opcode_handler_t *IP __asm__(ZEND_VM_IP_GLOBAL_REG);
441int emu(const opcode_handler_t *ip, void *fp) {
442	const opcode_handler_t *orig_ip = IP;
443	void *orig_fp = FP;
444	IP = ip;
445	FP = fp;
446	while ((*ip)());
447	FP = orig_fp;
448	IP = orig_ip;
449}
450  ]], [[
451  ]])], [
452    ZEND_GCC_GLOBAL_REGS=yes
453  ], [
454    ZEND_GCC_GLOBAL_REGS=no
455  ])
456fi
457if test "$ZEND_GCC_GLOBAL_REGS" = "yes"; then
458  AC_DEFINE([HAVE_GCC_GLOBAL_REGS], 1, [Define if the target system has support for global register variables])
459else
460  HAVE_GCC_GLOBAL_REGS=no
461fi
462AC_MSG_RESULT($ZEND_GCC_GLOBAL_REGS)
463
464dnl
465dnl Check if atof() accepts NAN
466dnl
467AC_CACHE_CHECK(whether atof() accepts NAN, ac_cv_atof_accept_nan,[
468AC_RUN_IFELSE([AC_LANG_SOURCE([[
469#include <math.h>
470#include <stdlib.h>
471
472#ifdef HAVE_ISNAN
473#define zend_isnan(a) isnan(a)
474#elif defined(HAVE_FPCLASS)
475#define zend_isnan(a) ((fpclass(a) == FP_SNAN) || (fpclass(a) == FP_QNAN))
476#else
477#define zend_isnan(a) 0
478#endif
479
480int main(int argc, char** argv)
481{
482	return zend_isnan(atof("NAN")) ? 0 : 1;
483}
484]])],[
485  ac_cv_atof_accept_nan=yes
486],[
487  ac_cv_atof_accept_nan=no
488],[
489  ac_cv_atof_accept_nan=no
490])])
491if test "$ac_cv_atof_accept_nan" = "yes"; then
492  AC_DEFINE([HAVE_ATOF_ACCEPTS_NAN], 1, [whether atof() accepts NAN])
493fi
494
495dnl
496dnl Check if atof() accepts INF
497dnl
498AC_CACHE_CHECK(whether atof() accepts INF, ac_cv_atof_accept_inf,[
499AC_RUN_IFELSE([AC_LANG_SOURCE([[
500#include <math.h>
501#include <stdlib.h>
502
503#ifdef HAVE_ISINF
504#define zend_isinf(a) isinf(a)
505#elif defined(INFINITY)
506/* Might not work, but is required by ISO C99 */
507#define zend_isinf(a) (((a)==INFINITY)?1:0)
508#elif defined(HAVE_FPCLASS)
509#define zend_isinf(a) ((fpclass(a) == FP_PINF) || (fpclass(a) == FP_NINF))
510#else
511#define zend_isinf(a) 0
512#endif
513
514int main(int argc, char** argv)
515{
516	return zend_isinf(atof("INF")) && zend_isinf(atof("-INF")) ? 0 : 1;
517}
518]])],[
519  ac_cv_atof_accept_inf=yes
520],[
521  ac_cv_atof_accept_inf=no
522],[
523  ac_cv_atof_accept_inf=no
524])])
525if test "$ac_cv_atof_accept_inf" = "yes"; then
526  AC_DEFINE([HAVE_ATOF_ACCEPTS_INF], 1, [whether atof() accepts INF])
527fi
528
529dnl
530dnl Check if HUGE_VAL == INF
531dnl
532AC_CACHE_CHECK(whether HUGE_VAL == INF, ac_cv_huge_val_inf,[
533AC_RUN_IFELSE([AC_LANG_SOURCE([[
534#include <math.h>
535#include <stdlib.h>
536
537#ifdef HAVE_ISINF
538#define zend_isinf(a) isinf(a)
539#elif defined(INFINITY)
540/* Might not work, but is required by ISO C99 */
541#define zend_isinf(a) (((a)==INFINITY)?1:0)
542#elif defined(HAVE_FPCLASS)
543#define zend_isinf(a) ((fpclass(a) == FP_PINF) || (fpclass(a) == FP_NINF))
544#else
545#define zend_isinf(a) 0
546#endif
547
548int main(int argc, char** argv)
549{
550	return zend_isinf(HUGE_VAL) ? 0 : 1;
551}
552]])],[
553  ac_cv_huge_val_inf=yes
554],[
555  ac_cv_huge_val_inf=no
556],[
557  ac_cv_huge_val_inf=yes
558])])
559dnl This is the most probable fallback so we assume yes in case of cross compile.
560if test "$ac_cv_huge_val_inf" = "yes"; then
561  AC_DEFINE([HAVE_HUGE_VAL_INF], 1, [whether HUGE_VAL == INF])
562fi
563
564dnl
565dnl Check if HUGE_VAL + -HUGEVAL == NAN
566dnl
567AC_CACHE_CHECK(whether HUGE_VAL + -HUGEVAL == NAN, ac_cv_huge_val_nan,[
568AC_RUN_IFELSE([AC_LANG_SOURCE([[
569#include <math.h>
570#include <stdlib.h>
571
572#ifdef HAVE_ISNAN
573#define zend_isnan(a) isnan(a)
574#elif defined(HAVE_FPCLASS)
575#define zend_isnan(a) ((fpclass(a) == FP_SNAN) || (fpclass(a) == FP_QNAN))
576#else
577#define zend_isnan(a) 0
578#endif
579
580int main(int argc, char** argv)
581{
582#if defined(__sparc__) && !(__GNUC__ >= 3)
583	/* prevent bug #27830 */
584	return 1;
585#else
586	return zend_isnan(HUGE_VAL + -HUGE_VAL) ? 0 : 1;
587#endif
588}
589]])],[
590  ac_cv_huge_val_nan=yes
591],[
592  ac_cv_huge_val_nan=no
593],[
594  ac_cv_huge_val_nan=yes
595])])
596dnl This is the most probable fallback so we assume yes in case of cross compile.
597if test "$ac_cv_huge_val_nan" = "yes"; then
598  AC_DEFINE([HAVE_HUGE_VAL_NAN], 1, [whether HUGE_VAL + -HUGEVAL == NAN])
599fi
600
601dnl
602dnl Check whether __cpuid_count is available
603dnl
604AC_CACHE_CHECK(whether __cpuid_count is available, ac_cv_cpuid_count_available, [
605AC_LINK_IFELSE([AC_LANG_PROGRAM([[
606  #include <cpuid.h>
607]], [[
608  unsigned eax, ebx, ecx, edx;
609  __cpuid_count(0, 0, eax, ebx, ecx, edx);
610]])], [
611  ac_cv_cpuid_count_available=yes
612], [
613  ac_cv_cpuid_count_available=no
614])])
615if test "$ac_cv_cpuid_count_available" = "yes"; then
616  AC_DEFINE([HAVE_CPUID_COUNT], 1, [whether __cpuid_count is available])
617fi
618