add new module Unsafe.Coerce to build system
[haskell-directory.git] / aclocal.m4
1 # FP_DECL_ALTZONE
2 # ---------------
3 # Defines HAVE_DECL_ALTZONE to 1 if declared, 0 otherwise.
4 #
5 # Used by base package.
6 AC_DEFUN([FP_DECL_ALTZONE],
7 [AC_REQUIRE([AC_HEADER_TIME])dnl
8 AC_CHECK_HEADERS([sys/time.h])
9 AC_CHECK_DECLS([altzone], [], [],[#if TIME_WITH_SYS_TIME
10 # include <sys/time.h>
11 # include <time.h>
12 #else
13 # if HAVE_SYS_TIME_H
14 #  include <sys/time.h>
15 # else
16 #  include <time.h>
17 # endif
18 #endif])
19 ])# FP_DECL_ALTZONE
20
21
22 # FP_COMPUTE_INT(EXPRESSION, VARIABLE, INCLUDES, IF-FAILS)
23 # --------------------------------------------------------
24 # Assign VARIABLE the value of the compile-time EXPRESSION using INCLUDES for
25 # compilation. Execute IF-FAILS when unable to determine the value. Works for
26 # cross-compilation, too.
27 #
28 # Implementation note: We are lazy and use an internal autoconf macro, but it
29 # is supported in autoconf versions 2.50 up to the actual 2.57, so there is
30 # little risk.
31 AC_DEFUN([FP_COMPUTE_INT],
32 [_AC_COMPUTE_INT([$1], [$2], [$3], [$4])[]dnl
33 ])# FP_COMPUTE_INT
34
35
36 # FP_CHECK_CONST(EXPRESSION, [INCLUDES = DEFAULT-INCLUDES], [VALUE-IF-FAIL = -1])
37 # -------------------------------------------------------------------------------
38 # Defines CONST_EXPRESSION to the value of the compile-time EXPRESSION, using
39 # INCLUDES. If the value cannot be determined, use VALUE-IF-FAIL.
40 AC_DEFUN([FP_CHECK_CONST],
41 [AS_VAR_PUSHDEF([fp_Cache], [fp_cv_const_$1])[]dnl
42 AC_CACHE_CHECK([value of $1], fp_Cache,
43 [FP_COMPUTE_INT([$1], fp_check_const_result, [AC_INCLUDES_DEFAULT([$2])],
44                 [fp_check_const_result=m4_default([$3], ['-1'])])
45 AS_VAR_SET(fp_Cache, [$fp_check_const_result])])[]dnl
46 AC_DEFINE_UNQUOTED(AS_TR_CPP([CONST_$1]), AS_VAR_GET(fp_Cache), [The value of $1.])[]dnl
47 AS_VAR_POPDEF([fp_Cache])[]dnl
48 ])# FP_CHECK_CONST
49
50
51 # FP_CHECK_CONSTS_TEMPLATE(EXPRESSION...)
52 # ---------------------------------------
53 # autoheader helper for FP_CHECK_CONSTS
54 m4_define([FP_CHECK_CONSTS_TEMPLATE],
55 [AC_FOREACH([fp_Const], [$1],
56   [AH_TEMPLATE(AS_TR_CPP(CONST_[]fp_Const),
57                [The value of ]fp_Const[.])])[]dnl
58 ])# FP_CHECK_CONSTS_TEMPLATE
59
60
61 # FP_CHECK_CONSTS(EXPRESSION..., [INCLUDES = DEFAULT-INCLUDES], [VALUE-IF-FAIL = -1])
62 # -----------------------------------------------------------------------------------
63 # List version of FP_CHECK_CONST
64 AC_DEFUN([FP_CHECK_CONSTS],
65 [FP_CHECK_CONSTS_TEMPLATE([$1])dnl
66 for fp_const_name in $1
67 do
68 FP_CHECK_CONST([$fp_const_name], [$2], [$3])
69 done
70 ])# FP_CHECK_CONSTS
71
72
73 dnl ** Map an arithmetic C type to a Haskell type.
74 dnl    Based on autconf's AC_CHECK_SIZEOF.
75
76 dnl FPTOOLS_CHECK_HTYPE(TYPE [, DEFAULT_VALUE, [, VALUE-FOR-CROSS-COMPILATION])
77 AC_DEFUN([FPTOOLS_CHECK_HTYPE],
78 [changequote(<<, >>)dnl
79 dnl The name to #define.
80 define(<<AC_TYPE_NAME>>, translit(htype_$1, [a-z *], [A-Z_P]))dnl
81 dnl The cache variable name.
82 define(<<AC_CV_NAME>>, translit(fptools_cv_htype_$1, [ *], [_p]))dnl
83 define(<<AC_CV_NAME_supported>>, translit(fptools_cv_htype_sup_$1, [ *], [_p]))dnl
84 changequote([, ])dnl
85 AC_MSG_CHECKING(Haskell type for $1)
86 AC_CACHE_VAL(AC_CV_NAME,
87 [AC_CV_NAME_supported=yes
88 fp_check_htype_save_cppflags="$CPPFLAGS"
89 CPPFLAGS="$CPPFLAGS $X_CFLAGS"
90 AC_RUN_IFELSE([AC_LANG_SOURCE([[#include <stdio.h>
91 #include <stddef.h>
92
93 #if HAVE_SYS_TYPES_H
94 # include <sys/types.h>
95 #endif
96
97 #if HAVE_UNISTD_H
98 # include <unistd.h>
99 #endif
100
101 #if HAVE_SYS_STAT_H
102 # include <sys/stat.h>
103 #endif
104
105 #if HAVE_FCNTL_H
106 # include <fcntl.h>
107 #endif
108
109 #if HAVE_SIGNAL_H
110 # include <signal.h>
111 #endif
112
113 #if HAVE_TIME_H
114 # include <time.h>
115 #endif
116
117 #if HAVE_TERMIOS_H
118 # include <termios.h>
119 #endif
120
121 #if HAVE_STRING_H
122 # include <string.h>
123 #endif
124
125 #if HAVE_CTYPE_H
126 # include <ctype.h>
127 #endif
128
129 #if HAVE_INTTYPES_H
130 # include <inttypes.h>
131 #else
132 # if HAVE_STDINT_H
133 #  include <stdint.h>
134 # endif
135 #endif
136
137 #if defined(HAVE_GL_GL_H)
138 # include <GL/gl.h>
139 #elif defined(HAVE_OPENGL_GL_H)
140 # include <OpenGL/gl.h>
141 #endif
142
143 #if defined(HAVE_AL_AL_H)
144 # include <AL/al.h>
145 #elif defined(HAVE_OPENAL_AL_H)
146 # include <OpenAL/al.h>
147 #endif
148
149 #if defined(HAVE_AL_ALC_H)
150 # include <AL/alc.h>
151 #elif defined(HAVE_OPENAL_ALC_H)
152 # include <OpenAL/alc.h>
153 #endif
154
155 #if HAVE_SYS_RESOURCE_H
156 # include <sys/resource.h>
157 #endif
158
159 typedef $1 testing;
160
161 main() {
162   FILE *f=fopen("conftestval", "w");
163   if (!f) exit(1);
164   if (((testing)((int)((testing)1.4))) == ((testing)1.4)) {
165     fprintf(f, "%s%d\n",
166            ((testing)(-1) < (testing)0) ? "Int" : "Word",
167            sizeof(testing)*8);
168   } else {
169     fprintf(f,"%s\n",
170            (sizeof(testing) >  sizeof(double)) ? "LDouble" :
171            (sizeof(testing) == sizeof(double)) ? "Double"  : "Float");
172   }
173   fclose(f);
174   exit(0);
175 }]])],[AC_CV_NAME=`cat conftestval`],
176 [ifelse([$2], , [AC_CV_NAME=NotReallyAType; AC_CV_NAME_supported=no], [AC_CV_NAME=$2])],
177 [ifelse([$3], , [AC_CV_NAME=NotReallyATypeCross; AC_CV_NAME_supported=no], [AC_CV_NAME=$3])])
178 CPPFLAGS="$fp_check_htype_save_cppflags"]) dnl
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, [Define to Haskell type for $1])
182 else
183   AC_MSG_RESULT([not supported])
184 fi
185 undefine([AC_TYPE_NAME])dnl
186 undefine([AC_CV_NAME])dnl
187 undefine([AC_CV_NAME_supported])dnl
188 ])
189
190
191 # FP_READDIR_EOF_ERRNO
192 # --------------------
193 # Defines READDIR_ERRNO_EOF to what readdir() sets 'errno' to upon reaching end
194 # of directory (not set => 0); not setting it is the correct thing to do, but
195 # MinGW based versions have set it to ENOENT until recently (summer 2004).
196 AC_DEFUN([FP_READDIR_EOF_ERRNO],
197 [AC_CACHE_CHECK([what readdir sets errno to upon EOF], [fptools_cv_readdir_eof_errno],
198 [AC_RUN_IFELSE([AC_LANG_SOURCE([[#include <dirent.h>
199 #include <stdio.h>
200 #include <errno.h>
201 int
202 main(argc, argv)
203 int argc;
204 char **argv;
205 {
206   FILE *f=fopen("conftestval", "w");
207 #if defined(__MINGW32__)
208   int fd = mkdir("testdir");
209 #else
210   int fd = mkdir("testdir", 0666);
211 #endif
212   DIR* dp;
213   struct dirent* de;
214   int err = 0;
215
216   if (!f) return 1;
217   if (fd == -1) { 
218      fprintf(stderr,"unable to create directory; quitting.\n");
219      return 1;
220   }
221   close(fd);
222   dp = opendir("testdir");
223   if (!dp) { 
224      fprintf(stderr,"unable to browse directory; quitting.\n");
225      rmdir("testdir");
226      return 1;
227   }
228
229   /* the assumption here is that readdir() will only return NULL
230    * due to reaching the end of the directory.
231    */
232   while (de = readdir(dp)) {
233         ;
234   }
235   err = errno;
236   fprintf(f,"%d", err);
237   fclose(f);
238   closedir(dp);
239   rmdir("testdir");
240   return 0;
241 }]])],
242 [fptools_cv_readdir_eof_errno=`cat conftestval`],
243 [AC_MSG_WARN([failed to determine the errno value])
244  fptools_cv_readdir_eof_errno=0],
245 [fptools_cv_readdir_eof_errno=0])])
246 AC_DEFINE_UNQUOTED([READDIR_ERRNO_EOF], [$fptools_cv_readdir_eof_errno], [readdir() sets errno to this upon EOF])
247 ])# FP_READDIR_EOF_ERRNO