+
+builtin_mul_overflow_code="
+#include <stddef.h>
+int main(int argc, char **argv)
+{
+ size_t n = 0, size = 0, total;
+ __builtin_mul_overflow(n, size, &total);
+ return 0;
+}
+"
+
+TLOGN "checking for __builtin_mul_overflow"
+if bup_try_c_code "$builtin_mul_overflow_code"; then
+ AC_DEFINE BUP_HAVE_BUILTIN_MUL_OVERFLOW 1
+ TLOG ' (found)'
+else
+ TLOG ' (not found)'
+fi
+
+
+AC_CHECK_FUNCS mincore
+
+mincore_incore_code="
+#if 0$ac_defined_HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#if 0$ac_defined_HAVE_SYS_MMAN_H
+#include <sys/mman.h>
+#endif
+int main(int argc, char **argv)
+{
+ if (MINCORE_INCORE)
+ return 0;
+}
+"
+
+mincore_buf_type_code()
+{
+ local vec_type="$1"
+ echo "
+#include <sys/mman.h>
+int main(int argc, char **argv)
+{
+ void *x = 0;
+ $vec_type *buf = 0;
+ return mincore(x, 0, buf);
+}" || exit $?
+}
+
+if test "$ac_defined_HAVE_MINCORE"; then
+ TLOGN "checking for MINCORE_INCORE"
+ if bup_try_c_code "$mincore_incore_code"; then
+ AC_DEFINE BUP_HAVE_MINCORE_INCORE 1
+ TLOG ' (found)'
+ else
+ TLOG ' (not found)'
+ fi
+
+ TLOGN "checking mincore buf type"
+ if bup_try_c_code "$(mincore_buf_type_code char)"; then
+ AC_DEFINE BUP_MINCORE_BUF_TYPE 'char'
+ TLOG ' (char)'
+ elif bup_try_c_code "$(mincore_buf_type_code 'unsigned char')"; then
+ AC_DEFINE BUP_MINCORE_BUF_TYPE 'unsigned char'
+ TLOG ' (unsigned char)'
+ else
+ AC_FAIL "ERROR: unexpected mincore definition; please notify bup-list@googlegroups.com"
+ fi
+fi
+
+
+TLOGN "checking for readline"
+bup_have_readline=''
+bup_readline_includes_in_subdir=''
+bup_readline_via_pkg_config=''
+# We test this specific thing because it should work everywhere and it was
+# a particulary problem on macos (we'd get the wrong includes if we just
+# tested that the includes work).
+readline_test_code='
+ static char *on_completion_entry(const char *text, int state) { return NULL; }
+ void bup_test(void) { rl_completion_entry_function = on_completion_entry; }
+'
+if pkg-config readline; then
+ bup_readline_cflags="$(pkg-config readline --cflags)" || exit $?
+ bup_readline_ldflags="$(pkg-config readline --libs)" || exit $?
+ # It looks like it's not uncommon for pkg-config to provide a -I
+ # that doesn't support the documentation's specified #include
+ # <readline/readline.h>. See what's really going on.
+ if bup_try_c_code "#include <readline/readline.h> $readline_test_code" \
+ "$bup_readline_cflags"
+ then
+ bup_have_readline=1
+ bup_readline_includes_in_subdir=1
+ elif bup_try_c_code "#include <readline.h> $readline_test_code" \
+ "$bup_readline_cflags"
+ then
+ bup_have_readline=1
+ fi
+ if test "$bup_have_readline"; then
+ bup_readline_via_pkg_config=1
+ else
+ bup_readline_cflags=''
+ bup_readline_ldflags=''
+ fi
+fi
+if ! test "$bup_have_readline"; then
+ if bup_try_c_code "#include <readline/readline.h> $readline_test_code"; then
+ bup_readline_ldflags=-lreadline
+ bup_have_readline=1
+ bup_readline_includes_in_subdir=1
+ elif bup_try_c_code "#include <readline.h> $readline_test_code"; then
+ bup_readline_ldflags=-lreadline
+ bup_have_readline=1
+ fi
+fi
+if test "$bup_have_readline"; then
+ AC_DEFINE BUP_HAVE_READLINE 1
+ if test "$bup_readline_includes_in_subdir"; then
+ AC_DEFINE BUP_READLINE_INCLUDES_IN_SUBDIR 1
+ fi
+ if test "$bup_readline_via_pkg_config"; then
+ TLOG ' (yes, pkg-config)'
+ else
+ TLOG ' (yes)'
+ fi
+fi
+
+
+AC_SUB bup_readline_cflags "$bup_readline_cflags"
+AC_SUB bup_readline_ldflags "$bup_readline_ldflags"
+AC_SUB bup_have_readline "$bup_have_readline"
+
+