add GHC.HetMet.{hetmet_kappa,hetmet_kappa_app}
[ghc-base.git] / aclocal.m4
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.
6 #
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
9 # little risk.
10 # The public AC_COMPUTE_INT macro isn't supported by some versions of
11 # autoconf.
12 AC_DEFUN([FP_COMPUTE_INT],
13 [_AC_COMPUTE_INT([$2], [$1], [$3], [$4])[]dnl
14 ])# FP_COMPUTE_INT
15
16
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
29 ])# FP_CHECK_CONST
30
31
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
40
41
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
48 do
49 FP_CHECK_CONST([$fp_const_name], [$2], [$3])
50 done
51 ])# FP_CHECK_CONSTS
52
53
54 dnl FPTOOLS_HTYPE_INCLUDES
55 AC_DEFUN([FPTOOLS_HTYPE_INCLUDES],
56 [
57 #include <stdio.h>
58 #include <stddef.h>
59
60 #if HAVE_SYS_TYPES_H
61 # include <sys/types.h>
62 #endif
63
64 #if HAVE_UNISTD_H
65 # include <unistd.h>
66 #endif
67
68 #if HAVE_SYS_STAT_H
69 # include <sys/stat.h>
70 #endif
71
72 #if HAVE_FCNTL_H
73 # include <fcntl.h>
74 #endif
75
76 #if HAVE_SIGNAL_H
77 # include <signal.h>
78 #endif
79
80 #if HAVE_TIME_H
81 # include <time.h>
82 #endif
83
84 #if HAVE_TERMIOS_H
85 # include <termios.h>
86 #endif
87
88 #if HAVE_STRING_H
89 # include <string.h>
90 #endif
91
92 #if HAVE_CTYPE_H
93 # include <ctype.h>
94 #endif
95
96 #if HAVE_INTTYPES_H
97 # include <inttypes.h>
98 #else
99 # if HAVE_STDINT_H
100 #  include <stdint.h>
101 # endif
102 #endif
103
104 #if HAVE_SYS_RESOURCE_H
105 # include <sys/resource.h>
106 #endif
107
108 #include <stdlib.h>
109 ])
110
111
112 dnl ** Map an arithmetic C type to a Haskell type.
113 dnl    Based on autconf's AC_CHECK_SIZEOF.
114
115 dnl FPTOOLS_CHECK_HTYPE_ELSE(TYPE, WHAT_TO_DO_IF_TYPE_DOES_NOT_EXIST)
116 AC_DEFUN([FPTOOLS_CHECK_HTYPE_ELSE],[
117     changequote(<<, >>)
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]))
123     changequote([, ])
124
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"
132         then
133             if test "$HTYPE_IS_INTEGRAL" -eq 0
134             then
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
145                 then
146                     AC_CV_NAME=Float
147                 elif test "$HTYPE_IS_DOUBLE" -eq 1
148                 then
149                     AC_CV_NAME=Double
150                 elif test "$HTYPE_IS_LDOUBLE" -eq 1
151                 then
152                     AC_CV_NAME=LDouble
153                 else
154                     AC_CV_NAME_supported=no
155                 fi
156             else
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
164                 then
165                     AC_CV_NAME="Word$HTYPE_SIZE"
166                 else
167                     AC_CV_NAME="Int$HTYPE_SIZE"
168                 fi
169             fi
170         fi
171         ])
172     if test "$AC_CV_NAME_supported" = no
173     then
174         $2
175     fi
176
177     dnl Note: evaluating dollar-2 can change the value of
178     dnl $AC_CV_NAME_supported, so we might now get a different answer
179     if test "$AC_CV_NAME_supported" = yes; then
180         AC_MSG_RESULT($AC_CV_NAME)
181         AC_DEFINE_UNQUOTED(AC_TYPE_NAME, $AC_CV_NAME,
182                            [Define to Haskell type for $1])
183     fi
184     undefine([AC_TYPE_NAME])dnl
185     undefine([AC_CV_NAME])dnl
186     undefine([AC_CV_NAME_supported])dnl
187 ])
188
189 dnl FPTOOLS_CHECK_HTYPE(TYPE)
190 AC_DEFUN([FPTOOLS_CHECK_HTYPE],[
191     FPTOOLS_CHECK_HTYPE_ELSE([$1],[
192         AC_CV_NAME=NotReallyAType
193         AC_MSG_RESULT([not supported])
194     ])
195 ])
196
197
198 # FP_SEARCH_LIBS_PROTO(WHAT, PROTOTYPE, FUNCTION, SEARCH-LIBS,
199 #                [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND],
200 #                [OTHER-LIBRARIES])
201 # --------------------------------------------------------
202 # Search for a library defining FUNC, if it's not already available.
203 # This is a copy of the AC_SEARCH_LIBS definition, but extended to take
204 # the name of the thing we are looking for as its first argument, and
205 # prototype text as its second argument. It also calls AC_LANG_PROGRAM
206 # instead of AC_LANG_CALL
207 AC_DEFUN([FP_SEARCH_LIBS_PROTO],
208 [AS_VAR_PUSHDEF([ac_Search], [ac_cv_search_$1])dnl
209 AC_CACHE_CHECK([for library containing $1], [ac_Search],
210 [ac_func_search_save_LIBS=$LIBS
211 AC_LANG_CONFTEST([AC_LANG_PROGRAM([$2], [$3])])
212 for ac_lib in '' $4; do
213   if test -z "$ac_lib"; then
214     ac_res="none required"
215   else
216     ac_res=-l$ac_lib
217     LIBS="-l$ac_lib $7 $ac_func_search_save_LIBS"
218   fi
219   AC_LINK_IFELSE([], [AS_VAR_SET([ac_Search], [$ac_res])])
220   AS_VAR_SET_IF([ac_Search], [break])
221 done
222 AS_VAR_SET_IF([ac_Search], , [AS_VAR_SET([ac_Search], [no])])
223 rm conftest.$ac_ext
224 LIBS=$ac_func_search_save_LIBS])
225 ac_res=AS_VAR_GET([ac_Search])
226 AS_IF([test "$ac_res" != no],
227   [test "$ac_res" = "none required" || LIBS="$ac_res $LIBS"
228   $5],
229       [$6])dnl
230 AS_VAR_POPDEF([ac_Search])dnl
231 ])