Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Check the GRAS_ARCH; cosmetics
[simgrid.git] / acmacro / gras_arch.m4
1 dnl
2 dnl GRAS_DO_CHECK_SIZEOF: Get the size of a datatype (even in cross-compile)
3 dnl  1: type tested
4 dnl  2: extra include lines
5 dnl  3: extra sizes to test
6 dnl ("adapted" from openldap)
7 dnl
8 AC_DEFUN(GRAS_DO_CHECK_SIZEOF,
9 [changequote(<<, >>)dnl 
10  dnl The cache variable name (and of the result). 
11  define(<<GRAS_CHECK_SIZEOF_RES>>, translit(ac_cv_sizeof_$1, [ *()], [_pLR]))dnl
12  changequote([, ])dnl 
13  AC_CACHE_VAL(GRAS_CHECK_SIZEOF_RES, 
14  [for ac_size in 4 8 1 2 16 $3 ; do # List sizes in rough order of prevalence. 
15    AC_TRY_COMPILE([#include "confdefs.h" 
16    #include <sys/types.h> 
17    $2 
18    ], [switch (0) case 0: case (sizeof ($1) == $ac_size):;], GRAS_CHECK_SIZEOF_RES=$ac_size) 
19    if test x$GRAS_CHECK_SIZEOF_RES != x ; then break; fi 
20   done 
21  ]) 
22 ])
23
24 dnl
25 dnl GRAS_CHECK_SIZEOF: Get the size of a datatype (even in cross-compile), with msg display, and define the result
26 dnl  1: type tested
27 dnl  2: extra include lines
28 dnl  3: extra sizes to test
29 dnl ("adapted" from openldap)
30 dnl
31 AC_DEFUN(GRAS_CHECK_SIZEOF,
32 [AC_MSG_CHECKING(size of $1) 
33 GRAS_DO_CHECK_SIZEOF($1,$2)
34 if test x$GRAS_CHECK_SIZEOF_RES = x ; then 
35   AC_MSG_ERROR([cannot determine a size for $1]) 
36 fi 
37 AC_MSG_RESULT($GRAS_CHECK_SIZEOF_RES) 
38 changequote(<<, >>)dnl 
39 dnl The name to #define. 
40 define(<<TYPE_NAME>>, translit(sizeof_$1, [a-z *()], [A-Z_P__]))dnl 
41 changequote([, ])dnl 
42 AC_DEFINE_UNQUOTED(TYPE_NAME, $GRAS_CHECK_SIZEOF_RES, [The number of bytes in type $1]) 
43 undefine([TYPE_NAME])dnl 
44 ])
45
46
47 dnl
48 dnl GRAS_SIGNED_SIZEOF: Get the size of the datatype, and make sure that
49 dnl signed, unsigned and unspecified have the same size
50 dnl
51 AC_DEFUN(GRAS_SIGNED_SIZEOF,
52 [AC_MSG_CHECKING(size of $1)
53 GRAS_DO_CHECK_SIZEOF($1,$2)
54 unspecif=$GRAS_CHECK_SIZEOF_RES
55 if test x$unspecif = x ; then
56   AC_MSG_ERROR([cannot determine a size for $1]) 
57 fi 
58
59 GRAS_DO_CHECK_SIZEOF(signed $1,$2)
60 signed=$GRAS_CHECK_SIZEOF_RES
61 if test x$signed = x ; then
62   AC_MSG_ERROR([cannot determine a size for signed $1]) 
63 fi 
64 if test x$unspecif != x$signed ; then
65   AC_MSG_ERROR(['signed $1' and '$1' have different sizes ! ($signed != $unspecif)]) 
66 fi 
67
68 GRAS_DO_CHECK_SIZEOF(unsigned $1,$2)
69 unsigned=$GRAS_CHECK_SIZEOF_RES
70 if test x$unsigned = x ; then
71   AC_MSG_ERROR([cannot determine a size for unsigned $1]) 
72 fi 
73 if test x$unsigned != x$signed ; then
74   AC_MSG_ERROR(['signed $1' and 'unsigned $1' have different sizes ! ($signed != $unsigned)]) 
75 fi 
76
77 AC_MSG_RESULT($GRAS_CHECK_SIZEOF_RES) 
78 changequote(<<, >>)dnl 
79 dnl The name to #define. 
80 define(<<TYPE_NAME>>, translit(sizeof_$1, [a-z *()], [A-Z_P__]))dnl 
81 changequote([, ])dnl 
82 AC_DEFINE_UNQUOTED(TYPE_NAME, $GRAS_CHECK_SIZEOF_RES, [The number of bytes in type $1]) 
83 undefine([TYPE_NAME])dnl 
84 ])
85
86 dnl
87 dnl End of CHECK_SIGNED_SIZEOF
88 dnl
89
90 dnl CHECK_IEEE_FP: determines if floating points are IEEE754 compliant
91 dnl (inspired from NWS code)
92 dnl
93 AC_DEFUN(CHECK_IEEE_FP,
94 [AC_MSG_CHECKING(if floating point datatypes are IEEE 754 compliant) 
95 AC_TRY_COMPILE([#include "confdefs.h"
96 union {
97         double testFP;
98         unsigned char bytes[sizeof(double)];
99 } doubleTester;
100 union {
101         float testFP;
102         unsigned char bytes[sizeof(float)];
103 } floatTester;
104 ],[
105 memset(&doubleTester, 0, sizeof(doubleTester));
106 memset(&floatTester, 0, sizeof(floatTester));
107
108 doubleTester.bytes[GRAS_BIGENDIAN ? sizeof(double) - 1 : 0]=192;
109 doubleTester.bytes[GRAS_BIGENDIAN ? sizeof(double) - 2 : 1] =
110   (sizeof(double) == 4)  ? 128 :
111   (sizeof(double) == 8)  ? 16 :
112   (sizeof(double) == 16) ? 1 : 0;
113 if (doubleTester.testFP != -4.0) return 1;
114
115 floatTester.bytes[GRAS_BIGENDIAN ? sizeof(float) - 1 : 0]=192;
116 floatTester.bytes[GRAS_BIGENDIAN ? sizeof(float) - 2 : 1] =
117   (sizeof(float) == 4)  ? 128 :
118   (sizeof(float) == 8)  ? 16 :
119   (sizeof(float) == 16) ? 1 : 0;
120 if (floatTester.testFP != -4.0) return 1;
121
122 return 0;],[IEEE_FP=yes
123 AC_DEFINE(IEEE_FP,1,[defines if this architecture floating point types are IEEE754 compliant])
124 ],[IEEE_FP=no 
125    AC_MSG_ERROR([GRAS works only for little or big endian systems (yet)])])dnl end of AC_TRY_COMPILE
126 AC_MSG_RESULT($IEEE_FP)
127 ])dnl end of CHECK_IEEE_FP
128
129
130
131 dnl *************************8
132 dnl 
133 AC_DEFUN(GRAS_ARCH,
134 [
135 # Check for the architecture
136 AC_C_BIGENDIAN(endian=1,endian=0,AC_MSG_ERROR([GRAS works only for little or big endian systems (yet)]))
137 AC_DEFINE_UNQUOTED(GRAS_BIGENDIAN,$endian,[define if big endian])
138                                                                   
139 GRAS_SIGNED_SIZEOF(char)
140 GRAS_SIGNED_SIZEOF(short int)
141 GRAS_SIGNED_SIZEOF(int)
142 GRAS_SIGNED_SIZEOF(long int)
143 GRAS_SIGNED_SIZEOF(long long int)
144                                                                   
145
146 GRAS_CHECK_SIZEOF(void *)
147 GRAS_CHECK_SIZEOF(void (*) (void))
148                                                                   
149 GRAS_CHECK_SIZEOF(float)
150 GRAS_CHECK_SIZEOF(double)
151 CHECK_IEEE_FP
152                                                                   
153 AC_MSG_CHECKING(the GRAS signature of this architecture)
154 if test x$endian = x1 ; then
155   trace_endian=B
156 else
157   trace_endian=l
158 fi
159 gras_arch=unknown
160 trace="$trace_endian"
161 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}"
162 trace="${trace}:${ac_cv_sizeof_void_p}.${ac_cv_sizeof_void_LpR_LvoidR}"
163 trace="${trace}:${ac_cv_sizeof_float}.${ac_cv_sizeof_double}"
164 case $trace in
165   l:1.2.4.4.8:4.4:4.8) gras_arch=0; gras_arch_name=i386;;
166 esac
167 if test x$gras_arch = xunknown ; then
168   AC_MSG_RESULT([damnit ($trace)])
169   AC_MSG_ERROR([Impossible to determine the GRAS architecture signature.
170 Please report this architecture trace ($trace) and what it corresponds to.])
171 fi
172 echo "$as_me:$LINENO: GRAS trace of this machine: $trace" >&AS_MESSAGE_LOG_FD
173 AC_DEFINE_UNQUOTED(GRAS_THISARCH_NAME,"$gras_arch_name",[defines the GRAS architecture name of this machine])
174 AC_DEFINE_UNQUOTED(GRAS_THISARCH,$gras_arch,[defines the GRAS architecture signature of this machine])
175 AC_MSG_RESULT($gras_arch ($gras_arch_name))
176 ])