summaryrefslogtreecommitdiff
path: root/lib/ccan/libccan.m4
blob: 3b71d7b02343e28f99007ec65fb360ba1155b220 (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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
dnl find the ccan sources.
ccandir="../lib/ccan"
for d in $ccanpaths; do
	if test -f "$srcdir/$d/str/str.c"; then
		ccandir="$d"
		AC_SUBST(ccandir)
		break
	fi
done
if test -f "$ccandir/str/str.c"; then :; else
   AC_MSG_ERROR([cannot find ccan source in $ccandir])
fi
CCAN_OBJ="$ccandir/hash/hash.o $ccandir/htable/htable.o $ccandir/ilog/ilog.o $ccandir/likely/likely.o $ccandir/str/debug.o $ccandir/str/str.o $ccandir/tally/tally.o"

AC_SUBST(CCAN_OBJ)

# Preferred method for including ccan modules is #include <ccan/module/...>.
CCAN_CFLAGS="-I$ccandir/.."
AC_SUBST(CCAN_CFLAGS)

# All the configuration checks.  Regrettably, the __attribute__ checks will
# give false positives on old GCCs, since they just cause warnings.  But that's
# fairly harmless.
AC_CACHE_CHECK([whether we can compile with __attribute__((cold))],
	       samba_cv_attribute_cold,
	       [
	         AC_COMPILE_IFELSE([AC_LANG_SOURCE(
			[
				static void __attribute__((cold))
				cleanup(void) { }
			])],
			samba_cv_attribute_cold=yes)
		])

if test x"$samba_cv_attribute_cold" = xyes ; then
   AC_DEFINE(HAVE_ATTRIBUTE_COLD, 1,
	     [whether we can compile with __attribute__((cold))])
fi

AC_CACHE_CHECK([whether we can compile with __attribute__((const))],
	       samba_cv_attribute_const,
	       [
	         AC_COMPILE_IFELSE([AC_LANG_SOURCE(
			[
				static void __attribute__((const))
				cleanup(void) { }
			])],
			samba_cv_attribute_const=yes)
		])

if test x"$samba_cv_attribute_const" = xyes ; then
   AC_DEFINE(HAVE_ATTRIBUTE_CONST, 1,
	     [whether we can compile with __attribute__((const))])
fi

AC_CACHE_CHECK([whether we can compile with __attribute__((noreturn))],
	       samba_cv_attribute_noreturn,
	       [
	         AC_COMPILE_IFELSE([AC_LANG_SOURCE(
			[
				static void __attribute__((noreturn))
				cleanup(void) { exit(1); }
			])],
			samba_cv_attribute_noreturn=yes)
		])

if test x"$samba_cv_attribute_noreturn" = xyes ; then
   AC_DEFINE(HAVE_ATTRIBUTE_NORETURN, 1,
	     [whether we can compile with __attribute__((noreturn))])
fi

AC_CACHE_CHECK([whether we can compile with __attribute__((printf))],
	       samba_cv_attribute_printf,
	       [
	         AC_COMPILE_IFELSE([AC_LANG_SOURCE(
			[
				static void __attribute__((format(__printf__, 1, 2)))
				cleanup(const char *fmt, ...) { }
			])],
			samba_cv_attribute_printf=yes)
		])

if test x"$samba_cv_attribute_printf" = xyes ; then
   AC_DEFINE(HAVE_ATTRIBUTE_PRINTF, 1,
	     [whether we can compile with __attribute__((format(printf)))])
fi

AC_CACHE_CHECK([whether we can compile with __attribute__((unused))],
	       samba_cv_attribute_unused,
	       [
	         AC_COMPILE_IFELSE([AC_LANG_SOURCE(
			[
				static void __attribute__((unused))
				cleanup(void) { }
			])],
			samba_cv_attribute_unused=yes)
		])

if test x"$samba_cv_attribute_unused" = xyes ; then
   AC_DEFINE(HAVE_ATTRIBUTE_UNUSED, 1,
	     [whether we can compile with __attribute__((unused))])
fi

AC_CACHE_CHECK([whether we can compile with __attribute__((used))],
	       samba_cv_attribute_used,
	       [
	         AC_COMPILE_IFELSE([AC_LANG_SOURCE(
			[
				static void __attribute__((used))
				cleanup(void) { }
			])],
			samba_cv_attribute_used=yes)
		])

if test x"$samba_cv_attribute_used" = xyes ; then
   AC_DEFINE(HAVE_ATTRIBUTE_USED, 1,
	     [whether we can compile with __attribute__((used))])
fi

# FIXME: We could use endian.h or sys/endian.h here, and __BYTE_ORDER for
# cross-compiling.
AC_CACHE_CHECK([whether we are big endian],samba_cv_big_endian,[
AC_TRY_RUN([int main(void) {
union { int i; char c[sizeof(int)]; } u;
	  u.i = 0x01020304;
	  return u.c[0] == 0x01 && u.c[1] == 0x02 && u.c[2] == 0x03 && u.c[3] == 0x04 ? 0 : 1;
}],
samba_cv_big_endian=yes,
samba_cv_big_endian=no)])
if test x"$samba_cv_big_endian" = xyes ; then
   AC_DEFINE(HAVE_BIG_ENDIAN, 1,
	     [whether we are big endian])
fi

AC_CACHE_CHECK([whether we have __builtin_clz],
	       samba_cv_builtin_clz,
	       [
	         AC_LINK_IFELSE([AC_LANG_SOURCE(
			[int main(void) {
				return __builtin_clz(1) == (sizeof(int)*8 - 1) ? 0 : 1;
			}])],
			samba_cv_builtin_clz=yes)
		])

if test x"$samba_cv_builtin_clz" = xyes ; then
   AC_DEFINE(HAVE_BUILTIN_CLZ, 1,
	     [whether we have __builtin_clz])
fi

AC_CACHE_CHECK([whether we have __builtin_clzl],
	       samba_cv_builtin_clzl,
	       [
	         AC_LINK_IFELSE([AC_LANG_SOURCE(
			[int main(void) {
				return __builtin_clzl(1) == (sizeof(int)*8 - 1) ? 0 : 1;
			}])],
			samba_cv_builtin_clzl=yes)
		])

if test x"$samba_cv_builtin_clzl" = xyes ; then
   AC_DEFINE(HAVE_BUILTIN_CLZL, 1,
	     [whether we have __builtin_clzl])
fi
AC_CACHE_CHECK([whether we have __builtin_clzll],
	       samba_cv_builtin_clzll,
	       [
	         AC_LINK_IFELSE([AC_LANG_SOURCE(
			[int main(void) {
				return __builtin_clzll(1) == (sizeof(int)*8 - 1) ? 0 : 1;
			}])],
			samba_cv_builtin_clzll=yes)
		])

if test x"$samba_cv_builtin_clzll" = xyes ; then
   AC_DEFINE(HAVE_BUILTIN_CLZLL, 1,
	     [whether we have __builtin_clzll])
fi

AC_CACHE_CHECK([whether we have __builtin_constant_p],
	       samba_cv_builtin_constant_p,
	       [
	         AC_LINK_IFELSE([AC_LANG_SOURCE(
			[int main(void) {
				return __builtin_constant_p(1) ? 0 : 1;
			}])],
			samba_cv_builtin_constant_p=yes)
		])

if test x"$samba_cv_builtin_constant_p" = xyes ; then
   AC_DEFINE(HAVE_BUILTIN_CONSTANT_P, 1,
	     [whether we have __builtin_constant_p])
fi

AC_CACHE_CHECK([whether we have __builtin_expect],
	       samba_cv_builtin_expect,
	       [
	         AC_LINK_IFELSE([AC_LANG_SOURCE(
			[int main(void) {
				return __builtin_expect(main != 0, 1) ? 0 : 1;
			}])],
			samba_cv_builtin_expect=yes)
		])

if test x"$samba_cv_builtin_expect" = xyes ; then
   AC_DEFINE(HAVE_BUILTIN_EXPECT, 1,
	     [whether we have __builtin_expect])
fi

AC_CACHE_CHECK([whether we have __builtin_popcountl],
	       samba_cv_builtin_popcountl,
	       [
	         AC_LINK_IFELSE([AC_LANG_SOURCE(
			[int main(void) {
				return __builtin_popcountl(255L) == 8 ? 0 : 1;
			}])],
			samba_cv_builtin_popcountl=yes)
		])

if test x"$samba_cv_builtin_popcountl" = xyes ; then
   AC_DEFINE(HAVE_BUILTIN_POPCOUNTL, 1,
	     [whether we have __builtin_popcountl])
fi

AC_CACHE_CHECK([whether we have __builtin_types_compatible_p],
	       samba_cv_builtin_types_compatible_p,
	       [
	         AC_LINK_IFELSE([AC_LANG_SOURCE(
			[int main(void) {
				return __builtin_types_compatible_p(char *, int) ? 1 : 0;
			}])],
			samba_cv_builtin_types_compatible_p=yes)
		])

if test x"$samba_cv_builtin_types_compatible_p" = xyes ; then
   AC_DEFINE(HAVE_BUILTIN_TYPES_COMPATIBLE_P, 1,
	     [whether we have __builtin_types_compatible_p])
fi

AC_CACHE_CHECK([whether we have __builtin_choose_expr],
	       samba_cv_builtin_choose_expr,
	       [
	         AC_LINK_IFELSE([AC_LANG_SOURCE(
			[int main(void) {
				return __builtin_choose_expr(1, 0, "garbage");
			}])],
			samba_cv_builtin_choose_expr=yes)
		])

if test x"$samba_cv_builtin_choose_expr" = xyes ; then
   AC_DEFINE(HAVE_BUILTIN_CHOOSE_EXPR, 1,
	     [whether we have __builtin_choose_expr])
fi

# We use @<:@ and @:>@ here for embedded [ and ].
AC_CACHE_CHECK([whether we have compound literals],
	       samba_cv_compound_literals,
	       [
	         AC_COMPILE_IFELSE([AC_LANG_SOURCE(
			[int main(void) {
				int *foo = (int@<:@@:>@) { 1, 2, 3, 4 };
				return foo@<:@0@:>@ == 1 ? 0 : 1;
			}])],
			samba_cv_compound_literals=yes)
		])

if test x"$samba_cv_compound_literals" = xyes ; then
   AC_DEFINE(HAVE_COMPOUND_LITERALS, 1,
	     [whether we have compound literals])
fi

AC_CACHE_CHECK([whether we have isblank],
	       samba_cv_have_isblank,
	       [
	         AC_LINK_IFELSE([AC_LANG_SOURCE(
			[#include <ctype.h>
			 int main(void) { return isblank(' ') ? 0 : 1; }
			])],
			samba_cv_have_isblank=yes)
		])

if test x"$samba_cv_have_isblank" = xyes ; then
   AC_DEFINE(HAVE_ISBLANK, 1,
	     [whether we have isblank])
fi

# FIXME: We could use endian.h or sys/endian.h here, and __BYTE_ORDER for
# cross-compiling.
AC_CACHE_CHECK([whether we are little endian],samba_cv_little_endian,[
AC_TRY_RUN([int main(void) {
union { int i; char c[sizeof(int)]; } u;
	  u.i = 0x01020304;
	  return u.c[0] == 0x04 && u.c[1] == 0x03 && u.c[2] == 0x02 && u.c[3] == 0x01 ? 0 : 1;
}],
samba_cv_little_endian=yes,
samba_cv_little_endian=no)])
if test x"$samba_cv_little_endian" = xyes ; then
   AC_DEFINE(HAVE_LITTLE_ENDIAN, 1,
	     [whether we are little endian])
fi

AC_CACHE_CHECK([whether we have __typeof__],
	       samba_cv_typeof,
	       [
	         AC_COMPILE_IFELSE([AC_LANG_SOURCE(
			[int main(void) {
				int x = 1;
				__typeof__(x) i;
				i = x;
				return i == x ? 0 : 1;
			}])],
			samba_cv_typeof=yes)
		])

if test x"$samba_cv_typeof" = xyes ; then
   AC_DEFINE(HAVE_TYPEOF, 1,
	     [whether we have __typeof__])
fi

AC_CACHE_CHECK([whether we have __attribute__((warn_unused_result))],
	       samba_cv_warn_unused_result,
	       [
	         AC_COMPILE_IFELSE([AC_LANG_SOURCE(
			[int __attribute__((warn_unused_result)) func(int x)
			    { return x; }])],
			samba_cv_warn_unused_result=yes)
		])

if test x"$samba_cv_warn_unused_result" = xyes ; then
   AC_DEFINE(HAVE_WARN_UNUSED_RESULT, 1,
	     [whether we have __attribute__((warn_unused_result))])
fi