1 # BEGIN OF GRAS ARCH CHECK
3 dnl GRAS_DO_CHECK_SIZEOF: Get the size of a datatype (even in cross-compile)
5 dnl 2: extra include lines
6 dnl 3: extra sizes to test
7 dnl ("adapted" from openldap)
9 AC_DEFUN([GRAS_DO_CHECK_SIZEOF],
10 [changequote(<<, >>)dnl
11 dnl The cache variable name (and of the result).
12 define(<<GRAS_CHECK_SIZEOF_RES>>, translit(ac_cv_sizeof_$1, [ *()], [_pLR]))dnl
14 AC_CACHE_VAL(GRAS_CHECK_SIZEOF_RES,
15 [for ac_size in 4 8 1 2 16 $3 ; do # List sizes in rough order of prevalence.
16 AC_COMPILE_IFELSE(AC_LANG_PROGRAM([#include "confdefs.h"
17 #include <sys/types.h>
19 ], [switch (0) case 0: case (sizeof ($1) == $ac_size):;]), GRAS_CHECK_SIZEOF_RES=$ac_size)
20 if test x$GRAS_CHECK_SIZEOF_RES != x ; then break; fi
26 dnl GRAS_CHECK_SIZEOF: Get the size of a datatype (even in cross-compile), with msg display, and define the result
28 dnl 2: extra include lines
29 dnl 3: extra sizes to test
30 dnl ("adapted" from openldap)
32 AC_DEFUN([GRAS_CHECK_SIZEOF],
33 [AC_MSG_CHECKING(size of $1)
34 GRAS_DO_CHECK_SIZEOF($1,$2)
35 if test x$GRAS_CHECK_SIZEOF_RES = x ; then
36 AC_MSG_ERROR([cannot determine a size for $1])
38 AC_MSG_RESULT($GRAS_CHECK_SIZEOF_RES)
42 dnl GRAS_TWO_COMPLIMENT([type]): Make sure the type is two-compliment
43 dnl warning, this does not work with char (quite logical)
45 AC_DEFUN([GRAS_TWO_COMPLIMENT],
47 AC_MSG_CHECKING(whether $1 is two-compliment)
48 AC_RUN_IFELSE([AC_LANG_PROGRAM([[#include "confdefs.h"
51 unsigned char bytes[sizeof($1)];
54 intTester.testInt = -2;
55 return ((unsigned int)intTester.bytes[0] +
56 (unsigned int)intTester.bytes[sizeof($1) - 1]) - 509; /* should be 0 */
57 ]])], dnl end of AC LANG PROGRAM
58 [two_compliment=yes],[two_compliment=no] )dnl end of AC COMPILE IFELSE
60 AC_MSG_RESULT($two_compliment)
61 if test x$two_compliment != xyes ; then
62 AC_MSG_ERROR([GRAS works only two-compliment integers (yet)])
67 dnl GRAS_SIGNED_SIZEOF: Get the size of the datatype, and make sure that
68 dnl signed, unsigned and unspecified have the same size
70 AC_DEFUN([GRAS_SIGNED_SIZEOF],
71 [AC_MSG_CHECKING(size of $1)
72 GRAS_DO_CHECK_SIZEOF($1,$2)
73 unspecif=$GRAS_CHECK_SIZEOF_RES
74 if test x$unspecif = x ; then
75 AC_MSG_ERROR([cannot determine a size for $1])
78 GRAS_DO_CHECK_SIZEOF(signed $1,$2)
79 signed=$GRAS_CHECK_SIZEOF_RES
80 if test x$signed = x ; then
81 AC_MSG_ERROR([cannot determine a size for signed $1])
83 if test x$unspecif != x$signed ; then
84 AC_MSG_ERROR(['signed $1' and '$1' have different sizes ! ($signed != $unspecif)])
87 GRAS_DO_CHECK_SIZEOF(unsigned $1,$2)
88 unsigned=$GRAS_CHECK_SIZEOF_RES
89 if test x$unsigned = x ; then
90 AC_MSG_ERROR([cannot determine a size for unsigned $1])
92 if test x$unsigned != x$signed ; then
93 AC_MSG_ERROR(['signed $1' and 'unsigned $1' have different sizes ! ($signed != $unsigned)])
96 AC_MSG_RESULT($GRAS_CHECK_SIZEOF_RES)
100 dnl End of CHECK_SIGNED_SIZEOF
103 dnl CHECK_IEEE_FP: determines if floating points are IEEE754 compliant
104 dnl (inspired from NWS code)
106 AC_DEFUN([CHECK_IEEE_FP],
107 [AC_MSG_CHECKING(if floating point datatypes are IEEE 754 compliant)
108 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include "confdefs.h"
111 unsigned char bytes[sizeof(double)];
115 unsigned char bytes[sizeof(float)];
118 if (sizeof(double) != 8 || sizeof(float) != 4)
121 memset(&doubleTester, 0, sizeof(doubleTester));
122 memset(&floatTester, 0, sizeof(floatTester));
124 doubleTester.bytes[GRAS_BIGENDIAN ? sizeof(double) - 1 : 0]=192;
125 doubleTester.bytes[GRAS_BIGENDIAN ? sizeof(double) - 2 : 1] =
126 (sizeof(double) == 4) ? 128 :
127 (sizeof(double) == 8) ? 16 :
128 (sizeof(double) == 16) ? 1 : 0;
129 if (doubleTester.testFP != -4.0) return 1;
131 floatTester.bytes[GRAS_BIGENDIAN ? sizeof(float) - 1 : 0]=192;
132 floatTester.bytes[GRAS_BIGENDIAN ? sizeof(float) - 2 : 1] =
133 (sizeof(float) == 4) ? 128 :
134 (sizeof(float) == 8) ? 16 :
135 (sizeof(float) == 16) ? 1 : 0;
136 if (floatTester.testFP != -4.0) return 1;]])],[IEEE_FP=yes],[IEEE_FP=no])
137 AC_MSG_RESULT($IEEE_FP)
139 if test x$IEEE_FP != xyes ; then
140 AC_MSG_ERROR([GRAS works only on IEEE754 compliant systems (yet)])
142 AC_DEFINE(IEEE_FP,1,[defines if this architecture floating point types are IEEE754 compliant])
144 ])dnl end of CHECK_IEEE_FP
148 dnl *************************8
150 AC_DEFUN([GRAS_ARCH],
152 # Check for the architecture
153 AC_C_BIGENDIAN(endian=1,endian=0,AC_MSG_ERROR([GRAS works only for little or big endian systems (yet)]))
154 dnl Make sure we don't run on a non-two-compliment arch, since we dunno convert them
155 GRAS_TWO_COMPLIMENT(int)
156 AC_DEFINE_UNQUOTED(GRAS_BIGENDIAN,$endian,[define if big endian])
158 GRAS_SIGNED_SIZEOF(char)
159 GRAS_SIGNED_SIZEOF(short int)
160 GRAS_SIGNED_SIZEOF(int)
161 GRAS_SIGNED_SIZEOF(long int)
162 GRAS_SIGNED_SIZEOF(long long int)
165 GRAS_CHECK_SIZEOF(void *)
166 GRAS_CHECK_SIZEOF(void (*) (void))
168 GRAS_CHECK_SIZEOF(float)
169 GRAS_CHECK_SIZEOF(double)
172 AC_MSG_CHECKING(the GRAS signature of this architecture)
173 if test x$endian = x1 ; then
179 trace="$trace_endian"
180 trace="${trace}:${ac_cv_sizeof_char}.${ac_cv_sizeof_short_int}.${ac_cv_sizeof_int}.${ac_cv_sizeof_long_int}.${ac_cv_sizeof_long_long_int}"
181 trace="${trace}:${ac_cv_sizeof_void_p}.${ac_cv_sizeof_void_LpR_LvoidR}"
182 trace="${trace}:${ac_cv_sizeof_float}.${ac_cv_sizeof_double}"
184 l:1.2.4.4.8:4.4:4.8) gras_arch=0; gras_arch_name=little32;;
185 l:1.2.4.8.8:8.8:4.8) gras_arch=1; gras_arch_name=little64;;
186 B:1.2.4.4.8:4.4:4.8) gras_arch=2; gras_arch_name=big32;;
187 B:1.2.4.8.8:8.8:4.8) gras_arch=3; gras_arch_name=big64;;
189 if test x$gras_arch = xunknown ; then
190 AC_MSG_RESULT([damnit ($trace)])
191 AC_MSG_ERROR([Impossible to determine the GRAS architecture signature.
192 Please report this architecture trace ($trace) and what it corresponds to.])
194 echo "$as_me:$LINENO: GRAS trace of this machine: $trace" >&AS_MESSAGE_LOG_FD
195 AC_DEFINE_UNQUOTED(GRAS_THISARCH,$gras_arch,[defines the GRAS architecture signature of this machine])
196 AC_MSG_RESULT($gras_arch ($gras_arch_name))
198 # END OF GRAS ARCH CHECK
200 AC_DEFUN([GRAS_CHECK_STRUCT_COMPACTION],
201 [ AC_MSG_CHECKING(whether the struct gets packed)
202 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include "confdefs.h"
203 #include <sys/types.h>
204 #include <stddef.h> /* offsetof() */
205 struct s {char c; double d;};
208 case (sizeof(struct s) == sizeof(double)+sizeof(char)):;
209 ]])],[gras_struct_packed=yes],[gras_struct_packed="no (good)"])
211 AC_MSG_RESULT($gras_struct_packed)
212 if test x$gras_struct_packed = xyes ; then
213 AC_MSG_ERROR([GRAS does not support packed structures since it leads to nasty misalignments])
216 AC_MSG_CHECKING(whether the struct gets compacted)
217 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include "confdefs.h"
218 #include <sys/types.h>
219 #include <stddef.h> /* offsetof() */
220 struct s {double d; int i; char c;};
223 case (offsetof(struct s,c) == sizeof(double)+sizeof(int)):;
224 ]])],[gras_struct_compact=yes],[gras_struct_compact=no])
226 AC_MSG_RESULT($gras_struct_compact)
228 if test x$gras_struct_compact = xyes ; then
229 AC_DEFINE_UNQUOTED(GRAS_STRUCT_COMPACT, 1,
230 [Defined if structures are compacted when possible.
232 Consider this structure: struct s {double d; int i; char c;};
234 If it is allowed, the char is placed just after the int. If not,
235 it has to be on the 8 bytes boundary imposed by the double.
237 AC_MSG_CHECKING(whether arrays in struct can straddle struct alignment boundaries)
239 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include "confdefs.h"
240 #include <sys/types.h>
241 #include <stddef.h> /* offsetof() */
242 struct s { double d; int i; char c[6]; };
245 case (offsetof(struct s,c) == sizeof(double)+sizeof(int)):;
246 ]])],[gras_array_straddle_struct=yes],[gras_array_straddle_struct=no])
248 AC_MSG_RESULT($gras_array_straddle_struct)
250 if test x$gras_array_straddle_struct = xyes ; then
251 AC_DEFINE_UNQUOTED(GRAS_ARRAY_STRADDLE_STRUCT, 1,
252 [Defined if arrays in struct can straddle struct alignment boundaries])
254 AC_MSG_ERROR([GRAS can only work on either architecture not compacting structures, or allowing array fields to straddle alignment boundaries (yet)])
258 AC_MSG_CHECKING(for changing alignment boundary structures)
259 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include "confdefs.h"
260 #include <sys/types.h>
262 struct s {int i;double d;};
265 case (sizeof(struct s) == sizeof(double)+sizeof(int)):;
266 ]])],[gras_struct_changing=yes],[gras_struct_changing=no])
268 AC_MSG_RESULT($gras_struct_changing)
270 if test x$gras_struct_changing = xyes ; then
271 AC_DEFINE_UNQUOTED(GRAS_STRUCT_CHANGING, 1,
272 [Defined if the alignment of structures can vary over fields.
274 Consider the following structure:
280 On Solaris, sizeof(struct s)=16, ie all fields get aligned to the
281 biggest boundary (and this will not be defined). On Linux,
282 sizeof(struct s)=12 (and this will be defined).
286 # END OF GRAS CHECK STRUCT COMPACTION
288 AC_DEFUN([GRAS_C_COMPACT_STRUCT],
289 [ AC_MSG_CHECKING(whether the struct gets compacted)
290 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include "confdefs.h"
291 #include <sys/types.h>
292 #include <stddef.h> /* offsetof() */
293 struct s {double d; int a; int b;};
296 case (offsetof(struct s,b) == sizeof(double)+sizeof(int)):;
297 ]])],[gras_compact_struct=yes],[gras_compact_struct=no])
299 AC_MSG_RESULT($gras_compact_struct)
301 if test x$gras_compact_struct = xyes ; then
302 AC_DEFINE_UNQUOTED(GRAS_COMPACT_STRUCT, 1,
303 [Defined if structures are compacted when possible])
306 # END OF GRAS COMPACT STRUCT