Zend.m4 9.6 KB

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