summaryrefslogtreecommitdiff
path: root/dist/aclocal/types.m4
blob: af7b53543e952b621c28f5cc06d0152c77bee2cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# $Id$

# Check the sizes we know about, and see if any of them match what's needed.
#
# Prefer ints to anything else, because read, write and others historically
# returned an int.
AC_DEFUN(AM_SEARCH_USIZES, [
	case "$3" in
	"$ac_cv_sizeof_unsigned_int")
		$1="typedef unsigned int $2;";;
	"$ac_cv_sizeof_unsigned_char")
		$1="typedef unsigned char $2;";;
	"$ac_cv_sizeof_unsigned_short")
		$1="typedef unsigned short $2;";;
	"$ac_cv_sizeof_unsigned_long")
		$1="typedef unsigned long $2;";;
	"$ac_cv_sizeof_unsigned_long_long")
		$1="typedef unsigned long long $2;";;
	*)
		if test "$4" != "notfatal"; then
			AC_MSG_ERROR([No unsigned $3-byte integral type])
		fi;;
	esac])
AC_DEFUN(AM_SEARCH_SSIZES, [
	case "$3" in
	"$ac_cv_sizeof_int")
		$1="typedef int $2;";;
	"$ac_cv_sizeof_char")
		$1="typedef char $2;";;
	"$ac_cv_sizeof_short")
		$1="typedef short $2;";;
	"$ac_cv_sizeof_long")
		$1="typedef long $2;";;
	"$ac_cv_sizeof_long_long")
		$1="typedef long long $2;";;
	*)
		if test "$4" != "notfatal"; then
			AC_MSG_ERROR([No signed $3-byte integral type])
		fi;;
	esac])

# Check for the standard system types.
AC_DEFUN(AM_TYPES, [

# db.h includes <sys/types.h> and <stdio.h>, not the other default includes
# autoconf usually includes.  For that reason, we specify a set of includes
# for all type checking tests. [#5060]
#
# C99 says types should be in <stdint.h>; include <stdint.h> if it exists.
#
# Some systems have types in <stddef.h>; include <stddef.h> if it exists.
#
# IBM's OS/390 and z/OS releases have types in <inttypes.h> not also found
# in <sys/types.h>; include <inttypes.h> if it exists.
db_includes="#include <sys/types.h>"
AC_SUBST(inttypes_h_decl)
AC_CHECK_HEADER(inttypes.h, [
	db_includes="$db_includes
#include <inttypes.h>"
	inttypes_h_decl="#include <inttypes.h>"])

# IRIX has stdint.h that is only available when using c99 (i.e. __c99
# is defined). Problem with having it in a public header is that a c++
# compiler cannot #include <db.h> if db.h #includes stdint.h, so we
# need to check that stdint.h is available for all cases.  Also the
# IRIX compiler does not exit with a non-zero exit code when it sees
# #error, so we actually need to use the header for the compiler to fail.
AC_SUBST(stdint_h_decl)
AC_MSG_CHECKING(for stdint.h)
AC_COMPILE_IFELSE([AC_LANG_SOURCE([
#include <stdint.h>
  int main() {
  uint_least8_t x=0;
  return x;
  }])],[AC_MSG_RESULT(yes)
if test "$db_cv_cxx" = "yes"; then
  AC_MSG_CHECKING([if stdint.h can be used by C++])
  AC_LANG_PUSH(C++)
  AC_COMPILE_IFELSE([AC_LANG_SOURCE([#include <stdint.h>
    int main() {
    uint_least8_t x=0;
    return x;
  }])],[AC_MSG_RESULT(yes)
    stdint_h_decl="#include <stdint.h>"
    db_includes="$db_includes
#include <stdint.h>"
],[AC_MSG_RESULT(no)
    stdint_h_decl="#ifndef __cplusplus
#include <stdint.h>
#endif"
	db_includes="$db_includes
#ifndef __cplusplus
#include <stdint.h>
#endif"
])
    AC_LANG_POP
else
    stdint_h_decl="#include <stdint.h>"
    db_includes="$db_includes
#include <stdint.h>"
fi],[AC_MSG_RESULT(no)])

AC_SUBST(stddef_h_decl)
AC_CHECK_HEADER(stddef.h, [
	db_includes="$db_includes
#include <stddef.h>"
	stddef_h_decl="#include <stddef.h>"])
AC_SUBST(unistd_h_decl)
AC_CHECK_HEADER(unistd.h, [
	db_includes="$db_includes
#include <unistd.h>"
	unistd_h_decl="#include <unistd.h>"])
db_includes="$db_includes
#include <stdio.h>"

# We need to know the sizes of various objects on this system.
AC_CHECK_SIZEOF(char,, $db_includes)
AC_CHECK_SIZEOF(unsigned char,, $db_includes)
AC_CHECK_SIZEOF(short,, $db_includes)
AC_CHECK_SIZEOF(unsigned short,, $db_includes)
AC_CHECK_SIZEOF(int,, $db_includes)
AC_CHECK_SIZEOF(unsigned int,, $db_includes)
AC_CHECK_SIZEOF(long,, $db_includes)
AC_CHECK_SIZEOF(unsigned long,, $db_includes)
AC_CHECK_SIZEOF(long long,, $db_includes)
AC_CHECK_SIZEOF(unsigned long long,, $db_includes)
AC_CHECK_SIZEOF(char *,, $db_includes)

# We look for u_char, u_short, u_int, u_long -- if we can't find them,
# we create our own.
AC_SUBST(u_char_decl)
AC_CHECK_TYPE(u_char,,
    [u_char_decl="typedef unsigned char u_char;"], $db_includes)

AC_SUBST(u_short_decl)
AC_CHECK_TYPE(u_short,,
    [u_short_decl="typedef unsigned short u_short;"], $db_includes)

AC_SUBST(u_int_decl)
AC_CHECK_TYPE(u_int,,
    [u_int_decl="typedef unsigned int u_int;"], $db_includes)

AC_SUBST(u_long_decl)
AC_CHECK_TYPE(u_long,,
    [u_long_decl="typedef unsigned long u_long;"], $db_includes)

# We look for fixed-size variants of u_char, u_short, u_int, u_long as well.
AC_SUBST(u_int8_decl)
AC_CHECK_TYPE(u_int8_t,,
    [AM_SEARCH_USIZES(u_int8_decl, u_int8_t, 1)], $db_includes)

AC_SUBST(u_int16_decl)
AC_CHECK_TYPE(u_int16_t,,
    [AM_SEARCH_USIZES(u_int16_decl, u_int16_t, 2)], $db_includes)

AC_SUBST(int16_decl)
AC_CHECK_TYPE(int16_t,,
    [AM_SEARCH_SSIZES(int16_decl, int16_t, 2)], $db_includes)

AC_SUBST(u_int32_decl)
AC_CHECK_TYPE(u_int32_t,,
    [AM_SEARCH_USIZES(u_int32_decl, u_int32_t, 4)], $db_includes)

AC_SUBST(int32_decl)
AC_CHECK_TYPE(int32_t,,
    [AM_SEARCH_SSIZES(int32_decl, int32_t, 4)], $db_includes)

AC_SUBST(u_int64_decl)
AC_CHECK_TYPE(u_int64_t,,
    [AM_SEARCH_USIZES(u_int64_decl, u_int64_t, 8, notfatal)], $db_includes)

AC_SUBST(int64_decl)
AC_CHECK_TYPE(int64_t,,
    [AM_SEARCH_SSIZES(int64_decl, int64_t, 8, notfatal)], $db_includes)

# No currently autoconf'd systems lack FILE, off_t pid_t, size_t, time_t.
#
# We require them, we don't try to substitute our own if we can't find them.
AC_SUBST(FILE_t_decl)
AC_CHECK_TYPE(FILE *,, AC_MSG_ERROR([No FILE type.]), $db_includes)
AC_SUBST(off_t_decl)
AC_CHECK_TYPE(off_t,, AC_MSG_ERROR([No off_t type.]), $db_includes)
AC_CHECK_SIZEOF(off_t,, $db_includes)

# db_off_t should be set to a signed integer type that is the same
# size as off_t
AC_SUBST(db_off_t_decl)
AC_CHECK_TYPE(db_off_t,,
    [AM_SEARCH_SSIZES(db_off_t_decl, db_off_t, $ac_cv_sizeof_off_t)])
AC_SUBST(pid_t_decl)
AC_CHECK_TYPE(pid_t,, AC_MSG_ERROR([No pid_t type.]), $db_includes)
AC_SUBST(size_t_decl)
AC_CHECK_TYPE(size_t,, AC_MSG_ERROR([No size_t type.]), $db_includes)
AC_SUBST(time_t_decl)
AC_CHECK_TYPE(time_t,, AC_MSG_ERROR([No time_t type.]), $db_includes)

# Check for ssize_t -- if none exists, find a signed integral type that's
# the same size as a size_t.
AC_CHECK_SIZEOF(size_t,, $db_includes)
AC_SUBST(ssize_t_decl)
AC_CHECK_TYPE(ssize_t,,
    [AM_SEARCH_SSIZES(ssize_t_decl, ssize_t, $ac_cv_sizeof_size_t)],
    $db_includes)

# Check for uintmax_t -- if none exists, find the largest unsigned integral
# type available.
AC_SUBST(uintmax_t_decl)
AC_CHECK_TYPE(uintmax_t,, [AC_CHECK_TYPE(unsigned long long,
    [uintmax_t_decl="typedef unsigned long long uintmax_t;"],
    [uintmax_t_decl="typedef unsigned long uintmax_t;"], $db_includes)])

# Check for uintptr_t -- if none exists, find an integral type which is
# the same size as a pointer.
AC_SUBST(uintptr_t_decl)
AC_CHECK_TYPE(uintptr_t,,
    [AM_SEARCH_USIZES(uintptr_t_decl, uintptr_t, $ac_cv_sizeof_char_p)])

AM_SOCKLEN_T
])