configure: add --enable-psi-maintainer-mode
[m6w6/ext-psi] / m4 / psi / psi.m4
index b0bbbf3056f3908fbfd07427b684192e4b5b1416..b979719862a2db08fff771411158c4c7def3fe7d 100644 (file)
@@ -15,8 +15,39 @@ 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
+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)
+       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
+       
+       cat >$PHP_PSI_BUILDDIR/php_psi.dep <<EOF
+\$(PHP_PSI_SRCDIR)/php_psi.h:
+php_psi.h:
+\$(PHP_PSI_SRCDIR)/php_psi_stdinc.h:
+php_psi_stdinc.h:
+EOF
        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 >>$PHP_PSI_BUILDDIR/php_psi.dep <<EOF
+$i:
+$(basename $i):
+EOF
                cat >$i <<EOF
 /* generated by configure */
 #include "php_psi_stdinc.h"
@@ -104,10 +135,37 @@ EOF
 dnl PSI_CONFIG_DONE()
 dnl Finish the headers with the pre-defined types etc.
 AC_DEFUN(PSI_CONFIG_DONE, [
+       
+       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)
+       
        cat >$PSI_STDINC <<EOF
 /* generated by configure */
-#ifndef _PSI_STDINC
-# define _PSI_STDINC
+#ifndef PSI_STDINC_H
+#define PSI_STDINC_H
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#else
+# include "php_config.h"
+#endif
+
+#ifndef _GNU_SOURCE
+# define _GNU_SOURCE
+#endif
+#ifndef _REENTRANT
+# define _REENTRANT
+#endif
+
 PSI_INCLUDES
 #endif
 EOF
@@ -157,13 +215,44 @@ AC_DEFUN(PSI_SH_TEST_POSIX_ENABLED, [
 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
+               if $PSI_FAST_CONFIG; then
+                       PSI_CONFIG_POSIX_PARALLEL($1, $2)
+               else
+                       ifelse([$2],,:,[AC_CHECK_HEADERS($2)])
+                       AS_TR_CPP([PSI_CHECK_$1])
+               fi 
        ])
 ])
 
+AC_DEFUN([PSI_CONFIG_POSIX_PARALLEL], [
+       (
+               dnl setup
+               mkdir $PSI_CONFIG_TMP/AS_TR_SH([$1])
+               ln -s $(pwd)/confdefs.h $PSI_CONFIG_TMP/AS_TR_SH([$1])/confdefs.h
+               
+               dnl restore stdio
+               exec 66>&AS_MESSAGE_FD
+               exec AS_MESSAGE_FD>$PSI_CONFIG_TMP/AS_TR_SH([$1])/stdout.log
+               exec 2>$PSI_CONFIG_TMP/AS_TR_SH([$1])/stderr.log
+               
+               dnl check for headers?
+               ifelse([$2],,:,[AC_CHECK_HEADERS($2)])
+               
+               dnl chaway
+               cd $PSI_CONFIG_TMP/AS_TR_SH([$1])
+               
+               dnl run checks
+               AS_TR_CPP([PSI_CHECK_$1])
+               
+               dnl save libs
+               cat >$PSI_CONFIG_TMP/AS_TR_SH([$1])/conf.env <<EOF
+LIBS="$LIBS \$LIBS"
+EOF
+               dnl done
+               printf "%s " "$1" >&66
+       ) &
+])
+
 AC_DEFUN(PSI_PTHREAD_ONCE, [
        AX_PTHREAD([
                LIBS="$PTHREAD_LIBS $LIBS"
@@ -177,7 +266,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 +275,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
@@ -264,7 +369,10 @@ 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, ./lemon)
+       fi
        PHP_SUBST(LEMON)
 ])
 
@@ -407,6 +515,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}