3 dnl Creates stubs of the headers with pre-defined types etc.
4 dnl These headers are included by src/context.c.
5 dnl This macro must be called prior any checks for a type, struct, decl etc.
6 AC_DEFUN(PSI_CONFIG_INIT, [
10 if test "$PHP_PSI_MAINTAINER_MODE" = "yes"; then
17 PSI_CONFIG_TMP=$(mktemp -d)
22 if test "$PHP_DEBUG" = "1"; then
25 PSI_EXTRA_REDIRS=false
38 [$PHP_PSI_BUILDDIR/php_psi_stdinc.h:$PHP_PSI_SRCDIR/php_psi_stdinc.h.in]
39 [$PHP_PSI_BUILDDIR/php_psi_posix.h:$PHP_PSI_SRCDIR/php_psi_posix.h.in]
45 dnl Finish the headers with the pre-defined types etc.
46 AC_DEFUN(PSI_CONFIG_DONE, [
47 if $PSI_FAST_CONFIG; then
49 for conf_env in $PSI_CONFIG_TMP/*/conf.env; do
56 PHP_EVAL_LIBLINE($psi_eval_LIBS, PSI_SHARED_LIBADD)
58 [PSI_INCLUDES]="PSI_INCLUDES"
59 AC_SUBST([PSI_INCLUDES])
60 AC_SUBST([PSI_STDTYPES])
62 AC_SUBST([PSI_COMPOSITES])
63 AC_SUBST([PSI_CONSTS])
64 AC_SUBST([PSI_REDIRS])
65 AC_SUBST([PSI_MACROS])
69 dnl PSI_SH_CONFIG_POSIX_ENABLED(section)
70 dnl Expand to $psi_config_posix_<section>
71 AC_DEFUN(PSI_SH_CONFIG_POSIX_ENABLED, [$AS_TR_SH([psi_config_posix_]$1)])
73 dnl PSI_CONFIG_POSIX_ENABLED(section, action-if-yes, action-if-not)
74 dnl Internal. Used to check if --enable-psi-posix=section was given.
75 AC_DEFUN(PSI_CONFIG_POSIX_ENABLED, [
76 AS_TR_SH([psi_config_posix_]$1)=false
77 case "$PHP_PSI_POSIX" in
79 AS_TR_SH([psi_config_posix_]$1)=true
82 if expr "$PHP_PSI_POSIX" : '.*\b$1\b' >/dev/null; then
83 AS_TR_SH([psi_config_posix_]$1)=true
87 if $AS_TR_SH([psi_config_posix_]$1); then
94 dnl PSI_TEST_POSIX_ENABLED(section, action-if-yes, action-if-not)
95 dnl Shell-if test if PSI POSIX section was configured.
96 AC_DEFUN(PSI_SH_TEST_POSIX_ENABLED, [
97 if test "PSI_SH_CONFIG_POSIX_ENABLED([$1])" && $PSI_SH_CONFIG_POSIX_ENABLED([$1]); then
104 dnl PSI_CONFIG_POSIX(section, headers, dependents)
105 AC_DEFUN(PSI_CONFIG_POSIX, [
106 PSI_CONFIG_POSIX_ENABLED($1, [
107 if $PSI_FAST_CONFIG; then
108 PSI_CONFIG_POSIX_PARALLEL($1, $2, [$3])
110 ifelse([$2],,:,[AC_CHECK_HEADERS($2)])
111 AS_TR_CPP([PSI_CHECK_$1])
117 AC_DEFUN([PSI_CONFIG_POSIX_PARALLEL], [
120 mkdir $PSI_CONFIG_TMP/AS_TR_SH([$1])
121 printenv > $PSI_CONFIG_TMP/AS_TR_SH([$1])/start.env
122 ln -s $(pwd)/confdefs.h $PSI_CONFIG_TMP/AS_TR_SH([$1])/confdefs.h
125 exec 66>&AS_MESSAGE_FD
126 exec AS_MESSAGE_FD>$PSI_CONFIG_TMP/AS_TR_SH([$1])/stdout.log
127 exec 2>$PSI_CONFIG_TMP/AS_TR_SH([$1])/stderr.log
129 dnl check for headers?
130 ifelse([$2],,:,[AC_CHECK_HEADERS($2)])
133 cd $PSI_CONFIG_TMP/AS_TR_SH([$1])
142 AS_TR_CPP([PSI_CHECK_$1])
145 printenv > $PSI_CONFIG_TMP/AS_TR_SH([$1])/end.env
146 cat >$PSI_CONFIG_TMP/AS_TR_SH([$1])/conf.env <<EOF
149 for env in TYPES CONSTS COMPOSITES MACROS REDIRS DECLS; do
151 if test -n "$var"; then
152 cat >>$PSI_CONFIG_TMP/AS_TR_SH([$1])/conf.env <<EOF
159 _AC_CACHE_DUMP >>$PSI_CONFIG_TMP/AS_TR_SH([$1])/conf.env
162 printf "%s " "$1" >&66
169 AC_DEFUN(PSI_PTHREAD_ONCE, [
171 LIBS="$PTHREAD_LIBS $LIBS"
172 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
175 AC_DEFUN(PSI_PTHREAD, [
176 AC_REQUIRE([PSI_PTHREAD_ONCE])
180 dnl Expands to a complete list of include statements including
181 dnl AC_INCLUDES_DEFAULT().
182 AC_DEFUN(PSI_INCLUDES, [dnl
190 AC_INCLUDES_DEFAULT()
191 #ifdef HAVE_STDBOOL_H
192 # include <stdbool.h>
198 # define _Bool signed char
204 # define __bool_true_false_are_defined 1
215 #ifdef HAVE_XLOCALE_H
216 # include <xlocale.h>
218 #ifdef HAVE_NETINET_IN_H
219 # include <netinet/in.h>
221 #ifdef HAVE_NETINET_TCP_H
222 # include <netinet/tcp.h>
224 #ifdef HAVE_ARPA_NAMESER_H
225 # include <arpa/nameser.h>
234 #elif HAVE_GDBM_NDBM_H
235 # include <gdbm-ndbm.h>
246 #ifdef HAVE_SYS_SELECT_H
247 # include <sys/select.h>
249 #ifdef HAVE_SYS_SOCKET_H
250 # include <sys/socket.h>
252 #ifdef HAVE_SYS_TIME_H
253 # include <sys/time.h>
255 #ifdef HAVE_SYS_TIMES_H
256 # include <sys/times.h>
258 #ifdef HAVE_SYS_UIO_H
259 # include <sys/uio.h>
261 #ifdef HAVE_SYS_UTSNAME_H
262 # include <sys/utsname.h>
282 dnl Declare $LEMON precious, and check for a `lemon` in $PATH.
283 AC_DEFUN(PSI_LEMON, [
284 AC_ARG_VAR(LEMON, The lemon parser generator of the SQLite project)
287 AC_PATH_PROG(LEMON, lemon, $PHP_PSI_BUILDDIR/lemon)
293 dnl Check for `pkg-config` and add possible libjit and libffi directories to
294 dnl $PKG_CONFIG_PATH, because those libs often ship with headers etc. in
295 dnl arch-dependent locations.
296 AC_DEFUN([PSI_PKG_CONFIG], [
297 if test -z "$PKG_CONFIG"
299 AC_PATH_PROG(PKG_CONFIG, pkg-config, false)
301 export PKG_CONFIG_PATH="$PHP_PSI_LIBFFI/lib/pkgconfig:$PHP_PSI_LIBJIT/lib/pkgconfig:$PKG_CONFIG_PATH"
304 dnl PSI_SH_SIZEOF(type)
305 dnl expand to shell variable $ac_cv_sizeof_<TYPE>
306 AC_DEFUN([PSI_SH_SIZEOF], [$AS_TR_SH([ac_cv_sizeof_]$1)])
308 dnl PSI_SH_OFFSETOF(type)
309 dnl Expand to shell variable $ac_cv_offsetof_<TYPE>
310 AC_DEFUN([PSI_SH_OFFSETOF], [$AS_TR_SH([ac_cv_offsetof_]$1)])
312 dnl PSI_SH_ALIGNOF(type)
313 dnl Expand to shell variable $ac_cv_offsetof_<TYPE>
314 AC_DEFUN([PSI_SH_ALIGNOF], [$AS_TR_SH([ac_cv_alignof_]$1)])
316 dnl PSI_SH_TEST_SIZEOF(type)
317 dnl `if` condition to test if $ac_cv_sizeof_$1 is greater than 0.
318 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])
320 dnl PSI_SH_TEST_ALIGNOF(type)
321 dnl `if` condition to test if $ac_cv_alignof_$1 is greater than 0.
322 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])
324 dnl PSI_CHECK_SIZEOF(type, special-includes)
325 dnl AC_CHECK_SIZEOF wrapper with PSI_INCLUDES
326 dnl Defines psi\\SIZEOF_<TYPE> pre-defined constant in $PSI_CONSTS_H.
327 AC_DEFUN(PSI_CHECK_SIZEOF, [
328 AC_CHECK_SIZEOF($1, [], PSI_INCLUDES
330 if PSI_SH_TEST_SIZEOF($1); then
331 psi_add_int_const "AS_TR_CPP([SIZEOF_]$1)" "$AS_TR_SH([ac_cv_sizeof_]$1)"
335 dnl PSI_CHECK_ALIGNOF(type, special-includes)
336 dnl AC_CHECK_ALIGNOF wrapper with PSI_INCLUDES
337 dnl Defines psi\\ALIGNOF_<TYPE> pre-defined constant in $PSI_CONSTS_H.
338 AC_DEFUN(PSI_CHECK_ALIGNOF, [
339 AC_CHECK_ALIGNOF($1, PSI_INCLUDES
341 if PSI_SH_TEST_ALIGNOF($1); then
342 psi_add_int_const "AS_TR_CPP([ALIGNOF_]$1)" "$AS_TR_SH([ac_cv_alignof_]$1)"
346 dnl PSI_CHECK_OFFSETOF(struct, element)
347 dnl Check the offset of a struct element, implemented in the similar manner
348 dnl like AC_CHECK_SIZEOF.
349 dnl AC_DEFINEs OFFSETOF_<STRUCT>_<ELEMENT>.
350 AC_DEFUN(PSI_CHECK_OFFSETOF, [
352 [offset of $2 in $1],
353 [AS_TR_SH([ac_cv_offsetof_$1_$2])],
354 [(long int) (offsetof ($1, $2))],
356 [AC_MSG_FAILURE([cannot compute offsetof ($1, $2)])]
359 AS_TR_CPP(offsetof_$1_$2),
360 $AS_TR_SH([ac_cv_offsetof_$1_$2]),
361 [The offset of `$2' in `$1', as computed by offsetof.]
366 dnl PSI_COMPUTE_STR(variable, string or expression)
367 dnl Compute a string constant value in a similar manner like AC_COMPUTE_INT.
368 AC_DEFUN(PSI_COMPUTE_STR, [
372 return EOF == fputs($2, fopen("conftest.out", "w"));
375 eval $1=\\\"`cat conftest.out`\\\"
379 dnl PSI_CHECK_LIBJIT()
380 dnl Check for libjit in $PHP_PSI_LIBJIT or standard locations
381 dnl AC_DEFINEs HAVE_LIBJIT.
382 AC_DEFUN(PSI_CHECK_LIBJIT, [
383 AC_CACHE_CHECK(for libjit, psi_cv_libjit_dir, [
384 for psi_cv_libjit_dir in $PHP_PSI_LIBJIT {/usr{,/local},/opt}{,/libjit}
386 if test -e $psi_cv_libjit_dir/include/jit/jit.h
393 if test -n "$psi_cv_libjit_dir"
395 PHP_ADD_INCLUDE($psi_cv_libjit_dir/include)
396 PHP_ADD_LIBRARY_WITH_PATH(jit, $psi_cv_libjit_dir/$PHP_LIBDIR, PSI_SHARED_LIBADD)
397 AC_DEFINE(HAVE_LIBJIT, 1, Have libjit)
399 AC_MSG_WARN([Could not find libjit, please provide the base install path])
403 dnl PSI_CHECK_LIBFFI()
404 dnl Check for libffi with `pkg-config`. If that fails, `configure` looks into
405 dnl $PHP_PSI_LIBFFI or standard locations to find libjit deps.
406 dnl Checks for availability of recent closure API:
407 dnl \ffi_closure_alloc and \ffi_prep_closure.
408 dnl Checks for availability of recent vararg API:
409 dnl \ffi_prep_cif_var.
410 dnl AC_DEFINEs HAVE_LIBFFI, PSI_HAVE_FFI_CLOSURE_ALLOC,
411 dnl PSI_HAVE_FFI_PREP_CLOSURE and PSI_HAVE_FFO_PREP_VIF_VAR.
412 AC_DEFUN(PSI_CHECK_LIBFFI, [
413 AC_REQUIRE([PSI_PKG_CONFIG])dnl
415 AC_CACHE_CHECK(for libffi through pkg-config, psi_cv_libffi, [
416 if $PKG_CONFIG --exists libffi
425 AC_MSG_CHECKING(for libffi)
426 psi_cv_libffi_dir=`$PKG_CONFIG --variable=prefix libffi`
427 AC_MSG_RESULT($psi_cv_libffi_dir)
428 PHP_EVAL_INCLINE(`$PKG_CONFIG --cflags libffi`)
429 PHP_EVAL_LIBLINE(`$PKG_CONFIG --libs libffi`, PSI_SHARED_LIBADD)
430 AC_DEFINE(HAVE_LIBFFI, 1, Have libffi)
431 AC_DEFINE_UNQUOTED([PHP_PSI_LIBFFI_VERSION], ["`$PKG_CONFIG --modversion libffi`"], [libffi version])
433 AC_CACHE_CHECK(for libffi, psi_cv_libffi_dir, [
434 for psi_cv_libffi_dir in $PHP_PSI_LIBFFI {/usr{,/local},/opt}{,/libffi}
436 if test -e $psi_cv_libffi_dir/include/ffi/ffi.h
442 if test -n "$psi_cv_libffi_dir"
444 PHP_ADD_INCLUDE($psi_cv_libffi_dir/include/ffi)
445 PHP_ADD_LIBRARY_WITH_PATH(ffi, $psi_cv_libffi_dir/$PHP_LIBDIR, PSI_SHARED_LIBADD)
446 AC_DEFINE(HAVE_LIBFFI, 1, Have libffi)
448 AC_MSG_WARN([Could not find libffi, please provide the base install path])
451 PHP_CHECK_LIBRARY(ffi, ffi_closure_alloc, [
452 PHP_CHECK_LIBRARY(ffi, ffi_prep_closure_loc, [
453 AC_DEFINE(PSI_HAVE_FFI_PREP_CLOSURE_LOC, 1, [ ])
454 ], [], -L$psi_cv_libffi_dir/$PHP_LIBDIR)
455 AC_DEFINE(PSI_HAVE_FFI_CLOSURE_ALLOC, 1, [ ])
457 PHP_CHECK_LIBRARY(ffi, ffi_prep_closure, [
458 AC_CHECK_HEADERS(sys/mman.h)
460 AC_DEFINE(PSI_HAVE_FFI_PREP_CLOSURE, 1, [ ])
462 ], -L$psi_cv_libffi_dir/$PHP_LIBDIR)
463 ], -L$psi_cv_libffi_dir/$PHP_LIBDIR)
464 PHP_CHECK_LIBRARY(ffi, ffi_prep_cif_var, [
465 AC_DEFINE(PSI_HAVE_FFI_PREP_CIF_VAR, 1, [ ])
467 ], -L$psi_cv_libffi_dir/$PHP_LIBDIR)