forked from Juniper/contrail-vrouter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSConscript
328 lines (283 loc) · 11.4 KB
/
SConscript
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
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
#
# Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
#
import subprocess
import sys
import os
import copy
import re
import platform
AddOption('--kernel-dir', dest = 'kernel-dir', action='store',
help='Linux kernel source directory for vrouter.ko')
AddOption('--system-header-path', dest = 'system-header-path', action='store',
help='Linux kernel headers for applications')
env = DefaultEnvironment().Clone()
VRouterEnv = env
dpdk_exists = os.path.isdir('../third_party/dpdk')
# DPDK build configuration
DPDK_TARGET = 'x86_64-native-linuxapp-gcc'
DPDK_SRC_DIR = '#third_party/dpdk/'
DPDK_DST_DIR = env['TOP'] + '/vrouter/dpdk/' + DPDK_TARGET
DPDK_INC_DIR = DPDK_DST_DIR + '/include'
DPDK_LIB_DIR = DPDK_DST_DIR + '/lib'
# Include paths
env.Replace(CPPPATH = '#vrouter/include')
env.Append(CPPPATH = [env['TOP'] + '/vrouter/sandesh/gen-c'])
env.Append(CPPPATH = ['#src/contrail-common'])
env.Append(CPPPATH = ['#src/contrail-common/sandesh/library/c'])
if sys.platform.startswith('win'):
env.Append(CPPPATH = '#vrouter/windows')
# Make Sandesh quiet for production
if 'production' in env['OPT']:
DefaultEnvironment().Append(CPPDEFINES='SANDESH_QUIET')
vr_root = './'
makefile = vr_root + 'Makefile'
dp_dir = Dir(vr_root).srcnode().abspath + '/'
make_dir = dp_dir
def MakeTestCmdFn(self, env, test_name, test_list, deps):
sources = copy.copy(deps)
sources.append(test_name + '.c')
tgt = env.UnitTest(target = test_name, source = sources)
env.Alias('vrouter:'+ test_name, tgt)
test_list.append(tgt)
return tgt
VRouterEnv.AddMethod(MakeTestCmdFn, 'MakeTestCmd')
def shellCommand(cmd):
""" Return the output of a shell command
This wrapper is required since check_output is not supported in
python 2.6
"""
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)
(output, _) = proc.communicate()
return output.strip()
def genBuildVersion():
h_code = """
/*
* Autogenerated file. Do not edit
*/
#ifndef __VR_BUILDINFO_H__
#define __VR_BUILDINFO_H__
#define VROUTER_VERSIONID "%(build)s"
#endif /* __VR_BUILDINFO_H__ */
""" % { 'build': env.GetBuildVersion()[1] }
c_file = file(os.path.join(dp_dir, 'include/vr_buildinfo.h'), 'w')
c_file.write(h_code)
c_file.close()
return
if sys.platform.startswith('freebsd'):
make_dir = make_dir + '/freebsd'
env['ENV']['MAKEOBJDIR'] = make_dir
# XXX Temporary/transitional support for Ubuntu14.04.4 w/ kernel v4.*
#
# The logic here has to handle two different invocation models:
# default 'scons' build model; and build via packager.py build. The
# first is typical for unit-test builds.
#
# The second comes via:
# - common/debian/Makefile in contrail-packaging, which invokes:
# - debian/contrail/debian/rules.modules in contrail-packages
# This approach always uses --kernel-dir, which works for vrouter, but
# libdpdk still defaults to installed version and thus will fail.
#
if not sys.platform.startswith('win'):
default_kernel_ver = shellCommand("uname -r").strip()
kernel_build_dir = None
(PLATFORM, VERSION, EXTRA) = platform.linux_distribution()
if (PLATFORM.lower() == 'ubuntu' and VERSION.find('14.') == 0):
if re.search('^4\.', default_kernel_ver):
print("Warn: kernel version %s not supported for vrouter and dpdk" % default_kernel_ver)
kernel_build_dir = '/lib/modules/3.13.0-110-generic/build'
if os.path.isdir(kernel_build_dir):
default_kernel_ver = "3.13.0-110-generic"
print("info: libdpdk will be built against kernel version %s" % default_kernel_ver)
else:
print("*** Error: Cannot find kernel v3.13.0-110, build of vrouter will likely fail")
kernel_build_dir = '/lib/modules/%s/build' % default_kernel_ver
kernel_dir = GetOption('kernel-dir')
if kernel_dir:
kern_version = shellCommand('cat %s/include/config/kernel.release' % kernel_dir)
else:
kern_version = default_kernel_ver
if kernel_build_dir: kernel_dir = kernel_build_dir
kern_version = kern_version.strip()
if sys.platform != 'darwin':
if not sys.platform.startswith('win'):
install_root = GetOption('install_root')
if install_root == None:
install_root = ''
src_root = install_root + '/usr/src/vrouter/'
env.Replace(SRC_INSTALL_TARGET = src_root)
env.Install(src_root, ['LICENSE', 'Makefile', 'GPL-2.0.txt'])
env.Alias('install', src_root)
buildinfo = env.GenerateBuildInfoCCode(target = ['vr_buildinfo.c'],
source = [], path = dp_dir + 'dp-core')
buildversion = genBuildVersion()
subdirs = ['linux', 'include', 'dp-core', 'host', 'sandesh',
'windows', 'utils', 'uvrouter', 'test']
exports = ['VRouterEnv']
if dpdk_exists and not GetOption('without-dpdk'):
subdirs.append('dpdk')
exports.append('dpdk_lib')
rte_ver_filename = '../third_party/dpdk/lib/librte_eal/common/include/rte_version.h'
rte_ver_file = open(rte_ver_filename, 'r')
file_content = rte_ver_file.read()
rte_ver_file.close()
matches = re.findall("define RTE_VER_MAJOR 2", file_content)
if matches:
rte_libs = ('-lethdev', '-lrte_malloc')
else:
rte_libs = ('-lrte_ethdev',)
year_matches = re.findall("define RTE_VER_YEAR 17", file_content)
month_matches = re.findall("define RTE_VER_MONTH 11", file_content)
if year_matches and month_matches:
rte_libs = rte_libs + ('-lrte_mempool_ring', '-lrte_bus_pci', '-lrte_pci', '-lrte_bus_vdev')
#
# DPDK libraries need to be linked as a whole archive, otherwise some
# callbacks and constructors will not be linked in. Also some of the
# libraries need to be linked as a group for the cross-reference resolving.
#
# That is why we pass DPDK libraries as flags to the linker.
#
# Order is important: from higher level to lower level
# The list is from the rte.app.mk file
DPDK_LIBS = [
'-Wl,--whole-archive',
# '-lrte_distributor',
# '-lrte_reorder',
'-lrte_kni',
# '-lrte_ivshmem',
# '-lrte_pipeline',
# '-lrte_table',
'-lrte_port',
'-lrte_timer',
'-lrte_hash',
# '-lrte_jobstats',
# '-lrte_lpm',
# '-lrte_power',
# '-lrte_acl',
# '-lrte_meter',
'-lrte_sched',
'-lm',
'-lrt',
# '-lrte_vhost',
# '-lpcap',
# '-lfuse',
# '-libverbs',
'-Wl,--start-group',
'-lrte_kvargs',
'-lrte_mbuf',
'-lrte_ip_frag',
rte_libs,
'-lrte_mempool',
'-lrte_ring',
'-lrte_eal',
'-lrte_cmdline',
# '-lrte_cfgfile',
'-lrte_pmd_bond',
'-lrte_pmd_bnxt',
# '-lrte_pmd_xenvirt',
# '-lxenstore',
# '-lrte_pmd_vmxnet3_uio',
# '-lrte_pmd_virtio_uio',
'-lrte_pmd_enic',
'-lrte_pmd_i40e',
# '-lrte_pmd_fm10k',
'-lrte_pmd_ixgbe',
'-lrte_pmd_e1000',
# '-lrte_pmd_mlx4',
# '-lrte_pmd_ring',
# '-lrte_pmd_pcap',
'-lrte_pmd_af_packet',
'-Wl,--end-group',
'-Wl,--no-whole-archive'
]
if year_matches and month_matches:
DPDK_LIBS.append('-Wl,-lnuma')
# Pass -g and -O flags if present to DPDK
DPDK_FLAGS = ' '.join(o for o in env['CCFLAGS'] if ('-g' in o or '-O' in o))
# Make DPDK
dpdk_src_dir = Dir(DPDK_SRC_DIR).abspath
dpdk_dst_dir = Dir(DPDK_DST_DIR).abspath
make_cmd = 'make -C ' + dpdk_src_dir \
+ ' EXTRA_CFLAGS="' + DPDK_FLAGS + '"' \
+ ' ARCH=x86_64' \
+ ' O=' + dpdk_dst_dir \
+ ' '
# If this var is set, then we need to pass it to make cmd for libdpdk
if kernel_build_dir:
print("info: Adjusting libdpdk build to use RTE_KERNELDIR=%s" % kernel_build_dir)
make_cmd += "RTE_KERNELDIR=%s " % kernel_build_dir
dpdk_lib = env.Command('dpdk_lib', None,
make_cmd + 'config T=' + DPDK_TARGET
+ ' && ' + make_cmd)
env.Append(CPPPATH = DPDK_INC_DIR);
env.Append(LIBPATH = DPDK_LIB_DIR)
env.Append(DPDK_LINKFLAGS = DPDK_LIBS)
if GetOption('clean'):
os.system(make_cmd + 'clean')
for sdir in subdirs:
env.SConscript(sdir + '/SConscript',
exports = exports,
variant_dir = env['TOP'] + '/vrouter/' + sdir,
duplicate = 0)
if sys.platform.startswith('win'):
def make_cmd(target, source, env):
msbuild = [
os.environ['MSBUILD'],
'windows/vRouter.sln',
'/p:Platform=x64',
'/p:Configuration=' + env['VS_BUILDMODE']
]
subprocess.call(msbuild, cwd=Dir('#/vrouter').abspath)
vrouter_target = File('#/build/debug/vrouter/extension/vRouter/vRouter.sys')
else:
make_cmd = 'cd ' + make_dir + ' && make'
if kernel_dir: make_cmd += ' KERNELDIR=' + kernel_dir
make_cmd += ' SANDESH_HEADER_PATH=' + Dir(env['TOP'] + '/vrouter/').abspath
make_cmd += ' SANDESH_SRC_ROOT=' + '../build/kbuild/'
make_cmd += ' SANDESH_EXTRA_HEADER_PATH=' + Dir('#src/contrail-common/').abspath
vrouter_target = 'vrouter.ko'
if 'vrouter' in COMMAND_LINE_TARGETS:
if not sys.platform.startswith('win'):
BUILD_TARGETS.append('vrouter/uvrouter')
else:
BUILD_TARGETS.append('vrouter.msi')
if dpdk_exists:
BUILD_TARGETS.append('vrouter/dpdk')
BUILD_TARGETS.append('vrouter/utils')
kern = env.Command(vrouter_target, None, make_cmd)
env.Default(kern)
env.AlwaysBuild(kern)
env.Depends(kern, buildinfo)
env.Depends(kern, buildversion)
env.Depends(kern, env.Install(
'#build/kbuild/sandesh/gen-c',
env['TOP'] + '/vrouter/sandesh/gen-c/vr_types.c'))
sandesh_lib = [
'protocol/thrift_binary_protocol.c',
'protocol/thrift_protocol.c',
'sandesh.c',
'transport/thrift_fake_transport.c',
'transport/thrift_memory_buffer.c',
]
for src in sandesh_lib:
dirname = os.path.dirname(src)
env.Depends(kern,
env.Install(
'#build/kbuild/sandesh/library/c/' + dirname,
env['TOP'] + '/tools/sandesh/library/c/' + src))
if not sys.platform.startswith('win'):
if GetOption('clean') and (not COMMAND_LINE_TARGETS or 'vrouter' in COMMAND_LINE_TARGETS):
os.system(make_cmd + ' clean')
libmod_dir = install_root
libmod_dir += '/lib/modules/%s/extra/net/vrouter' % kern_version
env.Alias('build-kmodule', env.Install(libmod_dir, kern))
else:
env.Append(WIXCANDLEFLAGS = ['-doptimization=' + env['OPT']])
env.Append(WIXLIGHTFLAGS = ['-ext', 'WixUtilExtension.dll'])
msi_command = env.WiX(File('#/build/' + env['OPT'] + '/vrouter/extension/vRouter.msi'), ['windows/installer/vrouter_msi.wxs'])
env.Depends(msi_command, kern)
env.Alias('vrouter.msi', msi_command)
# Local Variables:
# mode: python
# End: