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 AC_DEFUN([FP_COMPUTE_INT],
11 [_AC_COMPUTE_INT([$1], [$2], [$3], [$4])[]dnl
15 # FP_CHECK_CONST(EXPRESSION, [INCLUDES = DEFAULT-INCLUDES], [VALUE-IF-FAIL = -1])
16 # -------------------------------------------------------------------------------
17 # Defines CONST_EXPRESSION to the value of the compile-time EXPRESSION, using
18 # INCLUDES. If the value cannot be determined, use VALUE-IF-FAIL.
19 AC_DEFUN([FP_CHECK_CONST],
20 [AS_VAR_PUSHDEF([fp_Cache], [fp_cv_const_$1])[]dnl
21 AC_CACHE_CHECK([value of $1], fp_Cache,
22 [FP_COMPUTE_INT([$1], fp_check_const_result, [AC_INCLUDES_DEFAULT([$2])],
23 [fp_check_const_result=m4_default([$3], ['-1'])])
24 AS_VAR_SET(fp_Cache, [$fp_check_const_result])])[]dnl
25 AC_DEFINE_UNQUOTED(AS_TR_CPP([CONST_$1]), AS_VAR_GET(fp_Cache), [The value of $1.])[]dnl
26 AS_VAR_POPDEF([fp_Cache])[]dnl
30 # FP_CHECK_CONSTS_TEMPLATE(EXPRESSION...)
31 # ---------------------------------------
32 # autoheader helper for FP_CHECK_CONSTS
33 m4_define([FP_CHECK_CONSTS_TEMPLATE],
34 [AC_FOREACH([fp_Const], [$1],
35 [AH_TEMPLATE(AS_TR_CPP(CONST_[]fp_Const),
36 [The value of ]fp_Const[.])])[]dnl
37 ])# FP_CHECK_CONSTS_TEMPLATE
40 # FP_CHECK_CONSTS(EXPRESSION..., [INCLUDES = DEFAULT-INCLUDES], [VALUE-IF-FAIL = -1])
41 # -----------------------------------------------------------------------------------
42 # List version of FP_CHECK_CONST
43 AC_DEFUN([FP_CHECK_CONSTS],
44 [FP_CHECK_CONSTS_TEMPLATE([$1])dnl
45 for fp_const_name in $1
47 FP_CHECK_CONST([$fp_const_name], [$2], [$3])
52 dnl ** Map an arithmetic C type to a Haskell type.
53 dnl Based on autconf's AC_CHECK_SIZEOF.
55 dnl FPTOOLS_CHECK_HTYPE(TYPE [, DEFAULT_VALUE, [, VALUE-FOR-CROSS-COMPILATION])
56 AC_DEFUN([FPTOOLS_CHECK_HTYPE],
57 [changequote(<<, >>)dnl
58 dnl The name to #define.
59 define(<<AC_TYPE_NAME>>, translit(htype_$1, [a-z *], [A-Z_P]))dnl
60 dnl The cache variable name.
61 define(<<AC_CV_NAME>>, translit(fptools_cv_htype_$1, [ *], [_p]))dnl
62 define(<<AC_CV_NAME_supported>>, translit(fptools_cv_htype_sup_$1, [ *], [_p]))dnl
64 AC_MSG_CHECKING(Haskell type for $1)
65 AC_CACHE_VAL(AC_CV_NAME,
66 [AC_CV_NAME_supported=yes
67 fp_check_htype_save_cppflags="$CPPFLAGS"
68 CPPFLAGS="$CPPFLAGS $X_CFLAGS"
69 AC_RUN_IFELSE([AC_LANG_SOURCE([[#include <stdio.h>
73 # include <sys/types.h>
81 # include <sys/stat.h>
108 #if defined(HAVE_GL_GL_H)
110 #elif defined(HAVE_OPENGL_GL_H)
111 # include <OpenGL/gl.h>
114 #if defined(HAVE_AL_AL_H)
116 #elif defined(HAVE_OPENAL_AL_H)
117 # include <OpenAL/al.h>
120 #if defined(HAVE_AL_ALC_H)
122 #elif defined(HAVE_OPENAL_ALC_H)
123 # include <OpenAL/alc.h>
126 #if HAVE_SYS_RESOURCE_H
127 # include <sys/resource.h>
133 FILE *f=fopen("conftestval", "w");
135 if (((testing)((int)((testing)1.4))) == ((testing)1.4)) {
137 ((testing)(-1) < (testing)0) ? "Int" : "Word",
141 (sizeof(testing) > sizeof(double)) ? "LDouble" :
142 (sizeof(testing) == sizeof(double)) ? "Double" : "Float");
146 }]])],[AC_CV_NAME=`cat conftestval`],
147 [ifelse([$2], , [AC_CV_NAME=NotReallyAType; AC_CV_NAME_supported=no], [AC_CV_NAME=$2])],
148 [ifelse([$3], , [AC_CV_NAME=NotReallyATypeCross; AC_CV_NAME_supported=no], [AC_CV_NAME=$3])])]) dnl
149 CPPFLAGS="$fp_check_htype_save_cppflags"
150 if test "$AC_CV_NAME_supported" = yes; then
151 AC_MSG_RESULT($AC_CV_NAME)
152 AC_DEFINE_UNQUOTED(AC_TYPE_NAME, $AC_CV_NAME, [Define to Haskell type for $1])
154 AC_MSG_RESULT([not supported])
156 undefine([AC_TYPE_NAME])dnl
157 undefine([AC_CV_NAME])dnl
158 undefine([AC_CV_NAME_supported])dnl
162 # FP_READDIR_EOF_ERRNO
163 # --------------------
164 # Defines READDIR_ERRNO_EOF to what readdir() sets 'errno' to upon reaching end
165 # of directory (not set => 0); not setting it is the correct thing to do, but
166 # MinGW based versions have set it to ENOENT until recently (summer 2004).
167 AC_DEFUN([FP_READDIR_EOF_ERRNO],
168 [AC_CACHE_CHECK([what readdir sets errno to upon EOF], [fptools_cv_readdir_eof_errno],
169 [AC_RUN_IFELSE([AC_LANG_SOURCE([[#include <dirent.h>
177 FILE *f=fopen("conftestval", "w");
178 #if defined(__MINGW32__)
179 int fd = mkdir("testdir");
181 int fd = mkdir("testdir", 0666);
189 fprintf(stderr,"unable to create directory; quitting.\n");
193 dp = opendir("testdir");
195 fprintf(stderr,"unable to browse directory; quitting.\n");
200 /* the assumption here is that readdir() will only return NULL
201 * due to reaching the end of the directory.
203 while (de = readdir(dp)) {
207 fprintf(f,"%d", err);
213 [fptools_cv_readdir_eof_errno=`cat conftestval`],
214 [AC_MSG_WARN([failed to determine the errno value])
215 fptools_cv_readdir_eof_errno=0],
216 [fptools_cv_readdir_eof_errno=0])])
217 AC_DEFINE_UNQUOTED([READDIR_ERRNO_EOF], [$fptools_cv_readdir_eof_errno], [readdir() sets errno to this upon EOF])
218 ])# FP_READDIR_EOF_ERRNO