1 # FP_COMPUTE_INT(EXPRESSION, VARIABLE, INCLUDES, IF-FAILS)
2 # --------------------------------------------------------
3 # Assign VARIABLE the value of the compile-time EXPRESSION using INCLUDES for
4 # compilation. Execute IF-FAILS when unable to determine the value. Works for
5 # cross-compilation, too.
7 # Implementation note: We are lazy and use an internal autoconf macro, but it
8 # is supported in autoconf versions 2.50 up to the actual 2.57, so there is
10 # The public AC_COMPUTE_INT macro isn't supported by some versions of
12 AC_DEFUN([FP_COMPUTE_INT],
13 [_AC_COMPUTE_INT([$2], [$1], [$3], [$4])[]dnl
17 # FP_CHECK_CONST(EXPRESSION, [INCLUDES = DEFAULT-INCLUDES], [VALUE-IF-FAIL = -1])
18 # -------------------------------------------------------------------------------
19 # Defines CONST_EXPRESSION to the value of the compile-time EXPRESSION, using
20 # INCLUDES. If the value cannot be determined, use VALUE-IF-FAIL.
21 AC_DEFUN([FP_CHECK_CONST],
22 [AS_VAR_PUSHDEF([fp_Cache], [fp_cv_const_$1])[]dnl
23 AC_CACHE_CHECK([value of $1], fp_Cache,
24 [FP_COMPUTE_INT(fp_check_const_result, [$1], [AC_INCLUDES_DEFAULT([$2])],
25 [fp_check_const_result=m4_default([$3], ['-1'])])
26 AS_VAR_SET(fp_Cache, [$fp_check_const_result])])[]dnl
27 AC_DEFINE_UNQUOTED(AS_TR_CPP([CONST_$1]), AS_VAR_GET(fp_Cache), [The value of $1.])[]dnl
28 AS_VAR_POPDEF([fp_Cache])[]dnl
32 # FP_CHECK_CONSTS_TEMPLATE(EXPRESSION...)
33 # ---------------------------------------
34 # autoheader helper for FP_CHECK_CONSTS
35 m4_define([FP_CHECK_CONSTS_TEMPLATE],
36 [AC_FOREACH([fp_Const], [$1],
37 [AH_TEMPLATE(AS_TR_CPP(CONST_[]fp_Const),
38 [The value of ]fp_Const[.])])[]dnl
39 ])# FP_CHECK_CONSTS_TEMPLATE
42 # FP_CHECK_CONSTS(EXPRESSION..., [INCLUDES = DEFAULT-INCLUDES], [VALUE-IF-FAIL = -1])
43 # -----------------------------------------------------------------------------------
44 # List version of FP_CHECK_CONST
45 AC_DEFUN([FP_CHECK_CONSTS],
46 [FP_CHECK_CONSTS_TEMPLATE([$1])dnl
47 for fp_const_name in $1
49 FP_CHECK_CONST([$fp_const_name], [$2], [$3])
54 dnl FPTOOLS_HTYPE_INCLUDES
55 AC_DEFUN([FPTOOLS_HTYPE_INCLUDES],
61 # include <sys/types.h>
69 # include <sys/stat.h>
97 # include <inttypes.h>
104 #if HAVE_SYS_RESOURCE_H
105 # include <sys/resource.h>
112 dnl ** Map an arithmetic C type to a Haskell type.
113 dnl Based on autconf's AC_CHECK_SIZEOF.
115 dnl FPTOOLS_CHECK_HTYPE(TYPE)
116 AC_DEFUN([FPTOOLS_CHECK_HTYPE],[
118 dnl The name to #define.
119 define(<<AC_TYPE_NAME>>, translit(htype_$1, [a-z *], [A-Z_P]))
120 dnl The cache variable names.
121 define(<<AC_CV_NAME>>, translit(fptools_cv_htype_$1, [ *], [_p]))
122 define(<<AC_CV_NAME_supported>>, translit(fptools_cv_htype_sup_$1, [ *], [_p]))
125 AC_MSG_CHECKING(Haskell type for $1)
126 AC_CACHE_VAL(AC_CV_NAME,[
127 AC_CV_NAME_supported=yes
128 FP_COMPUTE_INT([HTYPE_IS_INTEGRAL],
129 [(($1)((int)(($1)1.4))) == (($1)1.4)],
130 [FPTOOLS_HTYPE_INCLUDES],[AC_CV_NAME_supported=no])
131 if test "$AC_CV_NAME_supported" = "yes"
133 if test "$HTYPE_IS_INTEGRAL" -eq 0
135 FP_COMPUTE_INT([HTYPE_IS_FLOAT],[sizeof($1) == sizeof(float)],
136 [FPTOOLS_HTYPE_INCLUDES],
137 [AC_CV_NAME_supported=no])
138 FP_COMPUTE_INT([HTYPE_IS_DOUBLE],[sizeof($1) == sizeof(double)],
139 [FPTOOLS_HTYPE_INCLUDES],
140 [AC_CV_NAME_supported=no])
141 FP_COMPUTE_INT([HTYPE_IS_LDOUBLE],[sizeof($1) == sizeof(long double)],
142 [FPTOOLS_HTYPE_INCLUDES],
143 [AC_CV_NAME_supported=no])
144 if test "$HTYPE_IS_FLOAT" -eq 1
147 elif test "$HTYPE_IS_DOUBLE" -eq 1
150 elif test "$HTYPE_IS_LDOUBLE" -eq 1
154 AC_CV_NAME_supported=no
157 FP_COMPUTE_INT([HTYPE_IS_SIGNED],[(($1)(-1)) < (($1)0)],
158 [FPTOOLS_HTYPE_INCLUDES],
159 [AC_CV_NAME_supported=no])
160 FP_COMPUTE_INT([HTYPE_SIZE],[sizeof($1) * 8],
161 [FPTOOLS_HTYPE_INCLUDES],
162 [AC_CV_NAME_supported=no])
163 if test "$HTYPE_IS_SIGNED" -eq 0
165 AC_CV_NAME="Word$HTYPE_SIZE"
167 AC_CV_NAME="Int$HTYPE_SIZE"
172 if test "$AC_CV_NAME_supported" = yes; then
173 AC_MSG_RESULT($AC_CV_NAME)
174 AC_DEFINE_UNQUOTED(AC_TYPE_NAME, $AC_CV_NAME,
175 [Define to Haskell type for $1])
177 AC_CV_NAME=NotReallyAType
178 AC_MSG_RESULT([not supported])
180 undefine([AC_TYPE_NAME])dnl
181 undefine([AC_CV_NAME])dnl
182 undefine([AC_CV_NAME_supported])dnl
186 # FP_SEARCH_LIBS_PROTO(WHAT, PROTOTYPE, FUNCTION, SEARCH-LIBS,
187 # [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND],
189 # --------------------------------------------------------
190 # Search for a library defining FUNC, if it's not already available.
191 # This is a copy of the AC_SEARCH_LIBS definition, but extended to take
192 # the name of the thing we are looking for as its first argument, and
193 # prototype text as its second argument. It also calls AC_LANG_PROGRAM
194 # instead of AC_LANG_CALL
195 AC_DEFUN([FP_SEARCH_LIBS_PROTO],
196 [AS_VAR_PUSHDEF([ac_Search], [ac_cv_search_$1])dnl
197 AC_CACHE_CHECK([for library containing $1], [ac_Search],
198 [ac_func_search_save_LIBS=$LIBS
199 AC_LANG_CONFTEST([AC_LANG_PROGRAM([$2], [$3])])
200 for ac_lib in '' $4; do
201 if test -z "$ac_lib"; then
202 ac_res="none required"
205 LIBS="-l$ac_lib $7 $ac_func_search_save_LIBS"
207 AC_LINK_IFELSE([], [AS_VAR_SET([ac_Search], [$ac_res])])
208 AS_VAR_SET_IF([ac_Search], [break])
210 AS_VAR_SET_IF([ac_Search], , [AS_VAR_SET([ac_Search], [no])])
212 LIBS=$ac_func_search_save_LIBS])
213 ac_res=AS_VAR_GET([ac_Search])
214 AS_IF([test "$ac_res" != no],
215 [test "$ac_res" = "none required" || LIBS="$ac_res $LIBS"
218 AS_VAR_POPDEF([ac_Search])dnl