[PATCH:xmag] Use lrint() from math library if available

Alan Coopersmith alan.coopersmith at oracle.com
Tue Dec 20 20:58:58 PST 2011


Moves -lm from being hardcoded in Makefile.am to being added via
AC_SEARCH_LIBS in configure.ac setting it in $(LIBS)

Using lrint() [returns long int] instead of rint() [returns double]
clears a bunch of gcc warnings of the form:
"cast from function call of type ‘double’ to non-matching type ‘short int’"

Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
---
 Makefile.am  |    2 +-
 Scale.c      |    6 ++++++
 configure.ac |    6 ++++++
 3 files changed, 13 insertions(+), 1 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index 2ec463c..6c1a81c 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -23,7 +23,7 @@ SUBDIRS = man
 bin_PROGRAMS = xmag
 
 AM_CFLAGS = $(XMAG_CFLAGS) $(CWARNFLAGS)
-xmag_LDADD = $(XMAG_LIBS) -lm
+xmag_LDADD = $(XMAG_LIBS)
 
 xmag_SOURCES =	\
         CutPaste.c \
diff --git a/Scale.c b/Scale.c
index 94fef63..22d8649 100644
--- a/Scale.c
+++ b/Scale.c
@@ -30,6 +30,8 @@ from The Open Group.
  * Author:  Davor Matic, MIT X Consortium
  */
 
+#include "config.h"
+
 #include <stdio.h>
 #include <ctype.h>
 #include <math.h>
@@ -43,7 +45,11 @@ from The Open Group.
 #include "CutPaste.h"
 #include "ScaleP.h"
 
+#ifdef HAVE_LRINT
+#define myrint(x) lrint(x)
+#else
 #define myrint(x) floor(x + 0.5)
+#endif
 
 #define streq(a,b) (strcmp( (a), (b) ) == 0)
 #ifndef min
diff --git a/configure.ac b/configure.ac
index a688487..2dca039 100644
--- a/configure.ac
+++ b/configure.ac
@@ -37,6 +37,12 @@ AC_CONFIG_HEADERS([config.h])
 
 AC_CHECK_FUNCS([nanosleep poll select])
 
+# Math libraries & functions
+# - lrint() is a C99 addition not found on some older systems
+# - must do the libm check first so that the rint check will have it in $LIBS
+AC_SEARCH_LIBS([floor], [m])
+AC_CHECK_FUNCS([lrint])
+
 # Checks for pkg-config packages
 PKG_CHECK_MODULES(XMAG, xaw7 xmu xt x11)
 
-- 
1.7.3.2



More information about the xorg-devel mailing list