6 # FIXME: if they don't have -Werror, these will all fail. But they
7 # probably will anyway...
8 conf
.CHECK_CODE('int __attribute__((cold)) func(int x) { return x; }',
9 addmain
=False, link
=False, cflags
="-Werror",
10 define
='HAVE_ATTRIBUTE_COLD')
11 conf
.CHECK_CODE('int __attribute__((const)) func(int x) { return x; }',
12 addmain
=False, link
=False, cflags
="-Werror",
13 define
='HAVE_ATTRIBUTE_CONST')
14 conf
.CHECK_CODE('void __attribute__((noreturn)) func(int x) { exit(x); }',
15 addmain
=False, link
=False, cflags
="-Werror",
16 define
='HAVE_ATTRIBUTE_NORETURN')
17 conf
.CHECK_CODE('void __attribute__((format(__printf__, 1, 2))) func(const char *fmt, ...) { }',
18 addmain
=False, link
=False, cflags
="-Werror",
19 define
='HAVE_ATTRIBUTE_PRINTF')
20 conf
.CHECK_CODE('int __attribute__((unused)) func(int x) { return x; }',
21 addmain
=False, link
=False, cflags
="-Werror",
22 define
='HAVE_ATTRIBUTE_UNUSED')
23 conf
.CHECK_CODE('int __attribute__((used)) func(int x) { return x; }',
24 addmain
=False, link
=False, cflags
="-Werror",
25 define
='HAVE_ATTRIBUTE_USED')
26 # We try to use headers for a compile-time test.
27 conf
.CHECK_CODE(code
= """#ifdef __BYTE_ORDER
28 #define B __BYTE_ORDER
29 #elif defined(BYTE_ORDER)
33 #ifdef __LITTLE_ENDIAN
34 #define LITTLE __LITTLE_ENDIAN
35 #elif defined(LITTLE_ENDIAN)
36 #define LITTLE LITTLE_ENDIAN
39 #if !defined(LITTLE) || !defined(B) || LITTLE != B
40 #error Not little endian.
42 headers
="endian.h sys/endian.h",
43 define
="HAVE_LITTLE_ENDIAN")
44 conf
.CHECK_CODE(code
= """#ifdef __BYTE_ORDER
45 #define B __BYTE_ORDER
46 #elif defined(BYTE_ORDER)
51 #define BIG __BIG_ENDIAN
52 #elif defined(BIG_ENDIAN)
53 #define BIG BIG_ENDIAN
56 #if !defined(BIG) || !defined(B) || BIG != B
57 #error Not big endian.
59 headers
="endian.h sys/endian.h",
60 define
="HAVE_BIG_ENDIAN")
62 if not conf
.CONFIG_SET("HAVE_BIG_ENDIAN") and not conf
.CONFIG_SET("HAVE_LITTLE_ENDIAN"):
63 # That didn't work! Do runtime test.
64 conf
.CHECK_CODE("""union { int i; char c[sizeof(int)]; } u;
66 return u.c[0] == 0x04 && u.c[1] == 0x03 && u.c[2] == 0x02 && u.c[3] == 0x01 ? 0 : 1;""",
67 addmain
=True, execute
=True,
68 define
='HAVE_LITTLE_ENDIAN',
69 msg
="Checking for HAVE_LITTLE_ENDIAN - runtime")
70 conf
.CHECK_CODE("""union { int i; char c[sizeof(int)]; } u;
72 return u.c[0] == 0x01 && u.c[1] == 0x02 && u.c[2] == 0x03 && u.c[3] == 0x04 ? 0 : 1;""",
73 addmain
=True, execute
=True,
74 define
='HAVE_BIG_ENDIAN',
75 msg
="Checking for HAVE_BIG_ENDIAN - runtime")
78 if conf
.CONFIG_SET("HAVE_BIG_ENDIAN") == conf
.CONFIG_SET("HAVE_LITTLE_ENDIAN"):
79 Logs
.error("Failed endian determination. The PDP-11 is back?")
82 conf
.CHECK_CODE('return __builtin_clz(1) == (sizeof(int)*8 - 1) ? 0 : 1;',
84 define
='HAVE_BUILTIN_CLZ')
85 conf
.CHECK_CODE('return __builtin_clzl(1) == (sizeof(long)*8 - 1) ? 0 : 1;',
87 define
='HAVE_BUILTIN_CLZL')
88 conf
.CHECK_CODE('return __builtin_clzll(1) == (sizeof(long long)*8 - 1) ? 0 : 1;',
90 define
='HAVE_BUILTIN_CLZLL')
91 conf
.CHECK_CODE('return __builtin_constant_p(1) ? 0 : 1;',
93 define
='HAVE_BUILTIN_CONSTANT_P')
94 conf
.CHECK_CODE('return __builtin_expect(main != 0, 1) ? 0 : 1;',
96 define
='HAVE_BUILTIN_EXPECT')
97 conf
.CHECK_CODE('return __builtin_popcountl(255L) == 8 ? 0 : 1;',
99 define
='HAVE_BUILTIN_POPCOUNTL')
100 conf
.CHECK_CODE('return __builtin_types_compatible_p(char *, int) ? 1 : 0;',
102 define
='HAVE_BUILTIN_TYPES_COMPATIBLE_P')
103 conf
.CHECK_CODE('int *foo = (int[]) { 1, 2, 3, 4 }; return foo[0] ? 0 : 1;',
104 define
='HAVE_COMPOUND_LITERALS')
105 conf
.CHECK_CODE("""#include <ctype.h>
106 int main(void) { return isblank(' ') ? 0 : 1; }""",
107 link
=True, addmain
=False, add_headers
=False,
108 define
='HAVE_ISBLANK')
109 conf
.CHECK_CODE('int x = 1; __typeof__(x) i; i = x; return i == x ? 0 : 1;',
111 define
='HAVE_TYPEOF')
112 conf
.CHECK_CODE('int __attribute__((warn_unused_result)) func(int x) { return x; }',
113 addmain
=False, link
=False, cflags
="-Werror",
114 define
='HAVE_WARN_UNUSED_RESULT')
117 bld
.SAMBA_LIBRARY('ccan',
118 vnum
="0.1-init-1161-g661d41f",
119 source
=bld
.path
.ant_glob('*/*.c'),
120 private_library
=True)