better dependency management
[m6w6/ext-psi] / m4 / psi / psi.m4
index dbe3defc8f4d89acb3139b18d98c9e8c899b026b..c8eec1850d9f546efeef16b550e39bbf1be9c38a 100644 (file)
@@ -11,14 +11,22 @@ 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
 
-PSI_CONFIG_APPEND=
-
 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, [
+       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"
@@ -108,14 +116,22 @@ 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
+#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 _XOPEN_SOURCE
-# define _XOPEN_SOURCE
+#ifndef _REENTRANT
+# define _REENTRANT
 #endif
+
 PSI_INCLUDES
 #endif
 EOF
@@ -185,11 +201,30 @@ 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
-#define _GNU_SOURCE 1
-#define _POSIX_C_SOURCE 200809L
-#define _XOPEN_SOURCE 700
+AC_DEFUN(PSI_INCLUDES, [dnl
+#define PSI_INCLUDES
+#ifndef _GNU_SOURCE
+# define _GNU_SOURCE
+#endif
+#ifndef _REENTRANT
+# 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
@@ -214,7 +249,9 @@ AC_INCLUDES_DEFAULT()
 #ifdef HAVE_FCNTL_H
 # include <fcntl.h>
 #endif
-#ifdef HAVE_NDBM_H
+#ifdef HAVE_RELIC_H
+# include <relic.h>
+#elif HAVE_NDBM_H
 # include <ndbm.h>
 #elif HAVE_GDBM_NDBM_H
 # include <gdbm-ndbm.h>
@@ -267,7 +304,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)
 ])
 
@@ -410,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}