Merge branch 'slimconfigure'
[m6w6/ext-psi] / m4 / psi / psi.m4
index b137ec6484f23201d1ab4e7e5ea60013deb78ad2..ba869070d501cdf3c7f03559d978caf95b093e81 100644 (file)
@@ -7,6 +7,54 @@ AC_DEFUN(PSI_CONFIG_INIT, [
        psi_save_LIBS=$LIBS
        LIBS=
 
+       ac_includes_default="AC_INCLUDES_DEFAULT"
+       
+       AC_PROG_AWK
+       AC_PATH_PROG(NM, nm)
+       AC_CACHE_CHECK(for libc start main symbol, psi_cv_libc_main, [
+               psi_libc_main=
+               AC_TRY_LINK(PSI_INCLUDES, [(void)0;], [
+                       psi_libc_main=`nm -g conftest$ac_exeext | $AWK -F ' *|@' '/^@<:@@<:@:space:@:>@@:>@+U / {print$[]3; exit}'`
+               ])
+               psi_cv_libc_main=$psi_libc_main
+       ])
+       
+       AC_MSG_CHECKING(for preprocessor defaults)
+       psi_cpp_predef=`$CPP -Wp,-dM $CPPFLAGS -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 - </dev/null`
+       psi_cpp_search=`$CPP -Wp,-v $CPPFLAGS -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 - </dev/null 2>&1 >/dev/null \
+               | $AWK '
+                       /include.*search.*start/ { 
+                               capture = 1
+                               next
+                       }
+                       /@<:@Ee@:>@nd.*search/ {
+                               capture = 0
+                       }
+                       { 
+                               if (capture)
+                                       print $1
+                       }
+               ' \
+       `
+       psi_cpp_predef_count=`printf %s "$psi_cpp_predef" | wc -l`
+       psi_cpp_search_count=`printf %s "$psi_cpp_search" | wc -l`
+       AC_MSG_RESULT([$psi_cpp_predef_count predefined macros, and $psi_cpp_search_count search paths])
+       PSI_CPP_PREDEF=`printf "%s\n" "$psi_cpp_predef" | \
+               $AWK '{
+                       gsub(/"/, "\\\\\"");
+                       printf "\"%s\\\n\"\n", $[]0
+               }' \
+       `
+       PSI_CPP_SEARCH=`printf %s "$psi_cpp_search" | \
+               $AWK '{
+                       if (i) printf ":";
+                       gsub(/^@<:@@<:@:space:@:>@@:>@+/,"");
+                       gsub(/@<:@@<:@:space:@:>@@:>@+$/,"");
+                       printf "%s", $[]0;
+                       ++i
+               }' \
+       `
+
        if test "$PHP_PSI_MAINTAINER_MODE" = "yes"; then
                PSI_FAST_CONFIG=true
                PSI_DEPS=true
@@ -15,7 +63,6 @@ AC_DEFUN(PSI_CONFIG_INIT, [
                PHP_SUBST(PSI_DEPS)
                
                PSI_CONFIG_TMP=$(mktemp -d)
-               PSI_FUNC_LIBC_MAIN
        else
                PSI_FAST_CONFIG=false
                PSI_DEPS=false
@@ -37,6 +84,7 @@ AC_DEFUN(PSI_CONFIG_INIT, [
        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]
+               [$PHP_PSI_BUILDDIR/php_psi_cpp.h:$PHP_PSI_SRCDIR/php_psi_cpp.h.in]
        )
 
 ])
@@ -58,7 +106,9 @@ AC_DEFUN(PSI_CONFIG_DONE, [
        
        if $PSI_FAST_CONFIG; then
                for conf_env in $PSI_CONFIG_TMP/*/conf.env; do
-                       source $conf_env
+                       if test "$conf_env" != "$PSI_CONFIG_TMP/*/conf.env"; then
+                               source $conf_env
+                       fi
                done
        fi
        
@@ -75,6 +125,8 @@ AC_DEFUN(PSI_CONFIG_DONE, [
        AC_SUBST([PSI_REDIRS])
        AC_SUBST([PSI_MACROS])
        AC_SUBST([PSI_DECLS])
+       AC_SUBST([PSI_CPP_SEARCH])
+       AC_SUBST([PSI_CPP_PREDEF])
 ])
 
 dnl PSI_SH_CONFIG_POSIX_ENABLED(section)
@@ -166,7 +218,7 @@ EOF
                
                _AC_CACHE_DUMP >>conf.env
                dnl restore STDOUT,STDERR
-               exec >&$PSI_MESSAGE_FD 2>&$PSI_ERROR_FD
+               exec AS_MESSAGE_FD>&$PSI_MESSAGE_FD 2>&$PSI_ERROR_FD
                
                dnl done
                AS_ECHO_N(["$1 "])
@@ -191,16 +243,15 @@ 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, [dnl
-#define PSI_INCLUDES
+dnl autoconf's defaults.
+AC_DEFUN(PSI_INCLUDES, [
 #ifndef _GNU_SOURCE
 # define _GNU_SOURCE
 #endif
 #ifndef _REENTRANT
 # define _REENTRANT
 #endif
-AC_INCLUDES_DEFAULT()
+$ac_includes_default
 #ifdef HAVE_STDBOOL_H
 # include <stdbool.h>
 #else
@@ -237,6 +288,9 @@ typedef bool _Bool;
 #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
@@ -371,7 +425,7 @@ AC_DEFUN(PSI_CHECK_OFFSETOF, [
                [offset of $2 in $1],
                [AS_TR_SH([ac_cv_offsetof_$1_$2])],
                [(long int) (offsetof ($1, $2))],
-               [PSI_INCLUDES],
+               PSI_INCLUDES,
                [AC_MSG_FAILURE([cannot compute offsetof ($1, $2)])]
        )
        AC_DEFINE_UNQUOTED(
@@ -467,6 +521,13 @@ AC_DEFUN(PSI_CHECK_LIBFFI, [
                        AC_MSG_WARN([Could not find libffi, please provide the base install path])
                fi
        fi
+       
+       save_CFLAGS=$CFLAGS
+       CFLAGS="$CFLAGS $INCLUDES"
+       AC_CHECK_DECL(FFI_STDCALL,[AC_DEFINE([HAVE_FFI_STDCALL],[1],[ ])],,[#include "ffi.h"])
+       AC_CHECK_DECL(FFI_FASTCALL,[AC_DEFINE([HAVE_FFI_FASTCALL],[1],[ ])],,[#include "ffi.h"])
+       CFLAGS=$save_CFLAGS
+       
        PHP_CHECK_LIBRARY(ffi, ffi_closure_alloc, [
                PHP_CHECK_LIBRARY(ffi, ffi_prep_closure_loc, [
                        AC_DEFINE(PSI_HAVE_FFI_PREP_CLOSURE_LOC, 1, [ ])