build: fixes
[m6w6/ext-psi] / m4 / psi / psi.m4
index 0c2b16537cc58125c4c6b03092b243f3a2ce05e8..f99d582f4e519a5d972d6b1a7cb1a252a0dd25ca 100644 (file)
@@ -7,6 +7,18 @@ 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
+       ])
+
        if test "$PHP_PSI_MAINTAINER_MODE" = "yes"; then
                PSI_FAST_CONFIG=true
                PSI_DEPS=true
@@ -15,7 +27,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
@@ -41,11 +52,22 @@ AC_DEFUN(PSI_CONFIG_INIT, [
 
 ])
 
+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, [
+       PSI_CONFIG_WAIT
+       
        if $PSI_FAST_CONFIG; then
-               wait
                for conf_env in $PSI_CONFIG_TMP/*/conf.env; do
                        source $conf_env
                done
@@ -116,22 +138,20 @@ AC_DEFUN(PSI_CONFIG_POSIX, [
 
 AC_DEFUN([PSI_CONFIG_POSIX_PARALLEL], [
        (
-               dnl setup
+               dnl chaway
                mkdir $PSI_CONFIG_TMP/AS_TR_SH([$1])
-               printenv > $PSI_CONFIG_TMP/AS_TR_SH([$1])/start.env
-               ln -s $(pwd)/confdefs.h $PSI_CONFIG_TMP/AS_TR_SH([$1])/confdefs.h
+               cd $PSI_CONFIG_TMP/AS_TR_SH([$1])
+               
+               dnl AC_DEFINEs 
+               ln -s $abs_builddir/confdefs.h 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 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 chaway
-               cd $PSI_CONFIG_TMP/AS_TR_SH([$1])
-               
                dnl run checks
                PSI_TYPES=
                PSI_CONSTS=
@@ -142,27 +162,31 @@ AC_DEFUN([PSI_CONFIG_POSIX_PARALLEL], [
                AS_TR_CPP([PSI_CHECK_$1])
                
                dnl save env
-               printenv > $PSI_CONFIG_TMP/AS_TR_SH([$1])/end.env
-               cat >$PSI_CONFIG_TMP/AS_TR_SH([$1])/conf.env <<EOF
+               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 >>$PSI_CONFIG_TMP/AS_TR_SH([$1])/conf.env <<EOF
+                               cat >>conf.env <<EOF
 PSI_$env='$var'"
 \$PSI_$env"
 EOF
                        fi
                done
                
-               _AC_CACHE_DUMP >>$PSI_CONFIG_TMP/AS_TR_SH([$1])/conf.env
+               _AC_CACHE_DUMP >>conf.env
+               dnl restore STDOUT,STDERR
+               exec AS_MESSAGE_FD>&$PSI_MESSAGE_FD 2>&$PSI_ERROR_FD
                
                dnl done
-               printf "%s " "$1" >&66
+               AS_ECHO_N(["$1 "])
+               cd - >/dev/null
                
+               dnl run dependents
                $3
-               wait
+               
+               PSI_CONFIG_WAIT
        ) &
 ])
 
@@ -178,16 +202,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
@@ -224,6 +247,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
@@ -285,7 +311,13 @@ AC_DEFUN(PSI_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)
 ])
 
@@ -352,7 +384,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(
@@ -448,6 +480,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, [ ])