summaryrefslogtreecommitdiffstats
path: root/lib/ccan/wscript
blob: 0e540dbf0887c039e33c435a34fe2e20e59a51d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/usr/bin/env python

import Logs, sys, Options

def configure(conf):
    conf.DEFINE('HAVE_CCAN', 1)
    conf.CHECK_HEADERS('err.h')
    conf.CHECK_HEADERS('byteswap.h')
    conf.CHECK_FUNCS('bswap_64', link=False, headers="byteswap.h")
    conf.CHECK_CODE('int __attribute__((cold)) func(int x) { return x; }',
                    addmain=False, link=False, cflags=conf.env['WERROR_CFLAGS'],
                    define='HAVE_ATTRIBUTE_COLD')
    conf.CHECK_CODE('int __attribute__((const)) func(int x) { return x; }',
                    addmain=False, link=False, cflags=conf.env['WERROR_CFLAGS'],
                    define='HAVE_ATTRIBUTE_CONST')
    conf.CHECK_CODE('void __attribute__((noreturn)) func(int x) { exit(x); }',
                    addmain=False, link=False, cflags=conf.env['WERROR_CFLAGS'],
                    define='HAVE_ATTRIBUTE_NORETURN')
    conf.CHECK_CODE('void __attribute__((format(__printf__, 1, 2))) func(const char *fmt, ...) { }',
                    addmain=False, link=False, cflags=conf.env['WERROR_CFLAGS'],
                    define='HAVE_ATTRIBUTE_PRINTF')
    conf.CHECK_CODE('int __attribute__((unused)) func(int x) { return x; }',
                    addmain=False, link=False, cflags=conf.env['WERROR_CFLAGS'],
                    define='HAVE_ATTRIBUTE_UNUSED')
    conf.CHECK_CODE('int __attribute__((used)) func(int x) { return x; }',
                    addmain=False, link=False, cflags=conf.env['WERROR_CFLAGS'],
                    define='HAVE_ATTRIBUTE_USED')

    conf.CHECK_CODE('return __builtin_choose_expr(1, 0, "garbage");',
                    link=True,
                    define='HAVE_BUILTIN_CHOOSE_EXPR')
    conf.CHECK_CODE('return __builtin_clz(1) == (sizeof(int)*8 - 1) ? 0 : 1;',
                    link=True,
                    define='HAVE_BUILTIN_CLZ')
    conf.CHECK_CODE('return __builtin_clzl(1) == (sizeof(long)*8 - 1) ? 0 : 1;',
                    link=True,
                    define='HAVE_BUILTIN_CLZL')
    conf.CHECK_CODE('return __builtin_clzll(1) == (sizeof(long long)*8 - 1) ? 0 : 1;',
                    link=True,
                    define='HAVE_BUILTIN_CLZLL')
    conf.CHECK_CODE('return __builtin_constant_p(1) ? 0 : 1;',
                    link=True,
                    define='HAVE_BUILTIN_CONSTANT_P')
    conf.CHECK_CODE('return __builtin_expect(main != 0, 1) ? 0 : 1;',
                    link=True,
                    define='HAVE_BUILTIN_EXPECT')
    conf.CHECK_CODE('return __builtin_popcountl(255L) == 8 ? 0 : 1;',
                    link=True,
                    define='HAVE_BUILTIN_POPCOUNTL')
    conf.CHECK_CODE('return __builtin_types_compatible_p(char *, int) ? 1 : 0;',
                    link=True,
                    define='HAVE_BUILTIN_TYPES_COMPATIBLE_P')
    conf.CHECK_CODE('int *foo = (int[]) { 1, 2, 3, 4 }; return foo[0] ? 0 : 1;',
                    define='HAVE_COMPOUND_LITERALS')
    conf.CHECK_CODE('struct foo { unsigned int x; int arr[]; };',
                    addmain=False, link=False,
                    define='HAVE_FLEXIBLE_ARRAY_MEMBER')
    conf.CHECK_CODE("""#include <ctype.h>
	  int main(void) { return isblank(' ') ? 0 : 1; }""",
                    link=True, addmain=False, add_headers=False,
                    define='HAVE_ISBLANK')
    conf.CHECK_CODE('int x = 1; __typeof__(x) i; i = x; return i == x ? 0 : 1;',
                    link=True,
                    define='HAVE_TYPEOF')
    conf.CHECK_CODE('int __attribute__((warn_unused_result)) func(int x) { return x; }',
                    addmain=False, link=False, cflags=conf.env['WERROR_CFLAGS'],
                    define='HAVE_WARN_UNUSED_RESULT')

    # backtrace could be in libexecinfo or in libc
    conf.CHECK_FUNCS_IN('backtrace backtrace_symbols', 'execinfo', checklibc=True, headers='execinfo.h')

    # Only check for FILE_OFFSET_BITS=64 if off_t is normally small:
    # use raw routines because wrappers include previous _GNU_SOURCE
    # or _FILE_OFFSET_BITS defines.
    # The math for these tests is:
    # array[-1 * !((int)(condition)) ] (condition is true) = array[0] = builds
    # array[-1 * !((int)(condition)) ] (condition is false) = array[-1] = fails
    conf.check(fragment="""#include <sys/types.h>
               int main(void) { static int test_array[1 - 2 * !(((long int)(sizeof(off_t))) < 8)]; }""",
               msg='Checking for small off_t',
               define_name='SMALL_OFF_T')
    # Unreliable return value above, hence use define.
    if conf.CONFIG_SET('SMALL_OFF_T'):
        conf.check(fragment="""#include <sys/types.h>
		   int main(void) { static int test_array[1 - 2 * !(((long int)(sizeof(off_t))) >= 8)]; }""",
                   msg='Checking for -D_FILE_OFFSET_BITS=64',
                   ccflags='-D_FILE_OFFSET_BITS=64',
                   define_name='HAVE_FILE_OFFSET_BITS')

def ccan_module(bld, name, deps=''):
    bld.SAMBA_SUBSYSTEM('ccan-%s' % name,
                        source=bld.path.ant_glob('%s/*.c' % name),
                        allow_warnings=True,
                        deps=deps)
    bld.env.CCAN_MODS += 'ccan-%s ' % name

def build(bld):
    bld.env.CCAN_MODS = ""

    # These have actual C files.
    ccan_module(bld, 'hash', 'ccan-build_assert')
    ccan_module(bld, 'ilog', 'ccan-compiler');
    ccan_module(bld, 'read_write_all')
    ccan_module(bld, 'str', 'ccan-build_assert')
    ccan_module(bld, 'tally', 'ccan-build_assert ccan-likely')

    # These are headers only.
    ccan_module(bld, 'array_size', 'ccan-build_assert')
    ccan_module(bld, 'asearch','ccan-typesafe_cb ccan-array_size')
    ccan_module(bld, 'build_assert')
    ccan_module(bld, 'cast', 'ccan-build_assert')
    ccan_module(bld, 'check_type', 'ccan-build_assert')
    ccan_module(bld, 'compiler')
    ccan_module(bld, 'endian')
    ccan_module(bld, 'likely', 'ccan-str')
    ccan_module(bld, 'typesafe_cb')
    ccan_module(bld, 'err', 'ccan-compiler')

    # Failtest pulls in a lot of stuff, and it's only for unit tests.
    if bld.env.DEVELOPER_MODE:
        ccan_module(bld, 'container_of', 'ccan-check_type')
        ccan_module(bld, 'htable', 'ccan-compiler')
        ccan_module(bld, 'list', 'ccan-container_of')
        ccan_module(bld, 'time')
        ccan_module(bld, 'tcon')
        ccan_module(bld, 'tlist', 'ccan-list ccan-tcon')
        ccan_module(bld, 'failtest',
                    '''
                    ccan-err ccan-hash ccan-htable ccan-list
                    ccan-read_write_all ccan-str ccan-time execinfo
                    ''')

    # This is the complete CCAN collection as one group.
    bld.SAMBA_LIBRARY('ccan',
                      source='',
                      deps=bld.env.CCAN_MODS,
                      allow_warnings=True,
                      private_library=True,
                      grouping_library=True)