-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwscript
101 lines (90 loc) · 3.05 KB
/
wscript
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
# -*- python -*-
import os
APPNAME = 'mapred'
VERSION = '0.1'
top = '.'
out = 'build'
def configure(conf):
conf.load('compiler_c')
conf.load('compiler_cxx')
def options(opt):
opt.load('compiler_c')
opt.load('compiler_cxx')
opt.add_option('--mode', action='store', default='release', help='Compile mode: release or debug')
opt.add_option('--san', action='store', default=None, help='Enable specific sanitizer')
opt.add_option('--gprof', action='store_true', default=False, help='Compile with gprof support')
opt.add_option('--lto', action='store_true', default=False, help='Enable LTO')
def build(bld):
cflags = {
'cflags' : ['-O2', '-Wall', '-Wextra', '-Werror', '-std=gnu11', '-D_GNU_SOURCE'],
'ldflags' : []
}
cxxflags = {
'cxxflags' : ['-O2', '-Wall', '-Wextra', '-Werror', '-std=gnu++14'],
'ldflags' : []
}
def add_cflag(flag):
if not isinstance(flag, list): flag = [flag]
cflags['cflags'] += flag
cxxflags['cxxflags'] += flag
def add_ldflag(flag):
if not isinstance(flag, list): flag = [flag]
cflags['ldflags'] += flag
cxxflags['ldflags'] += flag
def add_flag(flag):
add_cflag(flag)
add_ldflag(flag)
if bld.options.mode == 'debug' \
or bld.options.san \
or bld.options.gprof:
add_cflag(['-g', '-O0'])
if bld.options.san:
add_flag('-fsanitize=%s' % bld.options.san)
if 'thread' in bld.options.san:
add_cflag('-DTSAN')
if bld.options.gprof:
add_flag('-pg')
if bld.options.lto:
add_flag('-flto')
source = bld.path.ant_glob('src/*.c', excl=['**/%s_*.c' % x for x in ['test', 'bench']]+['**/main.c'])
features = {
'source' : source,
'target' : 'sh-mapred',
}
features.update(cflags)
bld.shlib(**features)
features = {
'source' : source,
'target' : 'st-mapred',
}
features.update(cflags)
bld.stlib(**features)
for test in bld.path.ant_glob('src/test_*.c'):
features = {
'source' : [test],
'target' : os.path.splitext(str(test))[0],
'use' : 'st-mapred',
'lib' : ['cunit', 'pthread'],
}
features.update(cflags)
bld.program(**features)
for bench in bld.path.ant_glob('src/bench_*.cc'):
features = {
'source' : [bench],
'target' : os.path.splitext(str(bench))[0],
'use' : 'st-mapred',
'stlib' : ['hayai_main'],
'lib' : ['pthread'],
}
if bld.options.san:
features['lib'] += ['ubsan', 'asan', 'tsan']
features.update(cxxflags)
bld.program(**features)
features = {
'source' : ['src/main.c'],
'target' : 'mapred',
'use' : 'st-mapred',
'lib' : ['pthread'],
}
features.update(cflags)
bld.program(**features)