]> www.ginac.de Git - cln.git/blob - m4/intparam.m4
Update and clean up autoconf template files.
[cln.git] / m4 / intparam.m4
1 # intparam.m4 serial 4  -*- Autoconf -*-
2 dnl Copyright (C) 1993-2008, 2017, 2020 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
6
7 dnl From Bruno Haible, Sam Steingold
8
9 AC_DEFUN([CL_INTPARAM_CROSS],
10 [
11   AC_REQUIRE([AC_C_BIGENDIAN])
12   cl_machine_file_h=$1
13   {
14     CL_INTPARAM_BITSIZE([signed char], [char_bitsize])
15     CL_INTPARAM_BITSIZE([short], [short_bitsize])
16     CL_INTPARAM_BITSIZE([int], [int_bitsize])
17     CL_INTPARAM_BITSIZE([long], [long_bitsize])
18     CL_INTPARAM_BITSIZE([long long], [longlong_bitsize])
19     CL_INTPARAM_BITSIZE([unsigned char], [uchar_bitsize])
20     CL_INTPARAM_BITSIZE([unsigned short], [ushort_bitsize])
21     CL_INTPARAM_BITSIZE([unsigned int], [uint_bitsize])
22     CL_INTPARAM_BITSIZE([unsigned long], [ulong_bitsize])
23     CL_INTPARAM_BITSIZE([unsigned long long], [ulonglong_bitsize])
24     if test -n "$char_bitsize"; then
25       echo "/* Integers of type char have $char_bitsize bits. */"
26       echo "#define char_bitsize $char_bitsize"
27       echo
28     else
29       echo "#error \"Integers of type char have no binary representation!!\""
30     fi
31     if test -n "$short_bitsize"; then
32       echo "/* Integers of type short have $short_bitsize bits. */"
33       echo "#define short_bitsize $short_bitsize"
34       echo
35     else
36       echo "#error \"Integers of type short have no binary representation!!\""
37     fi
38     if test -n "$int_bitsize"; then
39       echo "/* Integers of type int have $int_bitsize bits. */"
40       echo "#define int_bitsize $int_bitsize"
41       echo
42     else
43       echo "#error \"Integers of type int have no binary representation!!\""
44     fi
45     if test -n "$long_bitsize"; then
46       echo "/* Integers of type long have $long_bitsize bits. */"
47       echo "#define long_bitsize $long_bitsize"
48       echo
49     else
50       echo "#error \"Integers of type long have no binary representation!!\""
51     fi
52     if test -n "$longlong_bitsize"; then
53       echo "/* Integers of type long long have $longlong_bitsize bits. */"
54       echo "#define long_long_bitsize $longlong_bitsize"
55       echo
56     else
57       echo "#error \"Integers of type long long have no binary representation!!\""
58     fi
59     if test -n "$uchar_bitsize"; then
60       echo "/* Integers of type unsigned char have $uchar_bitsize bits. */"
61       echo
62     else
63       echo "#error \"Integers of type unsigned char have no binary representation!!\""
64     fi
65     if test -n "$ushort_bitsize"; then
66       echo "/* Integers of type unsigned short have $ushort_bitsize bits. */"
67       echo
68     else
69       echo "#error \"Integers of type unsigned short have no binary representation!!\""
70     fi
71     if test -n "$uint_bitsize"; then
72       echo "/* Integers of type unsigned int have $uint_bitsize bits. */"
73       echo
74     else
75       echo "#error \"Integers of type unsigned int have no binary representation!!\""
76     fi
77     if test -n "$ulong_bitsize"; then
78       echo "/* Integers of type unsigned long have $ulong_bitsize bits. */"
79       echo
80     else
81       echo "#error \"Integers of type unsigned long have no binary representation!!\""
82     fi
83     if test -n "$ulonglong_bitsize"; then
84       echo "/* Integers of type unsigned long long have $ulonglong_bitsize bits. */"
85       echo
86     else
87       echo "#error \"Integers of type unsigned long long have no binary representation!!\""
88     fi
89     if test "$char_bitsize" != "$uchar_bitsize"; then
90       echo "#error \"Integer types char and unsigned char have different sizes!!\""
91     fi
92     if test "$short_bitsize" != "$ushort_bitsize"; then
93       echo "#error \"Integer types short and unsigned short have different sizes!!\""
94     fi
95     if test "$int_bitsize" != "$uint_bitsize"; then
96       echo "#error \"Integer types int and unsigned int have different sizes!!\""
97     fi
98     if test "$long_bitsize" != "$ulong_bitsize"; then
99       echo "#error \"Integer types long and unsigned long have different sizes!!\""
100     fi
101     if test "$longlong_bitsize" != "$ulonglong_bitsize"; then
102       echo "#error \"Integer types long long and unsigned long long have different sizes!!\""
103     fi
104     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <stdint.h>]],
105       [[typedef int verify[2*(sizeof(char*)<=sizeof (intptr_t))-1];]])],
106       [], [echo "#error \"Type char * does not fit into an intptr_t!!\""])
107     AC_COMPUTE_INT([pointer_size], [sizeof (char *)], [], [])
108     pointer_bitsize=`expr $pointer_size '*' $char_bitsize`
109     echo "/* Pointers of type char * have $pointer_bitsize bits. */"
110     echo "#define pointer_bitsize $pointer_bitsize"
111     echo
112     CL_INTPARAM_SIZEOF([char], [sizeof_char])
113     CL_INTPARAM_ALIGNOF([char], [alignment_char])
114     echo "/* Type char has sizeof = $sizeof_char and alignment = $alignment_char. */"
115     echo "#define sizeof_char $sizeof_char"
116     echo "#define alignment_char $alignment_char"
117     echo
118     CL_INTPARAM_SIZEOF([unsigned char], [sizeof_uchar])
119     CL_INTPARAM_ALIGNOF([unsigned char], [alignment_uchar])
120     echo "/* Type unsigned char has sizeof = $sizeof_uchar and alignment = $alignment_uchar. */"
121     echo
122     CL_INTPARAM_SIZEOF([short], [sizeof_short])
123     CL_INTPARAM_ALIGNOF([short], [alignment_short])
124     echo "/* Type short has sizeof = $sizeof_short and alignment = $alignment_short. */"
125     echo "#define sizeof_short $sizeof_short"
126     echo "#define alignment_short $alignment_short"
127     echo
128     CL_INTPARAM_SIZEOF([unsigned short], [sizeof_ushort])
129     CL_INTPARAM_ALIGNOF([unsigned short], [alignment_ushort])
130     echo "/* Type unsigned short has sizeof = $sizeof_ushort and alignment = $alignment_ushort. */"
131     echo
132     CL_INTPARAM_SIZEOF([int], [sizeof_int])
133     CL_INTPARAM_ALIGNOF([int], [alignment_int])
134     echo "/* Type int has sizeof = $sizeof_int and alignment = $alignment_int. */"
135     echo "#define sizeof_int $sizeof_int"
136     echo "#define alignment_int $alignment_int"
137     echo
138     CL_INTPARAM_SIZEOF([unsigned int], [sizeof_uint])
139     CL_INTPARAM_ALIGNOF([unsigned int], [alignment_uint])
140     echo "/* Type unsigned int has sizeof = $sizeof_uint and alignment = $alignment_uint. */"
141     echo
142     CL_INTPARAM_SIZEOF([long], [sizeof_long])
143     CL_INTPARAM_ALIGNOF([long], [alignment_long])
144     echo "/* Type long has sizeof = $sizeof_long and alignment = $alignment_long. */"
145     echo "#define sizeof_long $sizeof_long"
146     echo "#define alignment_long $alignment_long"
147     echo
148     CL_INTPARAM_SIZEOF([unsigned long], [sizeof_ulong])
149     CL_INTPARAM_ALIGNOF([unsigned long], [alignment_ulong])
150     echo "/* Type unsigned long has sizeof = $sizeof_ulong and alignment = $alignment_ulong. */"
151     echo
152     CL_INTPARAM_SIZEOF([long long], [sizeof_longlong])
153     CL_INTPARAM_ALIGNOF([long long], [alignment_longlong])
154     echo "/* Type long long has sizeof = $sizeof_longlong and alignment = $alignment_longlong. */"
155     echo "#define sizeof_long_long $sizeof_longlong"
156     echo "#define alignment_long_long $alignment_longlong"
157     echo
158     CL_INTPARAM_SIZEOF([unsigned long long], [sizeof_ulonglong])
159     CL_INTPARAM_ALIGNOF([unsigned long long], [alignment_ulonglong])
160     echo "/* Type unsigned long long has sizeof = $sizeof_ulonglong and alignment = $alignment_ulonglong. */"
161     echo
162     CL_INTPARAM_SIZEOF([float], [sizeof_float])
163     CL_INTPARAM_ALIGNOF([float], [alignment_float])
164     echo "/* Type float has sizeof = $sizeof_float and alignment = $alignment_float. */"
165     echo "#define sizeof_float $sizeof_float"
166     echo "#define alignment_float $alignment_float"
167     echo
168     CL_INTPARAM_SIZEOF([double], [sizeof_double])
169     CL_INTPARAM_ALIGNOF([double], [alignment_double])
170     echo "/* Type double has sizeof = $sizeof_double and alignment = $alignment_double. */"
171     echo "#define sizeof_double $sizeof_double"
172     echo "#define alignment_double $alignment_double"
173     echo
174     CL_INTPARAM_SIZEOF([long double], [sizeof_longdouble])
175     CL_INTPARAM_ALIGNOF([long double], [alignment_longdouble])
176     echo "/* Type long double has sizeof = $sizeof_longdouble and alignment = $alignment_longdouble. */"
177     echo "#define sizeof_long_double $sizeof_longdouble"
178     echo "#define alignment_long_double $alignment_longdouble"
179     echo
180     CL_INTPARAM_SIZEOF([char *], [sizeof_char_ptr])
181     CL_INTPARAM_ALIGNOF([char *], [alignment_char_ptr])
182     echo "/* Type char * has sizeof = $sizeof_char_ptr and alignment = $alignment_char_ptr. */"
183     echo
184     CL_INTPARAM_SIZEOF([long *], [sizeof_long_ptr])
185     CL_INTPARAM_ALIGNOF([long *], [alignment_long_ptr])
186     echo "/* Type long * has sizeof = $sizeof_long_ptr and alignment = $alignment_long_ptr. */"
187     echo
188     dnl disabled because:
189     dnl - the results of these are not used anywhere
190     dnl - the results of non-cross are not generated (see src/intparam.h)
191     dnl - the C code fails with "expected identifier or '(' before ')' token"
192     dnl   on the line "typedef int verify[2*(alignof(void (*)(void)) == 256) - 1];"
193     dnl CL_INTPARAM_SIZEOF([void (*)(void)], [sizeof_function_ptr])
194     dnl CL_INTPARAM_ALIGNOF([void (*)(void)], [alignment_function_ptr])
195     echo "/* Type function * has sizeof = $sizeof_function_ptr and alignment = $alignment_function_ptr. */"
196     echo
197     case $ac_cv_c_bigendian in
198       yes)
199         echo "/* Type unsigned short is stored BIG-ENDIAN in memory (i.e. like mc68000 or sparc). */"
200         echo "#define short_big_endian"
201         echo "/* Type unsigned int is stored BIG-ENDIAN in memory (i.e. like mc68000 or sparc). */"
202         echo "#define int_big_endian"
203         echo "/* Type unsigned long is stored BIG-ENDIAN in memory (i.e. like mc68000 or sparc). */"
204         echo "#define long_big_endian"
205         echo "/* Type unsigned long long is stored BIG-ENDIAN in memory (i.e. like mc68000 or sparc). */"
206         echo "#define long_long_big_endian"
207         ;;
208       no)
209         echo "/* Type unsigned short is stored LITTLE-ENDIAN in memory (i.e. like Z80 or VAX). */"
210         echo "#define short_little_endian"
211         echo "/* Type unsigned int is stored LITTLE-ENDIAN in memory (i.e. like Z80 or VAX). */"
212         echo "#define int_little_endian"
213         echo "/* Type unsigned long is stored LITTLE-ENDIAN in memory (i.e. like Z80 or VAX). */"
214         echo "#define long_little_endian"
215         echo "/* Type unsigned long long is stored LITTLE-ENDIAN in memory (i.e. like Z80 or VAX). */"
216         echo "#define long_long_little_endian"
217         ;;
218       *)
219         echo "#error \"Type short is stored in memory in an obscure manner!!\""
220         echo "#error \"Type int is stored in memory in an obscure manner!!\""
221         echo "#error \"Type long is stored in memory in an obscure manner!!\""
222         echo "#error \"Type long long is stored in memory in an obscure manner!!\""
223         ;;
224     esac
225   } > "$cl_machine_file_h"
226 ])
227
228 dnl CL_INTPARAM_BITSIZE(type, variable)
229 dnl puts into variable the determined bitsize of the type.
230 AC_DEFUN([CL_INTPARAM_BITSIZE],
231 [
232   n=1; x="($1)2"
233   while true; do
234     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
235       [[typedef int verify[2*(($1)($x) == 0) - 1];]])],
236       [$2=$n; break;],
237       [if test $n = 1000; then $2=; break; fi;])
238     n=`expr $n + 1`; x="$x * ($1)2"
239   done
240 ])
241
242 dnl CL_INTPARAM_SIZEOF(type, variable)
243 dnl puts into variable the determined size of the type.
244 AC_DEFUN([CL_INTPARAM_SIZEOF],
245 [
246   AC_COMPUTE_INT([$2], [sizeof($1)], [], [])
247 ])
248
249 dnl CL_INTPARAM_ALIGNOF(type, variable)
250 dnl puts into variable the determined alignment of the type.
251 AC_DEFUN([CL_INTPARAM_ALIGNOF],[
252   dnl Simplify the guessing by assuming that the alignment is a power of 2.
253   n=1
254   while true; do
255     AC_COMPILE_IFELSE(
256       [AC_LANG_PROGRAM([[
257          #include <stddef.h>
258          #ifdef __cplusplus
259           #ifdef __GNUC__
260            #define alignof(type)  __alignof__ (type)
261           #else
262            template <class type> struct alignof_helper { char slot1; type slot2; };
263            #define alignof(type)  offsetof (alignof_helper<type>, slot2)
264           #endif
265          #else
266           #define alignof(type)  offsetof (struct { char slot1; type slot2; }, slot2)
267          #endif
268          ]],
269          [[typedef int verify[2*(alignof($1) == $n) - 1];]])],
270       [$2=$n; break;]
271       [if test $n = 0; then $2=; break; fi])
272     n=`expr $n '*' 2`
273   done
274 ])