wrlib: changed Gamma Correction calculation to use single-precision float
[wmaker-crm.git] / m4 / wm_libmath.m4
blob5a8143c144f1fa443042b746459f8e1dd343137c
1 # wm_libmath.m4 - Macros to check proper libMath usage for WINGs
3 # Copyright (c) 2013 Christophe Curis
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License along
16 # with this program; if not, write to the Free Software Foundation, Inc.,
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 # WM_CHECK_LIBM
21 # -------------
23 # Checks the needed library link flags needed to have math lib
24 # Sets variable LIBM with the appropriates flags
25 AC_DEFUN_ONCE([WM_CHECK_LIBM],
26 [AC_CHECK_HEADER([math.h], [],
27                  [AC_MSG_ERROR([header for math library not found])])
28 AC_CHECK_FUNC(atan,
29     [LIBM=],
30     [AC_CHECK_LIB(m, [atan],
31         [LIBM=-lm],
32         [AC_MSG_WARN(Could not find Math library, you may experience problems)
33          LIBM=] )] ) dnl
34 AC_CACHE_CHECK([if M_PI is defined in math.h], [wm_cv_libm_pi],
35     [wm_cv_libm_pi="no"
36      wm_save_CFLAGS="$CFLAGS"
37      for wm_arg in dnl
38        "% yes" dnl natively available (Unix98 compliant?)
39        "-D_XOPEN_SOURCE=500" ; dnl Explicit request
40      do
41        AS_IF([wm_fn_lib_try_compile "math.h" "double val;" "val = M_PI" dnl
42                   "`echo "$wm_arg" | sed -e 's, *%.*$,,' `"],
43            [wm_cv_libm_pi="`echo "$wm_arg" | sed -e 's,^.*% *,,' `" ; break])
44      done
45      CFLAGS="$wm_save_CFLAGS"])
46 AS_IF([test "x$wm_cv_libm_pi" = "xno"],
47     [AC_DEFINE([WM_PI], [(3.14159265358979323846)],
48         [Defines how to access the value of Pi])],
49     [AC_DEFINE([WM_PI], [(M_PI)],
50         [Defines how to access the value of Pi])
51      AS_IF([test "x$wm_cv_libm_pi" != "xyes"],
52         [CFLAGS="$CFLAGS $wm_cv_libm_pi"]) ])
53 AC_CACHE_CHECK([if sinf+cosf are defined in math.h], [wm_cv_libm_sinf],
54     [wm_cv_libm_sinf="no"
55      wm_save_CFLAGS="$CFLAGS"
56      wm_save_LIBS="$LIBS"
57      LIBS="$LIBS $LIBM"
58      for wm_arg in dnl
59        "% yes" dnl natively available (C99 compliant)
60        "-D_XOPEN_SOURCE=600" ; dnl Explicit request
61      do
62        CFLAGS="$wm_save_CFLAGS `echo "$wm_arg" | sed -e 's, *%.*$,,' `"
63        AC_LINK_IFELSE([AC_LANG_PROGRAM([dnl
64 @%:@include <math.h>
65 ], [dnl
66   float a, b;
68   a = WM_PI;
69   b = sqrtf(a);
70   a = atan2f(a, b);
71   b = cosf(a);
72   a = sinf(b);
73   a = powf(a, b);
74   return (int)a;])],
75            [wm_cv_libm_sinf="`echo "$wm_arg" | sed -e 's,^.*% *,,' `" ; break])
76      done
77      LIBS="$wm_save_LIBS"
78      CFLAGS="$wm_save_CFLAGS"])
79 AS_IF([test "x$wm_cv_libm_sinf" != "xno"],
80     [AC_DEFINE([HAVE_FLOAT_MATHFUNC], [1],
81         [Defined if the 'float'-typed math function are available (sinf, cosf)])
82      AS_IF([test "x$wm_cv_libm_sinf" != "xyes"],
83         [CFLAGS="$CFLAGS $wm_cd_libm_sinf"]) ])
84 AC_SUBST(LIBM) dnl