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_TRY_COMPILE([#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)
39 changequote(<<, >>)dnl
40 dnl The name to #define.
41 define(<<TYPE_NAME>>, translit(sizeof_$1, [a-z *()], [A-Z_P__]))dnl
43 AC_DEFINE_UNQUOTED(TYPE_NAME, $GRAS_CHECK_SIZEOF_RES, [The number of bytes in type $1])
44 undefine([TYPE_NAME])dnl
48 dnl GRAS_TWO_COMPLIMENT: Make sure the type is two-compliment
50 AC_DEFUN([GRAS_TWO_COMPLIMENT],
52 AC_TRY_COMPILE([#include "confdefs.h"
55 unsigned char bytes[sizeof($1)];
58 intTester.testInt = -2;
59 return ((unsigned int)intTester.bytes[0] +
60 (unsigned int)intTester.bytes[sizeof($1) - 1]) != 509;
61 ],[],[AC_MSG_ERROR([GRAS works only two-compliment integers (yet)])])dnl end of AC_TRY_COMPILE
65 dnl GRAS_SIGNED_SIZEOF: Get the size of the datatype, and make sure that
66 dnl signed, unsigned and unspecified have the same size
68 AC_DEFUN([GRAS_SIGNED_SIZEOF],
69 [AC_MSG_CHECKING(size of $1)
70 GRAS_DO_CHECK_SIZEOF($1,$2)
71 unspecif=$GRAS_CHECK_SIZEOF_RES
72 if test x$unspecif = x ; then
73 AC_MSG_ERROR([cannot determine a size for $1])
76 GRAS_DO_CHECK_SIZEOF(signed $1,$2)
77 signed=$GRAS_CHECK_SIZEOF_RES
78 if test x$signed = x ; then
79 AC_MSG_ERROR([cannot determine a size for signed $1])
81 if test x$unspecif != x$signed ; then
82 AC_MSG_ERROR(['signed $1' and '$1' have different sizes ! ($signed != $unspecif)])
85 GRAS_DO_CHECK_SIZEOF(unsigned $1,$2)
86 unsigned=$GRAS_CHECK_SIZEOF_RES
87 if test x$unsigned = x ; then
88 AC_MSG_ERROR([cannot determine a size for unsigned $1])
90 if test x$unsigned != x$signed ; then
91 AC_MSG_ERROR(['signed $1' and 'unsigned $1' have different sizes ! ($signed != $unsigned)])
94 dnl Make sure we don't run on a non-two-compliment arch, since we dunno
96 GRAS_TWO_COMPLIMENT($1)
98 AC_MSG_RESULT($GRAS_CHECK_SIZEOF_RES)
99 changequote(<<, >>)dnl
100 dnl The name to #define.
101 define(<<TYPE_NAME>>, translit(sizeof_$1, [a-z *()], [A-Z_P__]))dnl
103 AC_DEFINE_UNQUOTED(TYPE_NAME, $GRAS_CHECK_SIZEOF_RES, [The number of bytes in type $1])
104 undefine([TYPE_NAME])dnl
108 dnl End of CHECK_SIGNED_SIZEOF
111 dnl CHECK_IEEE_FP: determines if floating points are IEEE754 compliant
112 dnl (inspired from NWS code)
114 AC_DEFUN([CHECK_IEEE_FP],
115 [AC_MSG_CHECKING(if floating point datatypes are IEEE 754 compliant)
116 AC_TRY_COMPILE([#include "confdefs.h"
119 unsigned char bytes[sizeof(double)];
123 unsigned char bytes[sizeof(float)];
126 if (sizeof(double) != 8 || sizeof(float) != 4)
129 memset(&doubleTester, 0, sizeof(doubleTester));
130 memset(&floatTester, 0, sizeof(floatTester));
132 doubleTester.bytes[GRAS_BIGENDIAN ? sizeof(double) - 1 : 0]=192;
133 doubleTester.bytes[GRAS_BIGENDIAN ? sizeof(double) - 2 : 1] =
134 (sizeof(double) == 4) ? 128 :
135 (sizeof(double) == 8) ? 16 :
136 (sizeof(double) == 16) ? 1 : 0;
137 if (doubleTester.testFP != -4.0) return 1;
139 floatTester.bytes[GRAS_BIGENDIAN ? sizeof(float) - 1 : 0]=192;
140 floatTester.bytes[GRAS_BIGENDIAN ? sizeof(float) - 2 : 1] =
141 (sizeof(float) == 4) ? 128 :
142 (sizeof(float) == 8) ? 16 :
143 (sizeof(float) == 16) ? 1 : 0;
144 if (floatTester.testFP != -4.0) return 1;
146 return 0;],[IEEE_FP=yes
147 AC_DEFINE(IEEE_FP,1,[defines if this architecture floating point types are IEEE754 compliant])
149 AC_MSG_ERROR([GRAS works only for little or big endian systems (yet)])])dnl end of AC_TRY_COMPILE
150 AC_MSG_RESULT($IEEE_FP)
151 ])dnl end of CHECK_IEEE_FP
155 dnl *************************8
157 AC_DEFUN([GRAS_ARCH],
159 # Check for the architecture
160 AC_C_BIGENDIAN(endian=1,endian=0,AC_MSG_ERROR([GRAS works only for little or big endian systems (yet)]))
161 AC_DEFINE_UNQUOTED(GRAS_BIGENDIAN,$endian,[define if big endian])
163 GRAS_SIGNED_SIZEOF(char)
164 GRAS_SIGNED_SIZEOF(short int)
165 GRAS_SIGNED_SIZEOF(int)
166 GRAS_SIGNED_SIZEOF(long int)
167 GRAS_SIGNED_SIZEOF(long long int)
170 GRAS_CHECK_SIZEOF(void *)
171 GRAS_CHECK_SIZEOF(void (*) (void))
173 GRAS_CHECK_SIZEOF(float)
174 GRAS_CHECK_SIZEOF(double)
177 AC_MSG_CHECKING(the GRAS signature of this architecture)
178 if test x$endian = x1 ; then
184 trace="$trace_endian"
185 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}"
186 trace="${trace}:${ac_cv_sizeof_void_p}.${ac_cv_sizeof_void_LpR_LvoidR}"
187 trace="${trace}:${ac_cv_sizeof_float}.${ac_cv_sizeof_double}"
189 l:1.2.4.4.8:4.4:4.8) gras_arch=0; gras_arch_name=little32;;
190 l:1.2.4.8.8:8.8:4.8) gras_arch=1; gras_arch_name=little64;;
191 B:1.2.4.4.8:4.4:4.8) gras_arch=2; gras_arch_name=big32;;
192 B:1.2.4.8.8:8.8:4.8) gras_arch=3; gras_arch_name=big64;;
194 if test x$gras_arch = xunknown ; then
195 AC_MSG_RESULT([damnit ($trace)])
196 AC_MSG_ERROR([Impossible to determine the GRAS architecture signature.
197 Please report this architecture trace ($trace) and what it corresponds to.])
199 echo "$as_me:$LINENO: GRAS trace of this machine: $trace" >&AS_MESSAGE_LOG_FD
200 AC_DEFINE_UNQUOTED(GRAS_THISARCH_NAME,"$gras_arch_name",[defines the GRAS architecture name of this machine])
201 AC_DEFINE_UNQUOTED(GRAS_THISARCH,$gras_arch,[defines the GRAS architecture signature of this machine])
202 AC_MSG_RESULT($gras_arch ($gras_arch_name))
204 # END OF GRAS ARCH CHECK