selftest: Remove samba3.smb2.lock.*.rw-exclusive from flapping file
[Samba.git] / lib / ccan / wscript
blob59b82059c90dcdc721d6098b4d2bd59a4a34487e
1 #!/usr/bin/env python
3 import Logs, sys, Options
5 def configure(conf):
6 conf.DEFINE('HAVE_CCAN', 1)
7 conf.CHECK_HEADERS('err.h')
8 conf.CHECK_HEADERS('byteswap.h')
9 conf.CHECK_FUNCS('bswap_64', link=False, headers="byteswap.h")
10 conf.CHECK_CODE('int __attribute__((cold)) func(int x) { return x; }',
11 addmain=False, link=False, cflags=conf.env['WERROR_CFLAGS'],
12 define='HAVE_ATTRIBUTE_COLD')
13 conf.CHECK_CODE('int __attribute__((const)) func(int x) { return x; }',
14 addmain=False, link=False, cflags=conf.env['WERROR_CFLAGS'],
15 define='HAVE_ATTRIBUTE_CONST')
16 conf.CHECK_CODE('void __attribute__((noreturn)) func(int x) { exit(x); }',
17 addmain=False, link=False, cflags=conf.env['WERROR_CFLAGS'],
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=conf.env['WERROR_CFLAGS'],
21 define='HAVE_ATTRIBUTE_PRINTF')
22 conf.CHECK_CODE('int __attribute__((unused)) func(int x) { return x; }',
23 addmain=False, link=False, cflags=conf.env['WERROR_CFLAGS'],
24 define='HAVE_ATTRIBUTE_UNUSED')
25 conf.CHECK_CODE('int __attribute__((used)) func(int x) { return x; }',
26 addmain=False, link=False, cflags=conf.env['WERROR_CFLAGS'],
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)
32 #define B BYTE_ORDER
33 #endif
35 #ifdef __LITTLE_ENDIAN
36 #define LITTLE __LITTLE_ENDIAN
37 #elif defined(LITTLE_ENDIAN)
38 #define LITTLE LITTLE_ENDIAN
39 #endif
41 #if !defined(LITTLE) || !defined(B) || LITTLE != B
42 #error Not little endian.
43 #endif""",
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)
49 #define B BYTE_ORDER
50 #endif
52 #ifdef __BIG_ENDIAN
53 #define BIG __BIG_ENDIAN
54 #elif defined(BIG_ENDIAN)
55 #define BIG BIG_ENDIAN
56 #endif
58 #if !defined(BIG) || !defined(B) || BIG != B
59 #error Not big endian.
60 #endif""",
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;
67 u.i = 0x01020304;
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;
73 u.i = 0x01020304;
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")
79 # Extra sanity check.
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?")
82 sys.exit(1)
84 conf.CHECK_CODE('return __builtin_choose_expr(1, 0, "garbage");',
85 link=True,
86 define='HAVE_BUILTIN_CHOOSE_EXPR')
87 conf.CHECK_CODE('return __builtin_clz(1) == (sizeof(int)*8 - 1) ? 0 : 1;',
88 link=True,
89 define='HAVE_BUILTIN_CLZ')
90 conf.CHECK_CODE('return __builtin_clzl(1) == (sizeof(long)*8 - 1) ? 0 : 1;',
91 link=True,
92 define='HAVE_BUILTIN_CLZL')
93 conf.CHECK_CODE('return __builtin_clzll(1) == (sizeof(long long)*8 - 1) ? 0 : 1;',
94 link=True,
95 define='HAVE_BUILTIN_CLZLL')
96 conf.CHECK_CODE('return __builtin_constant_p(1) ? 0 : 1;',
97 link=True,
98 define='HAVE_BUILTIN_CONSTANT_P')
99 conf.CHECK_CODE('return __builtin_expect(main != 0, 1) ? 0 : 1;',
100 link=True,
101 define='HAVE_BUILTIN_EXPECT')
102 conf.CHECK_CODE('return __builtin_popcountl(255L) == 8 ? 0 : 1;',
103 link=True,
104 define='HAVE_BUILTIN_POPCOUNTL')
105 conf.CHECK_CODE('return __builtin_types_compatible_p(char *, int) ? 1 : 0;',
106 link=True,
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('struct foo { unsigned int x; int arr[]; };',
111 addmain=False, link=False,
112 define='HAVE_FLEXIBLE_ARRAY_MEMBER')
113 conf.CHECK_CODE("""#include <ctype.h>
114 int main(void) { return isblank(' ') ? 0 : 1; }""",
115 link=True, addmain=False, add_headers=False,
116 define='HAVE_ISBLANK')
117 conf.CHECK_CODE('int x = 1; __typeof__(x) i; i = x; return i == x ? 0 : 1;',
118 link=True,
119 define='HAVE_TYPEOF')
120 conf.CHECK_CODE('int __attribute__((warn_unused_result)) func(int x) { return x; }',
121 addmain=False, link=False, cflags=conf.env['WERROR_CFLAGS'],
122 define='HAVE_WARN_UNUSED_RESULT')
124 # backtrace could be in libexecinfo or in libc
125 conf.CHECK_FUNCS_IN('backtrace backtrace_symbols', 'execinfo', checklibc=True, headers='execinfo.h')
127 # Only check for FILE_OFFSET_BITS=64 if off_t is normally small:
128 # use raw routines because wrappers include previous _GNU_SOURCE
129 # or _FILE_OFFSET_BITS defines.
130 conf.check(fragment="""#include <sys/types.h>
131 int main(void) { return !(sizeof(off_t) < 8); }""",
132 execute=True, msg='Checking for small off_t',
133 define_name='SMALL_OFF_T')
134 # Unreliable return value above, hence use define.
135 if conf.CONFIG_SET('SMALL_OFF_T'):
136 conf.check(fragment="""#include <sys/types.h>
137 int main(void) { return !(sizeof(off_t) >= 8); }""",
138 execute=True, msg='Checking for -D_FILE_OFFSET_BITS=64',
139 ccflags='-D_FILE_OFFSET_BITS=64',
140 define_name='HAVE_FILE_OFFSET_BITS')
142 def ccan_module(bld, name, deps=''):
143 bld.SAMBA_SUBSYSTEM('ccan-%s' % name,
144 source=bld.path.ant_glob('%s/*.c' % name),
145 deps=deps)
146 bld.env.CCAN_MODS += 'ccan-%s ' % name
148 def build(bld):
149 bld.env.CCAN_MODS = ""
151 # These have actual C files.
152 ccan_module(bld, 'hash', 'ccan-build_assert')
153 ccan_module(bld, 'ilog', 'ccan-compiler');
154 ccan_module(bld, 'read_write_all')
155 ccan_module(bld, 'str', 'ccan-build_assert')
156 ccan_module(bld, 'tally', 'ccan-build_assert ccan-likely')
158 # These are headers only.
159 ccan_module(bld, 'array_size', 'ccan-build_assert')
160 ccan_module(bld, 'asearch','ccan-typesafe_cb ccan-array_size')
161 ccan_module(bld, 'build_assert')
162 ccan_module(bld, 'cast', 'ccan-build_assert')
163 ccan_module(bld, 'check_type', 'ccan-build_assert')
164 ccan_module(bld, 'compiler')
165 ccan_module(bld, 'endian')
166 ccan_module(bld, 'likely', 'ccan-str')
167 ccan_module(bld, 'typesafe_cb')
168 ccan_module(bld, 'err', 'ccan-compiler')
170 # Failtest pulls in a lot of stuff, and it's only for unit tests.
171 if bld.env.DEVELOPER_MODE:
172 ccan_module(bld, 'container_of', 'ccan-check_type')
173 ccan_module(bld, 'htable', 'ccan-compiler')
174 ccan_module(bld, 'list', 'ccan-container_of')
175 ccan_module(bld, 'time')
176 ccan_module(bld, 'tcon')
177 ccan_module(bld, 'tlist', 'ccan-list ccan-tcon')
178 ccan_module(bld, 'failtest',
180 ccan-err ccan-hash ccan-htable ccan-list
181 ccan-read_write_all ccan-str ccan-time execinfo
182 ''')
184 # This is the complete CCAN collection as one group.
185 bld.SAMBA_LIBRARY('ccan',
186 source='',
187 deps=bld.env.CCAN_MODS,
188 private_library=True,
189 grouping_library=True)