Declare system functions in a way that works with C++.
[gnulib.git] / m4 / logb.m4
1 # logb.m4 serial 3
2 dnl Copyright (C) 2010-2011 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.
6
7 AC_DEFUN([gl_FUNC_LOGB],
8 [
9   AC_REQUIRE([gl_MATH_H_DEFAULTS])
10   dnl Test whether logb() is declared.
11   AC_CHECK_DECLS([logb], , , [#include <math.h>])
12   if test "$ac_cv_have_decl_logb" != yes; then
13     HAVE_DECL_LOGB=0
14   fi
15   dnl Test whether logb() can be used without libm.
16   LOGB_LIBM=?
17   AC_LINK_IFELSE(
18     [AC_LANG_PROGRAM(
19        [[#ifndef __NO_MATH_INLINES
20          # define __NO_MATH_INLINES 1 /* for glibc */
21          #endif
22          #include <math.h>
23          extern
24          #ifdef __cplusplus
25          "C"
26          #endif
27          double logb (double x);
28          double x;]],
29        [[x = logb(x);]])],
30     [LOGB_LIBM=])
31   if test "$LOGB_LIBM" = "?"; then
32     save_LIBS="$LIBS"
33     LIBS="$LIBS -lm"
34     AC_LINK_IFELSE(
35       [AC_LANG_PROGRAM(
36          [[#ifndef __NO_MATH_INLINES
37            # define __NO_MATH_INLINES 1 /* for glibc */
38            #endif
39            #include <math.h>
40            extern
41            #ifdef __cplusplus
42            "C"
43            #endif
44            double logb (double x);
45            double x;]],
46          [[x = logb(x);]])],
47       [LOGB_LIBM="-lm"])
48     LIBS="$save_LIBS"
49   fi
50   if test "$LOGB_LIBM" = "?"; then
51     LOGB_LIBM=
52   fi
53   AC_SUBST([LOGB_LIBM])
54 ])