5
from Utils import cmd_output
6
from os.path import join, dirname, abspath
7
from logging import fatal
19
if os.environ.has_key('JOBS'):
20
jobs = int(os.environ['JOBS'])
23
import multiprocessing
24
jobs = multiprocessing.cpu_count()
29
# the gcc module provides a --debug-level option
30
opt.tool_options('compiler_cxx')
31
opt.tool_options('compiler_cc')
32
opt.tool_options('misc')
33
opt.add_option( '--debug'
36
, help='Build debug variant [Default: False]'
39
opt.add_option( '--efence'
42
, help='Build with -lefence for debugging [Default: False]'
46
opt.add_option( '--without-snapshot'
49
, help='Build without snapshotting V8 libraries. You might want to set this for cross-compiling. [Default: False]'
50
, dest='without_snapshot'
53
opt.add_option( '--without-ssl'
56
, help='Build without SSL'
61
opt.add_option('--shared-v8'
64
, help='Link to a shared V8 DLL instead of static linking'
68
opt.add_option( '--shared-v8-includes'
71
, help='Directory containing V8 header files'
72
, dest='shared_v8_includes'
75
opt.add_option( '--shared-v8-libpath'
78
, help='A directory to search for the shared V8 DLL'
79
, dest='shared_v8_libpath'
82
opt.add_option( '--shared-v8-libname'
85
, help="Alternative lib name to link to (default: 'v8')"
86
, dest='shared_v8_libname'
90
opt.add_option('--shared-cares'
93
, help='Link to a shared C-Ares DLL instead of static linking'
97
opt.add_option( '--shared-cares-includes'
100
, help='Directory containing C-Ares header files'
101
, dest='shared_cares_includes'
104
opt.add_option( '--shared-cares-libpath'
107
, help='A directory to search for the shared C-Ares DLL'
108
, dest='shared_cares_libpath'
112
opt.add_option('--shared-libev'
113
, action='store_true'
115
, help='Link to a shared libev DLL instead of static linking'
116
, dest='shared_libev'
119
opt.add_option( '--shared-libev-includes'
122
, help='Directory containing libev header files'
123
, dest='shared_libev_includes'
126
opt.add_option( '--shared-libev-libpath'
129
, help='A directory to search for the shared libev DLL'
130
, dest='shared_libev_libpath'
137
conf.check_tool('compiler_cxx')
138
if not conf.env.CXX: conf.fatal('c++ compiler not found')
139
conf.check_tool('compiler_cc')
140
if not conf.env.CC: conf.fatal('c compiler not found')
144
conf.env["USE_DEBUG"] = o.debug
145
conf.env["SNAPSHOT_V8"] = not o.without_snapshot
147
conf.env["USE_SHARED_V8"] = o.shared_v8 or o.shared_v8_includes or o.shared_v8_libpath or o.shared_v8_libname
148
conf.env["USE_SHARED_CARES"] = o.shared_cares or o.shared_cares_includes or o.shared_cares_libpath
149
conf.env["USE_SHARED_LIBEV"] = o.shared_libev or o.shared_libev_includes or o.shared_libev_libpath
151
conf.check(lib='dl', uselib_store='DL')
152
if not sys.platform.startswith("sunos") and not sys.platform.startswith("cygwin"):
153
conf.env.append_value("CCFLAGS", "-rdynamic")
154
conf.env.append_value("LINKFLAGS_DL", "-rdynamic")
156
if sys.platform.startswith("freebsd"):
157
conf.check(lib='kvm', uselib_store='KVM')
159
#if Options.options.debug:
160
# conf.check(lib='profiler', uselib_store='PROFILER')
162
if Options.options.efence:
163
conf.check(lib='efence', libpath=['/usr/lib', '/usr/local/lib'], uselib_store='EFENCE')
165
if not conf.check(lib="execinfo", includes=['/usr/include', '/usr/local/include'], libpath=['/usr/lib', '/usr/local/lib'], uselib_store="EXECINFO"):
166
# Note on Darwin/OS X: This will fail, but will still be used as the
167
# execinfo stuff are part of the standard library.
168
if sys.platform.startswith("freebsd"):
169
conf.fatal("Install the libexecinfo port from /usr/ports/devel/libexecinfo.")
171
if not Options.options.without_ssl:
172
if conf.check_cfg(package='openssl',
173
args='--cflags --libs',
174
uselib_store='OPENSSL'):
175
Options.options.use_openssl = conf.env["USE_OPENSSL"] = True
176
conf.env.append_value("CXXFLAGS", "-DHAVE_OPENSSL=1")
178
libssl = conf.check_cc(lib='ssl',
179
header_name='openssl/ssl.h',
180
function_name='SSL_library_init',
181
libpath=['/usr/lib', '/usr/local/lib', '/opt/local/lib', '/usr/sfw/lib'],
182
uselib_store='OPENSSL')
183
libcrypto = conf.check_cc(lib='crypto',
184
header_name='openssl/crypto.h',
185
uselib_store='OPENSSL')
186
if libcrypto and libssl:
187
conf.env["USE_OPENSSL"] = Options.options.use_openssl = True
188
conf.env.append_value("CXXFLAGS", "-DHAVE_OPENSSL=1")
190
conf.check(lib='rt', uselib_store='RT')
192
if sys.platform.startswith("sunos"):
193
if not conf.check(lib='socket', uselib_store="SOCKET"):
194
conf.fatal("Cannot find socket library")
195
if not conf.check(lib='nsl', uselib_store="NSL"):
196
conf.fatal("Cannot find nsl library")
198
conf.sub_config('deps/libeio')
200
if conf.env['USE_SHARED_V8']:
202
if o.shared_v8_includes: v8_includes.append(o.shared_v8_includes);
205
if o.shared_v8_libpath: v8_libpath.append(o.shared_v8_libpath);
207
if not o.shared_v8_libname: o.shared_v8_libname = 'v8'
209
if not conf.check_cxx(lib=o.shared_v8_libname, header_name='v8.h',
211
includes=v8_includes,
213
conf.fatal("Cannot find v8")
216
if not conf.check_cxx(lib=o.shared_v8_libname + '_g', header_name='v8.h',
218
includes=v8_includes,
220
conf.fatal("Cannot find v8_g")
222
if conf.env['USE_SHARED_CARES']:
224
if o.shared_cares_includes: cares_includes.append(o.shared_cares_includes);
226
if o.shared_cares_libpath: cares_libpath.append(o.shared_cares_libpath);
227
if not conf.check_cxx(lib='cares',
228
header_name='ares.h',
229
uselib_store='CARES',
230
includes=cares_includes,
231
libpath=cares_libpath):
232
conf.fatal("Cannot find c-ares")
234
conf.sub_config('deps/c-ares')
237
if conf.env['USE_SHARED_LIBEV']:
239
if o.shared_libev_includes: libev_includes.append(o.shared_libev_includes);
241
if o.shared_libev_libpath: libev_libpath.append(o.shared_libev_libpath);
242
if not conf.check_cxx(lib='ev', header_name='ev.h',
244
includes=libev_includes,
245
libpath=libev_libpath):
246
conf.fatal("Cannot find libev")
248
conf.sub_config('deps/libev')
252
conf.define("HAVE_CONFIG_H", 1)
254
if sys.platform.startswith("sunos"):
255
conf.env.append_value ('CCFLAGS', '-threads')
256
conf.env.append_value ('CXXFLAGS', '-threads')
257
#conf.env.append_value ('LINKFLAGS', ' -threads')
258
elif not sys.platform.startswith("cygwin"):
259
threadflags='-pthread'
260
conf.env.append_value ('CCFLAGS', threadflags)
261
conf.env.append_value ('CXXFLAGS', threadflags)
262
conf.env.append_value ('LINKFLAGS', threadflags)
263
if sys.platform.startswith("darwin"):
264
# used by platform_darwin_*.cc
265
conf.env.append_value('LINKFLAGS', ['-framework','Carbon'])
267
conf.env.append_value("CCFLAGS", "-DX_STACKSIZE=%d" % (1024*64))
270
conf.env.append_value('CCFLAGS', '-D_LARGEFILE_SOURCE')
271
conf.env.append_value('CXXFLAGS', '-D_LARGEFILE_SOURCE')
272
conf.env.append_value('CCFLAGS', '-D_FILE_OFFSET_BITS=64')
273
conf.env.append_value('CXXFLAGS', '-D_FILE_OFFSET_BITS=64')
275
## needed for node_file.cc fdatasync
276
## Strangely on OSX 10.6 the g++ doesn't see fdatasync but gcc does?
286
if conf.check_cxx(msg="Checking for fdatasync(2) with c++", fragment=code):
287
conf.env.append_value('CXXFLAGS', '-DHAVE_FDATASYNC=1')
289
conf.env.append_value('CXXFLAGS', '-DHAVE_FDATASYNC=0')
292
platform_def = '-DPLATFORM="' + conf.env['DEST_OS'] + '"'
293
conf.env.append_value('CCFLAGS', platform_def)
294
conf.env.append_value('CXXFLAGS', platform_def)
296
# Split off debug variant before adding variant specific defines
297
debug_env = conf.env.copy()
298
conf.set_env_name('debug', debug_env)
300
# Configure debug variant
302
debug_env.set_variant('debug')
303
debug_env.append_value('CCFLAGS', ['-DDEBUG', '-g', '-O0', '-Wall', '-Wextra'])
304
debug_env.append_value('CXXFLAGS', ['-DDEBUG', '-g', '-O0', '-Wall', '-Wextra'])
305
conf.write_config_header("config.h")
307
# Configure default variant
308
conf.setenv('default')
309
conf.env.append_value('CCFLAGS', ['-DNDEBUG', '-g', '-O3'])
310
conf.env.append_value('CXXFLAGS', ['-DNDEBUG', '-g', '-O3'])
311
conf.write_config_header("config.h")
314
def v8_cmd(bld, variant):
315
scons = join(cwd, 'tools/scons/scons.py')
316
deps_src = join(bld.path.abspath(),"deps")
317
v8dir_src = join(deps_src,"v8")
319
# NOTE: We want to compile V8 to export its symbols. I.E. Do not want
320
# -fvisibility=hidden. When using dlopen() it seems that the loaded DSO
321
# cannot see symbols in the executable which are hidden, even if the
322
# executable is statically linked together...
324
# XXX Remove this when v8 defaults x86_64 to native builds
326
if bld.env['DEST_CPU'] == 'x86_64':
329
if variant == "default":
334
if bld.env["SNAPSHOT_V8"]:
335
snapshot = "snapshot=on"
339
cmd_R = 'python "%s" -j %d -C "%s" -Y "%s" visibility=default mode=%s %s library=static %s'
341
cmd = cmd_R % ( scons
342
, Options.options.jobs
343
, bld.srcnode.abspath(bld.env_of_name(variant))
350
return ("echo '%s' && " % cmd) + cmd
354
v8 = bld.new_task_gen(
355
source = 'deps/v8/SConstruct '
356
+ bld.path.ant_glob('v8/include/*')
357
+ bld.path.ant_glob('v8/src/*'),
358
target = bld.env["staticlib_PATTERN"] % "v8",
359
rule = v8_cmd(bld, "default"),
362
v8.uselib = "EXECINFO"
363
bld.env["CPPPATH_V8"] = "deps/v8/include"
364
t = join(bld.srcnode.abspath(bld.env_of_name("default")), v8.target)
365
bld.env_of_name('default').append_value("LINKFLAGS_V8", t)
369
if bld.env["USE_DEBUG"]:
370
v8_debug = v8.clone("debug")
371
v8_debug.rule = v8_cmd(bld, "debug")
372
v8_debug.target = bld.env["staticlib_PATTERN"] % "v8_g"
373
v8_debug.uselib = "EXECINFO"
374
bld.env["CPPPATH_V8_G"] = "deps/v8/include"
375
t = join(bld.srcnode.abspath(bld.env_of_name("debug")), v8_debug.target)
376
bld.env_of_name('debug').append_value("LINKFLAGS_V8_G", t)
378
bld.install_files('${PREFIX}/include/node/', 'deps/v8/include/*.h')
382
## This snippet is to show full commands as WAF executes
384
old = Build.BuildContext.exec_command
385
def exec_command(self, cmd, **kw):
386
if isinstance(cmd, list): print(" ".join(cmd))
387
return old(self, cmd, **kw)
388
Build.BuildContext.exec_command = exec_command
390
Options.options.jobs=jobs
392
print "DEST_OS: " + bld.env['DEST_OS']
393
print "DEST_CPU: " + bld.env['DEST_CPU']
394
print "Parallel Jobs: " + str(Options.options.jobs)
396
bld.add_subdirs('deps/libeio')
398
if not bld.env['USE_SHARED_V8']: build_v8(bld)
399
if not bld.env['USE_SHARED_LIBEV']: bld.add_subdirs('deps/libev')
400
if not bld.env['USE_SHARED_CARES']: bld.add_subdirs('deps/c-ares')
404
http_parser = bld.new_task_gen("cc")
405
http_parser.source = "deps/http_parser/http_parser.c"
406
http_parser.includes = "deps/http_parser/"
407
http_parser.name = "http_parser"
408
http_parser.target = "http_parser"
409
http_parser.install_path = None
410
if bld.env["USE_DEBUG"]:
411
http_parser.clone("debug")
414
def make_macros(loc, content):
419
macros_loc_debug = join(
420
bld.srcnode.abspath(bld.env_of_name("debug")),
424
macros_loc_default = join(
425
bld.srcnode.abspath(bld.env_of_name("default")),
429
make_macros(macros_loc_debug, "") # leave debug(x) as is in debug build
430
# replace debug(x) with nothing in release build
431
make_macros(macros_loc_default, "macro debug(x) = ;\n")
433
def javascript_in_c(task):
435
source = map(lambda x: x.srcpath(env), task.inputs)
436
targets = map(lambda x: x.srcpath(env), task.outputs)
437
source.append(macros_loc_default)
438
js2c.JS2C(source, targets)
440
def javascript_in_c_debug(task):
442
source = map(lambda x: x.srcpath(env), task.inputs)
443
targets = map(lambda x: x.srcpath(env), task.outputs)
444
source.append(macros_loc_debug)
445
js2c.JS2C(source, targets)
447
native_cc = bld.new_task_gen(
448
source='src/node.js ' + bld.path.ant_glob('lib/*.js'),
449
target="src/node_natives.h",
454
# Add the rule /after/ cloning the debug
455
# This is a work around for an error had in python 2.4.3 (I'll paste the
456
# error that was had into the git commit meessage. git-blame to find out
458
if bld.env["USE_DEBUG"]:
459
native_cc_debug = native_cc.clone("debug")
460
native_cc_debug.rule = javascript_in_c_debug
462
native_cc.rule = javascript_in_c
465
node = bld.new_task_gen("cxx", "program")
468
node.uselib = 'RT EV OPENSSL CARES EXECINFO DL KVM SOCKET NSL'
469
node.add_objects = 'eio http_parser'
470
node.install_path = '${PREFIX}/lib'
471
node.install_path = '${PREFIX}/bin'
476
src/node_extensions.cc
477
src/node_http_parser.cc
479
src/node_io_watcher.cc
480
src/node_child_process.cc
481
src/node_constants.cc
485
src/node_signal_watcher.cc
486
src/node_stat_watcher.cc
492
platform_file = "src/platform_%s.cc" % bld.env['DEST_OS']
493
if os.path.exists(join(cwd, platform_file)):
494
node.source += platform_file
496
node.source += "src/platform_none.cc "
499
if bld.env["USE_OPENSSL"]: node.source += " src/node_crypto.cc "
507
if not bld.env["USE_SHARED_V8"]: node.includes += ' deps/v8/include '
509
if not bld.env["USE_SHARED_LIBEV"]:
510
node.add_objects += ' ev '
511
node.includes += ' deps/libev '
513
if not bld.env["USE_SHARED_CARES"]:
514
node.add_objects += ' cares '
515
node.includes += ' deps/c-ares deps/c-ares/' + bld.env['DEST_OS'] + '-' + bld.env['DEST_CPU']
517
if sys.platform.startswith('cygwin'):
518
bld.env.append_value('LINKFLAGS', '-Wl,--export-all-symbols')
519
bld.env.append_value('LINKFLAGS', '-Wl,--out-implib,default/libnode.dll.a')
520
bld.env.append_value('LINKFLAGS', '-Wl,--output-def,default/libnode.def')
521
bld.install_files('${PREFIX}/lib', "build/default/libnode.*")
523
def subflags(program):
524
x = { 'CCFLAGS' : " ".join(program.env["CCFLAGS"]).replace('"', '\\"')
525
, 'CPPFLAGS' : " ".join(program.env["CPPFLAGS"]).replace('"', '\\"')
526
, 'LIBFLAGS' : " ".join(program.env["LIBFLAGS"]).replace('"', '\\"')
527
, 'PREFIX' : program.env["PREFIX"]
531
# process file.pc.in -> file.pc
533
node_conf = bld.new_task_gen('subst', before="cxx")
534
node_conf.source = 'src/node_config.h.in'
535
node_conf.target = 'src/node_config.h'
536
node_conf.dict = subflags(node)
537
node_conf.install_path = '${PREFIX}/include/node'
539
if bld.env["USE_DEBUG"]:
540
node_g = node.clone("debug")
541
node_g.target = "node_g"
542
node_g.uselib += ' V8_G'
544
node_conf_g = node_conf.clone("debug")
545
node_conf_g.dict = subflags(node_g)
546
node_conf_g.install_path = None
548
# After creating the debug clone, append the V8 dep
551
bld.install_files('${PREFIX}/include/node/', """
554
src/node_object_wrap.h
560
# Only install the man page if it exists.
561
# Do 'make doc install' to build and install it.
562
if os.path.exists('doc/nodejs.1'):
563
bld.install_files('${PREFIX}/share/man/man1/', 'doc/nodejs.1')
565
bld.install_files('${PREFIX}/bin/', 'bin/*', chmod=0755)
566
bld.install_files('${PREFIX}/share/nodejs/wafadmin', 'tools/wafadmin/*.py')
567
bld.install_files('${PREFIX}/share/nodejs/wafadmin/Tools', 'tools/wafadmin/Tools/*.py')
570
Options.options.debug
571
# HACK to get binding.node out of build directory.
572
# better way to do this?
573
if Options.commands['configure']:
574
if not Options.options.use_openssl:
575
print "WARNING WARNING WARNING"
576
print "OpenSSL not found. Will compile Node without crypto support!"
577
elif not Options.commands['clean']:
578
if os.path.exists('build/default/node') and not os.path.exists('node'):
579
os.symlink('build/default/node', 'node')
580
if os.path.exists('build/debug/node_g') and not os.path.exists('node_g'):
581
os.symlink('build/debug/node_g', 'node_g')
583
if os.path.exists('node'): os.unlink('node')
584
if os.path.exists('node_g'): os.unlink('node_g')