[PATCH] configure.ac: Include math.h when checking for sqrt/cbrt

Daniel Stone daniel at fooishbar.org
Mon Jul 26 08:31:15 PDT 2010


sqrt and cbrt are only defined in math.h, so we have to include that
when checking for them, lest we miss it, and then some other header
pulling in math.h causes build failures due to multiple definitions.

As far as I can tell, this is actually genuinely the best way to do this
in autoconf. \o/

Signed-off-by: Daniel Stone <daniel at fooishbar.org>
---
 configure.ac |   37 +++++++++++++++++++++++++++++++++++--
 1 files changed, 35 insertions(+), 2 deletions(-)

diff --git a/configure.ac b/configure.ac
index baa0b5c..d4ac033 100644
--- a/configure.ac
+++ b/configure.ac
@@ -227,8 +227,41 @@ dnl Check for mmap support for Xvfb
 AC_CHECK_FUNC([mmap], AC_DEFINE(HAS_MMAP, 1, [Have the 'mmap' function.]))
 
 dnl Find the math libary
-AC_CHECK_LIB(m, sqrt)
-AC_CHECK_LIB(m, cbrt, AC_DEFINE(HAVE_CBRT, 1, [Have the 'cbrt' function]))
+AC_MSG_CHECKING([for sqrt])
+old_LIBS="$LIBS";
+LIBS="$old_LIBS -lm";
+AC_TRY_LINK([
+    #include <math.h>
+], [
+{
+    int i = sqrt(4);
+    return !!(i == 2);
+}], have_sqrt=yes, have_sqrt=no)
+if test "x$have_sqrt" = xyes; then
+    AC_DEFINE(HAVE_SQRT, 1, [Have the square root function])
+    AC_MSG_RESULT(yes)
+else
+    AC_MSG_RESULT(no)
+fi
+LIBS="$old_LIBS"
+
+AC_MSG_CHECKING([for cbrt])
+old_LIBS="$LIBS";
+LIBS="$old_LIBS -lm";
+AC_TRY_LINK([
+    #include <math.h>
+], [
+{
+    int i = cbrt(8);
+    return !!(i == 2);
+}], have_cbrt=yes, have_cbrt=no)
+if test "x$have_cbrt" = xyes; then
+    AC_DEFINE(HAVE_CBRT, 1, [Have the cube root function])
+    AC_MSG_RESULT(yes)
+else
+    AC_MSG_RESULT(no)
+fi
+LIBS="$old_LIBS"
 
 AC_CHECK_HEADERS([ndbm.h dbm.h rpcsvc/dbm.h])
 
-- 
1.7.1



More information about the xorg-devel mailing list