[project @ 2004-11-06 11:10:18 by panne]
[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 AC_DEFUN([FP_COMPUTE_INT],
11 [_AC_COMPUTE_INT([$1], [$2], [$3], [$4])[]dnl
12 ])# FP_COMPUTE_INT
13
14
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
27 ])# FP_CHECK_CONST
28
29
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
38
39
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
46 do
47 FP_CHECK_CONST([$fp_const_name], [$2], [$3])
48 done
49 ])# FP_CHECK_CONSTS
50
51
52 dnl ** Map an arithmetic C type to a Haskell type.
53 dnl    Based on autconf's AC_CHECK_SIZEOF.
54
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
63 changequote([, ])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>
70 #include <stddef.h>
71
72 #if HAVE_SYS_TYPES_H
73 # include <sys/types.h>
74 #endif
75
76 #if HAVE_UNISTD_H
77 # include <unistd.h>
78 #endif
79
80 #if HAVE_SYS_STAT_H
81 # include <sys/stat.h>
82 #endif
83
84 #if HAVE_FCNTL_H
85 # include <fcntl.h>
86 #endif
87
88 #if HAVE_SIGNAL_H
89 # include <signal.h>
90 #endif
91
92 #if HAVE_TIME_H
93 # include <time.h>
94 #endif
95
96 #if HAVE_TERMIOS_H
97 # include <termios.h>
98 #endif
99
100 #if HAVE_STRING_H
101 # include <string.h>
102 #endif
103
104 #if HAVE_CTYPE_H
105 # include <ctype.h>
106 #endif
107
108 #if defined(HAVE_GL_GL_H)
109 # include <GL/gl.h>
110 #elif defined(HAVE_OPENGL_GL_H)
111 # include <OpenGL/gl.h>
112 #endif
113
114 #if defined(HAVE_AL_ALC_H)
115 # include <AL/alc.h>
116 #elif defined(HAVE_OPENAL_ALC_H)
117 # include <OpenAL/alc.h>
118 #endif
119
120 #if HAVE_SYS_RESOURCE_H
121 # include <sys/resource.h>
122 #endif
123
124 typedef $1 testing;
125
126 main() {
127   FILE *f=fopen("conftestval", "w");
128   if (!f) exit(1);
129   if (((testing)((int)((testing)1.4))) == ((testing)1.4)) {
130     fprintf(f, "%s%d\n",
131            ((testing)(-1) < (testing)0) ? "Int" : "Word",
132            sizeof(testing)*8);
133   } else {
134     fprintf(f,"%s\n",
135            (sizeof(testing) >  sizeof(double)) ? "LDouble" :
136            (sizeof(testing) == sizeof(double)) ? "Double"  : "Float");
137   }
138   fclose(f);
139   exit(0);
140 }]])],[AC_CV_NAME=`cat conftestval`],
141 [ifelse([$2], , [AC_CV_NAME=NotReallyAType; AC_CV_NAME_supported=no], [AC_CV_NAME=$2])],
142 [ifelse([$3], , [AC_CV_NAME=NotReallyATypeCross; AC_CV_NAME_supported=no], [AC_CV_NAME=$3])])]) dnl
143 CPPFLAGS="$fp_check_htype_save_cppflags"
144 if test "$AC_CV_NAME_supported" = yes; then
145   AC_MSG_RESULT($AC_CV_NAME)
146   AC_DEFINE_UNQUOTED(AC_TYPE_NAME, $AC_CV_NAME, [Define to Haskell type for $1])
147 else
148   AC_MSG_RESULT([not supported])
149 fi
150 undefine([AC_TYPE_NAME])dnl
151 undefine([AC_CV_NAME])dnl
152 undefine([AC_CV_NAME_supported])dnl
153 ])
154
155
156 dnl @synopsis FP_READDIR_EOF_ERRNO
157 dnl
158 dnl Check what readdir() sets 'errno' to upon reaching 
159 dnl end of directory; not setting it is the correct thing to do,
160 dnl but mingw based versions have set it to ENOENT until recently
161 dnl (summer 2004).
162 dnl
163 dnl
164 AC_DEFUN(FP_READDIR_EOF_ERRNO,
165 [AC_CACHE_CHECK([what readdir sets errno to upon EOF], fptools_cv_readdir_eof_errno,
166 [AC_RUN_IFELSE([AC_LANG_SOURCE([[#include <dirent.h>
167 #include <stdio.h>
168 #include <errno.h>
169 int
170 main(argc, argv)
171 int argc;
172 char **argv;
173 {
174   FILE *f=fopen("conftestval", "w");
175 #if defined(__MINGW32__)
176   int fd = mkdir("testdir");
177 #else
178   int fd = mkdir("testdir", 0666);
179 #endif
180   DIR* dp;
181   struct dirent* de;
182   int err = 0;
183
184   if (!f) return 1;
185   if (fd == -1) { 
186      fprintf(stderr,"unable to create directory; quitting.\n");
187      return 1;
188   }
189   close(fd);
190   dp = opendir("testdir");
191   if (!dp) { 
192      fprintf(stderr,"unable to browse directory; quitting.\n");
193      rmdir("testdir");
194      return 1;
195   }
196
197   /* the assumption here is that readdir() will only return NULL
198    * due to reaching the end of the directory.
199    */
200   while (de = readdir(dp)) {
201         ;
202   }
203   err = errno;
204   fprintf(f,"%d", err);
205   fclose(f);
206   closedir(dp);
207   rmdir("testdir");
208   return 0;
209 }]])],[fptools_cv_readdir_eof_errno=`cat conftestval`],[fptools_cv_readdir_eof_errno=bogus],[fptools_cv_readdir_eof_errno=0])])
210 dnl the cross value is somewhat bogus.
211 AC_DEFINE_UNQUOTED([READDIR_ERRNO_EOF], [$fptools_cv_readdir_eof_errno], [readdir() sets errno to this upon EOF])
212 ])
213
214 dnl @synopsis FP_DIRENT_FLAT_LAYOUT
215 dnl
216 dnl Check whether 'struct dirent' (in dirent.h) has d_name defined
217 dnl as being the final field in a struct, or a pointer to somewhere
218 dnl else. The former is the standardly thing to do, but mingw defns
219 dnl have for the longest time gone for the latter. They no longer do,
220 dnl hence the need to configure test for this.
221 dnl
222 dnl
223 AC_DEFUN(FP_DIRENT_FLAT_LAYOUT,
224 [AC_CACHE_CHECK([if struct dirent layout is flat], fptools_cv_dirent_flat_layout,
225 [AC_RUN_IFELSE([AC_LANG_SOURCE([[#include <dirent.h>
226 #include <stdio.h>
227 #include <string.h>
228 int
229 main(argc, argv)
230 int argc;
231 char **argv;
232 {
233   struct dirent de;
234   /*
235    * Check whether d_name is defined as
236    *    struct dirent { .... ; char d_name[..]; } 
237    * or
238    *    struct dirent { .... ; char* d_name; } 
239    * 
240    * Returns 0 if the former.
241    */
242   memset(&de,0,sizeof(struct dirent));
243   return ((int)de.d_name == 0);
244 }]])],[fptools_cv_dirent_flat_layout=yes],[fptools_cv_dirent_flat_layout=no],[fptools_cv_dirent_flat_layout=yes])])
245 dnl the cross value is somewhat bogus.
246 if test "$fptools_cv_dirent_flat_layout" = yes; then
247 AC_DEFINE([STRUCT_DIRENT_FLAT_LAYOUT], [1], [Define to 1 if struct dirent is a flat structure])
248 fi
249 ])