[project @ 2004-11-06 10:45:46 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 @synopsis FP_READDIR_EOF_ERRNO
53 dnl
54 dnl Check what readdir() sets 'errno' to upon reaching 
55 dnl end of directory; not setting it is the correct thing to do,
56 dnl but mingw based versions have set it to ENOENT until recently
57 dnl (summer 2004).
58 dnl
59 dnl
60 AC_DEFUN(FP_READDIR_EOF_ERRNO,
61 [AC_CACHE_CHECK([what readdir sets errno to upon EOF], fptools_cv_readdir_eof_errno,
62 [AC_RUN_IFELSE([AC_LANG_SOURCE([[#include <dirent.h>
63 #include <stdio.h>
64 #include <errno.h>
65 int
66 main(argc, argv)
67 int argc;
68 char **argv;
69 {
70   FILE *f=fopen("conftestval", "w");
71 #if defined(__MINGW32__)
72   int fd = mkdir("testdir");
73 #else
74   int fd = mkdir("testdir", 0666);
75 #endif
76   DIR* dp;
77   struct dirent* de;
78   int err = 0;
79
80   if (!f) return 1;
81   if (fd == -1) { 
82      fprintf(stderr,"unable to create directory; quitting.\n");
83      return 1;
84   }
85   close(fd);
86   dp = opendir("testdir");
87   if (!dp) { 
88      fprintf(stderr,"unable to browse directory; quitting.\n");
89      rmdir("testdir");
90      return 1;
91   }
92
93   /* the assumption here is that readdir() will only return NULL
94    * due to reaching the end of the directory.
95    */
96   while (de = readdir(dp)) {
97         ;
98   }
99   err = errno;
100   fprintf(f,"%d", err);
101   fclose(f);
102   closedir(dp);
103   rmdir("testdir");
104   return 0;
105 }]])],[fptools_cv_readdir_eof_errno=`cat conftestval`],[fptools_cv_readdir_eof_errno=bogus],[fptools_cv_readdir_eof_errno=0])])
106 dnl the cross value is somewhat bogus.
107 AC_DEFINE_UNQUOTED([READDIR_ERRNO_EOF], [$fptools_cv_readdir_eof_errno], [readdir() sets errno to this upon EOF])
108 ])
109
110 dnl @synopsis FP_DIRENT_FLAT_LAYOUT
111 dnl
112 dnl Check whether 'struct dirent' (in dirent.h) has d_name defined
113 dnl as being the final field in a struct, or a pointer to somewhere
114 dnl else. The former is the standardly thing to do, but mingw defns
115 dnl have for the longest time gone for the latter. They no longer do,
116 dnl hence the need to configure test for this.
117 dnl
118 dnl
119 AC_DEFUN(FP_DIRENT_FLAT_LAYOUT,
120 [AC_CACHE_CHECK([if struct dirent layout is flat], fptools_cv_dirent_flat_layout,
121 [AC_RUN_IFELSE([AC_LANG_SOURCE([[#include <dirent.h>
122 #include <stdio.h>
123 #include <string.h>
124 int
125 main(argc, argv)
126 int argc;
127 char **argv;
128 {
129   struct dirent de;
130   /*
131    * Check whether d_name is defined as
132    *    struct dirent { .... ; char d_name[..]; } 
133    * or
134    *    struct dirent { .... ; char* d_name; } 
135    * 
136    * Returns 0 if the former.
137    */
138   memset(&de,0,sizeof(struct dirent));
139   return ((int)de.d_name == 0);
140 }]])],[fptools_cv_dirent_flat_layout=yes],[fptools_cv_dirent_flat_layout=no],[fptools_cv_dirent_flat_layout=yes])])
141 dnl the cross value is somewhat bogus.
142 if test "$fptools_cv_dirent_flat_layout" = yes; then
143 AC_DEFINE([STRUCT_DIRENT_FLAT_LAYOUT], [1], [Define to 1 if struct dirent is a flat structure])
144 fi
145 ])