summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2011-12-20 21:47:56 -0800
committerAlan Coopersmith <alan.coopersmith@oracle.com>2011-12-20 21:48:09 -0800
commit67ab447959b62454f4e0273177baa19711babb96 (patch)
treef0a0a7c4bdad446a6311d65d18d19a2e534db81a
parent1c2b70d13c42f5461a2d7c3cae7adf8d9b2e3cea (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 $(MATH_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>
-rw-r--r--Graphics.c10
-rw-r--r--Makefile.am2
-rw-r--r--configure.ac12
3 files changed, 22 insertions, 2 deletions
diff --git a/Graphics.c b/Graphics.c
index b3ec1bc..43c48b9 100644
--- a/Graphics.c
+++ b/Graphics.c
@@ -30,6 +30,10 @@ from The Open Group.
* Author: Davor Matic, MIT X Consortium
*/
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
#include <X11/IntrinsicP.h>
#include <X11/StringDefs.h>
#include <X11/Xfuncs.h>
@@ -46,7 +50,11 @@ from The Open Group.
#define min(x, y) (((int)(x) < (int)(y)) ? (x) : (y))
#define max(x, y) (((int)(x) > (int)(y)) ? (x) : (y))
#ifndef rint
-#define rint(x) floor(x + 0.5)
+# if HAVE_LRINT
+# define rint(x) lrint(x)
+# else
+# define rint(x) floor(x + 0.5)
+# endif
#endif
/*****************************************************************************\
diff --git a/Makefile.am b/Makefile.am
index 7a5ca35..88cc611 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -23,7 +23,7 @@ SUBDIRS=man
bin_PROGRAMS = bitmap bmtoa atobm
bitmap_CFLAGS = $(CWARNFLAGS) $(BITMAP_CFLAGS)
-bitmap_LDADD = $(BITMAP_LIBS) -lm
+bitmap_LDADD = $(BITMAP_LIBS) $(MATH_LIBS)
bitmap_SOURCES = \
BitEdit.c \
CutPaste.c \
diff --git a/configure.ac b/configure.ac
index ecb71ce..c3fcba9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -42,6 +42,18 @@ AM_PROG_CC_C_O
AC_CHECK_FUNCS([mkstemp])
+# Math libraries & functions
+# - some compilers use builtin inlines for floor when optimizing
+# - 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
+save_LIBS="$LIBS"
+AC_SEARCH_LIBS([floor], [m])
+AC_SEARCH_LIBS([lrint], [m])
+AC_CHECK_FUNCS([lrint])
+MATH_LIBS="$LIBS"
+LIBS="$save_LIBS"
+AC_SUBST([MATH_LIBS])
+
# Obtain compiler/linker options from dependencies
PKG_CHECK_MODULES(BMTOA, x11 xmu)
PKG_CHECK_MODULES(ATOBM, xproto)