wintest: extend get_is_dc function with additional expectations
[Samba/gbeck.git] / lib / ccan / wscript
blobc1dae41611d42ef693d161214275c465b9747e95
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 # 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)
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("""#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;',
115 link=True,
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')
124 def build(bld):
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',
137 source='',
138 deps='ccan-err ccan-hash ccan-ilog ccan-likely ccan-tally',
139 private_library=True)