build: add a build suffix ("4") for s4-binaries
[Samba/gebeck_regimport.git] / lib / ccan / libccan.m4
blob1efa0f0f42fa974c92710aecad1bb3b845756d75
1 dnl find the ccan sources.
2 ccandir="../lib/ccan"
3 for d in $ccanpaths; do
4         if test -f "$srcdir/$d/str/str.c"; then
5                 ccandir="$d"
6                 AC_SUBST(ccandir)
7                 break
8         fi
9 done
10 if test -f "$ccandir/str/str.c"; then :; else
11    AC_MSG_ERROR([cannot find ccan source in $ccandir])
13 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"
15 AC_SUBST(CCAN_OBJ)
17 # Preferred method for including ccan modules is #include <ccan/module/...>.
18 CCAN_CFLAGS="-I$ccandir/.."
19 AC_SUBST(CCAN_CFLAGS)
21 # All the configuration checks.  Regrettably, the __attribute__ checks will
22 # give false positives on old GCCs, since they just cause warnings.  But that's
23 # fairly harmless.
24 AC_CACHE_CHECK([whether we can compile with __attribute__((cold))],
25                samba_cv_attribute_cold,
26                [
27                  AC_COMPILE_IFELSE(
28                         [
29                                 static void __attribute__((cold))
30                                 cleanup(void) { }
31                         ],
32                         samba_cv_attribute_cold=yes)
33                 ])
35 if test x"$samba_cv_attribute_cold" = xyes ; then
36    AC_DEFINE(HAVE_ATTRIBUTE_COLD, 1,
37              [whether we can compile with __attribute__((cold))])
40 AC_CACHE_CHECK([whether we can compile with __attribute__((const))],
41                samba_cv_attribute_const,
42                [
43                  AC_COMPILE_IFELSE(
44                         [
45                                 static void __attribute__((const))
46                                 cleanup(void) { }
47                         ],
48                         samba_cv_attribute_const=yes)
49                 ])
51 if test x"$samba_cv_attribute_const" = xyes ; then
52    AC_DEFINE(HAVE_ATTRIBUTE_CONST, 1,
53              [whether we can compile with __attribute__((const))])
56 AC_CACHE_CHECK([whether we can compile with __attribute__((noreturn))],
57                samba_cv_attribute_noreturn,
58                [
59                  AC_COMPILE_IFELSE(
60                         [
61                                 static void __attribute__((noreturn))
62                                 cleanup(void) { exit(1); }
63                         ],
64                         samba_cv_attribute_noreturn=yes)
65                 ])
67 if test x"$samba_cv_attribute_noreturn" = xyes ; then
68    AC_DEFINE(HAVE_ATTRIBUTE_NORETURN, 1,
69              [whether we can compile with __attribute__((noreturn))])
72 AC_CACHE_CHECK([whether we can compile with __attribute__((printf))],
73                samba_cv_attribute_printf,
74                [
75                  AC_COMPILE_IFELSE(
76                         [
77                                 static void __attribute__((format(__printf__, 1, 2)))
78                                 cleanup(const char *fmt, ...) { }
79                         ],
80                         samba_cv_attribute_printf=yes)
81                 ])
83 if test x"$samba_cv_attribute_printf" = xyes ; then
84    AC_DEFINE(HAVE_ATTRIBUTE_PRINTF, 1,
85              [whether we can compile with __attribute__((format(printf)))])
88 AC_CACHE_CHECK([whether we can compile with __attribute__((unused))],
89                samba_cv_attribute_unused,
90                [
91                  AC_COMPILE_IFELSE(
92                         [
93                                 static void __attribute__((unused))
94                                 cleanup(void) { }
95                         ],
96                         samba_cv_attribute_unused=yes)
97                 ])
99 if test x"$samba_cv_attribute_unused" = xyes ; then
100    AC_DEFINE(HAVE_ATTRIBUTE_UNUSED, 1,
101              [whether we can compile with __attribute__((unused))])
104 AC_CACHE_CHECK([whether we can compile with __attribute__((used))],
105                samba_cv_attribute_used,
106                [
107                  AC_COMPILE_IFELSE(
108                         [
109                                 static void __attribute__((used))
110                                 cleanup(void) { }
111                         ],
112                         samba_cv_attribute_used=yes)
113                 ])
115 if test x"$samba_cv_attribute_used" = xyes ; then
116    AC_DEFINE(HAVE_ATTRIBUTE_USED, 1,
117              [whether we can compile with __attribute__((used))])
120 # FIXME: We could use endian.h or sys/endian.h here, and __BYTE_ORDER for
121 # cross-compiling.
122 AC_CACHE_CHECK([whether we are big endian],samba_cv_big_endian,[
123 AC_TRY_RUN([int main(void) {
124 union { int i; char c[sizeof(int)]; } u;
125           u.i = 0x01020304;
126           return u.c[0] == 0x01 && u.c[1] == 0x02 && u.c[2] == 0x03 && u.c[3] == 0x04 ? 0 : 1;
128 samba_cv_big_endian=yes,
129 samba_cv_big_endian=no)])
130 if test x"$samba_cv_big_endian" = xyes ; then
131    AC_DEFINE(HAVE_BIG_ENDIAN, 1,
132              [whether we are big endian])
135 AC_CACHE_CHECK([whether we have __builtin_clz],
136                samba_cv_builtin_clz,
137                [
138                  AC_LINK_IFELSE(
139                         [int main(void) {
140                                 return __builtin_clz(1) == (sizeof(int)*8 - 1) ? 0 : 1;
141                         }],
142                         samba_cv_builtin_clz=yes)
143                 ])
145 if test x"$samba_cv_builtin_clz" = xyes ; then
146    AC_DEFINE(HAVE_BUILTIN_CLZ, 1,
147              [whether we have __builtin_clz])
150 AC_CACHE_CHECK([whether we have __builtin_clzl],
151                samba_cv_builtin_clzl,
152                [
153                  AC_LINK_IFELSE(
154                         [int main(void) {
155                                 return __builtin_clzl(1) == (sizeof(int)*8 - 1) ? 0 : 1;
156                         }],
157                         samba_cv_builtin_clzl=yes)
158                 ])
160 if test x"$samba_cv_builtin_clzl" = xyes ; then
161    AC_DEFINE(HAVE_BUILTIN_CLZL, 1,
162              [whether we have __builtin_clzl])
164 AC_CACHE_CHECK([whether we have __builtin_clzll],
165                samba_cv_builtin_clzll,
166                [
167                  AC_LINK_IFELSE(
168                         [int main(void) {
169                                 return __builtin_clzll(1) == (sizeof(int)*8 - 1) ? 0 : 1;
170                         }],
171                         samba_cv_builtin_clzll=yes)
172                 ])
174 if test x"$samba_cv_builtin_clzll" = xyes ; then
175    AC_DEFINE(HAVE_BUILTIN_CLZLL, 1,
176              [whether we have __builtin_clzll])
179 AC_CACHE_CHECK([whether we have __builtin_constant_p],
180                samba_cv_builtin_constant_p,
181                [
182                  AC_LINK_IFELSE(
183                         [int main(void) {
184                                 return __builtin_constant_p(1) ? 0 : 1;
185                         }],
186                         samba_cv_builtin_constant_p=yes)
187                 ])
189 if test x"$samba_cv_builtin_constant_p" = xyes ; then
190    AC_DEFINE(HAVE_BUILTIN_CONSTANT_P, 1,
191              [whether we have __builtin_constant_p])
194 AC_CACHE_CHECK([whether we have __builtin_expect],
195                samba_cv_builtin_expect,
196                [
197                  AC_LINK_IFELSE(
198                         [int main(void) {
199                                 return __builtin_expect(main != 0, 1) ? 0 : 1;
200                         }],
201                         samba_cv_builtin_expect=yes)
202                 ])
204 if test x"$samba_cv_builtin_expect" = xyes ; then
205    AC_DEFINE(HAVE_BUILTIN_EXPECT, 1,
206              [whether we have __builtin_expect])
209 AC_CACHE_CHECK([whether we have __builtin_popcountl],
210                samba_cv_builtin_popcountl,
211                [
212                  AC_LINK_IFELSE(
213                         [int main(void) {
214                                 return __builtin_popcountl(255L) == 8 ? 0 : 1;
215                         }],
216                         samba_cv_builtin_popcountl=yes)
217                 ])
219 if test x"$samba_cv_builtin_popcountl" = xyes ; then
220    AC_DEFINE(HAVE_BUILTIN_POPCOUNTL, 1,
221              [whether we have __builtin_popcountl])
224 AC_CACHE_CHECK([whether we have __builtin_types_compatible_p],
225                samba_cv_builtin_types_compatible_p,
226                [
227                  AC_LINK_IFELSE(
228                         [int main(void) {
229                                 return __builtin_types_compatible_p(char *, int) ? 1 : 0;
230                         }],
231                         samba_cv_builtin_types_compatible_p=yes)
232                 ])
234 if test x"$samba_cv_builtin_types_compatible_p" = xyes ; then
235    AC_DEFINE(HAVE_BUILTIN_TYPES_COMPATIBLE_P, 1,
236              [whether we have __builtin_types_compatible_p])
239 AC_CACHE_CHECK([whether we have __builtin_choose_expr],
240                samba_cv_builtin_choose_expr,
241                [
242                  AC_LINK_IFELSE(
243                         [int main(void) {
244                                 return __builtin_choose_expr(1, 0, "garbage");
245                         }],
246                         samba_cv_builtin_choose_expr=yes)
247                 ])
249 if test x"$samba_cv_builtin_choose_expr" = xyes ; then
250    AC_DEFINE(HAVE_BUILTIN_CHOOSE_EXPR, 1,
251              [whether we have __builtin_choose_expr])
254 # We use @<:@ and @:>@ here for embedded [ and ].
255 AC_CACHE_CHECK([whether we have compound literals],
256                samba_cv_compound_literals,
257                [
258                  AC_COMPILE_IFELSE(
259                         [int main(void) {
260                                 int *foo = (int@<:@@:>@) { 1, 2, 3, 4 };
261                                 return foo@<:@0@:>@ == 1 ? 0 : 1;
262                         }],
263                         samba_cv_compound_literals=yes)
264                 ])
266 if test x"$samba_cv_compound_literals" = xyes ; then
267    AC_DEFINE(HAVE_COMPOUND_LITERALS, 1,
268              [whether we have compound literals])
271 AC_CACHE_CHECK([whether we have __builtin_have_isblank],
272                samba_cv_builtin_have_isblank,
273                [
274                  AC_LINK_IFELSE(
275                         [#include <ctype.h>
276                          int main(void) { return isblank(' ') ? 0 : 1; }
277                         ],
278                         samba_cv_builtin_have_isblank=yes)
279                 ])
281 if test x"$samba_cv_builtin_have_isblank" = xyes ; then
282    AC_DEFINE(HAVE_BUILTIN_HAVE_ISBLANK, 1,
283              [whether we have __builtin_have_isblank])
286 # FIXME: We could use endian.h or sys/endian.h here, and __BYTE_ORDER for
287 # cross-compiling.
288 AC_CACHE_CHECK([whether we are little endian],samba_cv_little_endian,[
289 AC_TRY_RUN([int main(void) {
290 union { int i; char c[sizeof(int)]; } u;
291           u.i = 0x01020304;
292           return u.c[0] == 0x04 && u.c[1] == 0x03 && u.c[2] == 0x02 && u.c[3] == 0x01 ? 0 : 1;
294 samba_cv_little_endian=yes,
295 samba_cv_little_endian=no)])
296 if test x"$samba_cv_little_endian" = xyes ; then
297    AC_DEFINE(HAVE_LITTLE_ENDIAN, 1,
298              [whether we are little endian])
301 AC_CACHE_CHECK([whether we have __typeof__],
302                samba_cv_typeof,
303                [
304                  AC_COMPILE_IFELSE(
305                         [int main(void) {
306                                 int x = 1;
307                                 __typeof__(x) i;
308                                 i = x;
309                                 return i == x ? 0 : 1;
310                         }],
311                         samba_cv_typeof=yes)
312                 ])
314 if test x"$samba_cv_typeof" = xyes ; then
315    AC_DEFINE(HAVE_TYPEOF, 1,
316              [whether we have __typeof__])
319 AC_CACHE_CHECK([whether we have __attribute__((warn_unused_result))],
320                samba_cv_warn_unused_result,
321                [
322                  AC_COMPILE_IFELSE(
323                         [int __attribute__((warn_unused_result)) func(int x)
324                             { return x; }],
325                         samba_cv_warn_unused_result=yes)
326                 ])
328 if test x"$samba_cv_warn_unused_result" = xyes ; then
329    AC_DEFINE(HAVE_WARN_UNUSED_RESULT, 1,
330              [whether we have __attribute__((warn_unused_result))])