-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathwscript
248 lines (201 loc) · 7.87 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
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
#! /usr/bin/env python
import subprocess
import os.path
import sys
import platform
build_tools = os.path.join('.', 'tools', 'waf')
sys.path.append(build_tools)
APPNAME = 'stechec2'
VERSION = '2012'
top = '.'
out = 'build'
def options(opt):
opt.load('compiler_cxx')
opt.load('unittest_gtest')
opt.add_option('--enable-debug',
action='store_true',
default=False,
help='build a debug version',
dest='debug')
opt.add_option('--enable-asan',
dest='asan',
action='store_true',
help="Build with Clang's address sanitizer")
opt.add_option('--enable-msan',
dest='msan',
action='store_true',
help="Build with Clang's memory sanitizer")
opt.add_option('--enable-tsan',
dest='tsan',
action='store_true',
help="Build with Clang's thread sanitizer")
opt.add_option('--enable-gcov',
dest='gcov',
action='store_true',
help='Instrument build to compute code coverage')
opt.add_option('--enable-werror',
action='store_true',
default=False,
help='interpret warnings as errors',
dest='werror')
opt.add_option('--games-only',
action='store_true',
default=False,
help='only build and install games',
dest='games_only')
opt.recurse('games')
opt.recurse('tools')
def configure(conf):
if conf.options.asan or conf.options.msan or conf.options.tsan:
conf.find_program('clang++', var='CXX')
conf.load('compiler_cxx')
conf.load('unittest_gtest')
# Warning flags
conf.check_cxx(cxxflags='-Wall')
conf.check_cxx(cxxflags='-Wextra')
conf.env.append_value('CXXFLAGS', ['-Wall', '-Wextra'])
if 'clang' in conf.env.CXX[0]:
conf.env.append_value('CXXFLAGS', ['-Wno-return-type-c-linkage'])
# Check for C++0x
conf.check_cxx(cxxflags='-std=c++17')
conf.env.append_value('CXXFLAGS', '-std=c++17')
# Debug / Release
if conf.options.debug:
conf.check_cxx(cxxflags='-g')
conf.env.append_value('DEFINES', '__DEBUG__')
conf.env.append_value('CXXFLAGS', ['-g'])
else:
conf.check_cxx(cxxflags='-O2')
conf.check_cxx(cxxflags='-ffast-math')
conf.env.append_value('CXXFLAGS', ['-O2', '-ffast-math'])
if conf.options.asan:
conf.check_cxx(cxxflags='-fsanitize=address',
linkflags='-fsanitize=address')
conf.env.append_value('CXXFLAGS', ['-fsanitize=address'])
conf.env.append_value('LINKFLAGS', ['-fsanitize=address'])
if conf.options.msan:
conf.check_cxx(cxxflags='-fsanitize=memory',
linkflags='-fsanitize=memory')
conf.env.append_value('CXXFLAGS', ['-fsanitize=memory'])
conf.env.append_value('LINKFLAGS', ['-fsanitize=memory'])
if conf.options.tsan:
conf.check_cxx(cxxflags='-fsanitize=thread',
linkflags='-fsanitize=thread')
conf.env.append_value('CXXFLAGS', ['-fsanitize=thread'])
conf.env.append_value('LINKFLAGS', ['-fsanitize=thread'])
if conf.options.gcov:
conf.check_cxx(cxxflags='-fprofile-arcs -ftest-coverage',
linkflags='-fprofile-arcs')
conf.env.append_value('CXXFLAGS',
['-fprofile-arcs', '-ftest-coverage'])
conf.env.append_value('LINKFLAGS', ['-fprofile-arcs'])
conf.find_program('gcovr', var='GCOVR')
# ZeroMQ and C++ binding (cppzmq)
conf.check_cfg(package='libzmq',
uselib_store='ZeroMQ',
atleast_version='3.2.0',
args=['--cflags', '--libs'])
conf.check(header_name='zmq.hpp')
# Google Flags
conf.check_cxx(lib="gflags", mandatory=True, uselib_store="gflags")
# -lrt
conf.check_cxx(lib="rt", mandatory=True, uselib_store="rt")
# Werror support - at the end to avoid false negatives in the checks
if conf.options.werror:
conf.check_cxx(cxxflags='-Werror')
conf.env.append_value('CXXFLAGS', '-Werror')
# Games only?
conf.env.GAMES_ONLY = conf.options.games_only
# Configure games
conf.recurse('games')
# Configure tools
conf.recurse('tools')
def build(bld):
build_lib(bld)
bld.recurse('games')
if not bld.env.GAMES_ONLY:
build_client(bld)
build_replay(bld)
build_server(bld)
bld.recurse('tools')
def coverage(ctx):
"""Compute a code coverage report (Gcov)"""
# For some mysterious reason, "ctx" has no "env" attribute, here, so it's
# not possible to get the GCOVR environment variable.
subprocess.check_call(['mkdir', '-p', 'coverage'],
cwd=os.path.join(ctx.path.abspath(), out))
subprocess.check_call([
'gcovr', '-r', '..', '--html', '--html-details',
'--exclude=.*unittest-gtest.*', '-o', 'coverage/gcov-report.html'
],
cwd=os.path.join(ctx.path.abspath(), out))
def build_lib(bld):
bld.shlib(source='''
src/lib/utils/dll.cc
src/lib/utils/log.cc
src/lib/net/socket.cc
src/lib/net/server-socket.cc
src/lib/net/client-socket.cc
src/lib/net/message.cc
src/lib/rules/actions.cc
src/lib/rules/client-messenger.cc
src/lib/rules/replay-messenger.cc
src/lib/rules/server-messenger.cc
src/lib/rules/rules.cc
src/lib/rules/options.cc
''',
defines=['MODULE_COLOR=ANSI_COL_PURPLE', 'MODULE_NAME="lib"'],
includes='src/lib',
target='stechec2',
use=['ZeroMQ', 'rt', 'gflags'],
lib=([] if platform.system() == 'FreeBSD' else ['dl']),
export_includes='src/lib',
install_path=None if bld.env.GAMES_ONLY else '${PREFIX}/lib')
for test in []:
bld.program(features='gtest',
source='src/lib/net/tests/test-%s.cc' % test,
target='utils-test-%s' % test,
use=['stechec2'])
for test in ['buffer', 'sandbox']:
bld.program(features='gtest',
source='src/lib/utils/tests/test-%s.cc' % test,
target='utils-test-%s' % test,
use=['stechec2'])
for test in ['action', 'game-state-history']:
bld.program(features='gtest',
source='src/lib/rules/tests/test-%s.cc' % test,
target='rules-test-%s' % test,
use=['stechec2'])
def build_client(bld):
bld.program(source='''
src/client/main.cc
src/client/client.cc
''',
target='stechec2-client',
defines=[
'MODULE_COLOR=ANSI_COL_YELLOW', 'MODULE_NAME="client"',
'MODULE_VERSION="%s"' % VERSION
],
use=['stechec2', 'gflags'])
def build_server(bld):
bld.program(source='''
src/server/main.cc
src/server/server.cc
''',
target='stechec2-server',
defines=[
'MODULE_COLOR=ANSI_COL_RED', 'MODULE_NAME="server"',
'MODULE_VERSION="%s"' % VERSION
],
use=['stechec2', 'gflags'])
def build_replay(bld):
bld.program(source='''
src/replay/main.cc
src/replay/replay.cc
''',
target='stechec2-replay',
defines=[
'MODULE_COLOR=ANSI_COL_RED', 'MODULE_NAME="replay"',
'MODULE_VERSION="%s"' % VERSION
],
use=['stechec2', 'gflags'])