1# $Id: types.m4,v 12.8 2008/03/10 13:40:15 mjc Exp $
2
3# Check the sizes we know about, and see if any of them match what's needed.
4#
5# Prefer ints to anything else, because read, write and others historically
6# returned an int.
7AC_DEFUN(AM_SEARCH_USIZES, [
8	case "$3" in
9	"$ac_cv_sizeof_unsigned_int")
10		$1="typedef unsigned int $2;";;
11	"$ac_cv_sizeof_unsigned_char")
12		$1="typedef unsigned char $2;";;
13	"$ac_cv_sizeof_unsigned_short")
14		$1="typedef unsigned short $2;";;
15	"$ac_cv_sizeof_unsigned_long")
16		$1="typedef unsigned long $2;";;
17	"$ac_cv_sizeof_unsigned_long_long")
18		$1="typedef unsigned long long $2;";;
19	*)
20		if test "$4" != "notfatal"; then
21			AC_MSG_ERROR([No unsigned $3-byte integral type])
22		fi;;
23	esac])
24AC_DEFUN(AM_SEARCH_SSIZES, [
25	case "$3" in
26	"$ac_cv_sizeof_int")
27		$1="typedef int $2;";;
28	"$ac_cv_sizeof_char")
29		$1="typedef char $2;";;
30	"$ac_cv_sizeof_short")
31		$1="typedef short $2;";;
32	"$ac_cv_sizeof_long")
33		$1="typedef long $2;";;
34	"$ac_cv_sizeof_long_long")
35		$1="typedef long long $2;";;
36	*)
37		if test "$4" != "notfatal"; then
38			AC_MSG_ERROR([No signed $3-byte integral type])
39		fi;;
40	esac])
41
42# Check for the standard system types.
43AC_DEFUN(AM_TYPES, [
44
45# db.h includes <sys/types.h> and <stdio.h>, not the other default includes
46# autoconf usually includes.  For that reason, we specify a set of includes
47# for all type checking tests. [#5060]
48#
49# C99 says types should be in <stdint.h>; include <stdint.h> if it exists.
50#
51# Some systems have types in <stddef.h>; include <stddef.h> if it exists.
52#
53# IBM's OS/390 and z/OS releases have types in <inttypes.h> not also found
54# in <sys/types.h>; include <inttypes.h> if it exists.
55db_includes="#include <sys/types.h>"
56AC_SUBST(inttypes_h_decl)
57AC_CHECK_HEADER(inttypes.h, [
58	db_includes="$db_includes
59#include <inttypes.h>"
60	inttypes_h_decl="#include <inttypes.h>"])
61
62# IRIX has stdint.h that is only available when using c99 (i.e. __c99
63# is defined). Problem with having it in a public header is that a c++
64# compiler cannot #include <db.h> if db.h #includes stdint.h, so we
65# need to check that stdint.h is available for all cases.  Also the
66# IRIX compiler does not exit with a non-zero exit code when it sees
67# #error, so we actually need to use the header for the compiler to fail.
68AC_SUBST(stdint_h_decl)
69AC_MSG_CHECKING(for stdint.h)
70AC_COMPILE_IFELSE([#include <stdint.h>
71  int main() {
72  uint_least8_t x=0;
73  return x;
74  }],[AC_MSG_RESULT(yes)
75if test "$db_cv_cxx" = "yes"; then
76  AC_MSG_CHECKING([if stdint.h can be used by C++])
77  AC_LANG_PUSH(C++)
78  AC_COMPILE_IFELSE([#include <stdint.h>
79    int main() {
80    uint_least8_t x=0;
81    return x;
82  }],[AC_MSG_RESULT(yes)
83    stdint_h_decl="#include <stdint.h>"
84    db_includes="$db_includes
85#include <stdint.h>"
86],[AC_MSG_RESULT(no)
87    stdint_h_decl="#ifndef __cplusplus
88#include <stdint.h>
89#endif"
90	db_includes="$db_includes
91#ifndef __cplusplus
92#include <stdint.h>
93#endif"
94])
95    AC_LANG_POP
96else
97    stdint_h_decl="#include <stdint.h>"
98    db_includes="$db_includes
99#include <stdint.h>"
100fi],[AC_MSG_RESULT(no)])
101
102AC_SUBST(stddef_h_decl)
103AC_CHECK_HEADER(stddef.h, [
104	db_includes="$db_includes
105#include <stddef.h>"
106	stddef_h_decl="#include <stddef.h>"])
107AC_SUBST(unistd_h_decl)
108AC_CHECK_HEADER(unistd.h, [
109	db_includes="$db_includes
110#include <unistd.h>"
111	unistd_h_decl="#include <unistd.h>"])
112db_includes="$db_includes
113#include <stdio.h>"
114
115# We need to know the sizes of various objects on this system.
116AC_CHECK_SIZEOF(char,, $db_includes)
117AC_CHECK_SIZEOF(unsigned char,, $db_includes)
118AC_CHECK_SIZEOF(short,, $db_includes)
119AC_CHECK_SIZEOF(unsigned short,, $db_includes)
120AC_CHECK_SIZEOF(int,, $db_includes)
121AC_CHECK_SIZEOF(unsigned int,, $db_includes)
122AC_CHECK_SIZEOF(long,, $db_includes)
123AC_CHECK_SIZEOF(unsigned long,, $db_includes)
124AC_CHECK_SIZEOF(long long,, $db_includes)
125AC_CHECK_SIZEOF(unsigned long long,, $db_includes)
126AC_CHECK_SIZEOF(char *,, $db_includes)
127
128# We look for u_char, u_short, u_int, u_long -- if we can't find them,
129# we create our own.
130AC_SUBST(u_char_decl)
131AC_CHECK_TYPE(u_char,,
132    [u_char_decl="typedef unsigned char u_char;"], $db_includes)
133
134AC_SUBST(u_short_decl)
135AC_CHECK_TYPE(u_short,,
136    [u_short_decl="typedef unsigned short u_short;"], $db_includes)
137
138AC_SUBST(u_int_decl)
139AC_CHECK_TYPE(u_int,,
140    [u_int_decl="typedef unsigned int u_int;"], $db_includes)
141
142AC_SUBST(u_long_decl)
143AC_CHECK_TYPE(u_long,,
144    [u_long_decl="typedef unsigned long u_long;"], $db_includes)
145
146# We look for fixed-size variants of u_char, u_short, u_int, u_long as well.
147AC_SUBST(u_int8_decl)
148AC_CHECK_TYPE(u_int8_t,,
149    [AM_SEARCH_USIZES(u_int8_decl, u_int8_t, 1)], $db_includes)
150
151AC_SUBST(u_int16_decl)
152AC_CHECK_TYPE(u_int16_t,,
153    [AM_SEARCH_USIZES(u_int16_decl, u_int16_t, 2)], $db_includes)
154
155AC_SUBST(int16_decl)
156AC_CHECK_TYPE(int16_t,,
157    [AM_SEARCH_SSIZES(int16_decl, int16_t, 2)], $db_includes)
158
159AC_SUBST(u_int32_decl)
160AC_CHECK_TYPE(u_int32_t,,
161    [AM_SEARCH_USIZES(u_int32_decl, u_int32_t, 4)], $db_includes)
162
163AC_SUBST(int32_decl)
164AC_CHECK_TYPE(int32_t,,
165    [AM_SEARCH_SSIZES(int32_decl, int32_t, 4)], $db_includes)
166
167AC_SUBST(u_int64_decl)
168AC_CHECK_TYPE(u_int64_t,,
169    [AM_SEARCH_USIZES(u_int64_decl, u_int64_t, 8, notfatal)], $db_includes)
170
171AC_SUBST(int64_decl)
172AC_CHECK_TYPE(int64_t,,
173    [AM_SEARCH_SSIZES(int64_decl, int64_t, 8, notfatal)], $db_includes)
174
175# No currently autoconf'd systems lack FILE, off_t pid_t, size_t, time_t.
176#
177# We require them, we don't try to substitute our own if we can't find them.
178AC_SUBST(FILE_t_decl)
179AC_CHECK_TYPE(FILE *,, AC_MSG_ERROR([No FILE type.]), $db_includes)
180AC_SUBST(off_t_decl)
181AC_CHECK_TYPE(off_t,, AC_MSG_ERROR([No off_t type.]), $db_includes)
182AC_SUBST(pid_t_decl)
183AC_CHECK_TYPE(pid_t,, AC_MSG_ERROR([No pid_t type.]), $db_includes)
184AC_SUBST(size_t_decl)
185AC_CHECK_TYPE(size_t,, AC_MSG_ERROR([No size_t type.]), $db_includes)
186AC_SUBST(time_t_decl)
187AC_CHECK_TYPE(time_t,, AC_MSG_ERROR([No time_t type.]), $db_includes)
188
189# Check for ssize_t -- if none exists, find a signed integral type that's
190# the same size as a size_t.
191AC_CHECK_SIZEOF(size_t,, $db_includes)
192AC_SUBST(ssize_t_decl)
193AC_CHECK_TYPE(ssize_t,,
194    [AM_SEARCH_SSIZES(ssize_t_decl, ssize_t, $ac_cv_sizeof_size_t)],
195    $db_includes)
196
197# Check for uintmax_t -- if none exists, find the largest unsigned integral
198# type available.
199AC_SUBST(uintmax_t_decl)
200AC_CHECK_TYPE(uintmax_t,, [AC_CHECK_TYPE(unsigned long long,
201    [uintmax_t_decl="typedef unsigned long long uintmax_t;"],
202    [uintmax_t_decl="typedef unsigned long uintmax_t;"], $db_includes)])
203
204# Check for uintptr_t -- if none exists, find an integral type which is
205# the same size as a pointer.
206AC_SUBST(uintptr_t_decl)
207AC_CHECK_TYPE(uintptr_t,,
208    [AM_SEARCH_USIZES(uintptr_t_decl, uintptr_t, $ac_cv_sizeof_char_p)])
209
210AM_SOCKLEN_T
211])
212