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
49 dnl GRAS_SIGNED_SIZEOF: Get the size of the datatype, and make sure that
50 dnl signed, unsigned and unspecified have the same size
52 AC_DEFUN([GRAS_SIGNED_SIZEOF],
53 [AC_MSG_CHECKING(size of $1)
54 GRAS_DO_CHECK_SIZEOF($1,$2)
55 unspecif=$GRAS_CHECK_SIZEOF_RES
56 if test x$unspecif = x ; then
57 AC_MSG_ERROR([cannot determine a size for $1])
60 GRAS_DO_CHECK_SIZEOF(signed $1,$2)
61 signed=$GRAS_CHECK_SIZEOF_RES
62 if test x$signed = x ; then
63 AC_MSG_ERROR([cannot determine a size for signed $1])
65 if test x$unspecif != x$signed ; then
66 AC_MSG_ERROR(['signed $1' and '$1' have different sizes ! ($signed != $unspecif)])
69 GRAS_DO_CHECK_SIZEOF(unsigned $1,$2)
70 unsigned=$GRAS_CHECK_SIZEOF_RES
71 if test x$unsigned = x ; then
72 AC_MSG_ERROR([cannot determine a size for unsigned $1])
74 if test x$unsigned != x$signed ; then
75 AC_MSG_ERROR(['signed $1' and 'unsigned $1' have different sizes ! ($signed != $unsigned)])
78 AC_MSG_RESULT($GRAS_CHECK_SIZEOF_RES)
79 changequote(<<, >>)dnl
80 dnl The name to #define.
81 define(<<TYPE_NAME>>, translit(sizeof_$1, [a-z *()], [A-Z_P__]))dnl
83 AC_DEFINE_UNQUOTED(TYPE_NAME, $GRAS_CHECK_SIZEOF_RES, [The number of bytes in type $1])
84 undefine([TYPE_NAME])dnl
88 dnl End of CHECK_SIGNED_SIZEOF
91 dnl CHECK_IEEE_FP: determines if floating points are IEEE754 compliant
92 dnl (inspired from NWS code)
94 AC_DEFUN([CHECK_IEEE_FP],
95 [AC_MSG_CHECKING(if floating point datatypes are IEEE 754 compliant)
96 AC_TRY_COMPILE([#include "confdefs.h"
99 unsigned char bytes[sizeof(double)];
103 unsigned char bytes[sizeof(float)];
106 memset(&doubleTester, 0, sizeof(doubleTester));
107 memset(&floatTester, 0, sizeof(floatTester));
109 doubleTester.bytes[GRAS_BIGENDIAN ? sizeof(double) - 1 : 0]=192;
110 doubleTester.bytes[GRAS_BIGENDIAN ? sizeof(double) - 2 : 1] =
111 (sizeof(double) == 4) ? 128 :
112 (sizeof(double) == 8) ? 16 :
113 (sizeof(double) == 16) ? 1 : 0;
114 if (doubleTester.testFP != -4.0) return 1;
116 floatTester.bytes[GRAS_BIGENDIAN ? sizeof(float) - 1 : 0]=192;
117 floatTester.bytes[GRAS_BIGENDIAN ? sizeof(float) - 2 : 1] =
118 (sizeof(float) == 4) ? 128 :
119 (sizeof(float) == 8) ? 16 :
120 (sizeof(float) == 16) ? 1 : 0;
121 if (floatTester.testFP != -4.0) return 1;
123 return 0;],[IEEE_FP=yes
124 AC_DEFINE(IEEE_FP,1,[defines if this architecture floating point types are IEEE754 compliant])
126 AC_MSG_ERROR([GRAS works only for little or big endian systems (yet)])])dnl end of AC_TRY_COMPILE
127 AC_MSG_RESULT($IEEE_FP)
128 ])dnl end of CHECK_IEEE_FP
132 dnl *************************8
134 AC_DEFUN([GRAS_ARCH],
136 # Check for the architecture
137 AC_C_BIGENDIAN(endian=1,endian=0,AC_MSG_ERROR([GRAS works only for little or big endian systems (yet)]))
138 AC_DEFINE_UNQUOTED(GRAS_BIGENDIAN,$endian,[define if big endian])
140 dnl FIXME: Use SIGNED instead of CHECK to make sure signed and unsigned type
142 GRAS_CHECK_SIZEOF(char)
143 GRAS_CHECK_SIZEOF(short int)
144 GRAS_CHECK_SIZEOF(int)
145 GRAS_CHECK_SIZEOF(long int)
146 GRAS_CHECK_SIZEOF(long long int)
149 GRAS_CHECK_SIZEOF(void *)
150 GRAS_CHECK_SIZEOF(void (*) (void))
152 GRAS_CHECK_SIZEOF(float)
153 GRAS_CHECK_SIZEOF(double)
156 AC_MSG_CHECKING(the GRAS signature of this architecture)
157 if test x$endian = x1 ; then
163 trace="$trace_endian"
164 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}"
165 trace="${trace}:${ac_cv_sizeof_void_p}.${ac_cv_sizeof_void_LpR_LvoidR}"
166 trace="${trace}:${ac_cv_sizeof_float}.${ac_cv_sizeof_double}"
168 l:1.2.4.4.8:4.4:4.8) gras_arch=0; gras_arch_name=i386;;
169 l:1.2.4.8.8:8.8:4.8) gras_arch=1; gras_arch_name=alpha;;
170 B:1.2.4.4.8:4.4:4.8) gras_arch=2; gras_arch_name=powerpc;;
171 B:1.2.4.8.8:8.8:4.8) gras_arch=3; gras_arch_name=sparc;;
173 if test x$gras_arch = xunknown ; then
174 AC_MSG_RESULT([damnit ($trace)])
175 AC_MSG_ERROR([Impossible to determine the GRAS architecture signature.
176 Please report this architecture trace ($trace) and what it corresponds to.])
178 echo "$as_me:$LINENO: GRAS trace of this machine: $trace" >&AS_MESSAGE_LOG_FD
179 AC_DEFINE_UNQUOTED(GRAS_THISARCH_NAME,"$gras_arch_name",[defines the GRAS architecture name of this machine])
180 AC_DEFINE_UNQUOTED(GRAS_THISARCH,$gras_arch,[defines the GRAS architecture signature of this machine])
181 AC_MSG_RESULT($gras_arch ($gras_arch_name))
183 # END OF GRAS ARCH CHECK