aboutsummaryrefslogtreecommitdiff
path: root/libctf/configure.ac
diff options
context:
space:
mode:
authorNick Alcock <nick.alcock@oracle.com>2019-06-03 14:02:09 +0100
committerNick Alcock <nick.alcock@oracle.com>2019-06-04 17:05:08 +0100
commit6b22174ff163b828a2069f22353018ca97fc0fb4 (patch)
tree25224c057c20981bff2e95d098b189673f3e6847 /libctf/configure.ac
parent941accce38bc70a23c62e3c9439b67bf23298124 (diff)
downloadgdb-6b22174ff163b828a2069f22353018ca97fc0fb4.zip
gdb-6b22174ff163b828a2069f22353018ca97fc0fb4.tar.gz
gdb-6b22174ff163b828a2069f22353018ca97fc0fb4.tar.bz2
libctf: look for BSD versus GNU qsort_r signatures
We cannot just look for any declaration of qsort_r, because some operating systems have a qsort_r that has a different prototype but which still has a pair of pointers in the right places (the last two args are interchanged): so use AC_LINK_IFELSE to check for both known variants of qsort_r(), and swap their args into a consistent order in a suitable inline function. (The code for this is taken almost unchanged from gnulib.) (Now we are not using AC_LIBOBJ any more, we can use a better name for the qsort_r replacement as well.) libctf/ * qsort_r.c: Rename to... * ctf-qsort_r.c: ... this. (_quicksort): Define to ctf_qsort_r. * ctf-decls.h (qsort_r): Remove. (ctf_qsort_r): Add. (struct ctf_qsort_arg): New, transport the real ARG and COMPAR. (ctf_qsort_compar_thunk): Rearrange the arguments to COMPAR. * Makefile.am (libctf_a_LIBADD): Remove. (libctf_a_SOURCES): New, add ctf-qsort_r.c. * ctf-archive.c (ctf_arc_write): Call ctf_qsort_r, not qsort_r. * ctf-create.c (ctf_update): Likewise. * configure.ac: Check for BSD versus GNU qsort_r signature. * Makefile.in: Regenerate. * config.h.in: Likewise. * configure: Likewise.
Diffstat (limited to 'libctf/configure.ac')
-rw-r--r--libctf/configure.ac44
1 files changed, 42 insertions, 2 deletions
diff --git a/libctf/configure.ac b/libctf/configure.ac
index 8fd5388..beb90ba 100644
--- a/libctf/configure.ac
+++ b/libctf/configure.ac
@@ -90,8 +90,48 @@ fi
AC_C_BIGENDIAN
AC_CHECK_HEADERS(byteswap.h endian.h)
AC_CHECK_FUNCS(pread)
-AC_CHECK_DECLS([qsort_r])
-AC_LIBOBJ([qsort_r])
+
+dnl Check for qsort_r. (Taken from gnulib.)
+AC_CHECK_FUNCS_ONCE([qsort_r])
+if test $ac_cv_func_qsort_r = yes; then
+ AC_CACHE_CHECK([for qsort_r signature], [ac_cv_libctf_qsort_r_signature],
+ [AC_LINK_IFELSE(
+ [AC_LANG_PROGRAM([[#undef qsort_r
+ #include <stdlib.h>
+ void qsort_r (void *, size_t, size_t,
+ int (*) (void const *, void const *,
+ void *),
+ void *);
+ void (*p) (void *, size_t, size_t,
+ int (*) (void const *, void const *,
+ void *),
+ void *) = qsort_r;
+ ]])],
+ [ac_cv_libctf_qsort_r_signature=GNU],
+ [AC_LINK_IFELSE(
+ [AC_LANG_PROGRAM([[#undef qsort_r
+ #include <stdlib.h>
+ void qsort_r (void *, size_t, size_t, void *,
+ int (*) (void *,
+ void const *,
+ void const *));
+ void (*p) (void *, size_t, size_t, void *,
+ int (*) (void *, void const *,
+ void const *)) = qsort_r;
+ ]])],
+ [ac_cv_libctf_qsort_r_signature=BSD],
+ [ac_cv_libctf_qsort_r_signature=unknown])])])
+fi
+
+case x$ac_cv_libctf_qsort_r_signature in
+ xGNU) AC_DEFINE([HAVE_QSORT_R_ARG_LAST], 1,
+ [Whether a qsort_r exists with a void *arg as its last arg.]);;
+ xBSD) AC_DEFINE([HAVE_QSORT_R_COMPAR_LAST], 1,
+ [Whether a qsort_r exists with the compar function as its last arg.]);;
+ *) ac_cv_libctf_qsort_r_signature=unknown;;
+esac
+
+AM_CONDITIONAL(NEED_CTF_QSORT_R, test "${ac_cv_libctf_qsort_r_signature}" = unknown)
AC_CONFIG_FILES(Makefile)
AC_CONFIG_HEADERS(config.h)