summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2011-12-20 20:40:06 -0800
committerAlan Coopersmith <alan.coopersmith@oracle.com>2012-02-08 21:23:43 -0800
commit50ed4f69a5f5e535128c5e2d1abc252b093dff06 (patch)
tree9bd76eba679e974dee5f60c2061c678aedc13aad
parent43ffa427238cdfb132205375624a25c5c28e9f86 (diff)
Use lrint() from math library if available
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@oracle.com> Reviewed-by: James Cloos <cloos@jhcloos.com>
-rw-r--r--Makefile.am2
-rw-r--r--Scale.c6
-rw-r--r--configure.ac8
3 files changed, 15 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..4e7af49 100644
--- a/configure.ac
+++ b/configure.ac
@@ -37,6 +37,14 @@ AC_CONFIG_HEADERS([config.h])
AC_CHECK_FUNCS([nanosleep poll select])
+# Math libraries & functions
+# - some compilers use builtin inlines for floor
+# - lrint() is a C99 addition not found on some older systems
+# - must do the libm check first so that the lrint check will have it in $LIBS
+AC_SEARCH_LIBS([floor], [m])
+AC_SEARCH_LIBS([lrint], [m])
+AC_CHECK_FUNCS([lrint])
+
# Checks for pkg-config packages
PKG_CHECK_MODULES(XMAG, xaw7 xmu xt x11)