Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Do not configure subdirs (since they are result of interupted make dir); adapt to...
[simgrid.git] / acmacro / gras_arch.m4
1 # BEGIN OF GRAS ARCH CHECK
2 dnl
3 dnl GRAS_DO_CHECK_SIZEOF: Get the size of a datatype (even in cross-compile)
4 dnl  1: type tested
5 dnl  2: extra include lines
6 dnl  3: extra sizes to test
7 dnl ("adapted" from openldap)
8 dnl
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
13  changequote([, ])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> 
18    $2 
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 
21   done 
22  ]) 
23 ])
24
25 dnl
26 dnl GRAS_CHECK_SIZEOF: Get the size of a datatype (even in cross-compile), with msg display, and define the result
27 dnl  1: type tested
28 dnl  2: extra include lines
29 dnl  3: extra sizes to test
30 dnl ("adapted" from openldap)
31 dnl
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]) 
37 fi 
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 
42 changequote([, ])dnl 
43 AC_DEFINE_UNQUOTED(TYPE_NAME, $GRAS_CHECK_SIZEOF_RES, [The number of bytes in type $1]) 
44 undefine([TYPE_NAME])dnl 
45 ])
46
47 dnl
48 dnl GRAS_TWO_COMPLIMENT: Make sure the type is two-compliment
49 dnl
50 AC_DEFUN([GRAS_TWO_COMPLIMENT],
51 [
52 AC_TRY_COMPILE([#include "confdefs.h"
53 union {
54    signed $1 testInt;
55    unsigned char bytes[sizeof($1)];
56 } intTester;
57 ],[
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
62 ])
63
64 dnl
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
67 dnl
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]) 
74 fi 
75
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]) 
80 fi 
81 if test x$unspecif != x$signed ; then
82   AC_MSG_ERROR(['signed $1' and '$1' have different sizes ! ($signed != $unspecif)]) 
83 fi 
84
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]) 
89 fi 
90 if test x$unsigned != x$signed ; then
91   AC_MSG_ERROR(['signed $1' and 'unsigned $1' have different sizes ! ($signed != $unsigned)]) 
92 fi 
93
94 dnl Make sure we don't run on a non-two-compliment arch, since we dunno
95 dnl convert them
96 GRAS_TWO_COMPLIMENT($1)
97
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 
102 changequote([, ])dnl 
103 AC_DEFINE_UNQUOTED(TYPE_NAME, $GRAS_CHECK_SIZEOF_RES, [The number of bytes in type $1]) 
104 undefine([TYPE_NAME])dnl 
105 ])
106
107 dnl
108 dnl End of CHECK_SIGNED_SIZEOF
109 dnl
110
111 dnl CHECK_IEEE_FP: determines if floating points are IEEE754 compliant
112 dnl (inspired from NWS code)
113 dnl
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"
117 union {
118         double testFP;
119         unsigned char bytes[sizeof(double)];
120 } doubleTester;
121 union {
122         float testFP;
123         unsigned char bytes[sizeof(float)];
124 } floatTester;
125 ],[
126 if (sizeof(double) != 8 || sizeof(float) != 4)
127    return 1;
128
129 memset(&doubleTester, 0, sizeof(doubleTester));
130 memset(&floatTester, 0, sizeof(floatTester));
131
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;
138
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;
145
146 return 0;],[IEEE_FP=yes
147 AC_DEFINE(IEEE_FP,1,[defines if this architecture floating point types are IEEE754 compliant])
148 ],[IEEE_FP=no 
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
152
153
154
155 dnl *************************8
156 dnl 
157 AC_DEFUN([GRAS_ARCH],
158 [
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])
162           
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)
168                                                                   
169
170 GRAS_CHECK_SIZEOF(void *)
171 GRAS_CHECK_SIZEOF(void (*) (void))
172                                                                   
173 GRAS_CHECK_SIZEOF(float)
174 GRAS_CHECK_SIZEOF(double)
175 CHECK_IEEE_FP
176                                                                   
177 AC_MSG_CHECKING(the GRAS signature of this architecture)
178 if test x$endian = x1 ; then
179   trace_endian=B
180 else
181   trace_endian=l
182 fi
183 gras_arch=unknown
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}"
188 case $trace in
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;;
193 esac
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.])
198 fi
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))
203 ])
204 # END OF GRAS ARCH CHECK