configure: improve checks for funcs not in stdlib
authorMichael Wallner <mike@php.net>
Thu, 20 Oct 2016 13:47:22 +0000 (15:47 +0200)
committerMichael Wallner <mike@php.net>
Thu, 20 Oct 2016 13:47:22 +0000 (15:47 +0200)
config.m4
m4/posix/ndbm.m4
m4/posix/signal.m4
m4/posix/stdlib.m4
m4/posix/time.m4
m4/posix/unistd.m4
m4/psi/psi.m4
m4/psi/psi_decl.m4

index df18db6d66fe51b29e28c0950f4df8067862e90b..cece1cb375ff8a2cf7fd37e34f6501680c2af192 100644 (file)
--- a/config.m4
+++ b/config.m4
@@ -46,19 +46,19 @@ m4_foreach(incfile, [
 PHP_ARG_ENABLE(psi, whether to enable PHP System Interface support,
 [  --enable-psi            Enable PHP System Interface support])
 
-PHP_ARG_ENABLE(psi-posix, whether to pre-define POSIX decls,
-[  --enable-psi-posix=...  PSI: pre-define POSIX decls], [ ], [ ])
+if test "$PHP_PSI" != no; then
+       PHP_CONFIGURE_PART(Configuring PSI)
 
-PHP_ARG_WITH(psi-libjit, where to find libjit,
-[  --with-psi-libjit=DIR   PSI: path to libjit], [ ], [ ])
+       PHP_ARG_ENABLE(psi-posix, whether to pre-define POSIX decls,
+       [  --enable-psi-posix=...  PSI: pre-define POSIX decls], [ ], [ ])
 
-PHP_ARG_WITH(psi-libffi, where to find libffi,
-[  --with-psi-libffi=DIR   PSI: path to libffi], [ ], [ ])
+       PHP_ARG_WITH(psi-libjit, where to find libjit,
+       [  --with-psi-libjit=DIR   PSI: path to libjit], [ ], [ ])
 
-if test "$PHP_PSI" != no; then
-       PHP_CONFIGURE_PART(Configuring PSI)
+       PHP_ARG_WITH(psi-libffi, where to find libffi,
+       [  --with-psi-libffi=DIR   PSI: path to libffi], [ ], [ ])
 
-       save_LIBS=$LIBS
+       psi_save_LIBS=$LIBS
        LIBS=
 
        PSI_LEMON
@@ -99,22 +99,22 @@ if test "$PHP_PSI" != no; then
        PSI_CHECK_WCTYPE
        PSI_CONFIG_DONE
 
-       eval_LIBS=$LIBS
-       LIBS=$save_LIBS
-       PHP_EVAL_LIBLINE($eval_LIBS, PSI_SHARED_LIBADD)
+       psi_eval_LIBS=$LIBS
+       LIBS=$psi_save_LIBS
+       PHP_EVAL_LIBLINE($psi_eval_LIBS, PSI_SHARED_LIBADD)
        PHP_SUBST(PSI_SHARED_LIBADD)
 
        AC_DEFINE_UNQUOTED(PHP_PSI_SHLIB_SUFFIX, ["$SHLIB_SUFFIX_NAME"], DL suffix)
 
-       AC_DEFINE_UNQUOTED([PSI_STDINC], [$PSI_STDINC], [Standard includes])
-       AC_DEFINE_UNQUOTED([PSI_TYPES], [$PSI_TYPES], [Predefined types])
-       AC_DEFINE_UNQUOTED([PSI_STRUCTS], [$PSI_STRUCTS], [Predefined structs])
-       AC_DEFINE_UNQUOTED([PSI_UNIONS], [$PSI_UNIONS], [Predefined structs])
-       AC_DEFINE_UNQUOTED([PSI_CONSTS], [$PSI_CONSTS], [Predefined constants])
-       AC_DEFINE_UNQUOTED([PSI_MACROS], [$PSI_MACROS], [Redirected Macros])
-       AC_DEFINE_UNQUOTED([PSI_REDIRS], [$PSI_REDIRS], [Redirected functions])
-       AC_DEFINE_UNQUOTED([PSI_DECLS], [$PSI_DECLS], [Predefined functions])
-       AC_DEFINE_UNQUOTED([PSI_VA_DECLS], [$PSI_VA_DECLS], [Predefined vararg functions])
+       AC_DEFINE_UNQUOTED([PSI_STDINC], ["$PSI_STDINC"], [Standard includes])
+       AC_DEFINE_UNQUOTED([PSI_TYPES], ["$PSI_TYPES"], [Predefined types])
+       AC_DEFINE_UNQUOTED([PSI_STRUCTS], ["$PSI_STRUCTS"], [Predefined structs])
+       AC_DEFINE_UNQUOTED([PSI_UNIONS], ["$PSI_UNIONS"], [Predefined structs])
+       AC_DEFINE_UNQUOTED([PSI_CONSTS], ["$PSI_CONSTS"], [Predefined constants])
+       AC_DEFINE_UNQUOTED([PSI_MACROS], ["$PSI_MACROS"], [Redirected Macros])
+       AC_DEFINE_UNQUOTED([PSI_REDIRS], ["$PSI_REDIRS"], [Redirected functions])
+       AC_DEFINE_UNQUOTED([PSI_DECLS], ["$PSI_DECLS"], [Predefined functions])
+       AC_DEFINE_UNQUOTED([PSI_VA_DECLS], ["$PSI_VA_DECLS"], [Predefined vararg functions])
 
        PHP_ADD_INCLUDE($PHP_PSI_SRCDIR/src)
        PHP_ADD_INCLUDE($PHP_PSI_SRCDIR/src/types)
index 7b04504536b60495f9dc4afebff8b5cebc95c634..ee7159118d5ffaaad52bd51b0f1433bdf6b01f67 100644 (file)
@@ -1,11 +1,9 @@
 PSI_CHECK_NDBM() {
-       PSI_CONFIG_POSIX(ndbm, ndbm.h gdbm-ndbm.h)
-
-       PHP_CHECK_FUNC(dbm_open, gdbm_compat)
-       # See http://www.gnu.org.ua/software/gdbm/manual/html_section/gdbm_19.html
-       if expr X"$LIBS" : "X.*-lgdbm_compat" >/dev/null; then
-               LIBS="-lgdbm $LIBS"
-       fi
+       PSI_CONFIG_POSIX(ndbm, dnl
+               ndbm.h dnl posix
+               relic.h dnl qdbm
+               gdbm-ndbm.h dnl gdbm
+       )
 
        PSI_STRUCT(datum, [
                void *dptr,
@@ -17,13 +15,18 @@ PSI_CHECK_NDBM() {
        PSI_CONST(DBM_INSERT, int)
        PSI_CONST(DBM_REPLACE, int)
 
-       PSI_DECL(void dbm_clearerr, [(DBM *db)])
-       PSI_DECL(void dbm_close, [(DBM *db)])
-       PSI_DECL(int dbm_delete, [(DBM *db, datum key)])
-       PSI_DECL(int dbm_error, [(DBM *db)])
-       PSI_DECL(datum dbm_fetch, [(DBM *db, datum key)])
-       PSI_DECL(datum dbm_firstkey, [(DBM *db)])
-       PSI_DECL(datum dbm_nextkey, [(DBM *db)])
-       PSI_DECL(DBM *dbm_open, [(char *file, int open_flags, mode_t file_mode)])
-       PSI_DECL(int dbm_store, [(DBM *db, datum key, datum content, int store_mode)])
+       PSI_DECL(void dbm_clearerr, [(DBM *db)], [], [-lqdbm -lgdbm_compat])
+       PSI_DECL(void dbm_close, [(DBM *db)], [], [-lqdbm -lgdbm_compat])
+       PSI_DECL(int dbm_delete, [(DBM *db, datum key)], [], [-lqdbm -lgdbm_compat])
+       PSI_DECL(int dbm_error, [(DBM *db)], [], [-lqdbm -lgdbm_compat])
+       PSI_DECL(datum dbm_fetch, [(DBM *db, datum key)], [], [-lqdbm -lgdbm_compat])
+       PSI_DECL(datum dbm_firstkey, [(DBM *db)], [], [-lqdbm -lgdbm_compat])
+       PSI_DECL(datum dbm_nextkey, [(DBM *db)], [], [-lqdbm -lgdbm_compat])
+       PSI_DECL(DBM *dbm_open, [(char *file, int open_flags, mode_t file_mode)], [], [-lqdbm -lgdbm_compat])
+       PSI_DECL(int dbm_store, [(DBM *db, datum key, datum content, int store_mode)], [], [-lqdbm -lgdbm_compat])
+
+       # See http://www.gnu.org.ua/software/gdbm/manual/html_section/gdbm_19.html
+       if expr X"$LIBS" : "X.*-lgdbm_compat" >/dev/null; then
+               LIBS="-lgdbm $LIBS"
+       fi
 }
\ No newline at end of file
index a9225ceb3fcc42297737985e6bb6bdeb7f9234af..fe0c545347e15efe12719f310ee80dd98cdceff1 100644 (file)
@@ -123,14 +123,14 @@ PSI_CHECK_SIGNAL() {
                int ss_flags]
        )
        
-       PSI_FUNCTOR_TYPE(void sa_handler, [(int signo)])
-       PSI_FUNCTOR_TYPE(void sa_sigaction, [(int signo, siginfo_t *info, ucontext_t *context)])
+       PSI_FUNCTOR_TYPE(void sighandler_t, [(int signo)])
+       PSI_FUNCTOR_TYPE(void sigaction_t, [(int signo, siginfo_t *info, ucontext_t *context)])
        
        PSI_STRUCT(struct sigaction, [
-               sa_handler sa_handler,
+               sighandler_t sa_handler,
                sigset_t sa_mask,
                int sa_flags,
-               sa_sigaction sa_sigaction]
+               sigaction_t sa_sigaction]
        )
        
        PSI_STRUCT(ucontext_t, [
@@ -173,13 +173,13 @@ PSI_CHECK_SIGNAL() {
        PSI_DECL(int sigignore, [(int sig)])
        PSI_DECL(int siginterrupt, [(int sig, int flag)])
        PSI_DECL(int sigismember, [(const sigset_t *set, int signum)])
-       PSI_DECL(void *signal, [(int sig, void *func)])
+       PSI_DECL(sighandler_t signal, [(int sig, sighandler_t *func)])
        PSI_DECL(int sigpause, [(int sig)])
        PSI_DECL(int sigpending, [(sigset_t *set)])
        PSI_DECL(int sigprocmask, [(int how, const sigset_t *set, sigset_t *oset)])
        PSI_DECL(int sigqueue, [(pid_t pid, int sig, const union sigval value)])
        PSI_DECL(int sigrelse, [(int sig)])
-       PSI_DECL(void *sigset, [(int sig, void *disp)])
+       PSI_DECL(sighandler_t sigset, [(int sig, sighandler_t disp)])
        PSI_DECL(int sigsuspend, [(const sigset_t *sigmask)])
        PSI_DECL(int sigtimedwait, [(const sigset_t *set, siginfo_t *info, const struct timespec *timeout)])
        PSI_DECL(int sigwait, [(const sigset_t *set, int *sig)])
index 60a301558726182f2d05fdb1e1565816131692db..f1a0c959ccb35fc062994f848d2b5505b10fe27b 100644 (file)
@@ -57,11 +57,7 @@ PSI_CHECK_STDLIB() {
        PSI_DECL(char *realpath, [(char *path, char *resolved)])
        PSI_DECL(unsigned short *seed48, [(unsigned short seed16v@<:@3@:>@)])
        PSI_DECL(int setenv, [(char *var, char *val, int overwrite)])
-       
-       AC_SEARCH_LIBS(setkey, crypt, [
-               PSI_DECL(void setkey, [(char *key)])
-       ])
-       
+       PSI_DECL(void setkey, [(char *key)], [], [-lcrypt])
        PSI_DECL(char *setstate, [(char *state)])
        PSI_DECL(void srand, [(unsigned seed)])
        PSI_DECL(void srand48, [(long seed)])
index e1b4011c7910bf30c11f34fafb29c6809939c3d5..250e3c901b6ee208a6213a7fa3a0f90209922805 100644 (file)
@@ -27,15 +27,15 @@ PSI_CHECK_TIME() {
                struct timespec it_interval,
                struct timespec it_value]
        )
-
+       
        PSI_DECL(char *asctime, [(struct tm *tm)])
        PSI_DECL(char *asctime_r, [(struct tm *tm, char *buf)])
        PSI_DECL(clock_t clock, [()])
-       PSI_DECL(int clock_getcpuclockid, [(pid_t pid, clockid_t *clock_id)])
-       PSI_DECL(int clock_getres, [(clockid_t clk_id, struct timespec *res)])
-       PSI_DECL(int clock_gettime, [(clockid_t clk_id, struct timespec *tp)])
-       PSI_DECL(int clock_nanosleep, [(clockid_t clk_id, int flags, struct timespec *rqtp, struct timespec *rmtp)])
-       PSI_DECL(int clock_settime, [(clockid_t clk_id, struct timespec *tp)])
+       PSI_DECL(int clock_getcpuclockid, [(pid_t pid, clockid_t *clock_id)], [], [-lrt])
+       PSI_DECL(int clock_getres, [(clockid_t clk_id, struct timespec *res)], [], [-lrt])
+       PSI_DECL(int clock_gettime, [(clockid_t clk_id, struct timespec *tp)], [], [-lrt])
+       PSI_DECL(int clock_nanosleep, [(clockid_t clk_id, int flags, struct timespec *rqtp, struct timespec *rmtp)], [], [-lrt])
+       PSI_DECL(int clock_settime, [(clockid_t clk_id, struct timespec *tp)], [], [-lrt])
        PSI_DECL(char *ctime, [(time_t *t)])
        PSI_DECL(char *ctime_r, [(time_t *t, char *buf)])
        PSI_DECL(double difftime, [(time_t time1, time_t time0)])
@@ -47,14 +47,14 @@ PSI_CHECK_TIME() {
        PSI_DECL(time_t mktime, [(struct tm *tm)])
        PSI_DECL(int nanosleep, [(struct timespec *rqts, struct timespec *rmts)])
        PSI_DECL(size_t strftime, [(char *s, size_t max, char *fmt, struct tm *tm)])
-       dnl PSI_DECL(size_t strftime_l, [(char *s, size_t max, char *fmt, struct tm *tm, locale_t l)])
+       PSI_DECL(size_t strftime_l, [(char *s, size_t max, char *fmt, struct tm *tm, locale_t l)])
        PSI_DECL(char *strptime, [(char *s, char *fmt, struct tm *tm)])
        PSI_DECL(time_t time, [(time_t *t)])
-       dnl PSI_DECL(int timer_create, [(clockid_t clk_id, struct sigevent *se, timer_t *t)])
-       PSI_DECL(int timer_delete, [(timer_t t)])
-       PSI_DECL(int timer_getoverrun, [(timer_t t)])
-       PSI_DECL(int timer_gettime, [(timer_t t, struct itimerspec *ts)])
-       PSI_DECL(int timer_settime, [(timer_t t, int flags, struct itimerspec *value, struct itimerspec *ovalue)])
+       PSI_DECL(int timer_create, [(clockid_t clk_id, struct sigevent *se, timer_t *t)], [], [-lrt])
+       PSI_DECL(int timer_delete, [(timer_t t)], [], [-lrt])
+       PSI_DECL(int timer_getoverrun, [(timer_t t)], [], [-lrt])
+       PSI_DECL(int timer_gettime, [(timer_t t, struct itimerspec *ts)], [], [-lrt])
+       PSI_DECL(int timer_settime, [(timer_t t, int flags, struct itimerspec *value, struct itimerspec *ovalue)], [], [-lrt])
        PSI_DECL(void tzset, [()])
 
        PSI_EXTVAR(int daylight)
index 21265005fef8320ffd6d1055b0baa453859eae71..fde0fe9fc5272abbbe992d29381c2bf93f9418c0 100644 (file)
@@ -289,18 +289,10 @@ PSI_CHECK_UNISTD() {
        PSI_DECL(int chown, [(const char *path, uid_t owner, gid_t group)])
        PSI_DECL(int close, [(int fildes)])
        PSI_DECL(size_t confstr, [(int name, char *buf, size_t len)])
-       
-       AC_SEARCH_LIBS(crypt, crypt, [
-               PSI_DECL(char *crypt, [(const char *key, const char *salt)])
-       ])
-       
+       PSI_DECL(char *crypt, [(const char *key, const char *salt)], [], [-lcrypt])
        PSI_DECL(int dup, [(int fildes)])
        PSI_DECL(int dup2, [(int fildes, int fildes2)])
-       
-       AC_SEARCH_LIBS(encrypt, crypt, [
-               PSI_DECL(void encrypt, [(char block@<:@64@:>@, int edflag)])
-       ])
-       
+       PSI_DECL(void encrypt, [(char block@<:@64@:>@, int edflag)], [], [-lcrypt])
        PSI_DECL(void _exit, [(int status)])
        PSI_DECL(int execl, [(const char *path, const char *arg)], vararg)
        PSI_DECL(int execle, [(const char *path, const char *arg)], vararg)
index 6b3668e1600bf47ba9b4d0c02d938b430cfa1864..b0bbbf3056f3908fbfd07427b684192e4b5b1416 100644 (file)
@@ -11,13 +11,11 @@ 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, [
+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 */
@@ -180,9 +178,12 @@ 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
+#ifndef _GNU_SOURCE
+# define _GNU_SOURCE
+#endif
+#ifndef _REENTRANT
+# define _REENTRANT
+#endif
 AC_INCLUDES_DEFAULT()
 #ifdef HAVE_ERRNO_H
 # include <errno.h>
@@ -208,7 +209,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>
index fa2bf55ec6e8c87045db63689f3a730cd47c9af1..c5b90decf6b0e9bb499297f3883d8d4a909a6457 100644 (file)
@@ -77,25 +77,51 @@ AC_DEFUN(PSI_DECL_ARG, [
     psi_decl_args="[$psi_decl_args{]PSI_TYPE_PAIR(member_type)[, \"]member_name[\",] $pl, $as[}]"
 ])
 
-dnl PSI_DECL(type func, args, flags)
+dnl PSI_DECL(type func, args, flags, libs)
 dnl Check for a function or macro declaration and a possible asm redirection.
 dnl Adds a pre-defined (vararg) decl to $PSI_VA_DECLS/$PSI_DECLS.
 dnl Calls PSI_MACRO if PSI_FUNC fails.
 AC_DEFUN(PSI_DECL, [
-       AC_REQUIRE([PSI_FUNC_LIBC_MAIN])
+       AC_REQUIRE([PSI_FUNC_LIBC_MAIN])dnl
+       
        PSI_DECL_ARGS($1, $2)
 
        psi_symbol="PSI_VAR_NAME($1)"
        AC_CACHE_CHECK(for PSI_VAR_NAME($1), [psi_cv_fn_]PSI_VAR_NAME($1), [
+               psi_decl_check=
                psi_symbol_redirect=
-               AC_TRY_LINK(PSI_INCLUDES, [
-                       void (*fn)(void) = (void (*)(void)) $psi_symbol; (*fn)()
-               ], [
-                       psi_symbol_redirect=`nm -g conftest$ac_exeext | $AWK -F ' *|@' '/^@<:@@<:@:space:@:>@@:>@+U '$psi_cv_libc_main'/ {next} /^@<:@@<:@:space:@:>@@:>@+U / {print$[]3; exit}'`
-               ])
-               [psi_cv_fn_]PSI_VAR_NAME($1)=$psi_symbol_redirect
+               for lib in "" $4; do
+                       decl_save_LIBS=$LIBS
+                       LIBS=$lib
+                       AC_TRY_LINK(PSI_INCLUDES, [
+                               void (*fn)(void) = (void (*)(void)) $psi_symbol; (*fn)()
+                       ], [
+                               psi_symbol_redirect=`nm -g conftest$ac_exeext | $AWK -F ' *|@' '/^@<:@@<:@:space:@:>@@:>@+U '$psi_cv_libc_main'/ {next} /^@<:@@<:@:space:@:>@@:>@+U / {print$[]3; exit}'`
+                       ])
+                       LIBS=$decl_save_LIBS
+                       
+                       if test -n "$psi_symbol_redirect"; then
+                               if test -n "$lib"; then
+                                       psi_decl_check="$psi_symbol_redirect in $lib"
+                               else
+                                       psi_decl_check="$psi_symbol_redirect" 
+                               fi
+                               break
+                       fi
+               done
+               [psi_cv_fn_]PSI_VAR_NAME($1)=$psi_decl_check
        ])
-       case "$[psi_cv_fn_]PSI_VAR_NAME($1)" in
+       
+       psi_symbol_redirect=`AS_ECHO("$[psi_cv_fn_]PSI_VAR_NAME($1)") | $AWK -F " in " '{print [$]1}'`
+       psi_symbol_libflag=`AS_ECHO("$[psi_cv_fn_]PSI_VAR_NAME($1)") | $AWK -F " in " '{print [$]2}'`
+       
+       if test -n "$psi_symbol_libflag"; then
+               if ! expr "X$LIBS" : "X.*\b$psi_symbol_libflag\b" >/dev/null; then
+                       LIBS="$psi_symbol_libflag $LIBS"
+               fi
+       fi
+       
+       case "$psi_symbol_redirect" in
        "$psi_symbol"|"_$psi_symbol")
                case "$PHP_DEBUG-$3" in
                "1-")