3
# Copyright Joyent, Inc. and other Node contributors.
5
# Permission is hereby granted, free of charge, to any person obtaining a
6
# copy of this software and associated documentation files (the
7
# "Software"), to deal in the Software without restriction, including
8
# without limitation the rights to use, copy, modify, merge, publish,
9
# distribute, sublicense, and/or sell copies of the Software, and to permit
10
# persons to whom the Software is furnished to do so, subject to the
11
# following conditions:
13
# The above copyright notice and this permission notice shall be included
14
# in all copies or substantial portions of the Software.
16
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
19
# NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20
# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
22
# USE OR OTHER DEALINGS IN THE SOFTWARE.
26
import sys, os, shutil, glob
28
from Utils import cmd_output
29
from os.path import join, dirname, abspath, normpath
30
from logging import fatal
35
# Use the directory that this file is found in to find the tools
36
# directory where the js2c.py file can be found.
37
sys.path.append(sys.argv[0] + '/tools');
40
if sys.platform.startswith("cygwin"):
41
print "cygwin not supported"
46
supported_archs = ('arm', 'ia32', 'x64') # 'mips' supported by v8, but not node
49
if os.environ.has_key('JOBS'):
50
jobs = int(os.environ['JOBS'])
53
return path.replace("\\", "/")
55
def canonical_cpu_type(arch):
56
m = {'x86': 'ia32', 'i386':'ia32', 'x86_64':'x64', 'amd64':'x64'}
57
if arch in m: arch = m[arch]
58
if not arch in supported_archs:
59
raise Exception("supported architectures are "+', '.join(supported_archs)+\
60
" but NOT '" + arch + "'.")
64
# the gcc module provides a --debug-level option
65
opt.tool_options('compiler_cxx')
66
opt.tool_options('compiler_cc')
67
opt.tool_options('misc')
68
opt.add_option( '--libdir'
72
, help='Install into this libdir [Release: ${PREFIX}/lib]'
74
opt.add_option( '--debug'
77
, help='Build debug variant [Release: False]'
80
opt.add_option( '--profile'
83
, help='Enable profiling [Release: False]'
86
opt.add_option( '--efence'
89
, help='Build with -lefence for debugging [Release: False]'
93
opt.add_option( '--without-npm'
96
, help='Don\'t install the bundled npm package manager [Release: False]'
100
opt.add_option( '--without-snapshot'
101
, action='store_true'
103
, help='Build without snapshotting V8 libraries. You might want to set this for cross-compiling. [Release: False]'
104
, dest='without_snapshot'
107
opt.add_option( '--without-ssl'
108
, action='store_true'
110
, help='Build without SSL'
115
opt.add_option('--shared-v8'
116
, action='store_true'
118
, help='Link to a shared V8 DLL instead of static linking'
122
opt.add_option( '--shared-v8-includes'
125
, help='Directory containing V8 header files'
126
, dest='shared_v8_includes'
129
opt.add_option( '--shared-v8-libpath'
132
, help='A directory to search for the shared V8 DLL'
133
, dest='shared_v8_libpath'
136
opt.add_option( '--shared-v8-libname'
139
, help="Alternative lib name to link to (default: 'v8')"
140
, dest='shared_v8_libname'
143
opt.add_option( '--openssl-includes'
146
, help='A directory to search for the OpenSSL includes'
147
, dest='openssl_includes'
150
opt.add_option( '--openssl-libpath'
153
, help="A directory to search for the OpenSSL libraries"
154
, dest='openssl_libpath'
157
opt.add_option( '--no-ssl2'
158
, action='store_true'
160
, help="Disable OpenSSL v2"
161
, dest='openssl_nov2'
164
opt.add_option( '--gdb'
165
, action='store_true'
167
, help="add gdb support"
172
opt.add_option( '--shared-zlib'
173
, action='store_true'
175
, help='Link to a shared zlib DLL instead of static linking'
179
opt.add_option( '--shared-zlib-includes'
182
, help='Directory containing zlib header files'
183
, dest='shared_zlib_includes'
186
opt.add_option( '--shared-zlib-libpath'
189
, help='A directory to search for the shared zlib DLL'
190
, dest='shared_zlib_libpath'
194
opt.add_option( '--shared-cares'
195
, action='store_true'
197
, help='Link to a shared C-Ares DLL instead of static linking'
198
, dest='shared_cares'
201
opt.add_option( '--shared-cares-includes'
204
, help='Directory containing C-Ares header files'
205
, dest='shared_cares_includes'
208
opt.add_option( '--shared-cares-libpath'
211
, help='A directory to search for the shared C-Ares DLL'
212
, dest='shared_cares_libpath'
216
opt.add_option( '--with-dtrace'
217
, action='store_true'
219
, help='Build with DTrace (experimental)'
224
opt.add_option( '--product-type'
227
, help='What kind of product to produce (program, cstaticlib '\
228
'or cshlib) [default: %default]'
229
, dest='product_type'
232
opt.add_option( '--dest-cpu'
235
, help='CPU architecture to build for. Valid values are: '+\
236
', '.join(supported_archs)
240
def get_node_version():
241
def get_define_value(lines, define):
244
return line.split()[-1] #define <NAME> <VALUE>
246
lines = open("src/node_version.h").readlines()
247
node_major_version = get_define_value(lines, 'NODE_MAJOR_VERSION')
248
node_minor_version = get_define_value(lines, 'NODE_MINOR_VERSION')
249
node_patch_version = get_define_value(lines, 'NODE_PATCH_VERSION')
250
node_is_release = get_define_value(lines, 'NODE_VERSION_IS_RELEASE')
252
return "%s.%s.%s%s" % ( node_major_version,
255
node_is_release == "0" and "-pre" or ""
258
def arch_cflags(conf):
261
if 'DEST_CPU' in conf.env:
262
arch = conf.env['DEST_CPU']
267
if sys.platform.startswith('darwin'):
268
flags += ['-arch', {'ia32':'i386', 'x64':'x86_64'}.get(arch, arch)]
273
conf.check_tool('compiler_cxx')
274
if not conf.env.CXX: conf.fatal('c++ compiler not found')
275
conf.check_tool('compiler_cc')
276
if not conf.env.CC: conf.fatal('c compiler not found')
281
conf.env['LIBDIR'] = o.libdir
283
conf.env['LIBDIR'] = conf.env['PREFIX'] + '/lib'
285
conf.env["USE_DEBUG"] = o.debug
286
# Snapshot building does noet seem to work on mingw32
287
conf.env["SNAPSHOT_V8"] = not o.without_snapshot and not sys.platform.startswith("win32")
288
if sys.platform.startswith("sunos"):
289
conf.env["SNAPSHOT_V8"] = False
290
conf.env["USE_PROFILING"] = o.profile
292
conf.env["USE_SHARED_V8"] = o.shared_v8 or o.shared_v8_includes or o.shared_v8_libpath or o.shared_v8_libname
293
conf.env["USE_SHARED_CARES"] = o.shared_cares or o.shared_cares_includes or o.shared_cares_libpath
294
conf.env["USE_SHARED_ZLIB"] = o.shared_zlib or o.shared_zlib_includes or o.shared_zlib_libpath
296
conf.env["USE_GDBJIT"] = o.use_gdbjit
297
conf.env['USE_NPM'] = not o.without_npm
299
if not conf.env["USE_SHARED_ZLIB"] and not sys.platform.startswith("win32"):
300
conf.env.append_value("LINKFLAGS", "-lz")
302
conf.check(lib='dl', uselib_store='DL')
303
if not sys.platform.startswith("sunos") and not sys.platform.startswith("win32"):
304
conf.env.append_value("CCFLAGS", "-rdynamic")
305
conf.env.append_value("LINKFLAGS_DL", "-rdynamic")
307
if 'bsd' in sys.platform:
308
conf.check(lib='kvm', uselib_store='KVM')
310
#if Options.options.debug:
311
# conf.check(lib='profiler', uselib_store='PROFILER')
313
if Options.options.dtrace:
314
if not sys.platform.startswith("sunos"):
315
conf.fatal('DTrace support only currently available on Solaris')
317
conf.find_program('dtrace', var='DTRACE', mandatory=True)
318
conf.env["USE_DTRACE"] = True
319
conf.env.append_value("CXXFLAGS", "-DHAVE_DTRACE=1")
321
if Options.options.efence:
322
conf.check(lib='efence', libpath=['/usr/lib', '/usr/local/lib'], uselib_store='EFENCE')
324
if 'bsd' in sys.platform:
325
if not conf.check(lib="execinfo",
326
includes=['/usr/include', '/usr/local/include'],
327
libpath=['/usr/lib', '/usr/local/lib'],
328
uselib_store="EXECINFO"):
329
conf.fatal("Install the libexecinfo port from /usr/ports/devel/libexecinfo.")
331
if not Options.options.without_ssl:
332
# Don't override explicitly supplied openssl paths with pkg-config results.
333
explicit_openssl = o.openssl_includes or o.openssl_libpath
335
# Disable ssl v2 methods
337
conf.env.append_value("CPPFLAGS", "-DOPENSSL_NO_SSL2=1")
339
if not explicit_openssl and conf.check_cfg(package='openssl',
340
args='--cflags --libs',
341
uselib_store='OPENSSL'):
342
Options.options.use_openssl = conf.env["USE_OPENSSL"] = True
343
conf.env.append_value("CPPFLAGS", "-DHAVE_OPENSSL=1")
345
if o.openssl_libpath:
346
openssl_libpath = [o.openssl_libpath]
347
elif not sys.platform.startswith('win32'):
348
openssl_libpath = ['/usr/lib', '/usr/local/lib', '/opt/local/lib', '/usr/sfw/lib']
350
openssl_libpath = [normpath(join(cwd, '../openssl'))]
352
if o.openssl_includes:
353
openssl_includes = [o.openssl_includes]
354
elif not sys.platform.startswith('win32'):
355
openssl_includes = [];
357
openssl_includes = [normpath(join(cwd, '../openssl/include'))];
359
openssl_lib_names = ['ssl', 'crypto']
360
if sys.platform.startswith('win32'):
361
openssl_lib_names += ['ws2_32', 'gdi32']
363
libssl = conf.check_cc(lib=openssl_lib_names,
364
header_name='openssl/ssl.h',
365
function_name='SSL_library_init',
366
includes=openssl_includes,
367
libpath=openssl_libpath,
368
uselib_store='OPENSSL')
370
libcrypto = conf.check_cc(lib='crypto',
371
header_name='openssl/crypto.h',
372
includes=openssl_includes,
373
libpath=openssl_libpath,
374
uselib_store='OPENSSL')
376
if libcrypto and libssl:
377
conf.env["USE_OPENSSL"] = Options.options.use_openssl = True
378
conf.env.append_value("CPPFLAGS", "-DHAVE_OPENSSL=1")
379
elif sys.platform.startswith('win32'):
380
conf.fatal("Could not autodetect OpenSSL support. " +
381
"Use the --openssl-libpath and --openssl-includes options to set the search path. " +
382
"Use configure --without-ssl to disable this message.")
384
conf.fatal("Could not autodetect OpenSSL support. " +
385
"Make sure OpenSSL development packages are installed. " +
386
"Use configure --without-ssl to disable this message.")
388
Options.options.use_openssl = conf.env["USE_OPENSSL"] = False
390
conf.check(lib='util', libpath=['/usr/lib', '/usr/local/lib'],
393
# normalize DEST_CPU from --dest-cpu, DEST_CPU or built-in value
394
if Options.options.dest_cpu and Options.options.dest_cpu:
395
conf.env['DEST_CPU'] = canonical_cpu_type(Options.options.dest_cpu)
396
elif 'DEST_CPU' in os.environ and os.environ['DEST_CPU']:
397
conf.env['DEST_CPU'] = canonical_cpu_type(os.environ['DEST_CPU'])
398
elif 'DEST_CPU' in conf.env and conf.env['DEST_CPU']:
399
conf.env['DEST_CPU'] = canonical_cpu_type(conf.env['DEST_CPU'])
401
have_librt = conf.check(lib='rt', uselib_store='RT')
403
if sys.platform.startswith("sunos"):
407
struct ifaddrs hello;
412
if conf.check_cc(msg="Checking for ifaddrs on solaris", fragment=code):
413
conf.env.append_value('CPPFLAGS', '-DSUNOS_HAVE_IFADDRS')
415
if not conf.check(lib='socket', uselib_store="SOCKET"):
416
conf.fatal("Cannot find socket library")
417
if not conf.check(lib='nsl', uselib_store="NSL"):
418
conf.fatal("Cannot find nsl library")
419
if not conf.check(lib='kstat', uselib_store="KSTAT"):
420
conf.fatal("Cannot find kstat library")
422
if conf.env['USE_SHARED_V8']:
424
if o.shared_v8_includes: v8_includes.append(o.shared_v8_includes);
427
if o.shared_v8_libpath: v8_libpath.append(o.shared_v8_libpath);
429
if not o.shared_v8_libname: o.shared_v8_libname = 'v8'
431
if not conf.check_cxx(lib=o.shared_v8_libname, header_name='v8.h',
433
includes=v8_includes,
435
conf.fatal("Cannot find v8")
438
if not conf.check_cxx(lib=o.shared_v8_libname + '_g', header_name='v8.h',
440
includes=v8_includes,
442
conf.fatal("Cannot find v8_g")
444
conf.define("HAVE_CONFIG_H", 1)
446
if sys.platform.startswith("sunos"):
447
conf.env.append_value ('CCFLAGS', '-threads')
448
conf.env.append_value ('CXXFLAGS', '-threads')
449
#conf.env.append_value ('LINKFLAGS', ' -threads')
450
elif not sys.platform.startswith("win32"):
451
threadflags='-pthread'
452
conf.env.append_value ('CCFLAGS', threadflags)
453
conf.env.append_value ('CXXFLAGS', threadflags)
454
conf.env.append_value ('LINKFLAGS', threadflags)
456
if sys.platform.startswith('darwin'):
457
# used by platform_darwin_*.cc
458
conf.env.append_value('LINKFLAGS', ['-framework','Carbon'])
460
flags = arch_cflags(conf)
461
conf.env.append_value('CCFLAGS', flags)
462
conf.env.append_value('CXXFLAGS', flags)
463
conf.env.append_value('LINKFLAGS', flags)
466
conf.env.append_value('CPPFLAGS', '-D_LARGEFILE_SOURCE')
467
conf.env.append_value('CPPFLAGS', '-D_FILE_OFFSET_BITS=64')
469
if sys.platform.startswith('darwin'):
470
conf.env.append_value('CPPFLAGS', '-D_DARWIN_USE_64_BIT_INODE=1')
472
# Makes select on windows support more than 64 FDs
473
if sys.platform.startswith("win32"):
474
conf.env.append_value('CPPFLAGS', '-DFD_SETSIZE=1024');
476
## needed for node_file.cc fdatasync
477
## Strangely on OSX 10.6 the g++ doesn't see fdatasync but gcc does?
487
if conf.check_cxx(msg="Checking for fdatasync(2) with c++", fragment=code):
488
conf.env.append_value('CPPFLAGS', '-DHAVE_FDATASYNC=1')
490
conf.env.append_value('CPPFLAGS', '-DHAVE_FDATASYNC=0')
493
conf.env.append_value('CPPFLAGS', '-DARCH="' + conf.env['DEST_CPU'] + '"')
496
conf.env.append_value('CPPFLAGS', '-DPLATFORM="' + conf.env['DEST_OS'] + '"')
499
if not sys.platform.startswith('win'):
500
conf.env.append_value('CPPFLAGS', '-D__POSIX__=1')
502
platform_file = "src/platform_%s.cc" % conf.env['DEST_OS']
503
if os.path.exists(join(cwd, platform_file)):
504
Options.options.platform_file = True
505
conf.env["PLATFORM_FILE"] = platform_file
507
Options.options.platform_file = False
508
conf.env["PLATFORM_FILE"] = "src/platform_none.cc"
510
if conf.env['USE_PROFILING'] == True:
511
conf.env.append_value('CPPFLAGS', '-pg')
512
conf.env.append_value('LINKFLAGS', '-pg')
514
if sys.platform.startswith("win32"):
515
conf.env.append_value('LIB', 'psapi')
516
conf.env.append_value('LIB', 'winmm')
517
# This enforces ws2_32 to be linked after crypto, otherwise the linker
518
# will run into undefined references from libcrypto.a
519
if not Options.options.use_openssl:
520
conf.env.append_value('LIB', 'ws2_32')
522
conf.env.append_value('CPPFLAGS', '-Wno-unused-parameter');
523
conf.env.append_value('CPPFLAGS', '-D_FORTIFY_SOURCE=2');
525
# Split off debug variant before adding variant specific defines
526
debug_env = conf.env.copy()
527
conf.set_env_name('Debug', debug_env)
529
# Configure debug variant
531
debug_env.set_variant('Debug')
532
debug_env.append_value('CPPFLAGS', '-DDEBUG')
533
debug_compile_flags = ['-g', '-O0', '-Wall', '-Wextra']
534
debug_env.append_value('CCFLAGS', debug_compile_flags)
535
debug_env.append_value('CXXFLAGS', debug_compile_flags)
536
conf.write_config_header("config.h")
538
# Configure default variant
539
conf.setenv('Release')
540
default_compile_flags = ['-g', '-O3']
541
conf.env.append_value('CCFLAGS', default_compile_flags)
542
conf.env.append_value('CXXFLAGS', default_compile_flags)
543
conf.write_config_header("config.h")
546
def v8_cmd(bld, variant):
547
scons = join(cwd, 'tools/scons/scons.py')
548
deps_src = join(bld.path.abspath(),"deps")
549
v8dir_src = join(deps_src,"v8")
551
# NOTE: We want to compile V8 to export its symbols. I.E. Do not want
552
# -fvisibility=hidden. When using dlopen() it seems that the loaded DSO
553
# cannot see symbols in the executable which are hidden, even if the
554
# executable is statically linked together...
556
# XXX Change this when v8 defaults x86_64 to native builds
557
# Possible values are (arm, ia32, x64, mips).
559
if bld.env['DEST_CPU']:
560
arch = "arch="+bld.env['DEST_CPU']
564
if variant == "Release":
569
if bld.env["SNAPSHOT_V8"]:
570
snapshot = "snapshot=on"
574
cmd_R = sys.executable + ' "%s" -j %d -C "%s" -Y "%s" visibility=default mode=%s %s toolchain=%s library=static %s'
576
cmd = cmd_R % ( scons
577
, Options.options.jobs
578
, safe_path(bld.srcnode.abspath(bld.env_of_name(variant)))
579
, safe_path(v8dir_src)
586
if bld.env["USE_GDBJIT"]:
589
if sys.platform.startswith("sunos"):
590
cmd += ' toolchain=gcc strictaliasing=off'
594
return ("echo '%s' && " % cmd) + cmd
598
v8 = bld.new_task_gen(
599
source = 'deps/v8/SConstruct '
600
+ bld.path.ant_glob('v8/include/*')
601
+ bld.path.ant_glob('v8/src/*'),
602
target = bld.env["staticlib_PATTERN"] % "v8",
603
rule = v8_cmd(bld, "Release"),
607
v8.env.env = dict(os.environ)
608
v8.env.env['CC'] = sh_escape(bld.env['CC'][0])
609
v8.env.env['CXX'] = sh_escape(bld.env['CXX'][0])
611
v8.uselib = "EXECINFO"
612
bld.env["CPPPATH_V8"] = "deps/v8/include"
613
t = join(bld.srcnode.abspath(bld.env_of_name("Release")), v8.target)
614
bld.env_of_name('Release').append_value("LINKFLAGS_V8", t)
617
if bld.env["USE_DEBUG"]:
618
v8_debug = v8.clone("Debug")
619
v8_debug.rule = v8_cmd(bld, "Debug")
620
v8_debug.target = bld.env["staticlib_PATTERN"] % "v8_g"
621
v8_debug.uselib = "EXECINFO"
622
bld.env["CPPPATH_V8_G"] = "deps/v8/include"
623
t = join(bld.srcnode.abspath(bld.env_of_name("Debug")), v8_debug.target)
624
bld.env_of_name('Debug').append_value("LINKFLAGS_V8_G", t)
626
bld.install_files('${PREFIX}/include/node/', 'deps/v8/include/*.h')
629
if sys.platform.startswith('win32'):
632
return s.replace("\\", "\\\\").replace("(","\\(").replace(")","\\)").replace(" ","\\ ")
634
def uv_cmd(bld, variant):
635
srcdeps = join(bld.path.abspath(), "deps")
636
srcdir = join(srcdeps, "uv")
637
blddir = bld.srcnode.abspath(bld.env_of_name(variant)) + '/deps/uv'
639
# FIXME This is awful! We're copying the entire source directory into the
640
# build directory before each compile. This could be much improved by
641
# modifying libuv's build to send object files to a separate directory.
643
cmd = 'cp -r ' + sh_escape(srcdir) + '/* ' + sh_escape(blddir)
644
if not sys.platform.startswith('win32'):
645
make = ('if [ -z "$NODE_MAKE" ]; then NODE_MAKE=make; fi; '
646
'$NODE_MAKE -C ' + sh_escape(blddir))
647
flags = arch_cflags(bld)
648
if flags: make += ' CFLAGS=\'%s\'' % ' '.join(flags) # don't escape
650
make = 'make -C ' + sh_escape(blddir)
651
return '%s && (%s clean) && (%s all)' % (cmd, make, make)
655
uv = bld.new_task_gen(
657
source = 'deps/uv/include/uv.h',
658
target = 'deps/uv/uv.a',
660
rule = uv_cmd(bld, 'Release')
663
uv.env.env = dict(os.environ)
664
uv.env.env['CC'] = sh_escape(bld.env['CC'][0])
665
uv.env.env['CXX'] = sh_escape(bld.env['CXX'][0])
667
t = join(bld.srcnode.abspath(bld.env_of_name("Release")), uv.target)
668
bld.env_of_name('Release').append_value("LINKFLAGS_UV", t)
670
if bld.env["USE_DEBUG"]:
671
uv_debug = uv.clone("Debug")
672
uv_debug.rule = uv_cmd(bld, 'Debug')
673
uv_debug.env.env = dict(os.environ)
675
t = join(bld.srcnode.abspath(bld.env_of_name("Debug")), uv_debug.target)
676
bld.env_of_name('Debug').append_value("LINKFLAGS_UV", t)
678
bld.install_files('${PREFIX}/include/node/', 'deps/uv/include/*.h')
679
bld.install_files('${PREFIX}/include/node/uv-private', 'deps/uv/include/uv-private/*.h')
680
bld.install_files('${PREFIX}/include/node/ev', 'deps/uv/src/ev/*.h')
681
bld.install_files('${PREFIX}/include/node/c-ares', """
682
deps/uv/include/ares.h
683
deps/uv/include/ares_version.h
688
## This snippet is to show full commands as WAF executes
690
old = Build.BuildContext.exec_command
691
def exec_command(self, cmd, **kw):
692
if isinstance(cmd, list): print(" ".join(cmd))
693
return old(self, cmd, **kw)
694
Build.BuildContext.exec_command = exec_command
696
Options.options.jobs=jobs
697
product_type = Options.options.product_type
698
product_type_is_lib = product_type != 'program'
700
print "DEST_OS: " + bld.env['DEST_OS']
701
print "DEST_CPU: " + bld.env['DEST_CPU']
702
print "Parallel Jobs: " + str(Options.options.jobs)
703
print "Product type: " + product_type
707
if not bld.env['USE_SHARED_V8']: build_v8(bld)
711
http_parser = bld.new_task_gen("cc")
712
http_parser.source = "deps/http_parser/http_parser.c"
713
http_parser.includes = "deps/http_parser/"
714
http_parser.name = "http_parser"
715
http_parser.target = "http_parser"
716
http_parser.install_path = None
717
if bld.env["USE_DEBUG"]:
718
http_parser.clone("Debug")
719
if product_type_is_lib:
720
http_parser.ccflags = '-fPIC'
723
def make_macros(loc, content):
728
macros_loc_debug = join(
729
bld.srcnode.abspath(bld.env_of_name("Debug")),
733
macros_loc_default = join(
734
bld.srcnode.abspath(bld.env_of_name("Release")),
738
### We need to truncate the macros.py file
739
f = open(macros_loc_debug, 'w')
741
f = open(macros_loc_default, 'w')
744
make_macros(macros_loc_debug, "") # leave debug(x) as is in debug build
745
# replace debug(x) with nothing in release build
746
make_macros(macros_loc_default, "macro debug(x) = ;\n")
747
make_macros(macros_loc_default, "macro assert(x) = ;\n")
749
if not bld.env["USE_DTRACE"]:
751
'DTRACE_HTTP_CLIENT_REQUEST',
752
'DTRACE_HTTP_CLIENT_RESPONSE',
753
'DTRACE_HTTP_SERVER_REQUEST',
754
'DTRACE_HTTP_SERVER_RESPONSE',
755
'DTRACE_NET_SERVER_CONNECTION',
756
'DTRACE_NET_STREAM_END',
757
'DTRACE_NET_SOCKET_READ',
758
'DTRACE_NET_SOCKET_WRITE'
762
make_macros(macros_loc_default, "macro %s(x) = ;\n" % probe)
763
make_macros(macros_loc_debug, "macro %s(x) = ;\n" % probe)
765
def javascript_in_c(task):
767
source = map(lambda x: x.srcpath(env), task.inputs)
768
targets = map(lambda x: x.srcpath(env), task.outputs)
769
source.append(macros_loc_default)
770
js2c.JS2C(source, targets)
772
def javascript_in_c_debug(task):
774
source = map(lambda x: x.srcpath(env), task.inputs)
775
targets = map(lambda x: x.srcpath(env), task.outputs)
776
source.append(macros_loc_debug)
777
js2c.JS2C(source, targets)
779
native_cc = bld.new_task_gen(
780
source='src/node.js ' + bld.path.ant_glob('lib/*.js'),
781
target="src/node_natives.h",
786
# Add the rule /after/ cloning the debug
787
# This is a work around for an error had in python 2.4.3 (I'll paste the
788
# error that was had into the git commit meessage. git-blame to find out
790
if bld.env["USE_DEBUG"]:
791
native_cc_debug = native_cc.clone("Debug")
792
native_cc_debug.rule = javascript_in_c_debug
794
native_cc.rule = javascript_in_c_debug
796
if bld.env["USE_DTRACE"]:
797
dtrace_usdt = bld.new_task_gen(
798
name = "dtrace_usdt",
799
source = "src/node_provider.d",
800
target = "src/node_provider.h",
801
rule = "%s -x nolibs -h -o ${TGT} -s ${SRC}" % (bld.env.DTRACE),
805
if bld.env["USE_DEBUG"]:
806
dtrace_usdt_g = dtrace_usdt.clone("Debug")
808
bld.install_files('${LIBDIR}/dtrace', 'src/node.d')
810
if sys.platform.startswith("sunos"):
812
# The USDT DTrace provider works slightly differently on Solaris than on
813
# the Mac; on Solaris, any objects that have USDT DTrace probes must be
814
# post-processed with the DTrace command. (This is not true on the
815
# Mac, which has first-class linker support for USDT probes.) On
816
# Solaris, we must therefore post-process our object files. Waf doesn't
817
# seem to really have a notion for this, so we inject a task after
818
# compiling and before linking, and then find all of the node object
819
# files and shuck them off to dtrace (which will modify them in place
822
def dtrace_postprocess(task):
823
abspath = bld.srcnode.abspath(bld.env_of_name(task.env.variant()))
824
objs = glob.glob(abspath + 'src/*.o')
825
source = task.inputs[0].srcpath(task.env)
826
target = task.outputs[0].srcpath(task.env)
827
cmd = '%s -G -x nolibs -s %s -o %s %s' % (task.env.DTRACE,
831
Utils.exec_command(cmd)
834
# ustack helpers do not currently work on MacOS. We currently only
835
# support 32-bit x86.
837
def dtrace_do_ustack(task):
838
abspath = bld.srcnode.abspath(bld.env_of_name(task.env.variant()))
839
source = task.inputs[0].srcpath(task.env)
840
target = task.outputs[0].srcpath(task.env)
841
cmd = '%s -32 -I../src -C -G -s %s -o %s' % (task.env.DTRACE, source, target)
842
Utils.exec_command(cmd)
844
dtrace_ustack = bld.new_task_gen(
845
name = "dtrace_ustack-postprocess",
846
source = "src/v8ustack.d",
847
target = "v8ustack.o",
851
rule = dtrace_do_ustack
854
dtracepost = bld.new_task_gen(
855
name = "dtrace_usdt-postprocess",
856
source = "src/node_provider.d",
857
target = "node_provider.o",
861
rule = dtrace_postprocess
864
t = join(bld.srcnode.abspath(bld.env_of_name("Release")), dtracepost.target)
865
bld.env_of_name('Release').append_value('LINKFLAGS', t)
867
t = join(bld.srcnode.abspath(bld.env_of_name("Release")), dtrace_ustack.target)
868
bld.env_of_name('Release').append_value('LINKFLAGS', t)
871
# Note that for the same (mysterious) issue outlined above with respect
872
# to assigning the rule to native_cc/native_cc_debug, we must apply the
873
# rule to dtracepost/dtracepost_g only after they have been cloned. We
874
# also must put node_provider.o on the link line, but because we
875
# (apparently?) lack LINKFLAGS in debug, we (shamelessly) stowaway on
878
if bld.env["USE_DEBUG"]:
879
dtracepost_g = dtracepost.clone("Debug")
880
dtracepost_g.rule = dtrace_postprocess
881
t = join(bld.srcnode.abspath(bld.env_of_name("Debug")), dtracepost.target)
882
bld.env_of_name("Debug").append_value('LINKFLAGS_V8_G', t)
886
node = bld.new_task_gen("cxx", product_type)
889
node.uselib = 'RT OPENSSL ZLIB CARES EXECINFO DL KVM SOCKET NSL KSTAT UTIL OPROFILE'
890
node.add_objects = 'http_parser'
891
if product_type_is_lib:
892
node.install_path = '${LIBDIR}'
894
node.install_path = '${PREFIX}/bin'
899
src/node_javascript.cc
900
src/node_extensions.cc
901
src/node_http_parser.cc
902
src/node_constants.cc
919
src/v8_typed_array.cc
922
if bld.env["USE_DTRACE"]:
923
node.source += " src/node_dtrace.cc "
925
if not sys.platform.startswith("win32"):
926
node.source += " src/node_signal_watcher.cc "
927
node.source += " src/node_stat_watcher.cc "
928
node.source += " src/node_io_watcher.cc "
930
node.source += bld.env["PLATFORM_FILE"]
931
if not product_type_is_lib:
932
node.source = 'src/node_main.cc '+node.source
934
if bld.env["USE_OPENSSL"]: node.source += " src/node_crypto.cc "
944
if not bld.env["USE_SHARED_V8"]: node.includes += ' deps/v8/include '
946
if os.environ.has_key('RPATH'):
947
node.rpath = os.environ['RPATH']
949
if (sys.platform.startswith("win32")):
951
bld.env.append_value('LINKFLAGS', '-static-libgcc')
952
bld.env.append_value('LINKFLAGS', '-static-libstdc++')
954
def subflags(program):
955
x = { 'CCFLAGS' : " ".join(program.env["CCFLAGS"]).replace('"', '\\"')
956
, 'CPPFLAGS' : " ".join(program.env["CPPFLAGS"]).replace('"', '\\"')
957
, 'LIBFLAGS' : " ".join(program.env["LIBFLAGS"]).replace('"', '\\"')
958
, 'PREFIX' : safe_path(program.env["PREFIX"])
959
, 'VERSION' : get_node_version()
963
# process file.pc.in -> file.pc
965
node_conf = bld.new_task_gen('subst', before="cxx")
966
node_conf.source = 'src/node_config.h.in'
967
node_conf.target = 'src/node_config.h'
968
node_conf.dict = subflags(node)
969
node_conf.install_path = '${PREFIX}/include/node'
971
if bld.env["USE_DEBUG"]:
972
node_g = node.clone("Debug")
973
node_g.target = "node"
974
node_g.uselib += ' V8_G UV '
975
node_g.install_path = None
977
node_conf_g = node_conf.clone("Debug")
978
node_conf_g.dict = subflags(node_g)
979
node_conf_g.install_path = None
981
# After creating the debug clone, append the V8 dep
982
node.uselib += ' V8 UV '
984
bld.install_files('${PREFIX}/include/node/', """
987
src/node_object_wrap.h
992
# Only install the man page if it exists.
993
# Do 'make doc install' to build and install it.
994
if os.path.exists('doc/node.1'):
995
prefix = 'bsd' in sys.platform and '${PREFIX}' or '${PREFIX}/share'
996
bld.install_files(prefix + '/man/man1/', 'doc/node.1')
998
bld.install_files('${PREFIX}/bin/', 'tools/node-waf', chmod=0755)
999
bld.install_files('${LIBDIR}/node/wafadmin', 'tools/wafadmin/*.py')
1000
bld.install_files('${LIBDIR}/node/wafadmin/Tools', 'tools/wafadmin/Tools/*.py')
1002
if bld.env['USE_NPM']:
1005
def install_npm(bld):
1006
start_dir = bld.path.find_dir('deps/npm')
1007
# The chmod=-1 is a Node hack. We changed WAF so that when chmod was set to
1008
# -1 that the same permission in this tree are used. Necessary to get
1009
# npm-cli.js to be executable without having to list every file in npm.
1010
bld.install_files('${LIBDIR}/node_modules/npm',
1011
start_dir.ant_glob('**/*'),
1013
relative_trick=True,
1015
bld.symlink_as('${PREFIX}/bin/npm',
1016
'../lib/node_modules/npm/bin/npm-cli.js')
1019
Options.options.debug
1020
# HACK to get binding.node out of build directory.
1021
# better way to do this?
1022
if Options.commands['configure']:
1023
if not Options.options.use_openssl:
1024
print "WARNING WARNING WARNING"
1025
print "OpenSSL not found. Will compile Node without crypto support!"
1027
if not Options.options.platform_file:
1028
print "WARNING: Platform not fully supported. Using src/platform_none.cc"
1030
elif not Options.commands['clean']:
1031
if sys.platform.startswith("win32"):
1032
if os.path.exists('out/Release/node.exe'):
1033
os.system('cp out/Release/node.exe .')
1034
if os.path.exists('out/Debug/node.exe'):
1035
os.system('cp out/Debug/node.exe node_g.exe')
1037
if os.path.exists('out/Release/node') and not os.path.islink('node'):
1038
os.symlink('out/Release/node', 'node')
1039
if os.path.exists('out/Debug/node') and not os.path.islink('node_g'):
1040
os.symlink('out/Debug/node', 'node_g')
1042
if sys.platform.startswith("win32"):
1043
if os.path.exists('node.exe'): os.unlink('node.exe')
1044
if os.path.exists('node_g.exe'): os.unlink('node_g.exe')
1046
if os.path.exists('node'): os.unlink('node')
1047
if os.path.exists('node_g'): os.unlink('node_g')