isnan*: Separate the AC_LIBOBJ invocations.
[gnulib.git] / m4 / isnand.m4
1 # isnand.m4 serial 9
2 dnl Copyright (C) 2007-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 dnl Check how to get or define isnand().
8
9 AC_DEFUN([gl_FUNC_ISNAND],
10 [
11   AC_REQUIRE([gl_MATH_H_DEFAULTS])
12   ISNAND_LIBM=
13   gl_HAVE_ISNAND_NO_LIBM
14   if test $gl_cv_func_isnand_no_libm = no; then
15     gl_HAVE_ISNAND_IN_LIBM
16     if test $gl_cv_func_isnand_in_libm = yes; then
17       ISNAND_LIBM=-lm
18     fi
19   fi
20   dnl The variable gl_func_isnand set here is used by isnan.m4.
21   if test $gl_cv_func_isnand_no_libm = yes \
22      || test $gl_cv_func_isnand_in_libm = yes; then
23     gl_func_isnand=yes
24   else
25     gl_func_isnand=no
26     HAVE_ISNAND=0
27     AC_LIBOBJ([isnand])
28     gl_PREREQ_ISNAND
29   fi
30   AC_SUBST([ISNAND_LIBM])
31 ])
32
33 dnl Check how to get or define isnand() without linking with libm.
34
35 AC_DEFUN([gl_FUNC_ISNAND_NO_LIBM],
36 [
37   gl_HAVE_ISNAND_NO_LIBM
38   if test $gl_cv_func_isnand_no_libm = yes; then
39     AC_DEFINE([HAVE_ISNAND_IN_LIBC], [1],
40       [Define if the isnan(double) function is available in libc.])
41   else
42     AC_LIBOBJ([isnand])
43     gl_PREREQ_ISNAND
44   fi
45 ])
46
47 dnl Prerequisites of replacement isnand definition. It does not need -lm.
48 AC_DEFUN([gl_PREREQ_ISNAND],
49 [
50   gl_DOUBLE_EXPONENT_LOCATION
51 ])
52
53 dnl Test whether isnand() can be used with libm.
54
55 AC_DEFUN([gl_HAVE_ISNAND_IN_LIBM],
56 [
57   AC_CACHE_CHECK([whether isnan(double) can be used with libm],
58     [gl_cv_func_isnand_in_libm],
59     [
60       save_LIBS="$LIBS"
61       LIBS="$LIBS -lm"
62       AC_LINK_IFELSE(
63         [AC_LANG_PROGRAM(
64            [[#include <math.h>
65              #if __GNUC__ >= 4
66              # undef isnand
67              # define isnand(x) __builtin_isnan ((double)(x))
68              #elif defined isnan
69              # undef isnand
70              # define isnand(x) isnan ((double)(x))
71              #endif
72              double x;]],
73            [[return isnand (x);]])],
74         [gl_cv_func_isnand_in_libm=yes],
75         [gl_cv_func_isnand_in_libm=no])
76       LIBS="$save_LIBS"
77     ])
78 ])
79
80 AC_DEFUN([gl_HAVE_ISNAND_NO_LIBM],
81 [
82   AC_CACHE_CHECK([whether isnan(double) can be used without linking with libm],
83     [gl_cv_func_isnand_no_libm],
84     [
85       AC_LINK_IFELSE(
86         [AC_LANG_PROGRAM(
87            [[#include <math.h>
88              #if __GNUC__ >= 4
89              # undef isnand
90              # define isnand(x) __builtin_isnan ((double)(x))
91              #else
92              # undef isnand
93              # define isnand(x) isnan ((double)(x))
94              #endif
95              double x;]],
96            [[return isnand (x);]])],
97         [gl_cv_func_isnand_no_libm=yes],
98         [gl_cv_func_isnand_no_libm=no])
99     ])
100 ])