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') # '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', 'mipsel':'mips'}
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'
215
opt.add_option('--shared-libev'
216
, action='store_true'
218
, help='Link to a shared libev DLL instead of static linking'
219
, dest='shared_libev'
222
opt.add_option( '--shared-libev-includes'
225
, help='Directory containing libev header files'
226
, dest='shared_libev_includes'
229
opt.add_option( '--shared-libev-libpath'
232
, help='A directory to search for the shared libev DLL'
233
, dest='shared_libev_libpath'
236
opt.add_option( '--with-dtrace'
237
, action='store_true'
239
, help='Build with DTrace (experimental)'
244
opt.add_option( '--product-type'
247
, help='What kind of product to produce (program, cstaticlib '\
248
'or cshlib) [default: %default]'
249
, dest='product_type'
252
opt.add_option( '--dest-cpu'
255
, help='CPU architecture to build for. Valid values are: '+\
256
', '.join(supported_archs)
260
def get_node_version():
261
def get_define_value(lines, define):
264
return line.split()[-1] #define <NAME> <VALUE>
266
lines = open("src/node_version.h").readlines()
267
node_major_version = get_define_value(lines, 'NODE_MAJOR_VERSION')
268
node_minor_version = get_define_value(lines, 'NODE_MINOR_VERSION')
269
node_patch_version = get_define_value(lines, 'NODE_PATCH_VERSION')
270
node_is_release = get_define_value(lines, 'NODE_VERSION_IS_RELEASE')
272
return "%s.%s.%s%s" % ( node_major_version,
275
node_is_release == "0" and "-pre" or ""
278
def arch_cflags(conf):
281
if 'DEST_CPU' in conf.env:
282
arch = conf.env['DEST_CPU']
287
if sys.platform.startswith('darwin'):
288
flags += ['-arch', {'ia32':'i386', 'x64':'x86_64'}.get(arch, arch)]
293
conf.check_tool('compiler_cxx')
294
if not conf.env.CXX: conf.fatal('c++ compiler not found')
295
conf.check_tool('compiler_cc')
296
if not conf.env.CC: conf.fatal('c compiler not found')
301
conf.env['LIBDIR'] = o.libdir
303
conf.env['LIBDIR'] = conf.env['PREFIX'] + '/lib'
305
conf.env["USE_DEBUG"] = o.debug
306
# Snapshot building does noet seem to work on mingw32
307
conf.env["SNAPSHOT_V8"] = not o.without_snapshot and not sys.platform.startswith("win32")
308
if sys.platform.startswith("sunos"):
309
conf.env["SNAPSHOT_V8"] = False
310
conf.env["USE_PROFILING"] = o.profile
312
conf.env["USE_SHARED_V8"] = o.shared_v8 or o.shared_v8_includes or o.shared_v8_libpath or o.shared_v8_libname
313
conf.env["USE_SHARED_CARES"] = o.shared_cares or o.shared_cares_includes or o.shared_cares_libpath
314
conf.env["USE_SHARED_LIBEV"] = o.shared_libev or o.shared_libev_includes or o.shared_libev_libpath
315
conf.env["USE_SHARED_ZLIB"] = o.shared_zlib or o.shared_zlib_includes or o.shared_zlib_libpath
317
conf.env["USE_GDBJIT"] = o.use_gdbjit
318
conf.env['USE_NPM'] = not o.without_npm
320
conf.check(lib='dl', uselib_store='DL')
321
if not sys.platform.startswith("sunos") and not sys.platform.startswith("win32"):
322
conf.env.append_value("CCFLAGS", "-rdynamic")
323
conf.env.append_value("LINKFLAGS_DL", "-rdynamic")
325
if 'bsd' in sys.platform:
326
conf.check(lib='kvm', uselib_store='KVM')
328
#if Options.options.debug:
329
# conf.check(lib='profiler', uselib_store='PROFILER')
331
if Options.options.dtrace:
332
if not sys.platform.startswith("sunos"):
333
conf.fatal('DTrace support only currently available on Solaris')
335
conf.find_program('dtrace', var='DTRACE', mandatory=True)
336
conf.env["USE_DTRACE"] = True
337
conf.env.append_value("CXXFLAGS", "-DHAVE_DTRACE=1")
339
if Options.options.efence:
340
conf.check(lib='efence', libpath=['/usr/lib', '/usr/local/lib'], uselib_store='EFENCE')
342
if 'bsd' in sys.platform:
343
if not conf.check(lib="execinfo",
344
includes=['/usr/include', '/usr/local/include'],
345
libpath=['/usr/lib', '/usr/local/lib'],
346
uselib_store="EXECINFO"):
347
conf.fatal("Install the libexecinfo port from /usr/ports/devel/libexecinfo.")
349
if not Options.options.without_ssl:
350
# Don't override explicitly supplied openssl paths with pkg-config results.
351
explicit_openssl = o.openssl_includes or o.openssl_libpath
353
# Disable ssl v2 methods
355
conf.env.append_value("CPPFLAGS", "-DOPENSSL_NO_SSL2=1")
357
if not explicit_openssl and conf.check_cfg(package='openssl',
358
args='--cflags --libs',
359
uselib_store='OPENSSL'):
360
Options.options.use_openssl = conf.env["USE_OPENSSL"] = True
361
conf.env.append_value("CPPFLAGS", "-DHAVE_OPENSSL=1")
363
if o.openssl_libpath:
364
openssl_libpath = [o.openssl_libpath]
365
elif not sys.platform.startswith('win32'):
366
openssl_libpath = ['/usr/lib', '/usr/local/lib', '/opt/local/lib', '/usr/sfw/lib']
368
openssl_libpath = [normpath(join(cwd, '../openssl'))]
370
if o.openssl_includes:
371
openssl_includes = [o.openssl_includes]
372
elif not sys.platform.startswith('win32'):
373
openssl_includes = [];
375
openssl_includes = [normpath(join(cwd, '../openssl/include'))];
377
openssl_lib_names = ['ssl', 'crypto']
378
if sys.platform.startswith('win32'):
379
openssl_lib_names += ['ws2_32', 'gdi32']
381
libssl = conf.check_cc(lib=openssl_lib_names,
382
header_name='openssl/ssl.h',
383
function_name='SSL_library_init',
384
includes=openssl_includes,
385
libpath=openssl_libpath,
386
uselib_store='OPENSSL')
388
libcrypto = conf.check_cc(lib='crypto',
389
header_name='openssl/crypto.h',
390
includes=openssl_includes,
391
libpath=openssl_libpath,
392
uselib_store='OPENSSL')
394
if libcrypto and libssl:
395
conf.env["USE_OPENSSL"] = Options.options.use_openssl = True
396
conf.env.append_value("CPPFLAGS", "-DHAVE_OPENSSL=1")
397
elif sys.platform.startswith('win32'):
398
conf.fatal("Could not autodetect OpenSSL support. " +
399
"Use the --openssl-libpath and --openssl-includes options to set the search path. " +
400
"Use configure --without-ssl to disable this message.")
402
conf.fatal("Could not autodetect OpenSSL support. " +
403
"Make sure OpenSSL development packages are installed. " +
404
"Use configure --without-ssl to disable this message.")
406
Options.options.use_openssl = conf.env["USE_OPENSSL"] = False
408
conf.check(lib='util', libpath=['/usr/lib', '/usr/local/lib'],
411
# normalize DEST_CPU from --dest-cpu, DEST_CPU or built-in value
412
if Options.options.dest_cpu and Options.options.dest_cpu:
413
conf.env['DEST_CPU'] = canonical_cpu_type(Options.options.dest_cpu)
414
elif 'DEST_CPU' in os.environ and os.environ['DEST_CPU']:
415
conf.env['DEST_CPU'] = canonical_cpu_type(os.environ['DEST_CPU'])
416
elif 'DEST_CPU' in conf.env and conf.env['DEST_CPU']:
417
conf.env['DEST_CPU'] = canonical_cpu_type(conf.env['DEST_CPU'])
419
have_librt = conf.check(lib='rt', uselib_store='RT')
421
if sys.platform.startswith("sunos"):
425
struct ifaddrs hello;
430
if conf.check_cc(msg="Checking for ifaddrs on solaris", fragment=code):
431
conf.env.append_value('CPPFLAGS', '-DSUNOS_HAVE_IFADDRS')
433
if not conf.check(lib='socket', uselib_store="SOCKET"):
434
conf.fatal("Cannot find socket library")
435
if not conf.check(lib='nsl', uselib_store="NSL"):
436
conf.fatal("Cannot find nsl library")
437
if not conf.check(lib='kstat', uselib_store="KSTAT"):
438
conf.fatal("Cannot find kstat library")
440
if conf.env['USE_SHARED_V8']:
442
if o.shared_v8_includes: v8_includes.append(o.shared_v8_includes);
445
if o.shared_v8_libpath: v8_libpath.append(o.shared_v8_libpath);
447
if not o.shared_v8_libname: o.shared_v8_libname = 'v8'
449
if not conf.check_cxx(lib=o.shared_v8_libname, header_name='v8.h',
451
includes=v8_includes,
453
conf.fatal("Cannot find v8")
456
if not conf.check_cxx(lib=o.shared_v8_libname, header_name='v8.h',
458
includes=v8_includes,
460
conf.fatal("Cannot find v8_g")
462
if conf.env["USE_SHARED_ZLIB"] and not sys.platform.startswith("win32"):
463
conf.env.append_value("LINKFLAGS", "-lz")
465
if conf.env['USE_SHARED_CARES']:
467
if o.shared_cares_includes: cares_includes.append(o.shared_cares_includes);
469
if o.shared_cares_libpath: cares_libpath.append(o.shared_cares_libpath);
470
if not conf.check_cxx(lib='cares',
471
header_name='ares.h',
472
uselib_store='CARES',
473
includes=cares_includes,
474
libpath=cares_libpath):
475
conf.fatal("Cannot find c-ares")
478
if conf.env['USE_SHARED_LIBEV']:
480
if o.shared_libev_includes: libev_includes.append(o.shared_libev_includes);
482
if o.shared_libev_libpath: libev_libpath.append(o.shared_libev_libpath);
483
if not conf.check_cxx(lib='ev', header_name='ev.h',
485
includes=libev_includes,
486
libpath=libev_libpath):
487
conf.fatal("Cannot find libev")
489
conf.sub_config('deps/libev')
491
conf.define("HAVE_CONFIG_H", 1)
493
if sys.platform.startswith("sunos"):
494
conf.env.append_value ('CCFLAGS', '-threads')
495
conf.env.append_value ('CXXFLAGS', '-threads')
496
#conf.env.append_value ('LINKFLAGS', ' -threads')
497
elif not sys.platform.startswith("win32"):
498
threadflags='-pthread'
499
conf.env.append_value ('CCFLAGS', threadflags)
500
conf.env.append_value ('CXXFLAGS', threadflags)
501
conf.env.append_value ('LINKFLAGS', threadflags)
503
if sys.platform.startswith('darwin'):
504
# used by platform_darwin_*.cc
505
conf.env.append_value('LINKFLAGS', ['-framework','Carbon'])
507
flags = arch_cflags(conf)
508
conf.env.append_value('CCFLAGS', flags)
509
conf.env.append_value('CXXFLAGS', flags)
510
conf.env.append_value('LINKFLAGS', flags)
513
conf.env.append_value('CPPFLAGS', '-D_LARGEFILE_SOURCE')
514
conf.env.append_value('CPPFLAGS', '-D_FILE_OFFSET_BITS=64')
516
if sys.platform.startswith('darwin'):
517
conf.env.append_value('CPPFLAGS', '-D_DARWIN_USE_64_BIT_INODE=1')
519
# Makes select on windows support more than 64 FDs
520
if sys.platform.startswith("win32"):
521
conf.env.append_value('CPPFLAGS', '-DFD_SETSIZE=1024');
523
## needed for node_file.cc fdatasync
524
## Strangely on OSX 10.6 the g++ doesn't see fdatasync but gcc does?
534
if conf.check_cxx(msg="Checking for fdatasync(2) with c++", fragment=code):
535
conf.env.append_value('CPPFLAGS', '-DHAVE_FDATASYNC=1')
537
conf.env.append_value('CPPFLAGS', '-DHAVE_FDATASYNC=0')
540
conf.env.append_value('CPPFLAGS', '-DARCH="' + conf.env['DEST_CPU'] + '"')
543
conf.env.append_value('CPPFLAGS', '-DPLATFORM="' + conf.env['DEST_OS'] + '"')
546
if not sys.platform.startswith('win'):
547
conf.env.append_value('CPPFLAGS', '-D__POSIX__=1')
549
platform_file = "src/platform_%s.cc" % conf.env['DEST_OS']
550
if os.path.exists(join(cwd, platform_file)):
551
Options.options.platform_file = True
552
conf.env["PLATFORM_FILE"] = platform_file
554
Options.options.platform_file = False
555
conf.env["PLATFORM_FILE"] = "src/platform_none.cc"
557
if conf.env['USE_PROFILING'] == True:
558
conf.env.append_value('CPPFLAGS', '-pg')
559
conf.env.append_value('LINKFLAGS', '-pg')
561
if sys.platform.startswith("win32"):
562
conf.env.append_value('LIB', 'psapi')
563
conf.env.append_value('LIB', 'winmm')
564
# This enforces ws2_32 to be linked after crypto, otherwise the linker
565
# will run into undefined references from libcrypto.a
566
if not Options.options.use_openssl:
567
conf.env.append_value('LIB', 'ws2_32')
569
conf.env.append_value('CPPFLAGS', '-Wno-unused-parameter');
570
conf.env.append_value('CPPFLAGS', '-D_FORTIFY_SOURCE=2');
572
# Split off debug variant before adding variant specific defines
573
debug_env = conf.env.copy()
574
conf.set_env_name('Debug', debug_env)
576
# Configure debug variant
578
debug_env.set_variant('Debug')
579
debug_env.append_value('CPPFLAGS', '-DDEBUG')
580
debug_compile_flags = ['-g', '-O0', '-Wall', '-Wextra']
581
debug_env.append_value('CCFLAGS', debug_compile_flags)
582
debug_env.append_value('CXXFLAGS', debug_compile_flags)
583
conf.write_config_header("config.h")
585
# Configure default variant
586
conf.setenv('Release')
587
default_compile_flags = ['-g', '-O3']
588
conf.env.append_value('CCFLAGS', default_compile_flags)
589
conf.env.append_value('CXXFLAGS', default_compile_flags)
590
conf.write_config_header("config.h")
593
def v8_cmd(bld, variant):
594
scons = join(cwd, 'tools/scons/scons.py')
595
deps_src = join(bld.path.abspath(),"deps")
596
v8dir_src = join(deps_src,"v8")
598
# NOTE: We want to compile V8 to export its symbols. I.E. Do not want
599
# -fvisibility=hidden. When using dlopen() it seems that the loaded DSO
600
# cannot see symbols in the executable which are hidden, even if the
601
# executable is statically linked together...
603
# XXX Change this when v8 defaults x86_64 to native builds
604
# Possible values are (arm, ia32, x64, mips).
606
if bld.env['DEST_CPU']:
607
arch = "arch="+bld.env['DEST_CPU']
611
if variant == "Release":
616
if bld.env["SNAPSHOT_V8"]:
617
snapshot = "snapshot=on"
621
cmd_R = sys.executable + ' "%s" -j %d -C "%s" -Y "%s" visibility=default mode=%s %s toolchain=%s library=static %s'
623
cmd = cmd_R % ( scons
624
, Options.options.jobs
625
, safe_path(bld.srcnode.abspath(bld.env_of_name(variant)))
626
, safe_path(v8dir_src)
633
if bld.env["USE_GDBJIT"]:
636
if sys.platform.startswith("sunos"):
637
cmd += ' toolchain=gcc strictaliasing=off'
641
return ("echo '%s' && " % cmd) + cmd
645
v8 = bld.new_task_gen(
646
source = 'deps/v8/SConstruct '
647
+ bld.path.ant_glob('v8/include/*')
648
+ bld.path.ant_glob('v8/src/*'),
649
target = bld.env["staticlib_PATTERN"] % "v8",
650
rule = v8_cmd(bld, "Release"),
654
v8.env.env = dict(os.environ)
655
v8.env.env['CC'] = sh_escape(bld.env['CC'][0])
656
v8.env.env['CXX'] = sh_escape(bld.env['CXX'][0])
658
v8.uselib = "EXECINFO"
659
bld.env["CPPPATH_V8"] = "deps/v8/include"
660
t = join(bld.srcnode.abspath(bld.env_of_name("Release")), v8.target)
661
bld.env_of_name('Release').append_value("LINKFLAGS_V8", t)
664
if bld.env["USE_DEBUG"]:
665
v8_debug = v8.clone("Debug")
666
v8_debug.rule = v8_cmd(bld, "Debug")
667
v8_debug.target = bld.env["staticlib_PATTERN"] % "v8_g"
668
v8_debug.uselib = "EXECINFO"
669
bld.env["CPPPATH_V8_G"] = "deps/v8/include"
670
t = join(bld.srcnode.abspath(bld.env_of_name("Debug")), v8_debug.target)
671
bld.env_of_name('Debug').append_value("LINKFLAGS_V8_G", t)
673
bld.install_files('${PREFIX}/include/node/', 'deps/v8/include/*.h')
676
if sys.platform.startswith('win32'):
679
return s.replace("\\", "\\\\").replace("(","\\(").replace(")","\\)").replace(" ","\\ ")
681
def uv_cmd(bld, variant):
682
srcdeps = join(bld.path.abspath(), "deps")
683
srcdir = join(srcdeps, "uv")
684
blddir = bld.srcnode.abspath(bld.env_of_name(variant)) + '/deps/uv'
686
# FIXME This is awful! We're copying the entire source directory into the
687
# build directory before each compile. This could be much improved by
688
# modifying libuv's build to send object files to a separate directory.
690
cmd = 'cp -r ' + sh_escape(srcdir) + '/* ' + sh_escape(blddir)
691
if not sys.platform.startswith('win32'):
692
make = ('if [ -z "$NODE_MAKE" ]; then NODE_MAKE=make; fi; '
693
'$NODE_MAKE -C ' + sh_escape(blddir))
694
flags = arch_cflags(bld)
695
if flags: make += ' CFLAGS=\'%s\'' % ' '.join(flags) # don't escape
697
make = 'make -C ' + sh_escape(blddir)
698
return '%s && (%s clean) && (%s all)' % (cmd, make, make)
702
uv = bld.new_task_gen(
704
source = 'deps/uv/include/uv.h',
705
target = 'deps/uv/uv.a',
707
rule = uv_cmd(bld, 'Release')
710
uv.env.env = dict(os.environ)
711
uv.env.env['CC'] = sh_escape(bld.env['CC'][0])
712
uv.env.env['CXX'] = sh_escape(bld.env['CXX'][0])
714
t = join(bld.srcnode.abspath(bld.env_of_name("Release")), uv.target)
715
bld.env_of_name('Release').append_value("LINKFLAGS_UV", t)
717
if bld.env["USE_DEBUG"]:
718
uv_debug = uv.clone("Debug")
719
uv_debug.rule = uv_cmd(bld, 'Debug')
720
uv_debug.env.env = dict(os.environ)
722
t = join(bld.srcnode.abspath(bld.env_of_name("Debug")), uv_debug.target)
723
bld.env_of_name('Debug').append_value("LINKFLAGS_UV", t)
725
bld.install_files('${PREFIX}/include/node/', 'deps/uv/include/*.h')
726
bld.install_files('${PREFIX}/include/node/uv-private', 'deps/uv/include/uv-private/*.h')
727
bld.install_files('${PREFIX}/include/node/ev', 'deps/uv/src/ev/*.h')
731
## This snippet is to show full commands as WAF executes
733
old = Build.BuildContext.exec_command
734
def exec_command(self, cmd, **kw):
735
if isinstance(cmd, list): print(" ".join(cmd))
736
return old(self, cmd, **kw)
737
Build.BuildContext.exec_command = exec_command
739
Options.options.jobs=jobs
740
product_type = Options.options.product_type
741
product_type_is_lib = product_type != 'program'
743
print "DEST_OS: " + bld.env['DEST_OS']
744
print "DEST_CPU: " + bld.env['DEST_CPU']
745
print "Parallel Jobs: " + str(Options.options.jobs)
746
print "Product type: " + product_type
750
if not bld.env['USE_SHARED_V8']: build_v8(bld)
754
http_parser = bld.new_task_gen("cc")
755
http_parser.source = "deps/http_parser/http_parser.c"
756
http_parser.includes = "deps/http_parser/"
757
http_parser.name = "http_parser"
758
http_parser.target = "http_parser"
759
http_parser.install_path = None
760
if bld.env["USE_DEBUG"]:
761
http_parser.clone("Debug")
762
if product_type_is_lib:
763
http_parser.ccflags = '-fPIC'
766
def make_macros(loc, content):
771
macros_loc_debug = join(
772
bld.srcnode.abspath(bld.env_of_name("Debug")),
776
macros_loc_default = join(
777
bld.srcnode.abspath(bld.env_of_name("Release")),
781
### We need to truncate the macros.py file
782
f = open(macros_loc_debug, 'w')
784
f = open(macros_loc_default, 'w')
787
make_macros(macros_loc_debug, "") # leave debug(x) as is in debug build
788
# replace debug(x) with nothing in release build
789
make_macros(macros_loc_default, "macro debug(x) = ;\n")
790
make_macros(macros_loc_default, "macro assert(x) = ;\n")
792
if not bld.env["USE_DTRACE"]:
794
'DTRACE_HTTP_CLIENT_REQUEST',
795
'DTRACE_HTTP_CLIENT_RESPONSE',
796
'DTRACE_HTTP_SERVER_REQUEST',
797
'DTRACE_HTTP_SERVER_RESPONSE',
798
'DTRACE_NET_SERVER_CONNECTION',
799
'DTRACE_NET_STREAM_END',
800
'DTRACE_NET_SOCKET_READ',
801
'DTRACE_NET_SOCKET_WRITE'
805
make_macros(macros_loc_default, "macro %s(x) = ;\n" % probe)
806
make_macros(macros_loc_debug, "macro %s(x) = ;\n" % probe)
808
def javascript_in_c(task):
810
source = map(lambda x: x.srcpath(env), task.inputs)
811
targets = map(lambda x: x.srcpath(env), task.outputs)
812
source.append(macros_loc_default)
813
js2c.JS2C(source, targets)
815
def javascript_in_c_debug(task):
817
source = map(lambda x: x.srcpath(env), task.inputs)
818
targets = map(lambda x: x.srcpath(env), task.outputs)
819
source.append(macros_loc_debug)
820
js2c.JS2C(source, targets)
822
native_cc = bld.new_task_gen(
823
source='src/node.js ' + bld.path.ant_glob('lib/*.js'),
824
target="src/node_natives.h",
829
# Add the rule /after/ cloning the debug
830
# This is a work around for an error had in python 2.4.3 (I'll paste the
831
# error that was had into the git commit meessage. git-blame to find out
833
if bld.env["USE_DEBUG"]:
834
native_cc_debug = native_cc.clone("Debug")
835
native_cc_debug.rule = javascript_in_c_debug
837
native_cc.rule = javascript_in_c_debug
839
if bld.env["USE_DTRACE"]:
840
dtrace_usdt = bld.new_task_gen(
841
name = "dtrace_usdt",
842
source = "src/node_provider.d",
843
target = "src/node_provider.h",
844
rule = "%s -x nolibs -h -o ${TGT} -s ${SRC}" % (bld.env.DTRACE),
848
if bld.env["USE_DEBUG"]:
849
dtrace_usdt_g = dtrace_usdt.clone("Debug")
851
bld.install_files('${LIBDIR}/dtrace', 'src/node.d')
853
if sys.platform.startswith("sunos"):
855
# The USDT DTrace provider works slightly differently on Solaris than on
856
# the Mac; on Solaris, any objects that have USDT DTrace probes must be
857
# post-processed with the DTrace command. (This is not true on the
858
# Mac, which has first-class linker support for USDT probes.) On
859
# Solaris, we must therefore post-process our object files. Waf doesn't
860
# seem to really have a notion for this, so we inject a task after
861
# compiling and before linking, and then find all of the node object
862
# files and shuck them off to dtrace (which will modify them in place
865
def dtrace_postprocess(task):
866
abspath = bld.srcnode.abspath(bld.env_of_name(task.env.variant()))
867
objs = glob.glob(abspath + 'src/*.o')
868
source = task.inputs[0].srcpath(task.env)
869
target = task.outputs[0].srcpath(task.env)
870
cmd = '%s -G -x nolibs -s %s -o %s %s' % (task.env.DTRACE,
874
Utils.exec_command(cmd)
877
# ustack helpers do not currently work on MacOS. We currently only
878
# support 32-bit x86.
880
def dtrace_do_ustack(task):
881
abspath = bld.srcnode.abspath(bld.env_of_name(task.env.variant()))
882
source = task.inputs[0].srcpath(task.env)
883
target = task.outputs[0].srcpath(task.env)
884
cmd = '%s -32 -I../src -C -G -s %s -o %s' % (task.env.DTRACE, source, target)
885
Utils.exec_command(cmd)
887
dtrace_ustack = bld.new_task_gen(
888
name = "dtrace_ustack-postprocess",
889
source = "src/v8ustack.d",
890
target = "v8ustack.o",
894
rule = dtrace_do_ustack
897
dtracepost = bld.new_task_gen(
898
name = "dtrace_usdt-postprocess",
899
source = "src/node_provider.d",
900
target = "node_provider.o",
904
rule = dtrace_postprocess
907
t = join(bld.srcnode.abspath(bld.env_of_name("Release")), dtracepost.target)
908
bld.env_of_name('Release').append_value('LINKFLAGS', t)
910
t = join(bld.srcnode.abspath(bld.env_of_name("Release")), dtrace_ustack.target)
911
bld.env_of_name('Release').append_value('LINKFLAGS', t)
914
# Note that for the same (mysterious) issue outlined above with respect
915
# to assigning the rule to native_cc/native_cc_debug, we must apply the
916
# rule to dtracepost/dtracepost_g only after they have been cloned. We
917
# also must put node_provider.o on the link line, but because we
918
# (apparently?) lack LINKFLAGS in debug, we (shamelessly) stowaway on
921
if bld.env["USE_DEBUG"]:
922
dtracepost_g = dtracepost.clone("Debug")
923
dtracepost_g.rule = dtrace_postprocess
924
t = join(bld.srcnode.abspath(bld.env_of_name("Debug")), dtracepost.target)
925
bld.env_of_name("Debug").append_value('LINKFLAGS_V8_G', t)
929
node = bld.new_task_gen("cxx", product_type)
932
node.uselib = 'RT OPENSSL ZLIB CARES EV EXECINFO DL KVM SOCKET NSL KSTAT UTIL OPROFILE'
933
node.add_objects = 'http_parser'
934
if product_type_is_lib:
935
node.install_path = '${LIBDIR}'
937
node.install_path = '${PREFIX}/bin'
942
src/node_javascript.cc
943
src/node_extensions.cc
944
src/node_http_parser.cc
945
src/node_constants.cc
962
src/v8_typed_array.cc
965
if bld.env["USE_DTRACE"]:
966
node.source += " src/node_dtrace.cc "
968
if not sys.platform.startswith("win32"):
969
node.source += " src/node_signal_watcher.cc "
970
node.source += " src/node_stat_watcher.cc "
971
node.source += " src/node_io_watcher.cc "
973
node.source += bld.env["PLATFORM_FILE"]
974
if not product_type_is_lib:
975
node.source = 'src/node_main.cc '+node.source
977
if bld.env["USE_OPENSSL"]: node.source += " src/node_crypto.cc "
986
if not bld.env["USE_SHARED_V8"]: node.includes += ' deps/v8/include '
988
if os.environ.has_key('RPATH'):
989
node.rpath = os.environ['RPATH']
991
if (sys.platform.startswith("win32")):
993
bld.env.append_value('LINKFLAGS', '-static-libgcc')
994
bld.env.append_value('LINKFLAGS', '-static-libstdc++')
996
def subflags(program):
997
x = { 'CCFLAGS' : " ".join(program.env["CCFLAGS"]).replace('"', '\\"')
998
, 'CPPFLAGS' : " ".join(program.env["CPPFLAGS"]).replace('"', '\\"')
999
, 'LIBFLAGS' : " ".join(program.env["LIBFLAGS"]).replace('"', '\\"')
1000
, 'PREFIX' : safe_path(program.env["PREFIX"])
1001
, 'VERSION' : get_node_version()
1005
# process file.pc.in -> file.pc
1007
node_conf = bld.new_task_gen('subst', before="cxx")
1008
node_conf.source = 'src/node_config.h.in'
1009
node_conf.target = 'src/node_config.h'
1010
node_conf.dict = subflags(node)
1011
node_conf.install_path = '${PREFIX}/include/node'
1013
if bld.env["USE_DEBUG"]:
1014
node_g = node.clone("Debug")
1015
node_g.target = "node"
1016
node_g.uselib += ' V8_G UV '
1017
node_g.install_path = None
1019
node_conf_g = node_conf.clone("Debug")
1020
node_conf_g.dict = subflags(node_g)
1021
node_conf_g.install_path = None
1023
# After creating the debug clone, append the V8 dep
1024
node.uselib += ' V8 UV '
1026
bld.install_files('${PREFIX}/include/node/', """
1029
src/node_object_wrap.h
1034
# Only install the man page if it exists.
1035
# Do 'make doc install' to build and install it.
1036
if os.path.exists('doc/node.1'):
1037
prefix = 'bsd' in sys.platform and '${PREFIX}' or '${PREFIX}/share'
1038
bld.install_files(prefix + '/man/man1/', 'doc/node.1')
1040
bld.install_files('${PREFIX}/bin/', 'tools/node-waf', chmod=0755)
1041
bld.install_files('${LIBDIR}/node/wafadmin', 'tools/wafadmin/*.py')
1042
bld.install_files('${LIBDIR}/node/wafadmin/Tools', 'tools/wafadmin/Tools/*.py')
1044
if bld.env['USE_NPM']:
1047
def install_npm(bld):
1048
start_dir = bld.path.find_dir('deps/npm')
1049
# The chmod=-1 is a Node hack. We changed WAF so that when chmod was set to
1050
# -1 that the same permission in this tree are used. Necessary to get
1051
# npm-cli.js to be executable without having to list every file in npm.
1052
bld.install_files('${LIBDIR}/node_modules/npm',
1053
start_dir.ant_glob('**/*'),
1055
relative_trick=True,
1057
bld.symlink_as('${PREFIX}/bin/npm',
1058
'../lib/node_modules/npm/bin/npm-cli.js')
1061
Options.options.debug
1062
# HACK to get binding.node out of build directory.
1063
# better way to do this?
1064
if Options.commands['configure']:
1065
if not Options.options.use_openssl:
1066
print "WARNING WARNING WARNING"
1067
print "OpenSSL not found. Will compile Node without crypto support!"
1069
if not Options.options.platform_file:
1070
print "WARNING: Platform not fully supported. Using src/platform_none.cc"
1072
elif not Options.commands['clean']:
1073
if sys.platform.startswith("win32"):
1074
if os.path.exists('out/Release/node.exe'):
1075
os.system('cp out/Release/node.exe .')
1076
if os.path.exists('out/Debug/node.exe'):
1077
os.system('cp out/Debug/node.exe node_g.exe')
1079
if os.path.exists('out/Release/node') and not os.path.islink('node'):
1080
os.symlink('out/Release/node', 'node')
1081
if os.path.exists('out/Debug/node') and not os.path.islink('node_g'):
1082
os.symlink('out/Debug/node', 'node_g')
1084
if sys.platform.startswith("win32"):
1085
if os.path.exists('node.exe'): os.unlink('node.exe')
1086
if os.path.exists('node_g.exe'): os.unlink('node_g.exe')
1088
if os.path.exists('node'): os.unlink('node')
1089
if os.path.exists('node_g'): os.unlink('node_g')