Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
More debugging
[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
48 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
51 dnl
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]) 
58 fi 
59
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]) 
64 fi 
65 if test x$unspecif != x$signed ; then
66   AC_MSG_ERROR(['signed $1' and '$1' have different sizes ! ($signed != $unspecif)]) 
67 fi 
68
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]) 
73 fi 
74 if test x$unsigned != x$signed ; then
75   AC_MSG_ERROR(['signed $1' and 'unsigned $1' have different sizes ! ($signed != $unsigned)]) 
76 fi 
77
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 
82 changequote([, ])dnl 
83 AC_DEFINE_UNQUOTED(TYPE_NAME, $GRAS_CHECK_SIZEOF_RES, [The number of bytes in type $1]) 
84 undefine([TYPE_NAME])dnl 
85 ])
86
87 dnl
88 dnl End of CHECK_SIGNED_SIZEOF
89 dnl
90
91 dnl CHECK_IEEE_FP: determines if floating points are IEEE754 compliant
92 dnl (inspired from NWS code)
93 dnl
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"
97 union {
98         double testFP;
99         unsigned char bytes[sizeof(double)];
100 } doubleTester;
101 union {
102         float testFP;
103         unsigned char bytes[sizeof(float)];
104 } floatTester;
105 ],[
106 if (sizeof(double) != 8 || sizeof(float) != 4)
107    return 1;
108
109 memset(&doubleTester, 0, sizeof(doubleTester));
110 memset(&floatTester, 0, sizeof(floatTester));
111
112 doubleTester.bytes[GRAS_BIGENDIAN ? sizeof(double) - 1 : 0]=192;
113 doubleTester.bytes[GRAS_BIGENDIAN ? sizeof(double) - 2 : 1] =
114   (sizeof(double) == 4)  ? 128 :
115   (sizeof(double) == 8)  ? 16 :
116   (sizeof(double) == 16) ? 1 : 0;
117 if (doubleTester.testFP != -4.0) return 1;
118
119 floatTester.bytes[GRAS_BIGENDIAN ? sizeof(float) - 1 : 0]=192;
120 floatTester.bytes[GRAS_BIGENDIAN ? sizeof(float) - 2 : 1] =
121   (sizeof(float) == 4)  ? 128 :
122   (sizeof(float) == 8)  ? 16 :
123   (sizeof(float) == 16) ? 1 : 0;
124 if (floatTester.testFP != -4.0) return 1;
125
126 return 0;],[IEEE_FP=yes
127 AC_DEFINE(IEEE_FP,1,[defines if this architecture floating point types are IEEE754 compliant])
128 ],[IEEE_FP=no 
129    AC_MSG_ERROR([GRAS works only for little or big endian systems (yet)])])dnl end of AC_TRY_COMPILE
130 AC_MSG_RESULT($IEEE_FP)
131 ])dnl end of CHECK_IEEE_FP
132
133
134
135 dnl *************************8
136 dnl 
137 AC_DEFUN([GRAS_ARCH],
138 [
139 # Check for the architecture
140 AC_C_BIGENDIAN(endian=1,endian=0,AC_MSG_ERROR([GRAS works only for little or big endian systems (yet)]))
141 AC_DEFINE_UNQUOTED(GRAS_BIGENDIAN,$endian,[define if big endian])
142           
143 dnl FIXME: Use SIGNED instead of CHECK to make sure signed and unsigned type
144 dnl have same size        
145 GRAS_CHECK_SIZEOF(char)
146 GRAS_CHECK_SIZEOF(short int)
147 GRAS_CHECK_SIZEOF(int)
148 GRAS_CHECK_SIZEOF(long int)
149 GRAS_CHECK_SIZEOF(long long int)
150                                                                   
151
152 GRAS_CHECK_SIZEOF(void *)
153 GRAS_CHECK_SIZEOF(void (*) (void))
154                                                                   
155 GRAS_CHECK_SIZEOF(float)
156 GRAS_CHECK_SIZEOF(double)
157 CHECK_IEEE_FP
158                                                                   
159 AC_MSG_CHECKING(the GRAS signature of this architecture)
160 if test x$endian = x1 ; then
161   trace_endian=B
162 else
163   trace_endian=l
164 fi
165 gras_arch=unknown
166 trace="$trace_endian"
167 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}"
168 trace="${trace}:${ac_cv_sizeof_void_p}.${ac_cv_sizeof_void_LpR_LvoidR}"
169 trace="${trace}:${ac_cv_sizeof_float}.${ac_cv_sizeof_double}"
170 case $trace in
171   l:1.2.4.4.8:4.4:4.8) gras_arch=0; gras_arch_name=i386;;
172   l:1.2.4.8.8:8.8:4.8) gras_arch=1; gras_arch_name=alpha;;
173   B:1.2.4.4.8:4.4:4.8) gras_arch=2; gras_arch_name=powerpc;;
174   B:1.2.4.8.8:8.8:4.8) gras_arch=3; gras_arch_name=sparc;;
175 esac
176 if test x$gras_arch = xunknown ; then
177   AC_MSG_RESULT([damnit ($trace)])
178   AC_MSG_ERROR([Impossible to determine the GRAS architecture signature.
179 Please report this architecture trace ($trace) and what it corresponds to.])
180 fi
181 echo "$as_me:$LINENO: GRAS trace of this machine: $trace" >&AS_MESSAGE_LOG_FD
182 AC_DEFINE_UNQUOTED(GRAS_THISARCH_NAME,"$gras_arch_name",[defines the GRAS architecture name of this machine])
183 AC_DEFINE_UNQUOTED(GRAS_THISARCH,$gras_arch,[defines the GRAS architecture signature of this machine])
184 AC_MSG_RESULT($gras_arch ($gras_arch_name))
185 ])
186 # END OF GRAS ARCH CHECK