From c1bd76d6fcbbc7c07c99a5738dea99f830f79810 Mon Sep 17 00:00:00 2001
From: "Bryn M. Reeves" <bmr@redhat.com>
Date: Tue, 18 Aug 2015 15:21:19 +0100
Subject: [PATCH] configure: check for -lm and log10 function

We already use -lm functions in a couple of places (these are
satisfied by gcc built-ins for most builds): add a configure.in
check and explicitly link to -lm.
---
 configure         | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 configure.in      |  5 +++++
 libdm/Makefile.in |  2 +-
 make.tmpl.in      |  1 +
 4 files changed, 53 insertions(+), 1 deletion(-)

diff --git a/configure b/configure
index 630f12af3..57bec6986 100755
--- a/configure
+++ b/configure
@@ -665,6 +665,7 @@ PYTHON_LIBDIRS
 PYTHON_INCDIRS
 PYTHON_BINDINGS
 PTHREAD_LIBS
+M_LIBS
 POOL
 PKGCONFIG
 OCFDIR
@@ -12569,6 +12570,50 @@ if [ \( "$LVM1" = shared -o "$POOL" = shared -o "$CLUSTER" = shared \
 	as_fn_error $? "Features cannot be 'shared' when building statically" "$LINENO" 5
 fi
 
+################################################################################
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for log10 in -lm" >&5
+$as_echo_n "checking for log10 in -lm... " >&6; }
+if ${ac_cv_lib_m_log10+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lm  $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char log10 ();
+int
+main ()
+{
+return log10 ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_lib_m_log10=yes
+else
+  ac_cv_lib_m_log10=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_m_log10" >&5
+$as_echo "$ac_cv_lib_m_log10" >&6; }
+if test "x$ac_cv_lib_m_log10" = xyes; then :
+  M_LIBS="-lm"
+else
+  hard_bailout
+fi
+
+
 ################################################################################
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for pthread_mutex_lock in -lpthread" >&5
 $as_echo_n "checking for pthread_mutex_lock in -lpthread... " >&6; }
@@ -14151,6 +14196,7 @@ LVM_LIBAPI=`echo "$VER" | $AWK -F '[()]' '{print $2}'`
 
 
 
+
 
 
 ################################################################################
diff --git a/configure.in b/configure.in
index c3e55e9b5..2c89d8c6a 100644
--- a/configure.in
+++ b/configure.in
@@ -1537,6 +1537,10 @@ if [[ \( "$LVM1" = shared -o "$POOL" = shared -o "$CLUSTER" = shared \
 	AC_MSG_ERROR([Features cannot be 'shared' when building statically])
 fi
 
+################################################################################
+AC_CHECK_LIB(m, log10,
+	[M_LIBS="-lm"], hard_bailout)
+
 ################################################################################
 AC_CHECK_LIB([pthread], [pthread_mutex_lock],
 	[PTHREAD_LIBS="-lpthread"], hard_bailout)
@@ -1984,6 +1988,7 @@ AC_SUBST(OCF)
 AC_SUBST(OCFDIR)
 AC_SUBST(PKGCONFIG)
 AC_SUBST(POOL)
+AC_SUBST(M_LIBS)
 AC_SUBST(PTHREAD_LIBS)
 AC_SUBST(PYTHON)
 AC_SUBST(PYTHON_BINDINGS)
diff --git a/libdm/Makefile.in b/libdm/Makefile.in
index 880b40c68..1b924cef3 100644
--- a/libdm/Makefile.in
+++ b/libdm/Makefile.in
@@ -55,7 +55,7 @@ include $(top_builddir)/make.tmpl
 
 CFLAGS += $(UDEV_CFLAGS) $(VALGRIND_CFLAGS)
 
-LIBS += $(SELINUX_LIBS) $(UDEV_LIBS) $(PTHREAD_LIBS)
+LIBS += $(SELINUX_LIBS) $(UDEV_LIBS) $(PTHREAD_LIBS) $(M_LIBS)
 
 device-mapper: all
 
diff --git a/make.tmpl.in b/make.tmpl.in
index 731dab7ca..e4f8835fd 100644
--- a/make.tmpl.in
+++ b/make.tmpl.in
@@ -54,6 +54,7 @@ LDDEPS += @LDDEPS@
 LIB_SUFFIX = @LIB_SUFFIX@
 LVMINTERNAL_LIBS = -llvm-internal $(DAEMON_LIBS) $(UDEV_LIBS) $(DL_LIBS) $(BLKID_LIBS)
 DL_LIBS = @DL_LIBS@
+M_LIBS = @M_LIBS@
 PTHREAD_LIBS = @PTHREAD_LIBS@
 READLINE_LIBS = @READLINE_LIBS@
 SELINUX_LIBS = @SELINUX_LIBS@