xref: /PHP-5.5/Zend/Zend.m4 (revision dab17da3)
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_MSG_CHECKING([virtual machine dispatch method])
180AC_MSG_RESULT($PHP_ZEND_VM)
181
182AC_MSG_CHECKING(whether to enable thread-safety)
183AC_MSG_RESULT($ZEND_MAINTAINER_ZTS)
184
185AC_MSG_CHECKING(whether to enable inline optimization for GCC)
186AC_MSG_RESULT($ZEND_INLINE_OPTIMIZATION)
187
188AC_MSG_CHECKING(whether to enable Zend debugging)
189AC_MSG_RESULT($ZEND_DEBUG)
190
191case $PHP_ZEND_VM in
192  SWITCH)
193    AC_DEFINE(ZEND_VM_KIND,ZEND_VM_KIND_SWITCH,[virtual machine dispatch method])
194    ;;
195  GOTO)
196    AC_DEFINE(ZEND_VM_KIND,ZEND_VM_KIND_GOTO,[virtual machine dispatch method])
197    ;;
198  *)
199    PHP_ZEND_VM=CALL
200    AC_DEFINE(ZEND_VM_KIND,ZEND_VM_KIND_CALL,[virtual machine dispatch method])
201    ;;
202esac
203
204if test "$ZEND_DEBUG" = "yes"; then
205  AC_DEFINE(ZEND_DEBUG,1,[ ])
206  echo " $CFLAGS" | grep ' -g' >/dev/null || DEBUG_CFLAGS="-g"
207  if test "$CFLAGS" = "-g -O2"; then
208  	CFLAGS=-g
209  fi
210  test -n "$GCC" && DEBUG_CFLAGS="$DEBUG_CFLAGS -Wall"
211  test -n "$GCC" && test "$USE_MAINTAINER_MODE" = "yes" && \
212    DEBUG_CFLAGS="$DEBUG_CFLAGS -Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations"
213else
214  AC_DEFINE(ZEND_DEBUG,0,[ ])
215fi
216
217test -n "$DEBUG_CFLAGS" && CFLAGS="$CFLAGS $DEBUG_CFLAGS"
218
219if test "$ZEND_MAINTAINER_ZTS" = "yes"; then
220  AC_DEFINE(ZTS,1,[ ])
221  CFLAGS="$CFLAGS -DZTS"
222  LIBZEND_CPLUSPLUS_CHECKS
223fi
224
225changequote({,})
226if test -n "$GCC" && test "$ZEND_INLINE_OPTIMIZATION" != "yes"; then
227  INLINE_CFLAGS=`echo $ac_n "$CFLAGS $ac_c" | sed s/-O[0-9s]*//`
228else
229  INLINE_CFLAGS="$CFLAGS"
230fi
231changequote([,])
232
233AC_C_INLINE
234
235AC_SUBST(INLINE_CFLAGS)
236
237AC_MSG_CHECKING(target system is Darwin)
238if echo "$target" | grep "darwin" > /dev/null; then
239  AC_DEFINE([DARWIN], 1, [Define if the target system is darwin])
240  AC_MSG_RESULT(yes)
241else
242  AC_MSG_RESULT(no)
243fi
244
245dnl test and set the alignment define for ZEND_MM
246dnl this also does the logarithmic test for ZEND_MM.
247AC_MSG_CHECKING(for MM alignment and log values)
248
249AC_TRY_RUN([
250#include <stdio.h>
251
252typedef union _mm_align_test {
253  void *ptr;
254  double dbl;
255  long lng;
256} mm_align_test;
257
258#if (defined (__GNUC__) && __GNUC__ >= 2)
259#define ZEND_MM_ALIGNMENT (__alignof__ (mm_align_test))
260#else
261#define ZEND_MM_ALIGNMENT (sizeof(mm_align_test))
262#endif
263
264int main()
265{
266  int i = ZEND_MM_ALIGNMENT;
267  int zeros = 0;
268  FILE *fp;
269
270  while (i & ~0x1) {
271    zeros++;
272    i = i >> 1;
273  }
274
275  fp = fopen("conftest.zend", "w");
276  fprintf(fp, "%d %d\n", ZEND_MM_ALIGNMENT, zeros);
277  fclose(fp);
278
279  exit(0);
280}
281], [
282  LIBZEND_MM_ALIGN=`cat conftest.zend | cut -d ' ' -f 1`
283  LIBZEND_MM_ALIGN_LOG2=`cat conftest.zend | cut -d ' ' -f 2`
284  AC_DEFINE_UNQUOTED(ZEND_MM_ALIGNMENT, $LIBZEND_MM_ALIGN, [ ])
285  AC_DEFINE_UNQUOTED(ZEND_MM_ALIGNMENT_LOG2, $LIBZEND_MM_ALIGN_LOG2, [ ])
286], [], [
287  dnl cross-compile needs something here
288  LIBZEND_MM_ALIGN=8
289])
290
291AC_MSG_RESULT(done)
292
293dnl test for memory allocation using mmap(MAP_ANON)
294AC_MSG_CHECKING(for memory allocation using mmap(MAP_ANON))
295
296AC_TRY_RUN([
297#include <sys/types.h>
298#include <sys/stat.h>
299#include <fcntl.h>
300#include <sys/mman.h>
301#include <stdlib.h>
302#include <stdio.h>
303#ifndef MAP_ANON
304# ifdef MAP_ANONYMOUS
305#  define MAP_ANON MAP_ANONYMOUS
306# endif
307#endif
308#ifndef MREMAP_MAYMOVE
309# define MREMAP_MAYMOVE 0
310#endif
311#ifndef MAP_FAILED
312# define MAP_FAILED ((void*)-1)
313#endif
314
315#define SEG_SIZE (256*1024)
316
317int main()
318{
319	void *seg = mmap(NULL, SEG_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0);
320	if (seg == MAP_FAILED) {
321		return 1;
322	}
323	if (munmap(seg, SEG_SIZE) != 0) {
324		return 2;
325	}
326	return 0;
327}
328], [
329  AC_DEFINE([HAVE_MEM_MMAP_ANON], 1, [Define if the target system has support for memory allocation using mmap(MAP_ANON)])
330  AC_MSG_RESULT(yes)
331], [
332  AC_MSG_RESULT(no)
333], [
334  dnl cross-compile needs something here
335  AC_MSG_RESULT(no)
336])
337
338dnl test for memory allocation using mmap("/dev/zero")
339AC_MSG_CHECKING(for memory allocation using mmap("/dev/zero"))
340
341AC_TRY_RUN([
342#include <sys/types.h>
343#include <sys/stat.h>
344#include <fcntl.h>
345#include <sys/mman.h>
346#include <stdlib.h>
347#include <stdio.h>
348#ifndef MAP_ANON
349# ifdef MAP_ANONYMOUS
350#  define MAP_ANON MAP_ANONYMOUS
351# endif
352#endif
353#ifndef MREMAP_MAYMOVE
354# define MREMAP_MAYMOVE 0
355#endif
356#ifndef MAP_FAILED
357# define MAP_FAILED ((void*)-1)
358#endif
359
360#define SEG_SIZE (256*1024)
361
362int main()
363{
364	int fd;
365	void *seg;
366
367	fd = open("/dev/zero", O_RDWR, S_IRUSR | S_IWUSR);
368	if (fd < 0) {
369		return 1;
370	}
371	seg = mmap(NULL, SEG_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
372	if (seg == MAP_FAILED) {
373		return 2;
374	}
375	if (munmap(seg, SEG_SIZE) != 0) {
376		return 3;
377	}
378	if (close(fd) != 0) {
379		return 4;
380	}
381	return 0;
382}
383], [
384  AC_DEFINE([HAVE_MEM_MMAP_ZERO], 1, [Define if the target system has support for memory allocation using mmap("/dev/zero")])
385  AC_MSG_RESULT(yes)
386], [
387  AC_MSG_RESULT(no)
388], [
389  dnl cross-compile needs something here
390  AC_MSG_RESULT(no)
391])
392
393AC_CHECK_FUNCS(mremap)
394
395
396AC_ARG_ENABLE(zend-signals,
397[  --enable-zend-signals   Use zend signal handling],[
398  ZEND_SIGNALS=$enableval
399],[
400  ZEND_SIGNALS=no
401])
402
403AC_CHECK_FUNC(sigaction, [
404	AC_DEFINE(HAVE_SIGACTION, 1, [Whether sigaction() is available])
405], [
406	ZEND_SIGNALS=no
407])
408if test "$ZEND_SIGNALS" = "yes"; then
409	AC_DEFINE(ZEND_SIGNALS, 1, [Use zend signal handling])
410	CFLAGS="$CFLAGS -DZEND_SIGNALS"
411fi
412
413AC_MSG_CHECKING(whether to enable zend signal handling)
414AC_MSG_RESULT($ZEND_SIGNALS)
415
416])
417
418AC_DEFUN([LIBZEND_CPLUSPLUS_CHECKS],[
419
420])
421
422AC_MSG_CHECKING(whether /dev/urandom exists)
423if test -r "/dev/urandom" && test -c "/dev/urandom"; then
424  AC_DEFINE([HAVE_DEV_URANDOM], 1, [Define if the target system has /dev/urandom device])
425  AC_MSG_RESULT(yes)
426else
427  AC_MSG_RESULT(no)
428  AC_MSG_CHECKING(whether /dev/arandom exists)
429  if test -r "/dev/arandom" && test -c "/dev/arandom"; then
430    AC_DEFINE([HAVE_DEV_ARANDOM], 1, [Define if the target system has /dev/arandom device])
431    AC_MSG_RESULT(yes)
432  else
433    AC_MSG_RESULT(no)
434  fi
435fi
436