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