flush
[m6w6/ext-psi] / m4 / psi.m4
index ae6c81a2ebdc6f3d5e933170f9f62aa840ad8f20..63407beb24bb9fd0c61856c65668475fd0da3aed 100644 (file)
--- a/m4/psi.m4
+++ b/m4/psi.m4
@@ -1,7 +1,9 @@
 dnl Generated headers with pre-defined types, structs, consts and decls.
 PSI_STDINC=$PHP_PSI_SRCDIR/php_psi_stdinc.h
+PSI_STDTYPES=$PHP_PSI_SRCDIR/php_psi_stdtypes.h
 PSI_TYPES=$PHP_PSI_SRCDIR/php_psi_types.h
 PSI_STRUCTS=$PHP_PSI_SRCDIR/php_psi_structs.h
+PSI_UNIONS=$PHP_PSI_SRCDIR/php_psi_unions.h
 PSI_CONSTS=$PHP_PSI_SRCDIR/php_psi_consts.h
 PSI_REDIRS=$PHP_PSI_SRCDIR/php_psi_redirs.h
 PSI_MACROS=$PHP_PSI_SRCDIR/php_psi_macros.h
@@ -13,7 +15,24 @@ dnl Creates stubs of the headers with pre-defined types etc.
 dnl These headers are included by src/context.c.
 dnl This macro must be called prior any checks for a type, struct, decl etc.
 AC_DEFUN(PSI_CONFIG_INIT, [
+       cat >$PSI_STDTYPES <<EOF
+/* generated by configure */
+static struct psi_std_type {
+       token_t type_tag;
+       const char *type_name;
+       const char *alias;
+} psi_std_types@<:@@:>@ = {
+       {PSI_T_INT8, "int8_t", NULL},
+       {PSI_T_INT16, "int16_t", NULL},
+       {PSI_T_INT32, "int32_t", NULL},
+       {PSI_T_INT64, "int64_t", NULL},
+       {PSI_T_UINT8, "uint8_t", NULL},
+       {PSI_T_UINT16, "uint16_t", NULL},
+       {PSI_T_UINT32, "uint32_t", NULL},
+       {PSI_T_UINT64, "uint64_t", NULL},
+EOF
        cat >$PSI_TYPES <<EOF
+/* generated by configure */
 static struct psi_predef_type {
        token_t type_tag;
        const char *type_name;
@@ -21,6 +40,7 @@ static struct psi_predef_type {
 } psi_predef_types@<:@@:>@ = {
 EOF
        cat >$PSI_STRUCTS <<EOF
+/* generated by configure */
 static struct psi_predef_struct {
        token_t type_tag;
        const char *type_name;
@@ -30,8 +50,21 @@ static struct psi_predef_struct {
        size_t pointer_level;
        size_t array_size;
 } psi_predef_structs@<:@@:>@ = {
+EOF
+       cat >$PSI_UNIONS <<EOF
+/* generated by configure */
+static struct psi_predef_union {
+       token_t type_tag;
+       const char *type_name;
+       const char *var_name;
+       size_t offset;
+       size_t size;
+       size_t pointer_level;
+       size_t array_size;
+} psi_predef_unions@<:@@:>@ = {
 EOF
        cat >$PSI_CONSTS <<EOF
+/* generated by configure */
 static struct psi_predef_const {
        token_t type_tag;
        const char *type_name;
@@ -41,6 +74,7 @@ static struct psi_predef_const {
 } psi_predef_consts@<:@@:>@ = {
 EOF
        cat >$PSI_REDIRS <<EOF
+/* generated by configure */
 static struct psi_func_redir {
        const char *name;
        void (*func)(void);
@@ -48,6 +82,7 @@ static struct psi_func_redir {
 EOF
        cat >$PSI_MACROS </dev/null
        cat >$PSI_DECLS <<EOF
+/* generated by configure */
 static struct psi_predef_decl {
        token_t type_tag;
        const char *type_name;
@@ -57,6 +92,7 @@ static struct psi_predef_decl {
 } psi_predef_decls@<:@@:>@ = {
 EOF
        cat >$PSI_VA_DECLS <<EOF
+/* generated by configure */
 static struct psi_predef_decl psi_predef_vararg_decls@<:@@:>@ = {
 EOF
 ])
@@ -65,9 +101,10 @@ dnl PSI_CONFIG_DONE()
 dnl Finish the headers with the pre-defined types etc.
 AC_DEFUN(PSI_CONFIG_DONE, [
        cat >$PSI_STDINC <<EOF
+/* generated by configure */
 PSI_INCLUDES
 EOF
-       for i in $PSI_TYPES $PSI_STRUCTS $PSI_CONSTS $PSI_REDIRS $PSI_DECLS $PSI_VA_DECLS; do
+       for i in $PSI_STDTYPES $PSI_TYPES $PSI_STRUCTS $PSI_UNIONS $PSI_CONSTS $PSI_REDIRS $PSI_DECLS $PSI_VA_DECLS; do
                cat >>$i <<EOF
        {0}
 };
@@ -75,6 +112,61 @@ EOF
        done
 ])
 
+dnl PSI_SH_CONFIG_POSIX_ENABLED(section)
+dnl Expand to $psi_config_posix_<section>
+AC_DEFUN(PSI_SH_CONFIG_POSIX_ENABLED, [$AS_TR_SH([psi_config_posix_]$1)])
+
+dnl PSI_CONFIG_POSIX_ENABLED(section, action-if-yes, action-if-not)
+dnl Internal. Used to check if --enable-psi-posix=section was given.
+AC_DEFUN(PSI_CONFIG_POSIX_ENABLED, [
+       AS_TR_SH([psi_config_posix_]$1)=false
+       case "$PHP_PSI_POSIX" in
+       yes|all)
+               AS_TR_SH([psi_config_posix_]$1)=true 
+               ;;
+       *)
+               if expr "$PHP_PSI_POSIX" : '\b$1\b' >/dev/null; then
+                       AS_TR_SH([psi_config_posix_]$1)=true
+               fi
+               ;;
+       esac
+       if $AS_TR_SH([psi_config_posix_]$1); then
+               ifelse([$2],,:,[$2])
+       else
+               ifelse([$3],,:,[$3])
+       fi
+])
+
+dnl PSI_TEST_POSIX_ENABLED(section, action-if-yes, action-if-not)
+dnl Shell-if test if PSI POSIX section was configured.
+AC_DEFUN(PSI_SH_TEST_POSIX_ENABLED, [
+       if test "PSI_SH_CONFIG_POSIX_ENABLED([$1])" && $PSI_SH_CONFIG_POSIX_ENABLED([$1]); then
+               ifelse([$2],,:,[$2])
+       else
+               ifelse([$3],,:,[$3])
+       fi
+])
+
+dnl PSI_CONFIG_POSIX(section, headers)
+AC_DEFUN(PSI_CONFIG_POSIX, [
+       PSI_CONFIG_POSIX_ENABLED($1, [
+               PHP_CONFIGURE_PART(Configuring PSI POSIX: $1)
+               ifelse([$2],,,AC_CHECK_HEADERS($2))
+       ], [
+               return 0
+       ])
+])
+
+AC_DEFUN(PSI_PTHREAD_ONCE, [
+       AX_PTHREAD([
+               LIBS="$PTHREAD_LIBS $LIBS"
+               CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
+       ])
+])
+AC_DEFUN(PSI_PTHREAD, [
+       AC_REQUIRE([PSI_PTHREAD_ONCE])
+])
+
 dnl PSI_INCLUDES()
 dnl Expands to a complete list of include statements including
 dnl AC_INCLUDES_DEFAULT().
@@ -100,6 +192,12 @@ AC_DEFUN(PSI_INCLUDES, [AC_INCLUDES_DEFAULT()
 #ifdef HAVE_ARPA_NAMESER_H
 # include <arpa/nameser.h>
 #endif
+#ifdef HAVE_FCNTL_H
+# include <fcntl.h>
+#endif
+#ifdef HAVE_NDBM_H
+# include <ndbm.h>
+#endif
 #ifdef HAVE_NETDB_H
 # include <netdb.h>
 #endif
@@ -130,6 +228,9 @@ AC_DEFUN(PSI_INCLUDES, [AC_INCLUDES_DEFAULT()
 #ifdef HAVE_TIME_H
 # include <time.h>
 #endif
+#ifdef HAVE_SIGNAL_H
+# include <signal.h>
+#endif
 #ifdef HAVE_SYSLOG_H
 # include <syslog.h>
 #endif
@@ -151,7 +252,7 @@ AC_DEFUN(PSI_LEMON, [
 
 dnl PSI_PKG_CONFIG()
 dnl Check for `pkg-config` and add possible libjit and libffi directories to
-dnl $PKG_CONFIG_PATH, because those libs often ship with headers etc. in 
+dnl $PKG_CONFIG_PATH, because those libs often ship with headers etc. in
 dnl arch-dependent locations.
 AC_DEFUN([PSI_PKG_CONFIG], [
        if test -z "$PKG_CONFIG"
@@ -161,10 +262,26 @@ AC_DEFUN([PSI_PKG_CONFIG], [
        export PKG_CONFIG_PATH="$PHP_PSI_LIBFFI/lib/pkgconfig:$PHP_PSI_LIBJIT/lib/pkgconfig:$PKG_CONFIG_PATH"
 ])
 
+dnl PSI_SH_SIZEOF(type)
+dnl expand to shell variable $ac_cv_sizeof_<TYPE>
+AC_DEFUN([PSI_SH_SIZEOF], [$AS_TR_SH([ac_cv_sizeof_]$1)])
+
+dnl PSI_SH_OFFSETOF(type)
+dnl Expand to shell variable $ac_cv_offsetof_<TYPE>
+AC_DEFUN([PSI_SH_OFFSETOF], [$AS_TR_SH([ac_cv_offsetof_]$1)])
+
+dnl PSI_SH_ALIGNOF(type)
+dnl Expand to shell variable $ac_cv_offsetof_<TYPE>
+AC_DEFUN([PSI_SH_ALIGNOF], [$AS_TR_SH([ac_cv_alignof_]$1)])
+
 dnl PSI_SH_TEST_SIZEOF(type)
 dnl `if` condition to test if $ac_cv_sizeof_$1 is greater than 0.
 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])
 
+dnl PSI_SH_TEST_ALIGNOF(type)
+dnl `if` condition to test if $ac_cv_alignof_$1 is greater than 0.
+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])
+
 dnl PSI_CHECK_SIZEOF(type, special-includes)
 dnl AC_CHECK_SIZEOF wrapper with PSI_INCLUDES
 dnl Defines psi\\SIZEOF_<TYPE> pre-defined constant in $PSI_CONSTS.
@@ -176,6 +293,17 @@ AC_DEFUN(PSI_CHECK_SIZEOF, [
        fi
 ])
 
+dnl PSI_CHECK_ALIGNOF(type, special-includes)
+dnl AC_CHECK_ALIGNOF wrapper with PSI_INCLUDES
+dnl Defines psi\\ALIGNOF_<TYPE> pre-defined constant in $PSI_CONSTS.
+AC_DEFUN(PSI_CHECK_ALIGNOF, [
+       AC_CHECK_ALIGNOF($1, PSI_INCLUDES
+               $2)
+       if PSI_SH_TEST_ALIGNOF($1); then
+               psi_add_int_const "AS_TR_CPP([ALIGNOF_]$1)" "$AS_TR_SH([ac_cv_alignof_]$1)"
+       fi
+])
+
 dnl PSI_CHECK_OFFSETOF(struct, element)
 dnl Check the offset of a struct element, implemented in the similar manner
 dnl like AC_CHECK_SIZEOF.
@@ -195,6 +323,7 @@ AC_DEFUN(PSI_CHECK_OFFSETOF, [
        )
 ])
 
+
 dnl PSI_COMPUTE_STR(variable, string or expression)
 dnl Compute a string constant value in a similar manner like AC_COMPUTE_INT.
 AC_DEFUN(PSI_COMPUTE_STR, [
@@ -235,11 +364,11 @@ AC_DEFUN(PSI_CHECK_LIBJIT, [
 dnl PSI_CHECK_LIBFFI()
 dnl Check for libffi with `pkg-config`. If that fails, `configure` looks into
 dnl $PHP_PSI_LIBFFI or standard locations to find libjit deps.
-dnl Checks for availability of recent closure API: 
+dnl Checks for availability of recent closure API:
 dnl \ffi_closure_alloc and \ffi_prep_closure.
 dnl Checks for availability of recent vararg API:
 dnl \ffi_prep_cif_var.
-dnl AC_DEFINEs HAVE_LIBFFI, PSI_HAVE_FFI_CLOSURE_ALLOC, 
+dnl AC_DEFINEs HAVE_LIBFFI, PSI_HAVE_FFI_CLOSURE_ALLOC,
 dnl PSI_HAVE_FFI_PREP_CLOSURE and PSI_HAVE_FFO_PREP_VIF_VAR.
 AC_DEFUN(PSI_CHECK_LIBFFI, [
        AC_REQUIRE([PSI_PKG_CONFIG])dnl
@@ -251,7 +380,7 @@ AC_DEFUN(PSI_CHECK_LIBFFI, [
        else
                psi_cv_libffi=false
        fi])
-       
+
        if $psi_cv_libffi
        then
                AC_MSG_CHECKING(for libffi)