1 dnl Generated headers with pre-defined types, structs, consts and decls.
2 PSI_STDINC=$PHP_PSI_SRCDIR/php_psi_stdinc.h
3 PSI_STDTYPES=$PHP_PSI_SRCDIR/php_psi_stdtypes.h
4 PSI_TYPES=$PHP_PSI_SRCDIR/php_psi_types.h
5 PSI_STRUCTS=$PHP_PSI_SRCDIR/php_psi_structs.h
6 PSI_UNIONS=$PHP_PSI_SRCDIR/php_psi_unions.h
7 PSI_CONSTS=$PHP_PSI_SRCDIR/php_psi_consts.h
8 PSI_REDIRS=$PHP_PSI_SRCDIR/php_psi_redirs.h
9 PSI_MACROS=$PHP_PSI_SRCDIR/php_psi_macros.h
10 PSI_DECLS=$PHP_PSI_SRCDIR/php_psi_decls.h
11 PSI_VA_DECLS=$PHP_PSI_SRCDIR/php_psi_va_decls.h
12 PSI_FN_DECLS=$PHP_PSI_SRCDIR/php_psi_fn_decls.h
15 dnl Creates stubs of the headers with pre-defined types etc.
16 dnl These headers are included by src/context.c.
17 dnl This macro must be called prior any checks for a type, struct, decl etc.
18 AC_DEFUN(PSI_CONFIG_INIT, [
22 if test "$PHP_PSI_MAINTAINER_MODE" = "yes"; then
29 PSI_CONFIG_TMP=$(mktemp -d)
33 if test "$PHP_DEBUG" = "1"; then
36 PSI_EXTRA_REDIRS=false
40 cat >$PHP_PSI_BUILDDIR/php_psi.dep <<EOF
41 \$(PHP_PSI_SRCDIR)/php_psi.h:
43 \$(PHP_PSI_SRCDIR)/php_psi_stdinc.h:
46 for i in $PSI_STDTYPES $PSI_TYPES $PSI_STRUCTS $PSI_UNIONS $PSI_CONSTS $PSI_REDIRS $PSI_MACROS $PSI_DECLS $PSI_VA_DECLS $PSI_FN_DECLS; do
47 cat >>$PHP_PSI_BUILDDIR/php_psi.dep <<EOF
52 /* generated by configure */
53 #include "php_psi_stdinc.h"
56 cat >>$PSI_STDTYPES <<EOF
57 static struct psi_std_type {
59 const char *type_name;
61 } psi_std_types@<:@@:>@ = {
62 {PSI_T_INT8, "int8_t", NULL},
63 {PSI_T_INT16, "int16_t", NULL},
64 {PSI_T_INT32, "int32_t", NULL},
65 {PSI_T_INT64, "int64_t", NULL},
66 {PSI_T_UINT8, "uint8_t", NULL},
67 {PSI_T_UINT16, "uint16_t", NULL},
68 {PSI_T_UINT32, "uint32_t", NULL},
69 {PSI_T_UINT64, "uint64_t", NULL},
71 cat >>$PSI_TYPES <<EOF
72 static struct psi_predef_type {
74 const char *type_name;
76 } psi_predef_types@<:@@:>@ = {
78 cat >>$PSI_STRUCTS <<EOF
79 static struct psi_predef_struct {
81 const char *type_name;
87 } psi_predef_structs@<:@@:>@ = {
89 cat >>$PSI_UNIONS <<EOF
90 static struct psi_predef_union {
92 const char *type_name;
98 } psi_predef_unions@<:@@:>@ = {
100 cat >>$PSI_CONSTS <<EOF
101 static struct psi_predef_const {
103 const char *type_name;
104 const char *var_name;
105 const char *val_text;
106 token_t val_type_tag;
107 } psi_predef_consts@<:@@:>@ = {
109 cat >>$PSI_REDIRS <<EOF
110 typedef void (*psi_func_ptr)();
111 static struct psi_func_redir {
114 } psi_func_redirs@<:@@:>@ = {
116 cat >>$PSI_MACROS <<EOF
118 cat >>$PSI_DECLS <<EOF
119 static struct psi_predef_decl {
121 const char *type_name;
122 const char *var_name;
123 size_t pointer_level;
125 } psi_predef_decls@<:@@:>@ = {
127 cat >>$PSI_VA_DECLS <<EOF
128 static struct psi_predef_decl psi_predef_vararg_decls@<:@@:>@ = {
130 cat >>$PSI_FN_DECLS <<EOF
131 static struct psi_predef_decl psi_predef_functor_decls@<:@@:>@ = {
135 dnl PSI_CONFIG_DONE()
136 dnl Finish the headers with the pre-defined types etc.
137 AC_DEFUN(PSI_CONFIG_DONE, [
141 if $PSI_FAST_CONFIG; then
142 for conf_env in $PSI_CONFIG_TMP/*/conf.env; do
149 PHP_EVAL_LIBLINE($psi_eval_LIBS, PSI_SHARED_LIBADD)
151 cat >$PSI_STDINC <<EOF
152 /* generated by configure */
159 # include "php_config.h"
172 for i in $PSI_STDTYPES $PSI_TYPES $PSI_STRUCTS $PSI_UNIONS $PSI_CONSTS $PSI_REDIRS $PSI_DECLS $PSI_VA_DECLS $PSI_FN_DECLS; do
180 dnl PSI_SH_CONFIG_POSIX_ENABLED(section)
181 dnl Expand to $psi_config_posix_<section>
182 AC_DEFUN(PSI_SH_CONFIG_POSIX_ENABLED, [$AS_TR_SH([psi_config_posix_]$1)])
184 dnl PSI_CONFIG_POSIX_ENABLED(section, action-if-yes, action-if-not)
185 dnl Internal. Used to check if --enable-psi-posix=section was given.
186 AC_DEFUN(PSI_CONFIG_POSIX_ENABLED, [
187 AS_TR_SH([psi_config_posix_]$1)=false
188 case "$PHP_PSI_POSIX" in
190 AS_TR_SH([psi_config_posix_]$1)=true
193 if expr "$PHP_PSI_POSIX" : '\b$1\b' >/dev/null; then
194 AS_TR_SH([psi_config_posix_]$1)=true
198 if $AS_TR_SH([psi_config_posix_]$1); then
205 dnl PSI_TEST_POSIX_ENABLED(section, action-if-yes, action-if-not)
206 dnl Shell-if test if PSI POSIX section was configured.
207 AC_DEFUN(PSI_SH_TEST_POSIX_ENABLED, [
208 if test "PSI_SH_CONFIG_POSIX_ENABLED([$1])" && $PSI_SH_CONFIG_POSIX_ENABLED([$1]); then
215 dnl PSI_CONFIG_POSIX(section, headers)
216 AC_DEFUN(PSI_CONFIG_POSIX, [
217 PSI_CONFIG_POSIX_ENABLED($1, [
218 if $PSI_FAST_CONFIG; then
219 PSI_CONFIG_POSIX_PARALLEL($1, $2)
221 ifelse([$2],,:,[AC_CHECK_HEADERS($2)])
222 AS_TR_CPP([PSI_CHECK_$1])
227 AC_DEFUN([PSI_CONFIG_POSIX_PARALLEL], [
230 mkdir $PSI_CONFIG_TMP/AS_TR_SH([$1])
231 ln -s $(pwd)/confdefs.h $PSI_CONFIG_TMP/AS_TR_SH([$1])/confdefs.h
234 exec 66>&AS_MESSAGE_FD
235 exec AS_MESSAGE_FD>$PSI_CONFIG_TMP/AS_TR_SH([$1])/stdout.log
236 exec 2>$PSI_CONFIG_TMP/AS_TR_SH([$1])/stderr.log
238 dnl check for headers?
239 ifelse([$2],,:,[AC_CHECK_HEADERS($2)])
242 cd $PSI_CONFIG_TMP/AS_TR_SH([$1])
245 AS_TR_CPP([PSI_CHECK_$1])
248 cat >$PSI_CONFIG_TMP/AS_TR_SH([$1])/conf.env <<EOF
252 printf "%s " "$1" >&66
256 AC_DEFUN(PSI_PTHREAD_ONCE, [
258 LIBS="$PTHREAD_LIBS $LIBS"
259 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
262 AC_DEFUN(PSI_PTHREAD, [
263 AC_REQUIRE([PSI_PTHREAD_ONCE])
267 dnl Expands to a complete list of include statements including
268 dnl AC_INCLUDES_DEFAULT().
269 AC_DEFUN(PSI_INCLUDES, [dnl
277 AC_INCLUDES_DEFAULT()
278 #ifdef HAVE_STDBOOL_H
279 # include <stdbool.h>
285 # define _Bool signed char
291 # define __bool_true_false_are_defined 1
302 #ifdef HAVE_XLOCALE_H
303 # include <xlocale.h>
305 #ifdef HAVE_NETINET_IN_H
306 # include <netinet/in.h>
308 #ifdef HAVE_NETINET_TCP_H
309 # include <netinet/tcp.h>
311 #ifdef HAVE_ARPA_NAMESER_H
312 # include <arpa/nameser.h>
321 #elif HAVE_GDBM_NDBM_H
322 # include <gdbm-ndbm.h>
333 #ifdef HAVE_SYS_SELECT_H
334 # include <sys/select.h>
336 #ifdef HAVE_SYS_SOCKET_H
337 # include <sys/socket.h>
339 #ifdef HAVE_SYS_TIME_H
340 # include <sys/time.h>
342 #ifdef HAVE_SYS_TIMES_H
343 # include <sys/times.h>
345 #ifdef HAVE_SYS_UIO_H
346 # include <sys/uio.h>
348 #ifdef HAVE_SYS_UTSNAME_H
349 # include <sys/utsname.h>
369 dnl Declare $LEMON precious, and check for a `lemon` in $PATH.
370 AC_DEFUN(PSI_LEMON, [
371 AC_ARG_VAR(LEMON, The lemon parser generator of the SQLite project)
374 AC_PATH_PROG(LEMON, lemon, ./lemon)
380 dnl Check for `pkg-config` and add possible libjit and libffi directories to
381 dnl $PKG_CONFIG_PATH, because those libs often ship with headers etc. in
382 dnl arch-dependent locations.
383 AC_DEFUN([PSI_PKG_CONFIG], [
384 if test -z "$PKG_CONFIG"
386 AC_PATH_PROG(PKG_CONFIG, pkg-config, false)
388 export PKG_CONFIG_PATH="$PHP_PSI_LIBFFI/lib/pkgconfig:$PHP_PSI_LIBJIT/lib/pkgconfig:$PKG_CONFIG_PATH"
391 dnl PSI_SH_SIZEOF(type)
392 dnl expand to shell variable $ac_cv_sizeof_<TYPE>
393 AC_DEFUN([PSI_SH_SIZEOF], [$AS_TR_SH([ac_cv_sizeof_]$1)])
395 dnl PSI_SH_OFFSETOF(type)
396 dnl Expand to shell variable $ac_cv_offsetof_<TYPE>
397 AC_DEFUN([PSI_SH_OFFSETOF], [$AS_TR_SH([ac_cv_offsetof_]$1)])
399 dnl PSI_SH_ALIGNOF(type)
400 dnl Expand to shell variable $ac_cv_offsetof_<TYPE>
401 AC_DEFUN([PSI_SH_ALIGNOF], [$AS_TR_SH([ac_cv_alignof_]$1)])
403 dnl PSI_SH_TEST_SIZEOF(type)
404 dnl `if` condition to test if $ac_cv_sizeof_$1 is greater than 0.
405 AC_DEFUN([PSI_SH_TEST_SIZEOF], [test -n "$AS_TR_SH([ac_cv_sizeof_]$1)" && test "$AS_TR_SH([ac_cv_sizeof_]$1)" -gt 0])
407 dnl PSI_SH_TEST_ALIGNOF(type)
408 dnl `if` condition to test if $ac_cv_alignof_$1 is greater than 0.
409 AC_DEFUN([PSI_SH_TEST_ALIGNOF], [test -n "$AS_TR_SH([ac_cv_alignof_]$1)" && test "$AS_TR_SH([ac_cv_alignof_]$1)" -gt 0])
411 dnl PSI_CHECK_SIZEOF(type, special-includes)
412 dnl AC_CHECK_SIZEOF wrapper with PSI_INCLUDES
413 dnl Defines psi\\SIZEOF_<TYPE> pre-defined constant in $PSI_CONSTS.
414 AC_DEFUN(PSI_CHECK_SIZEOF, [
415 AC_CHECK_SIZEOF($1, [], PSI_INCLUDES
417 if PSI_SH_TEST_SIZEOF($1); then
418 psi_add_int_const "AS_TR_CPP([SIZEOF_]$1)" "$AS_TR_SH([ac_cv_sizeof_]$1)"
422 dnl PSI_CHECK_ALIGNOF(type, special-includes)
423 dnl AC_CHECK_ALIGNOF wrapper with PSI_INCLUDES
424 dnl Defines psi\\ALIGNOF_<TYPE> pre-defined constant in $PSI_CONSTS.
425 AC_DEFUN(PSI_CHECK_ALIGNOF, [
426 AC_CHECK_ALIGNOF($1, PSI_INCLUDES
428 if PSI_SH_TEST_ALIGNOF($1); then
429 psi_add_int_const "AS_TR_CPP([ALIGNOF_]$1)" "$AS_TR_SH([ac_cv_alignof_]$1)"
433 dnl PSI_CHECK_OFFSETOF(struct, element)
434 dnl Check the offset of a struct element, implemented in the similar manner
435 dnl like AC_CHECK_SIZEOF.
436 dnl AC_DEFINEs OFFSETOF_<STRUCT>_<ELEMENT>.
437 AC_DEFUN(PSI_CHECK_OFFSETOF, [
439 [offset of $2 in $1],
440 [AS_TR_SH([ac_cv_offsetof_$1_$2])],
441 [(long int) (offsetof ($1, $2))],
443 [AC_MSG_FAILURE([cannot compute offsetof ($1, $2)])]
446 AS_TR_CPP(offsetof_$1_$2),
447 $AS_TR_SH([ac_cv_offsetof_$1_$2]),
448 [The offset of `$2' in `$1', as computed by offsetof.]
453 dnl PSI_COMPUTE_STR(variable, string or expression)
454 dnl Compute a string constant value in a similar manner like AC_COMPUTE_INT.
455 AC_DEFUN(PSI_COMPUTE_STR, [
459 return EOF == fputs($2, fopen("conftest.out", "w"));
462 eval $1=\\\"`cat conftest.out`\\\"
466 dnl PSI_CHECK_LIBJIT()
467 dnl Check for libjit in $PHP_PSI_LIBJIT or standard locations
468 dnl AC_DEFINEs HAVE_LIBJIT.
469 AC_DEFUN(PSI_CHECK_LIBJIT, [
470 AC_CACHE_CHECK(for libjit, psi_cv_libjit_dir, [
471 for psi_cv_libjit_dir in $PHP_PSI_LIBJIT {/usr{,/local},/opt}{,/libjit}
473 if test -e $psi_cv_libjit_dir/include/jit/jit.h
480 if test -n "$psi_cv_libjit_dir"
482 PHP_ADD_INCLUDE($psi_cv_libjit_dir/include)
483 PHP_ADD_LIBRARY_WITH_PATH(jit, $psi_cv_libjit_dir/$PHP_LIBDIR, PSI_SHARED_LIBADD)
484 AC_DEFINE(HAVE_LIBJIT, 1, Have libjit)
486 AC_MSG_WARN([Could not find libjit, please provide the base install path])
490 dnl PSI_CHECK_LIBFFI()
491 dnl Check for libffi with `pkg-config`. If that fails, `configure` looks into
492 dnl $PHP_PSI_LIBFFI or standard locations to find libjit deps.
493 dnl Checks for availability of recent closure API:
494 dnl \ffi_closure_alloc and \ffi_prep_closure.
495 dnl Checks for availability of recent vararg API:
496 dnl \ffi_prep_cif_var.
497 dnl AC_DEFINEs HAVE_LIBFFI, PSI_HAVE_FFI_CLOSURE_ALLOC,
498 dnl PSI_HAVE_FFI_PREP_CLOSURE and PSI_HAVE_FFO_PREP_VIF_VAR.
499 AC_DEFUN(PSI_CHECK_LIBFFI, [
500 AC_REQUIRE([PSI_PKG_CONFIG])dnl
502 AC_CACHE_CHECK(for libffi through pkg-config, psi_cv_libffi, [
503 if $PKG_CONFIG --exists libffi
512 AC_MSG_CHECKING(for libffi)
513 psi_cv_libffi_dir=`$PKG_CONFIG --variable=prefix libffi`
514 AC_MSG_RESULT($psi_cv_libffi_dir)
515 PHP_EVAL_INCLINE(`$PKG_CONFIG --cflags libffi`)
516 PHP_EVAL_LIBLINE(`$PKG_CONFIG --libs libffi`, PSI_SHARED_LIBADD)
517 AC_DEFINE(HAVE_LIBFFI, 1, Have libffi)
518 AC_DEFINE_UNQUOTED([PHP_PSI_LIBFFI_VERSION], ["`$PKG_CONFIG --modversion libffi`"], [libffi version])
520 AC_CACHE_CHECK(for libffi, psi_cv_libffi_dir, [
521 for psi_cv_libffi_dir in $PHP_PSI_LIBFFI {/usr{,/local},/opt}{,/libffi}
523 if test -e $psi_cv_libffi_dir/include/ffi/ffi.h
529 if test -n "$psi_cv_libffi_dir"
531 PHP_ADD_INCLUDE($psi_cv_libffi_dir/include/ffi)
532 PHP_ADD_LIBRARY_WITH_PATH(ffi, $psi_cv_libffi_dir/$PHP_LIBDIR, PSI_SHARED_LIBADD)
533 AC_DEFINE(HAVE_LIBFFI, 1, Have libffi)
535 AC_MSG_WARN([Could not find libffi, please provide the base install path])
538 PHP_CHECK_LIBRARY(ffi, ffi_closure_alloc, [
539 PHP_CHECK_LIBRARY(ffi, ffi_prep_closure_loc, [
540 AC_DEFINE(PSI_HAVE_FFI_PREP_CLOSURE_LOC, 1, [ ])
541 ], [], -L$psi_cv_libffi_dir/$PHP_LIBDIR)
542 AC_DEFINE(PSI_HAVE_FFI_CLOSURE_ALLOC, 1, [ ])
544 PHP_CHECK_LIBRARY(ffi, ffi_prep_closure, [
545 AC_CHECK_HEADERS(sys/mman.h)
547 AC_DEFINE(PSI_HAVE_FFI_PREP_CLOSURE, 1, [ ])
549 ], -L$psi_cv_libffi_dir/$PHP_LIBDIR)
550 ], -L$psi_cv_libffi_dir/$PHP_LIBDIR)
551 PHP_CHECK_LIBRARY(ffi, ffi_prep_cif_var, [
552 AC_DEFINE(PSI_HAVE_FFI_PREP_CIF_VAR, 1, [ ])
554 ], -L$psi_cv_libffi_dir/$PHP_LIBDIR)