immutable: Add tests.
[gnulib.git] / m4 / ffsll.m4
blob97491eb2e632ce03faf664a2e37192d29d995a1c
1 # ffsll.m4 serial 2
2 dnl Copyright (C) 2011-2021 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
7 AC_DEFUN([gl_FUNC_FFSLL],
9   AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS])
10   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
12   dnl Persuade glibc <string.h> and AIX <strings.h> to declare ffsll().
13   AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
15   AC_CHECK_FUNCS_ONCE([ffsll])
16   if test $ac_cv_func_ffsll = yes; then
17     dnl Test whether ffsll works.
18     dnl On AIX 7.2 in 32-bit mode it is completely broken.
19     AC_CACHE_CHECK([whether ffsll works],
20       [gl_cv_func_ffsll_works],
21       [AC_RUN_IFELSE(
22          [AC_LANG_SOURCE([[
23             #include <string.h>
24             #include <strings.h>
25             int dummy (long long x) { return 42; }
26             int main (int argc, char *argv[])
27             {
28               int (* volatile my_ffsll) (long long) = argc ? ffsll : dummy;
29               long long int x = -128LL;
30               return my_ffsll (x) != 8;
31             }
32           ]])],
33          [gl_cv_func_ffsll_works=yes],
34          [gl_cv_func_ffsll_works=no],
35          [case "$host_os" in
36                            # Guess yes on glibc systems.
37             *-gnu* | gnu*) gl_cv_func_ffsll_works="guessing yes" ;;
38                            # Guess yes on musl systems.
39             *-musl*)       gl_cv_func_ffsll_works="guessing yes" ;;
40                            # Guess yes on native Windows.
41             mingw*)        gl_cv_func_ffsll_works="guessing yes" ;;
42                            # Guess no on AIX.
43             aix*)          gl_cv_func_ffsll_works="guessing no" ;;
44                            # If we don't know, obey --enable-cross-guesses.
45             *)             gl_cv_func_ffsll_works="$gl_cross_guess_normal" ;;
46           esac
47          ])
48       ])
49     case "$gl_cv_func_ffsll_works" in
50       *yes) ;;
51       *) REPLACE_FFSLL=1 ;;
52     esac
53   else
54     HAVE_FFSLL=0
55   fi