1dnl Search for libfailmalloc to use for testing 2dnl 3dnl Copyright (C) 2018-2021 Dan Fandrich <dan@coneharvesters.com>, et. al. 4dnl SPDX-License-Identifier: LGPL-2.0-or-later 5 6AC_DEFUN([CHECK_FAILMALLOC],[dnl 7 dnl Libtool sets the default library paths 8 LT_INIT([win32-dll]) 9 path_provided= 10 failmalloc_requested= dnl Either implicitly or explicitly 11 AC_ARG_WITH(failmalloc, [ --with-failmalloc=PATH use Failmalloc for tests], [ 12 failmalloc_requested=1 13 if test x"$withval" = "x" -o x"$withval" = x"yes"; then 14 failmalloc_search_path="$sys_lib_search_path_spec" 15 elif test x"$withval" = x"no"; then 16 failmalloc_search_path="" 17 failmalloc_requested= 18 else 19 failmalloc_search_path="$withval" 20 path_provided=1 21 fi 22 ], [failmalloc_search_path="$sys_lib_search_path_spec"] 23 ) 24 libfailmalloc_file=libfailmalloc.so.0 25 FAILMALLOC_PATH= 26 27 dnl Skip the check if we're cross-compiling, unless the user explicitly requested it 28 if test x"$cross_compiling" = x"no" -o x"$failmalloc_requested" = x"1"; then 29 dnl Check if the argument is a directory 30 for d in $failmalloc_search_path; do 31 AC_CHECK_FILE([$d/$libfailmalloc_file], [ 32 FAILMALLOC_PATH="$d/$libfailmalloc_file" 33 break 34 ], []) 35 done 36 if test -z "$FAILMALLOC_PATH" -a -n "$path_provided"; then 37 dnl Check if the argument is a file 38 AC_CHECK_FILE([$failmalloc_search_path], [FAILMALLOC_PATH="$failmalloc_search_path"], []) 39 fi 40 fi 41 42 AC_MSG_CHECKING([for failmalloc]) 43 dnl Make sure AC_CHECK_FILE didn't find a directory by mistake 44 if test -n "$FAILMALLOC_PATH" -a -f "$FAILMALLOC_PATH"; then 45 AC_MSG_RESULT([yes]) 46 else 47 if test -n "$path_provided"; then 48 AC_MSG_ERROR([$libfailmalloc_file was not found at $failmalloc_search_path]) 49 else 50 if test x"$cross_compiling" != x"no"; then 51 AC_MSG_RESULT([no (cross compiling)]) 52 else 53 AC_MSG_RESULT([no]) 54 fi 55 fi 56 fi 57 AC_SUBST(FAILMALLOC_PATH) 58 AM_CONDITIONAL(USE_FAILMALLOC, [test x"$FAILMALLOC_PATH" != x]) 59]) 60 61