3 import Logs
, sys
, Options
6 conf
.DEFINE('HAVE_CCAN', 1)
7 conf
.CHECK_HEADERS('err.h')
8 # FIXME: if they don't have -Werror, these will all fail. But they
9 # probably will anyway...
10 conf
.CHECK_CODE('int __attribute__((cold)) func(int x) { return x; }',
11 addmain
=False, link
=False, cflags
="-Werror",
12 define
='HAVE_ATTRIBUTE_COLD')
13 conf
.CHECK_CODE('int __attribute__((const)) func(int x) { return x; }',
14 addmain
=False, link
=False, cflags
="-Werror",
15 define
='HAVE_ATTRIBUTE_CONST')
16 conf
.CHECK_CODE('void __attribute__((noreturn)) func(int x) { exit(x); }',
17 addmain
=False, link
=False, cflags
="-Werror",
18 define
='HAVE_ATTRIBUTE_NORETURN')
19 conf
.CHECK_CODE('void __attribute__((format(__printf__, 1, 2))) func(const char *fmt, ...) { }',
20 addmain
=False, link
=False, cflags
="-Werror",
21 define
='HAVE_ATTRIBUTE_PRINTF')
22 conf
.CHECK_CODE('int __attribute__((unused)) func(int x) { return x; }',
23 addmain
=False, link
=False, cflags
="-Werror",
24 define
='HAVE_ATTRIBUTE_UNUSED')
25 conf
.CHECK_CODE('int __attribute__((used)) func(int x) { return x; }',
26 addmain
=False, link
=False, cflags
="-Werror",
27 define
='HAVE_ATTRIBUTE_USED')
28 # We try to use headers for a compile-time test.
29 conf
.CHECK_CODE(code
= """#ifdef __BYTE_ORDER
30 #define B __BYTE_ORDER
31 #elif defined(BYTE_ORDER)
35 #ifdef __LITTLE_ENDIAN
36 #define LITTLE __LITTLE_ENDIAN
37 #elif defined(LITTLE_ENDIAN)
38 #define LITTLE LITTLE_ENDIAN
41 #if !defined(LITTLE) || !defined(B) || LITTLE != B
42 #error Not little endian.
44 headers
="endian.h sys/endian.h",
45 define
="HAVE_LITTLE_ENDIAN")
46 conf
.CHECK_CODE(code
= """#ifdef __BYTE_ORDER
47 #define B __BYTE_ORDER
48 #elif defined(BYTE_ORDER)
53 #define BIG __BIG_ENDIAN
54 #elif defined(BIG_ENDIAN)
55 #define BIG BIG_ENDIAN
58 #if !defined(BIG) || !defined(B) || BIG != B
59 #error Not big endian.
61 headers
="endian.h sys/endian.h",
62 define
="HAVE_BIG_ENDIAN")
64 if not conf
.CONFIG_SET("HAVE_BIG_ENDIAN") and not conf
.CONFIG_SET("HAVE_LITTLE_ENDIAN"):
65 # That didn't work! Do runtime test.
66 conf
.CHECK_CODE("""union { int i; char c[sizeof(int)]; } u;
68 return u.c[0] == 0x04 && u.c[1] == 0x03 && u.c[2] == 0x02 && u.c[3] == 0x01 ? 0 : 1;""",
69 addmain
=True, execute
=True,
70 define
='HAVE_LITTLE_ENDIAN',
71 msg
="Checking for HAVE_LITTLE_ENDIAN - runtime")
72 conf
.CHECK_CODE("""union { int i; char c[sizeof(int)]; } u;
74 return u.c[0] == 0x01 && u.c[1] == 0x02 && u.c[2] == 0x03 && u.c[3] == 0x04 ? 0 : 1;""",
75 addmain
=True, execute
=True,
76 define
='HAVE_BIG_ENDIAN',
77 msg
="Checking for HAVE_BIG_ENDIAN - runtime")
80 if conf
.CONFIG_SET("HAVE_BIG_ENDIAN") == conf
.CONFIG_SET("HAVE_LITTLE_ENDIAN"):
81 Logs
.error("Failed endian determination. The PDP-11 is back?")
84 conf
.CHECK_CODE('return __builtin_choose_expr(1, 0, "garbage");',
86 define
='HAVE_BUILTIN_CHOOSE_EXPR')
87 conf
.CHECK_CODE('return __builtin_clz(1) == (sizeof(int)*8 - 1) ? 0 : 1;',
89 define
='HAVE_BUILTIN_CLZ')
90 conf
.CHECK_CODE('return __builtin_clzl(1) == (sizeof(long)*8 - 1) ? 0 : 1;',
92 define
='HAVE_BUILTIN_CLZL')
93 conf
.CHECK_CODE('return __builtin_clzll(1) == (sizeof(long long)*8 - 1) ? 0 : 1;',
95 define
='HAVE_BUILTIN_CLZLL')
96 conf
.CHECK_CODE('return __builtin_constant_p(1) ? 0 : 1;',
98 define
='HAVE_BUILTIN_CONSTANT_P')
99 conf
.CHECK_CODE('return __builtin_expect(main != 0, 1) ? 0 : 1;',
101 define
='HAVE_BUILTIN_EXPECT')
102 conf
.CHECK_CODE('return __builtin_popcountl(255L) == 8 ? 0 : 1;',
104 define
='HAVE_BUILTIN_POPCOUNTL')
105 conf
.CHECK_CODE('return __builtin_types_compatible_p(char *, int) ? 1 : 0;',
107 define
='HAVE_BUILTIN_TYPES_COMPATIBLE_P')
108 conf
.CHECK_CODE('int *foo = (int[]) { 1, 2, 3, 4 }; return foo[0] ? 0 : 1;',
109 define
='HAVE_COMPOUND_LITERALS')
110 conf
.CHECK_CODE("""#include <ctype.h>
111 int main(void) { return isblank(' ') ? 0 : 1; }""",
112 link
=True, addmain
=False, add_headers
=False,
113 define
='HAVE_ISBLANK')
114 conf
.CHECK_CODE('int x = 1; __typeof__(x) i; i = x; return i == x ? 0 : 1;',
116 define
='HAVE_TYPEOF')
117 conf
.CHECK_CODE('int __attribute__((warn_unused_result)) func(int x) { return x; }',
118 addmain
=False, link
=False, cflags
="-Werror",
119 define
='HAVE_WARN_UNUSED_RESULT')
121 # backtrace could be in libexecinfo or in libc
122 conf
.CHECK_FUNCS_IN('backtrace backtrace_symbols', 'execinfo', checklibc
=True, headers
='execinfo.h')
126 for ccan_dir
in ["err", "hash", "htable", "ilog", "likely", "list", "read_write_all", "str", "tally", "time"]:
127 bld
.SAMBA_SUBSYSTEM('ccan-%s' % ccan_dir
,
128 source
=bld
.path
.ant_glob('%s/*.c' % ccan_dir
))
130 if bld
.env
.DEVELOPER_MODE
:
131 bld
.SAMBA_LIBRARY('ccan-failtest',
132 source
=bld
.path
.ant_glob('failtest/*.c'),
133 deps
='execinfo ccan ccan-htable ccan-list ccan-read_write_all ccan-time',
134 private_library
=True)
136 bld
.SAMBA_LIBRARY('ccan',
138 deps
='ccan-err ccan-hash ccan-ilog ccan-likely ccan-tally',
139 private_library
=True)