-
Notifications
You must be signed in to change notification settings - Fork 36
/
wscript
executable file
·295 lines (252 loc) · 8.97 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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
#!/usr/bin/env
'''
wscript - Waf build script for NORM
See https://gitlab.com/ita1024/waf/ for more information.
In order to use different build directories (for example, a release and a debug
build), use the -o (--out) flag when configuring. For example:
./waf configure -o build-debug --debug
./waf
./waf configure -o build-release
./waf
To build examples, use the --target directive. For example:
./waf build --target=normClient,normServer
'''
import platform
import waflib
# Fetch VERSION from include/normVersion.h file
VERSION = None
vfile = open('include/normVersion.h', 'r')
for line in vfile.readlines():
line = line.split()
if len(line) != 3:
continue
if "#define" == line[0] and "VERSION" == line[1]:
VERSION = line[2].strip('"')
if VERSION is None:
print ("Warning: NORM VERSION not found!?")
# So you don't need to do ./waf configure if you are just using the defaults
waflib.Configure.autoconfig = True
# Top-level project directory
top = '.'
# Directory where build files are placed
out = 'build'
# System waf is running on: linux, darwin (Mac OSX), freebsd, windows, etc.
system = platform.system().lower()
def options(ctx):
ctx.recurse('protolib')
build_opts = ctx.parser.add_option_group('Compile/install Options', 'Use during build/install step.')
def configure(ctx):
ctx.recurse('protolib')
# Use this USE variable to add flags to NORM's compilation
ctx.env.USE_BUILD_NORM += ['BUILD_NORM']
if system in ('linux', 'darwin', 'freebsd', 'gnu', 'gnu/kfreebsd'):
ctx.env.DEFINES_BUILD_NORM += ['ECN_SUPPORT']
#if system == 'windows':
# ctx.env.DEFINES_BUILD_NORM += ['NORM_USE_DLL']
if ctx.env.COMPILER_CXX == 'g++' or ctx.env.COMPILER_CXX == 'clang++':
ctx.env.CFLAGS += ['-fvisibility=hidden', '-Wno-attributes']
ctx.env.CXXFLAGS += ['-fvisibility=hidden', '-Wno-attributes']
#if 'darwin' == system:
# ctx.env.LINKFLAGS += ['-L/opt/local/lib']
# Will be used by the pkg-config generator
ctx.env.VERSION = VERSION
def build(ctx):
ctx.recurse('protolib')
# Setup to install NORM header file
ctx.install_files("${PREFIX}/include/", "include/normApi.h")
ctx.objects(
target = 'normObjs',
includes = ['include', 'protolib/include'],
export_includes = ['include'],
use = ctx.env.USE_BUILD_NORM + ctx.env.USE_BUILD_PROTOLIB,
source = ['src/common/{0}.cpp'.format(x) for x in [
'galois',
'normEncoder',
'normEncoderMDP',
'normEncoderRS16',
'normEncoderRS8',
'normFile',
'normMessage',
'normNode',
'normObject',
'normSegment',
'normSession',
]],
)
# Protolib is incorporated into static and dynmamic NORM libs
ctx.shlib(
target = 'norm',
name = 'norm_shlib',
includes = ['include'],
export_includes = ['include'],
use = ['protoObjs', 'normObjs'],
defines = ['NORM_USE_DLL'] if 'windows' == system else [],
vnum = VERSION,
source = ['src/common/normApi.cpp'],
features = 'cxx cxxshlib',
install_path = '${LIBDIR}',
)
ctx.stlib(
target = 'norm' if 'windows' != system else 'norm_static',
name = 'norm_stlib',
includes = ['include'],
export_includes = ['include'],
use = ['protoObjs', 'normObjs'],
vnum = VERSION,
source = ['src/common/normApi.cpp'],
features = 'cxx cxxstlib',
install_path = '${LIBDIR}',
)
if ctx.env.BUILD_PYTHON:
ctx(
use = ['norm_shlib'],
features='py',
source=ctx.path.ant_glob('src/pynorm/**/*.py'),
install_from='src',
)
if ctx.env.BUILD_JAVA:
ctx.shlib(
target = 'mil_navy_nrl_norm',
includes = ['include'],
use = ['norm_shlib', 'JAVA'],
vnum = VERSION,
defines = ['NORM_USE_DLL'] if 'windows' == system else [],
source = ['src/java/jni/{0}.cpp'.format(x) for x in [
'normJni',
'normInstanceJni',
'normSessionJni',
'normObjectJni',
'normDataJni',
'normFileJni',
'normStreamJni',
'normEventJni',
'normNodeJni',
]],
)
ctx(
features = ['javac', 'jar'],
srcdir = 'src/java/src',
outdir = 'src/java/src',
basedir = 'src/java/src',
destfile = 'norm.jar',
)
# Links to static library since it uses C++ objects directly instead of API
# Hack to force clang to statically link stuff
if 'clang++' == ctx.env.COMPILER_CXX:
use = ['protoObjs', 'normObjs']
source = ['src/common/normApi.cpp']
else:
use = ['norm_stlib', 'protolib_st']
source = []
normapp = ctx.program(
# Need to explicitly set a different name, because
# the library is also named "norm"
name = 'normapp',
target = 'normapp',
includes = ['include', 'protolib/include'],
use = use,
defines = [],
source = source + ['src/common/{0}.cpp'.format(x) for x in [
'normPostProcess',
'normApp',
]],
# Disabled by default
posted = True,
)
if system in ('linux', 'darwin', 'freebsd', 'gnu', 'gnu/kfreebsd'):
normapp.source.append('src/unix/unixPostProcess.cpp')
if system == 'windows':
normapp.source.append('src/win32/win32PostProcess.cpp')
normapp.defines.append('_CONSOLE')
normapp.stlib = (["Shell32"]);
normCast = ctx.program(
target = 'normCast',
includes = ['include', 'protolib/include'],
use = use,
defines = [],
source = source + ['examples/normCast.cpp', 'src/common/normPostProcess.cpp'],
# Disabled by default
posted = True,
# Don't install examples
install_path = False,
)
if system in ('linux', 'darwin', 'freebsd', 'gnu', 'gnu/kfreebsd'):
normCast.source.append('src/unix/unixPostProcess.cpp')
normCastApp = ctx.program(
target = 'normCastApp',
includes = ['include', 'protolib/include'],
use = use,
defines = [],
source = source + ['examples/normCastApp.cpp', 'src/common/normPostProcess.cpp'],
# Disabled by default
posted = True,
# Don't install examples
install_path = False,
)
if system in ('linux', 'darwin', 'freebsd', 'gnu', 'gnu/kfreebsd'):
normCastApp.source.append('src/unix/unixPostProcess.cpp')
for example in (
#'normDataExample',
'normDataRecv',
'normDataSend',
'normFileRecv',
'normFileSend',
'normStreamRecv',
'normStreamSend',
'normMsgr',
'normStreamer',
'normCast',
'chant',
'normClient',
'normServer',
#'wintest' # Windows only (can uncomment on Windows)
):
_make_simple_example(ctx, example)
for prog in (
'fecTest',
'normPrecode',
'normTest',
'normThreadTest',
'raft',
):
_make_simple_example(ctx, prog, 'src/common')
# Enable example targets specified on the command line
ctx._parse_targets()
# Generate pkg-config file
# Add additional static compilation dependencies based on the system.
# libpcap is used by protolib on GNU/Hurd based systems.
static_libs = ''
if hasattr(ctx.options, 'enable_static_library'):
if ctx.options.enable_static_library:
static_libs += ' -lstdc++ -lprotokit'
if system == "gnu":
static_libs += ' -lpcap'
ctx(source='norm.pc.in', STATIC_LIBS = static_libs)
def _make_simple_example(ctx, name, path='examples'):
'''Makes a task from a single source file in the examples directory.
Note these tasks are not built by default.
Use the waf build --targets flag.
'''
# Hack to force clang to statically link stuff
if 'clang++' == ctx.env.COMPILER_CXX:
use = ['protoObjs', 'normObjs']
source = ['src/common/normApi.cpp']
else:
use = ['norm_stlib', 'protolib_st']
source = []
source += ['{0}/{1}.cpp'.format(path, name)]
if 'normClient' == name or 'normServer' == name:
source.append('%s/normSocket.cpp' % path)
example = ctx.program(
target = name,
includes = ['include', 'protolib/include'],
use = use,
defines = [],
source = source,
# Don't build examples by default
posted = True,
# Don't install examples
install_path = False,
)
if 'windows' == system:
example.defines.append('_CONSOLE')