configure: fix fd restoration
[m6w6/ext-psi] / m4 / psi / psi.m4
index b0bbbf3056f3908fbfd07427b684192e4b5b1416..67878346db61e5765024af4e225c09502888b94d 100644 (file)
-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
-PSI_DECLS=$PHP_PSI_SRCDIR/php_psi_decls.h
-PSI_VA_DECLS=$PHP_PSI_SRCDIR/php_psi_va_decls.h
-PSI_FN_DECLS=$PHP_PSI_SRCDIR/php_psi_fn_decls.h
 
 dnl PSI_CONFIG_INIT()
 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, [AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])dnl
-       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
-               cat >$i <<EOF
-/* generated by configure */
-#include "php_psi_stdinc.h"
-EOF
-       done
-       cat >>$PSI_STDTYPES <<EOF
-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
-static struct psi_predef_type {
-       token_t type_tag;
-       const char *type_name;
-       const char *alias;
-} psi_predef_types@<:@@:>@ = {
-EOF
-       cat >>$PSI_STRUCTS <<EOF
-static struct psi_predef_struct {
-       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_structs@<:@@:>@ = {
-EOF
-       cat >>$PSI_UNIONS <<EOF
-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
-static struct psi_predef_const {
-       token_t type_tag;
-       const char *type_name;
-       const char *var_name;
-       const char *val_text;
-       token_t val_type_tag;
-} psi_predef_consts@<:@@:>@ = {
-EOF
-       cat >>$PSI_REDIRS <<EOF
-typedef void (*psi_func_ptr)();
-static struct psi_func_redir {
-       const char *name;
-       psi_func_ptr func;
-} psi_func_redirs@<:@@:>@ = {
-EOF
-       cat >>$PSI_MACROS <<EOF
-EOF
-       cat >>$PSI_DECLS <<EOF
-static struct psi_predef_decl {
-       token_t type_tag;
-       const char *type_name;
-       const char *var_name;
-       size_t pointer_level;
-       size_t array_size;
-} psi_predef_decls@<:@@:>@ = {
-EOF
-       cat >>$PSI_VA_DECLS <<EOF
-static struct psi_predef_decl psi_predef_vararg_decls@<:@@:>@ = {
-EOF
-       cat >>$PSI_FN_DECLS <<EOF
-static struct psi_predef_decl psi_predef_functor_decls@<:@@:>@ = {
-EOF
+AC_DEFUN(PSI_CONFIG_INIT, [
+       psi_save_LIBS=$LIBS
+       LIBS=
+
+       if test "$PHP_PSI_MAINTAINER_MODE" = "yes"; then
+               PSI_FAST_CONFIG=true
+               PSI_DEPS=true
+               PSI_EXTRA_REDIRS=true
+               
+               PHP_SUBST(PSI_DEPS)
+               
+               PSI_CONFIG_TMP=$(mktemp -d)
+               PSI_FUNC_LIBC_MAIN
+       else
+               PSI_FAST_CONFIG=false
+               PSI_DEPS=false
+               if test "$PHP_DEBUG" = "1"; then
+                       PSI_EXTRA_REDIRS=true
+               else
+                       PSI_EXTRA_REDIRS=false
+               fi
+       fi
+       
+       PSI_STDTYPES=
+       PSI_TYPES=
+       PSI_COMPOSITES=
+       PSI_CONSTS=
+       PSI_REDIRS=
+       PSI_MACROS=
+       PSI_DECLS=
+       
+       AC_CONFIG_FILES(
+               [$PHP_PSI_BUILDDIR/php_psi_stdinc.h:$PHP_PSI_SRCDIR/php_psi_stdinc.h.in]
+               [$PHP_PSI_BUILDDIR/php_psi_posix.h:$PHP_PSI_SRCDIR/php_psi_posix.h.in]
+       )
+
+])
+
+dnl PSI_CONFIG_WAIT()
+dnl Internal: waits for sub configures in maintainer mode
+AC_DEFUN(PSI_CONFIG_WAIT, [
+       wait
+       if test $? -gt 0; then
+               cat $PSI_CONFIG_TMP/*/stderr.log >&2
+               exit 1
+       fi
 ])
 
 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 */
-#ifndef _PSI_STDINC
-# define _PSI_STDINC
-PSI_INCLUDES
-#endif
-EOF
-       for i in $PSI_STDTYPES $PSI_TYPES $PSI_STRUCTS $PSI_UNIONS $PSI_CONSTS $PSI_REDIRS $PSI_DECLS $PSI_VA_DECLS $PSI_FN_DECLS; do
-               cat >>$i <<EOF
-       {0}
-};
-EOF
-       done
+       PSI_CONFIG_WAIT
+       
+       if $PSI_FAST_CONFIG; then
+               for conf_env in $PSI_CONFIG_TMP/*/conf.env; do
+                       source $conf_env
+               done
+       fi
+       
+       psi_eval_LIBS=$LIBS
+       LIBS=$psi_save_LIBS
+       PHP_EVAL_LIBLINE($psi_eval_LIBS, PSI_SHARED_LIBADD)
+       
+       [PSI_INCLUDES]="PSI_INCLUDES"
+       AC_SUBST([PSI_INCLUDES])
+       AC_SUBST([PSI_STDTYPES])
+       AC_SUBST([PSI_TYPES])
+       AC_SUBST([PSI_COMPOSITES])
+       AC_SUBST([PSI_CONSTS])
+       AC_SUBST([PSI_REDIRS])
+       AC_SUBST([PSI_MACROS])
+       AC_SUBST([PSI_DECLS])
 ])
 
 dnl PSI_SH_CONFIG_POSIX_ENABLED(section)
@@ -132,7 +90,7 @@ AC_DEFUN(PSI_CONFIG_POSIX_ENABLED, [
                AS_TR_SH([psi_config_posix_]$1)=true
                ;;
        *)
-               if expr "$PHP_PSI_POSIX" : '\b$1\b' >/dev/null; then
+               if expr "$PHP_PSI_POSIX" : '.*\b$1\b' >/dev/null; then
                        AS_TR_SH([psi_config_posix_]$1)=true
                fi
                ;;
@@ -154,16 +112,73 @@ AC_DEFUN(PSI_SH_TEST_POSIX_ENABLED, [
        fi
 ])
 
-dnl PSI_CONFIG_POSIX(section, headers)
+dnl PSI_CONFIG_POSIX(section, headers, dependents)
 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
+               if $PSI_FAST_CONFIG; then
+                       PSI_CONFIG_POSIX_PARALLEL($1, $2, [$3])
+               else
+                       ifelse([$2],,:,[AC_CHECK_HEADERS($2)])
+                       AS_TR_CPP([PSI_CHECK_$1])
+                       $3
+               fi 
        ])
 ])
 
+AC_DEFUN([PSI_CONFIG_POSIX_PARALLEL], [
+       (
+               dnl chaway
+               mkdir $PSI_CONFIG_TMP/AS_TR_SH([$1])
+               cd $PSI_CONFIG_TMP/AS_TR_SH([$1])
+               
+               dnl AC_DEFINEs 
+               ln -s $abs_builddir/confdefs.h confdefs.h
+               
+               dnl STDOUT, STDERR
+               exec {PSI_MESSAGE_FD}>&AS_MESSAGE_FD {PSI_ERROR_FD}>&2
+               exec AS_MESSAGE_FD>stdout.log 2>stderr.log
+               
+               dnl check for headers?
+               ifelse([$2],,:,[AC_CHECK_HEADERS($2)])
+               
+               dnl run checks
+               PSI_TYPES=
+               PSI_CONSTS=
+               PSI_COMPOSITES=
+               PSI_REDIRS=
+               PSI_MACROS=
+               PSI_DECLS=
+               AS_TR_CPP([PSI_CHECK_$1])
+               
+               dnl save env
+               cat >conf.env <<EOF
+LIBS="$LIBS \$LIBS"
+EOF
+               for env in TYPES CONSTS COMPOSITES MACROS REDIRS DECLS; do
+                       eval var=\$PSI_$env
+                       if test -n "$var"; then
+                               cat >>conf.env <<EOF
+PSI_$env='$var'"
+\$PSI_$env"
+EOF
+                       fi
+               done
+               
+               _AC_CACHE_DUMP >>conf.env
+               dnl restore STDOUT,STDERR
+               exec AS_MESSAGE_FD>&$PSI_MESSAGE_FD 2>&$PSI_ERROR_FD
+               
+               dnl done
+               AS_ECHO_N(["$1 "])
+               cd - >/dev/null
+               
+               dnl run dependents
+               $3
+               
+               PSI_CONFIG_WAIT
+       ) &
+])
+
 AC_DEFUN(PSI_PTHREAD_ONCE, [
        AX_PTHREAD([
                LIBS="$PTHREAD_LIBS $LIBS"
@@ -177,7 +192,8 @@ AC_DEFUN(PSI_PTHREAD, [
 dnl PSI_INCLUDES()
 dnl Expands to a complete list of include statements including
 dnl AC_INCLUDES_DEFAULT().
-AC_DEFUN(PSI_INCLUDES, [#define PSI_INCLUDES
+AC_DEFUN(PSI_INCLUDES, [dnl
+#define PSI_INCLUDES
 #ifndef _GNU_SOURCE
 # define _GNU_SOURCE
 #endif
@@ -185,6 +201,21 @@ AC_DEFUN(PSI_INCLUDES, [#define PSI_INCLUDES
 # define _REENTRANT
 #endif
 AC_INCLUDES_DEFAULT()
+#ifdef HAVE_STDBOOL_H
+# include <stdbool.h>
+#else
+# ifndef HAVE__BOOL
+#  ifdef __cplusplus
+typedef bool _Bool;
+#  else
+#   define _Bool signed char
+#  endif
+# endif
+# define bool _Bool
+# define false 0
+# define true 1
+# define __bool_true_false_are_defined 1
+#endif
 #ifdef HAVE_ERRNO_H
 # include <errno.h>
 #endif
@@ -206,6 +237,9 @@ AC_INCLUDES_DEFAULT()
 #ifdef HAVE_ARPA_NAMESER_H
 # include <arpa/nameser.h>
 #endif
+#ifdef HAVE_ARPA_INET_H
+# include <arpa/inet.h>
+#endif
 #ifdef HAVE_FCNTL_H
 # include <fcntl.h>
 #endif
@@ -264,7 +298,16 @@ dnl PSI_LEMON()
 dnl Declare $LEMON precious, and check for a `lemon` in $PATH.
 AC_DEFUN(PSI_LEMON, [
        AC_ARG_VAR(LEMON, The lemon parser generator of the SQLite project)
-       AC_PATH_PROG(LEMON, lemon, ./lemon)
+       if test -z "$LEMON"
+       then
+               AC_PATH_PROG(LEMON, lemon, $PHP_PSI_BUILDDIR/lemon)
+               if expr + "$LEMON" : "/" >/dev/null; then
+                       LEMON_PATH=
+               else
+                       LEMON_PATH=$abs_builddir/
+               fi
+       fi
+       PHP_SUBST(LEMON_PATH)
        PHP_SUBST(LEMON)
 ])
 
@@ -302,7 +345,7 @@ AC_DEFUN([PSI_SH_TEST_ALIGNOF], [test -n "$AS_TR_SH([ac_cv_alignof_]$1)" && test
 
 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.
+dnl Defines psi\\SIZEOF_<TYPE> pre-defined constant in $PSI_CONSTS_H.
 AC_DEFUN(PSI_CHECK_SIZEOF, [
        AC_CHECK_SIZEOF($1, [], PSI_INCLUDES
                $2)
@@ -313,7 +356,7 @@ AC_DEFUN(PSI_CHECK_SIZEOF, [
 
 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.
+dnl Defines psi\\ALIGNOF_<TYPE> pre-defined constant in $PSI_CONSTS_H.
 AC_DEFUN(PSI_CHECK_ALIGNOF, [
        AC_CHECK_ALIGNOF($1, PSI_INCLUDES
                $2)
@@ -407,6 +450,7 @@ AC_DEFUN(PSI_CHECK_LIBFFI, [
                PHP_EVAL_INCLINE(`$PKG_CONFIG --cflags libffi`)
                PHP_EVAL_LIBLINE(`$PKG_CONFIG --libs libffi`, PSI_SHARED_LIBADD)
                AC_DEFINE(HAVE_LIBFFI, 1, Have libffi)
+               AC_DEFINE_UNQUOTED([PHP_PSI_LIBFFI_VERSION], ["`$PKG_CONFIG --modversion libffi`"], [libffi version])
        else
                AC_CACHE_CHECK(for libffi, psi_cv_libffi_dir, [
                for psi_cv_libffi_dir in $PHP_PSI_LIBFFI {/usr{,/local},/opt}{,/libffi}