From 67ab447959b62454f4e0273177baa19711babb96 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Tue, 20 Dec 2011 21:47:56 -0800 Subject: Use lrint() from math library if available MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- Graphics.c | 10 +++++++++- Makefile.am | 2 +- configure.ac | 12 ++++++++++++ 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 #include #include @@ -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) -- cgit v1.2.3