forked from syndicate-storage/syndicate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSConstruct
371 lines (280 loc) · 13.1 KB
/
SConstruct
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
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
"""
Copyright 2013 The Trustees of Princeton University
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
# SCons build script for Syndicate
import os
import sys
import types
import SCons
# add common tools
sys.path.append( os.path.join( os.getcwd(), "build/tools/" ) )
import common
# installation prefix
install_prefix = "/usr/local"
# default CPPPATH
CPPPATH = [
"#",
"/usr/include/",
"."
]
# for protobufs...
LIBPATH = [
"/usr/lib/x86_64-linux-gnu/",
"/usr/lib/i386-linux-gnu/",
"/usr/local/lib",
"/usr/lib"
]
# default CPPFLAGS
CPPFLAGS = "-g -Wall -D__STDC_FORMAT_MACROS -fstack-protector -fstack-protector-all -pthread -rdynamic"
LIBS = ""
LINK_FLAGS = ""
# parse options
devel = False
valgrind_fixes = True
old_boost = False
firewall = False
extra_args = {}
for key, value in ARGLIST:
if key == "DESTDIR":
install_prefix = value
elif key == "CPPFLAGS":
CPPFLAGS = value
# development flag
elif key == "devel":
if value == "true":
CPPFLAGS += " -D_DEVELOPMENT"
devel = True
# disable valgrind fix-ups flag
elif key == "no-valgrind-fixes":
if value == "true":
valgrind_fixes = False
# firewall flag - set true if this system works behind firewall
elif key == "firewall":
if value == "true":
CPPFLAGS += " -D_FIREWALL"
firewall = True
# PlanetLab (Fedora 12) flag
elif key == "old_boost":
if value == "true":
old_boost = True
else:
extra_args[key] = value
# modify CPPFLAGS to disable features
if not valgrind_fixes:
CPPFLAGS += " -D_NO_VALGRIND_FIXES"
# deduce the host linux distro
def deduce_distro():
distro = "UNKNOWN"
try:
fd = os.popen("lsb_release -i")
distro_id_text = fd.read()
fd.close()
except:
print "WARN: failed to run 'lsb_release -i'. Cannot deduce distribution (assuming defaults)"
return distro
_, distro = distro_id_text.split("\t")
distro = distro.strip().upper()
return distro
if not extra_args.has_key("DISTRO"):
extra_args["DISTRO"] = deduce_distro()
CPPFLAGS += " -D_DISTRO_%s" % extra_args["DISTRO"]
# TODO: possibly isolate this somewhere else?
# select the appropriate JSON library
if extra_args["DISTRO"] == "DEBIAN":
extra_args['LIBJSON'] = "json-c"
# install directories
bin_install_dir = os.path.join( install_prefix, "bin" )
lib_install_dir = os.path.join( install_prefix, "lib" )
inc_install_dir = os.path.join( install_prefix, "include/libsyndicate" )
etc_install_dir = os.path.join( install_prefix, "etc" )
pkg_install_dir = os.path.join( install_prefix, "pkg" )
env = Environment(
ENV = {'PATH': os.getenv('PATH'), 'PYTHONPATH': os.getenv('PYTHONPATH')},
CPPFLAGS = Split(CPPFLAGS),
CPPPATH = CPPPATH,
LIBPATH = LIBPATH,
LIBS = LIBS,
LINK_FLAGS = LINK_FLAGS,
toolpath = ['build/tools'],
tools = ['default', 'protoc'],
devel = devel,
firewall = firewall,
old_boost = old_boost, # for the UG
install_prefix = install_prefix
)
common.setup_env( env )
# begin build
Export("env")
Export("extra_args")
# ----------------------------------------
# protobuf build
protobuf_out = "build/out/protobufs"
protobufs, protobuf_header_paths = SConscript( "protobufs/SConscript", variant_dir=protobuf_out )
protobuf_cc_files = filter( lambda x: x.path.endswith(".cc"), protobufs )
protobuf_py_files = filter( lambda x: x.path.endswith(".py"), protobufs )
Export("protobuf_out") # needed by libsyndicate
Export("protobuf_cc_files") # needed by libsyndicate
Export("protobuf_py_files") # needed by MS and RG
# ----------------------------------------
# libsyndicate build
libsyndicate_out = "build/out/lib/libsyndicate"
libsyndicate_driver_out = "build/out/lib/syndicate-drivers/volume"
libsyndicate_driver_install = os.path.join( lib_install_dir, "syndicate-drivers/volume" )
libsyndicate, libsyndicate_header_paths, libsyndicate_scrypt_header_paths, libsyndicate_ms_client_header_paths, libsyndicate_source_paths = SConscript( "libsyndicate/SConscript", variant_dir=libsyndicate_out )
libsyndicate_drivers = SConscript( "libsyndicate/drivers/SConscript", variant_dir=libsyndicate_driver_out )
# all libsyndicate targets depends on protobufs
libsyndicate_protobuf_deps = [protobufs, protobuf_cc_files]
for libsyndicate_target in [libsyndicate, libsyndicate_header_paths, libsyndicate_source_paths]:
if libsyndicate_target is not None:
env.Depends( libsyndicate_target, libsyndicate_protobuf_deps )
# alias installation targets for libsyndicate
libsyndicate_install_headers = env.Install( inc_install_dir, libsyndicate_header_paths + protobuf_header_paths )
libsyndicate_install_scrypt_headers = env.Install( os.path.join( inc_install_dir, "scrypt" ), libsyndicate_scrypt_header_paths )
libsyndicate_install_ms_client_headers = env.Install( os.path.join( inc_install_dir, "ms" ), libsyndicate_ms_client_header_paths )
libsyndicate_install_library = env.Install( lib_install_dir, [libsyndicate] )
libsyndicate_install_drivers = env.Install( libsyndicate_driver_install, [libsyndicate_drivers] )
# main targets...
env.Alias( 'libsyndicate', [libsyndicate] )
env.Alias( 'libsyndicate-install', [libsyndicate_install_library, libsyndicate_install_headers, libsyndicate_install_scrypt_headers, libsyndicate_install_ms_client_headers] )
env.Alias( 'libsyndicate-drivers', [libsyndicate_drivers] )
env.Alias( 'libsyndicate-drivers-install', [libsyndicate_install_drivers] )
# ----------------------------------------
# UG build
libsyndicateUG_inc_install_dir = os.path.join( install_prefix, "include/libsyndicateUG" )
libsyndicateUG_inc_fs_install_dir = os.path.join( install_prefix, "include/libsyndicateUG/fs" )
ug_out = "build/out/bin/UG"
ug_driver_out = "build/out/lib/UG/drivers"
syndicatefs, syndicate_httpd, syndicate_ipc, libsyndicateUGclient, libsyndicateUG, libsyndicateUG_headers, libsyndicateUG_fs_headers, syndicate_watchdog = SConscript( "UG/SConscript", variant_dir=ug_out )
ug_drivers = SConscript( "UG/drivers/SConscript", variant_dir=ug_driver_out )
ugs_bin = [syndicatefs, syndicate_httpd, syndicate_ipc, syndicate_watchdog]
ugs_lib = [libsyndicateUGclient, libsyndicateUG]
ug_aliases = [syndicatefs, syndicate_httpd, syndicate_ipc, libsyndicateUGclient, libsyndicateUG, syndicate_watchdog]
env.Depends( syndicatefs, libsyndicate )
env.Depends( syndicate_ipc, libsyndicate )
env.Depends( syndicate_httpd, libsyndicate )
env.Depends( libsyndicateUG, libsyndicate )
env.Depends( libsyndicateUGclient, libsyndicate )
env.Alias("syndicatefs", syndicatefs)
env.Alias("UG-httpd", syndicate_httpd)
env.Alias("libsyndicateUG", libsyndicateUG)
env.Alias("libsyndicateUGclient", libsyndicateUGclient)
env.Alias("UG-ipc", syndicate_ipc)
env.Alias("UG-drivers", ug_drivers )
# UG installation
common.install_targets( env, 'UG-install', bin_install_dir, ugs_bin )
common.install_targets( env, 'UG-drivers-install', lib_install_dir, ug_drivers )
libsyndicateUG_install_library = env.Install( lib_install_dir, [libsyndicateUG, libsyndicateUGclient] )
libsyndicateUG_install_headers = env.Install( libsyndicateUG_inc_install_dir, libsyndicateUG_headers )
libsyndicateUG_install_fs_headers = env.Install( libsyndicateUG_inc_fs_install_dir, libsyndicateUG_fs_headers )
env.Alias( "libsyndicateUG-install", [libsyndicateUG_install_library, libsyndicateUG_install_headers, libsyndicateUG_install_fs_headers] )
env.Alias("UG", ug_aliases )
# ----------------------------------------
# AG build
ag_out = "build/out/bin/AG"
ags = SConscript( "AG/SConscript", variant_dir=ag_out )
env.Depends( ags, libsyndicate )
# AG disk driver
libAGdiskdriver_out = "build/out/lib/AG/drivers/disk"
libAGdiskdriver = SConscript( "AG/drivers/disk/SConscript", variant_dir=libAGdiskdriver_out )
ag_driver_disk_install = env.Install( lib_install_dir, libAGdiskdriver )
env.Alias( 'AG-disk-driver', libAGdiskdriver )
env.Alias( 'AG-disk-driver-install', [ag_driver_disk_install] )
# AG disk-polling driver
libAGdiskpollingdriver_out = "build/out/lib/AG/drivers/disk_polling"
libAGdiskpollingdriver = SConscript( "AG/drivers/disk_polling/SConscript", variant_dir=libAGdiskpollingdriver_out )
ag_driver_disk_polling_install = env.Install( lib_install_dir, libAGdiskpollingdriver )
env.Alias( 'AG-disk-polling-driver', libAGdiskpollingdriver )
env.Alias( 'AG-disk-polling-driver-install', [ag_driver_disk_polling_install] )
# AG Shell driver
libAGshelldriver_out = "build/out/lib/AG/drivers/shell"
libAGshelldriver = SConscript( "AG/drivers/shell/SConscript", variant_dir=libAGshelldriver_out )
ag_driver_shell_install = env.Install( lib_install_dir, libAGshelldriver )
env.Alias( 'AG-shell-driver', libAGshelldriver )
env.Alias( 'AG-shell-driver-install', [ag_driver_shell_install] )
# AG curl driver
libAGcurldriver_out = "build/out/lib/AG/drivers/curl"
libAGcurldriver = SConscript( "AG/drivers/curl/SConscript", variant_dir=libAGcurldriver_out )
ag_driver_curl_install = env.Install( lib_install_dir, libAGcurldriver )
env.Alias( 'AG-curl-driver', libAGcurldriver )
env.Alias( 'AG-curl-driver-install', [ag_driver_curl_install] )
# All drivers
#ag_drivers = [libAGcurldriver, libAGshelldriver, libAGdiskdriver, libAGdiskpollingdriver]
ag_drivers = [libAGcurldriver, libAGshelldriver, libAGdiskdriver]
# installation
common.install_targets( env, 'AG-bin-install', bin_install_dir, ags )
common.install_targets( env, 'AG-drivers-install', os.path.join(lib_install_dir, "syndicate/AG"), ag_drivers )
# main targets....
env.Alias('AG', [ags, ag_drivers])
env.Alias( 'AG-drivers', ag_drivers )
env.Alias('AG-install', ['AG-bin-install', 'AG-drivers-install'] )
# ----------------------------------------
# MS build
# Only parse the SConscript if we need to, since it performs argument validation.
ms_aliases = []
if "MS" in COMMAND_LINE_TARGETS:
ms_server_out = "build/out/ms"
ms_server = SConscript( "ms/SConscript.server", variant_dir=ms_server_out )
env.Depends( ms_server, protobuf_py_files ) # ms requires Python protobufs to be built first
env.Alias( "MS-server", ms_server )
ms_aliases.append( ms_server )
# MS clients build
ms_clients_bin_out = "build/out/bin/ms"
ms_client_bin, ms_client_bin_install = SConscript( "ms/SConscript.client", variant_dir=ms_clients_bin_out )
env.Alias( "MS-clients", [ms_client_bin] )
env.Alias( "MS", ms_aliases + [ms_client_bin] )
common.install_targets( env, 'MS-clients-install', bin_install_dir, ms_client_bin_install )
# ----------------------------------------
# RG build
# replica gateway server build
rg_out = "build/out/bin/RG"
rg_server = SConscript( "RG/SConscript", variant_dir=rg_out )
env.Alias("RG", [rg_server])
common.install_targets( env, "RG-install", bin_install_dir, rg_server )
# ----------------------------------------
# Automount daemon build
automount_out = "build/out/bin/automount"
automount_daemon = SConscript( "automount/SConscript", variant_dir=automount_out )
env.Alias("syndicated", [automount_daemon])
common.install_targets( env, "syndicated-install", bin_install_dir, automount_daemon )
# ----------------------------------------
# OpenCloud-specific automount daemon config
opencloud_out = "build/out/opencloud"
opencloud_automount_etc_files = SConscript( "automount/opencloud/SConscript", variant_dir=opencloud_out )
env.Alias("syndicated-opencloud-etc", [automount_daemon, opencloud_automount_etc_files] )
common.install_tree( env, "syndicated-opencloud-install-etc", etc_install_dir, opencloud_automount_etc_files, opencloud_out + "/etc" )
# ----------------------------------------
# OpenCloud-specific installation scripts
opencloud_pkg_out = "build/out/pkg/opencloud/syndicated"
opencloud_automount_pkgscripts = SConscript( "automount/opencloud/pkg/SConscript", variant_dir=opencloud_pkg_out )
env.Alias("syndicated-opencloud-pkg", opencloud_automount_pkgscripts )
common.install_tree( env, "syndicated-opencloud-install-pkg", pkg_install_dir, opencloud_automount_pkgscripts, opencloud_pkg_out + "/pkg" )
# ----------------------------------------
# Python build
syndicate_python_out = "build/out/python"
python_target, python_install, python_files = SConscript("python/SConscript", variant_dir=syndicate_python_out)
env.Depends(python_target, [python_files, protobuf_py_files, libsyndicate, libsyndicateUG])
env.Alias("syndicate-python", python_target)
env.Alias("python-syndicate", "syndicate-python")
env.Alias("syndicate-python-install", python_install)
env.Alias("python-syndicate-install", "syndicate-python-install")
# ----------------------------------------
# Top-level build
env.Alias("syndicate", ["RG", "AG", "UG"])
env.Alias("syndicate-install", ["RG-install", "AG-install", "UG-install"])
# ----------------------------------------
# initialization
# set umask correctly
try:
umask = os.umask(022)
except OSError:
pass
Default(None)