Merge pull request #2043 from RincewindsHat/cleanup/leftovers
[monitoring-plugins.git] / gl / m4 / builtin-expect.m4
blobc7af926b34c3b4e57c5a690aaea62ad62f984ea5
1 # builtin-expect.m4
2 # serial 1
3 dnl Copyright 2016-2024 Free Software Foundation, Inc.
4 dnl This file is free software; the Free Software Foundation
5 dnl gives unlimited permission to copy and/or distribute it,
6 dnl with or without modifications, as long as this notice is preserved.
8 dnl Check for __builtin_expect.
10 dnl Written by Paul Eggert.
12 AC_DEFUN([gl___BUILTIN_EXPECT],
14   AC_CACHE_CHECK([for __builtin_expect],
15     [gl_cv___builtin_expect],
16     [AC_LINK_IFELSE(
17        [AC_LANG_SOURCE([[
18          int
19          main (int argc, char **argv)
20          {
21            argc = __builtin_expect (argc, 100);
22            return argv[argc != 100][0];
23          }]])],
24        [gl_cv___builtin_expect=yes],
25        [AC_LINK_IFELSE(
26           [AC_LANG_SOURCE([[
27              #include <builtins.h>
28              int
29              main (int argc, char **argv)
30              {
31                argc = __builtin_expect (argc, 100);
32                return argv[argc != 100][0];
33              }]])],
34           [gl_cv___builtin_expect="in <builtins.h>"],
35           [gl_cv___builtin_expect=no])])])
36   if test "$gl_cv___builtin_expect" = yes; then
37     AC_DEFINE([HAVE___BUILTIN_EXPECT], [1])
38   elif test "$gl_cv___builtin_expect" = "in <builtins.h>"; then
39     AC_DEFINE([HAVE___BUILTIN_EXPECT], [2])
40   fi
41   AH_VERBATIM([HAVE___BUILTIN_EXPECT],
42     [/* Define to 1 if the compiler supports __builtin_expect,
43    and to 2 if <builtins.h> does.  */
44 #undef HAVE___BUILTIN_EXPECT
45 #ifndef HAVE___BUILTIN_EXPECT
46 # define __builtin_expect(e, c) (e)
47 #elif HAVE___BUILTIN_EXPECT == 2
48 # include <builtins.h>
49 #endif
50     ])