blob: 135a9a846739fc5e7d1020078a61a31333d9ed39 [file] [log] [blame]
Ryan Dahl7a251f32010-03-01 22:39:311#!/usr/bin/env python
Ryan8ddf9302009-09-02 18:19:522import re
Ryan1a126ed2009-04-04 12:50:153import Options
Ryan41d89f62009-07-28 10:29:184import sys, os, shutil
Ryan Dahld979ac92009-10-09 13:00:125from Utils import cmd_output
Ryan1a126ed2009-04-04 12:50:156from os.path import join, dirname, abspath
Ryana4593e32009-04-23 11:18:387from logging import fatal
8
Ryan Dahld979ac92009-10-09 13:00:129cwd = os.getcwd()
Ryan4d921992009-08-26 23:11:1610APPNAME="node.js"
11
Ryan63a9cd32009-04-15 08:08:2812import js2c
13
Ryan1a126ed2009-04-04 12:50:1514srcdir = '.'
15blddir = 'build'
16
Ryan Dahl311a62d2010-05-26 20:05:3117
18jobs=1
19if os.environ.has_key('JOBS'):
20 jobs = int(os.environ['JOBS'])
Ryan Dahl9922e4e2010-09-20 23:51:4721
Ryan Dahl311a62d2010-05-26 20:05:3122
Ryan1a126ed2009-04-04 12:50:1523def set_options(opt):
24 # the gcc module provides a --debug-level option
25 opt.tool_options('compiler_cxx')
26 opt.tool_options('compiler_cc')
Ryan4d921992009-08-26 23:11:1627 opt.tool_options('misc')
Ryan29b528c2009-04-23 15:29:3128 opt.add_option( '--debug'
29 , action='store_true'
30 , default=False
31 , help='Build debug variant [Default: False]'
32 , dest='debug'
33 )
Ryan7bad9de2009-06-16 13:47:5734 opt.add_option( '--efence'
35 , action='store_true'
36 , default=False
37 , help='Build with -lefence for debugging [Default: False]'
38 , dest='efence'
39 )
Ryan Dahl9e8df0e2010-06-02 21:05:3740
Ryan Dahlae5d6132010-08-15 21:27:0541 opt.add_option( '--without-snapshot'
42 , action='store_true'
43 , default=False
44 , help='Build without snapshotting V8 libraries. You might want to set this for cross-compiling. [Default: False]'
45 , dest='without_snapshot'
46 )
47
Ryan Dahla9b962a2010-05-14 23:34:4748 opt.add_option( '--without-ssl'
49 , action='store_true'
50 , default=False
51 , help='Build without SSL'
52 , dest='without_ssl'
53 )
Ryan1a126ed2009-04-04 12:50:1554
Ryan Dahl9e8df0e2010-06-02 21:05:3755
56 opt.add_option('--shared-v8'
57 , action='store_true'
58 , default=False
59 , help='Link to a shared V8 DLL instead of static linking'
60 , dest='shared_v8'
61 )
62
63 opt.add_option( '--shared-v8-includes'
64 , action='store'
65 , default=False
66 , help='Directory containing V8 header files'
67 , dest='shared_v8_includes'
68 )
69
70 opt.add_option( '--shared-v8-libpath'
71 , action='store'
72 , default=False
73 , help='A directory to search for the shared V8 DLL'
74 , dest='shared_v8_libpath'
75 )
76
77 opt.add_option( '--shared-v8-libname'
78 , action='store'
79 , default=False
80 , help="Alternative lib name to link to (default: 'v8')"
81 , dest='shared_v8_libname'
82 )
83
84
85 opt.add_option('--shared-cares'
86 , action='store_true'
87 , default=False
88 , help='Link to a shared C-Ares DLL instead of static linking'
89 , dest='shared_cares'
90 )
91
92 opt.add_option( '--shared-cares-includes'
93 , action='store'
94 , default=False
95 , help='Directory containing C-Ares header files'
96 , dest='shared_cares_includes'
97 )
98
99 opt.add_option( '--shared-cares-libpath'
100 , action='store'
101 , default=False
102 , help='A directory to search for the shared C-Ares DLL'
103 , dest='shared_cares_libpath'
104 )
105
106
107 opt.add_option('--shared-libev'
108 , action='store_true'
109 , default=False
110 , help='Link to a shared libev DLL instead of static linking'
111 , dest='shared_libev'
112 )
113
114 opt.add_option( '--shared-libev-includes'
115 , action='store'
116 , default=False
117 , help='Directory containing libev header files'
118 , dest='shared_libev_includes'
119 )
120
121 opt.add_option( '--shared-libev-libpath'
122 , action='store'
123 , default=False
124 , help='A directory to search for the shared libev DLL'
125 , dest='shared_libev_libpath'
126 )
127
128
129
130
Ryan1a126ed2009-04-04 12:50:15131def configure(conf):
132 conf.check_tool('compiler_cxx')
Ryan Dahlf379b772010-01-12 00:43:10133 if not conf.env.CXX: conf.fatal('c++ compiler not found')
Ryan1a126ed2009-04-04 12:50:15134 conf.check_tool('compiler_cc')
Ryan Dahlf379b772010-01-12 00:43:10135 if not conf.env.CC: conf.fatal('c compiler not found')
Ryana4593e32009-04-23 11:18:38136
Ryan Dahl9e8df0e2010-06-02 21:05:37137 o = Options.options
138
139 conf.env["USE_DEBUG"] = o.debug
Ryan Dahlae5d6132010-08-15 21:27:05140 conf.env["SNAPSHOT_V8"] = not o.without_snapshot
Ryan Dahl9e8df0e2010-06-02 21:05:37141
142 conf.env["USE_SHARED_V8"] = o.shared_v8 or o.shared_v8_includes or o.shared_v8_libpath or o.shared_v8_libname
143 conf.env["USE_SHARED_CARES"] = o.shared_cares or o.shared_cares_includes or o.shared_cares_libpath
144 conf.env["USE_SHARED_LIBEV"] = o.shared_libev or o.shared_libev_includes or o.shared_libev_libpath
Ryan1a126ed2009-04-04 12:50:15145
Ryan2b6d7242009-06-20 13:07:10146 conf.check(lib='dl', uselib_store='DL')
Raffaele Senab3b81d62010-06-09 04:08:05147 if not sys.platform.startswith("sunos") and not sys.platform.startswith("cygwin"):
Ryan Dahl0c125542010-01-19 23:38:20148 conf.env.append_value("CCFLAGS", "-rdynamic")
149 conf.env.append_value("LINKFLAGS_DL", "-rdynamic")
Ryana97dce72009-08-31 09:14:34150
Vanilla Hsud22952b2010-01-07 07:37:27151 if sys.platform.startswith("freebsd"):
152 conf.check(lib='kvm', uselib_store='KVM')
153
Ryan8152f9c2009-09-01 12:15:29154 #if Options.options.debug:
155 # conf.check(lib='profiler', uselib_store='PROFILER')
Ryan7bad9de2009-06-16 13:47:57156
Ryan Dahlb8c3d712010-01-27 02:34:42157 if Options.options.efence:
158 conf.check(lib='efence', libpath=['/usr/lib', '/usr/local/lib'], uselib_store='EFENCE')
Ryana3627c02009-05-27 14:29:55159
Ryan Dahle8b37512010-08-27 13:20:18160 if sys.platform.startswith("freebsd"):
161 if not conf.check(lib="execinfo",
162 includes=['/usr/include', '/usr/local/include'],
163 libpath=['/usr/lib', '/usr/local/lib'],
164 uselib_store="EXECINFO"):
165 conf.fatal("Install the libexecinfo port from /usr/ports/devel/libexecinfo.")
Ryana3627c02009-05-27 14:29:55166
Ryan Dahla9b962a2010-05-14 23:34:47167 if not Options.options.without_ssl:
168 if conf.check_cfg(package='openssl',
169 args='--cflags --libs',
170 uselib_store='OPENSSL'):
Ryan Dahla4906c72010-08-04 23:07:10171 Options.options.use_openssl = conf.env["USE_OPENSSL"] = True
Ryan Dahlfe060912010-09-28 10:17:44172 conf.env.append_value("CPPFLAGS", "-DHAVE_OPENSSL=1")
Ryan Dahla9b962a2010-05-14 23:34:47173 else:
174 libssl = conf.check_cc(lib='ssl',
175 header_name='openssl/ssl.h',
176 function_name='SSL_library_init',
177 libpath=['/usr/lib', '/usr/local/lib', '/opt/local/lib', '/usr/sfw/lib'],
178 uselib_store='OPENSSL')
179 libcrypto = conf.check_cc(lib='crypto',
180 header_name='openssl/crypto.h',
181 uselib_store='OPENSSL')
182 if libcrypto and libssl:
Ryan Dahla4906c72010-08-04 23:07:10183 conf.env["USE_OPENSSL"] = Options.options.use_openssl = True
Ryan Dahlfe060912010-09-28 10:17:44184 conf.env.append_value("CPPFLAGS", "-DHAVE_OPENSSL=1")
Paul Querna2d348bb2010-09-19 22:20:35185 else:
Ryan Dahl754fde72010-09-20 19:52:07186 conf.fatal("Could not autodetect OpenSSL support. " +
187 "Make sure OpenSSL development packages are installed. " +
188 "Use configure --without-ssl to disable this message.")
Tony Metzidis5c9b9c22010-09-11 04:37:43189 else:
190 Options.options.use_openssl = conf.env["USE_OPENSSL"] = False
Rhys Jonesfb3a9cd2010-04-02 23:11:53191
Ryan Dahle9a116f2010-04-06 10:41:32192 conf.check(lib='rt', uselib_store='RT')
193
Ryan Dahl0c125542010-01-19 23:38:20194 if sys.platform.startswith("sunos"):
195 if not conf.check(lib='socket', uselib_store="SOCKET"):
196 conf.fatal("Cannot find socket library")
197 if not conf.check(lib='nsl', uselib_store="NSL"):
198 conf.fatal("Cannot find nsl library")
199
Ryan1a126ed2009-04-04 12:50:15200 conf.sub_config('deps/libeio')
Ryan Dahl9e8df0e2010-06-02 21:05:37201
Ryan Dahl9e8df0e2010-06-02 21:05:37202 if conf.env['USE_SHARED_V8']:
203 v8_includes = [];
204 if o.shared_v8_includes: v8_includes.append(o.shared_v8_includes);
205
206 v8_libpath = [];
207 if o.shared_v8_libpath: v8_libpath.append(o.shared_v8_libpath);
208
209 if not o.shared_v8_libname: o.shared_v8_libname = 'v8'
210
211 if not conf.check_cxx(lib=o.shared_v8_libname, header_name='v8.h',
212 uselib_store='V8',
213 includes=v8_includes,
214 libpath=v8_libpath):
215 conf.fatal("Cannot find v8")
216
217 if o.debug:
218 if not conf.check_cxx(lib=o.shared_v8_libname + '_g', header_name='v8.h',
219 uselib_store='V8_G',
220 includes=v8_includes,
221 libpath=v8_libpath):
222 conf.fatal("Cannot find v8_g")
223
224 if conf.env['USE_SHARED_CARES']:
225 cares_includes = [];
226 if o.shared_cares_includes: cares_includes.append(o.shared_cares_includes);
227 cares_libpath = [];
228 if o.shared_cares_libpath: cares_libpath.append(o.shared_cares_libpath);
229 if not conf.check_cxx(lib='cares',
230 header_name='ares.h',
231 uselib_store='CARES',
232 includes=cares_includes,
233 libpath=cares_libpath):
Ryan Dahl501136b2010-06-02 16:15:54234 conf.fatal("Cannot find c-ares")
Ryan Dahl9e8df0e2010-06-02 21:05:37235 else:
236 conf.sub_config('deps/c-ares')
237
238
239 if conf.env['USE_SHARED_LIBEV']:
240 libev_includes = [];
241 if o.shared_libev_includes: libev_includes.append(o.shared_libev_includes);
242 libev_libpath = [];
243 if o.shared_libev_libpath: libev_libpath.append(o.shared_libev_libpath);
244 if not conf.check_cxx(lib='ev', header_name='ev.h',
245 uselib_store='EV',
246 includes=libev_includes,
247 libpath=libev_libpath):
248 conf.fatal("Cannot find libev")
249 else:
250 conf.sub_config('deps/libev')
251
252
Ryan41d89f62009-07-28 10:29:18253
Ryan1a126ed2009-04-04 12:50:15254 conf.define("HAVE_CONFIG_H", 1)
Ryanc62b1242009-04-22 17:55:08255
Ryan Dahl42797252010-03-31 20:36:20256 if sys.platform.startswith("sunos"):
257 conf.env.append_value ('CCFLAGS', '-threads')
258 conf.env.append_value ('CXXFLAGS', '-threads')
259 #conf.env.append_value ('LINKFLAGS', ' -threads')
Raffaele Senab3b81d62010-06-09 04:08:05260 elif not sys.platform.startswith("cygwin"):
Ryan Dahl42797252010-03-31 20:36:20261 threadflags='-pthread'
262 conf.env.append_value ('CCFLAGS', threadflags)
263 conf.env.append_value ('CXXFLAGS', threadflags)
264 conf.env.append_value ('LINKFLAGS', threadflags)
Rasmus Andersson758f12f2010-08-11 23:00:02265 if sys.platform.startswith("darwin"):
266 # used by platform_darwin_*.cc
267 conf.env.append_value('LINKFLAGS', ['-framework','Carbon'])
Ryan Dahl42797252010-03-31 20:36:20268
Ryan Dahlfe060912010-09-28 10:17:44269 # Needed for getaddrinfo in libeio
270 conf.env.append_value("CPPFLAGS", "-DX_STACKSIZE=%d" % (1024*64))
Ryan Dahl2b743aa2009-10-27 11:05:38271 # LFS
Ryan Dahlfe060912010-09-28 10:17:44272 conf.env.append_value('CPPFLAGS', '-D_LARGEFILE_SOURCE')
273 conf.env.append_value('CPPFLAGS', '-D_FILE_OFFSET_BITS=64')
Ryan Dahlfe742832010-10-09 23:04:38274 conf.env.append_value('CPPFLAGS', '-DEV_MULTIPLICITY=0')
Ryan Dahl2b743aa2009-10-27 11:05:38275
Andrew Johnston95996072010-03-22 07:25:24276 ## needed for node_file.cc fdatasync
277 ## Strangely on OSX 10.6 the g++ doesn't see fdatasync but gcc does?
278 code = """
279 #include <unistd.h>
280 int main(void)
281 {
282 int fd = 0;
283 fdatasync (fd);
284 return 0;
285 }
286 """
287 if conf.check_cxx(msg="Checking for fdatasync(2) with c++", fragment=code):
Ryan Dahlfe060912010-09-28 10:17:44288 conf.env.append_value('CPPFLAGS', '-DHAVE_FDATASYNC=1')
Andrew Johnston95996072010-03-22 07:25:24289 else:
Ryan Dahlfe060912010-09-28 10:17:44290 conf.env.append_value('CPPFLAGS', '-DHAVE_FDATASYNC=0')
Andrew Johnston95996072010-03-22 07:25:24291
Ryan Dahlf4811832009-11-02 23:21:00292 # platform
Ryan Dahlfe060912010-09-28 10:17:44293 conf.env.append_value('CPPFLAGS', '-DPLATFORM="' + conf.env['DEST_OS'] + '"')
Ryan Dahlf4811832009-11-02 23:21:00294
Ryan67af9582009-04-18 13:35:42295 # Split off debug variant before adding variant specific defines
Ryan7e1350f2009-04-16 09:37:44296 debug_env = conf.env.copy()
297 conf.set_env_name('debug', debug_env)
Ryan7e1350f2009-04-16 09:37:44298
Ryan67af9582009-04-18 13:35:42299 # Configure debug variant
300 conf.setenv('debug')
301 debug_env.set_variant('debug')
Ryan Dahlfe060912010-09-28 10:17:44302 debug_env.append_value('CPPFLAGS', '-DDEBUG')
303 debug_compile_flags = ['-g', '-O0', '-Wall', '-Wextra']
304 debug_env.append_value('CCFLAGS', debug_compile_flags)
305 debug_env.append_value('CXXFLAGS', debug_compile_flags)
Ryan67af9582009-04-18 13:35:42306 conf.write_config_header("config.h")
307
308 # Configure default variant
309 conf.setenv('default')
Ryan Dahlfe060912010-09-28 10:17:44310 conf.env.append_value('CPPFLAGS', '-DNDEBUG')
311 default_compile_flags = ['-g', '-O3']
312 conf.env.append_value('CCFLAGS', default_compile_flags)
313 conf.env.append_value('CXXFLAGS', default_compile_flags)
Ryan67af9582009-04-18 13:35:42314 conf.write_config_header("config.h")
Ryan63a9cd32009-04-15 08:08:28315
Ryan41d89f62009-07-28 10:29:18316
Ryan Dahl53ebe752009-10-08 21:20:14317def v8_cmd(bld, variant):
318 scons = join(cwd, 'tools/scons/scons.py')
Ryan1a126ed2009-04-04 12:50:15319 deps_src = join(bld.path.abspath(),"deps")
Ryan1a126ed2009-04-04 12:50:15320 v8dir_src = join(deps_src,"v8")
Ryan Dahl53ebe752009-10-08 21:20:14321
Ryan Dahlbc9b3432009-10-02 12:10:40322 # NOTE: We want to compile V8 to export its symbols. I.E. Do not want
323 # -fvisibility=hidden. When using dlopen() it seems that the loaded DSO
324 # cannot see symbols in the executable which are hidden, even if the
325 # executable is statically linked together...
Ryan8ddf9302009-09-02 18:19:52326
Ryan Dahl7d9d8812009-10-26 21:27:52327 # XXX Remove this when v8 defaults x86_64 to native builds
Ryan Dahld85724d2009-10-08 22:34:39328 arch = ""
Ryan Dahl7d9d8812009-10-26 21:27:52329 if bld.env['DEST_CPU'] == 'x86_64':
Ryan Dahld85724d2009-10-08 22:34:39330 arch = "arch=x64"
331
332 if variant == "default":
333 mode = "release"
334 else:
335 mode = "debug"
Ryana4593e32009-04-23 11:18:38336
Ryan Dahlae5d6132010-08-15 21:27:05337 if bld.env["SNAPSHOT_V8"]:
338 snapshot = "snapshot=on"
339 else:
340 snapshot = ""
341
342 cmd_R = 'python "%s" -j %d -C "%s" -Y "%s" visibility=default mode=%s %s library=static %s'
Ryan Dahl53ebe752009-10-08 21:20:14343
344 cmd = cmd_R % ( scons
Ryan Dahl23d680b2010-05-13 23:24:05345 , Options.options.jobs
Ryan Dahl53ebe752009-10-08 21:20:14346 , bld.srcnode.abspath(bld.env_of_name(variant))
347 , v8dir_src
348 , mode
349 , arch
Ryan Dahlae5d6132010-08-15 21:27:05350 , snapshot
Ryan Dahl53ebe752009-10-08 21:20:14351 )
Ryan Dahlae5d6132010-08-15 21:27:05352
353 return ("echo '%s' && " % cmd) + cmd
Ryan Dahl53ebe752009-10-08 21:20:14354
355
356def build_v8(bld):
Ryan1a126ed2009-04-04 12:50:15357 v8 = bld.new_task_gen(
Ryan Dahl9e8df0e2010-06-02 21:05:37358 source = 'deps/v8/SConstruct '
359 + bld.path.ant_glob('v8/include/*')
360 + bld.path.ant_glob('v8/src/*'),
Ryan Dahl53ebe752009-10-08 21:20:14361 target = bld.env["staticlib_PATTERN"] % "v8",
362 rule = v8_cmd(bld, "default"),
363 before = "cxx",
Ryan Dahl9e8df0e2010-06-02 21:05:37364 install_path = None)
Ryan Dahl8b62e862009-10-10 09:58:36365 v8.uselib = "EXECINFO"
Ryan1a126ed2009-04-04 12:50:15366 bld.env["CPPPATH_V8"] = "deps/v8/include"
Ryan Dahlfc937aa2009-10-27 21:50:46367 t = join(bld.srcnode.abspath(bld.env_of_name("default")), v8.target)
Ryan Dahl42797252010-03-31 20:36:20368 bld.env_of_name('default').append_value("LINKFLAGS_V8", t)
369
Ryana4593e32009-04-23 11:18:38370
371 ### v8 debug
Ryan29b528c2009-04-23 15:29:31372 if bld.env["USE_DEBUG"]:
Ryan29b528c2009-04-23 15:29:31373 v8_debug = v8.clone("debug")
Ryan Dahl53ebe752009-10-08 21:20:14374 v8_debug.rule = v8_cmd(bld, "debug")
375 v8_debug.target = bld.env["staticlib_PATTERN"] % "v8_g"
Ryan Dahl8b62e862009-10-10 09:58:36376 v8_debug.uselib = "EXECINFO"
Ryan Dahl9e8df0e2010-06-02 21:05:37377 bld.env["CPPPATH_V8_G"] = "deps/v8/include"
Ryan Dahlfc937aa2009-10-27 21:50:46378 t = join(bld.srcnode.abspath(bld.env_of_name("debug")), v8_debug.target)
Ryan Dahl9e8df0e2010-06-02 21:05:37379 bld.env_of_name('debug').append_value("LINKFLAGS_V8_G", t)
Ryan1a126ed2009-04-04 12:50:15380
Ryan Dahl53ebe752009-10-08 21:20:14381 bld.install_files('${PREFIX}/include/node/', 'deps/v8/include/*.h')
Ryan2b6d7242009-06-20 13:07:10382
Ryan Dahl545e10f2010-06-21 17:21:55383
Ryan41d89f62009-07-28 10:29:18384def build(bld):
Ryan Dahlef9f4042010-06-02 19:27:53385 ## This snippet is to show full commands as WAF executes
386 import Build
387 old = Build.BuildContext.exec_command
388 def exec_command(self, cmd, **kw):
389 if isinstance(cmd, list): print(" ".join(cmd))
390 return old(self, cmd, **kw)
391 Build.BuildContext.exec_command = exec_command
392
Ryan Dahl501136b2010-06-02 16:15:54393 Options.options.jobs=jobs
Ryan Dahlef9f4042010-06-02 19:27:53394
Ryan Dahl9ea8c9f2010-04-07 20:34:40395 print "DEST_OS: " + bld.env['DEST_OS']
396 print "DEST_CPU: " + bld.env['DEST_CPU']
Ryan Dahl23d680b2010-05-13 23:24:05397 print "Parallel Jobs: " + str(Options.options.jobs)
Ryan Dahl9ea8c9f2010-04-07 20:34:40398
Ryan Dahl9e8df0e2010-06-02 21:05:37399 bld.add_subdirs('deps/libeio')
400
401 if not bld.env['USE_SHARED_V8']: build_v8(bld)
402 if not bld.env['USE_SHARED_LIBEV']: bld.add_subdirs('deps/libev')
403 if not bld.env['USE_SHARED_CARES']: bld.add_subdirs('deps/c-ares')
Ryan41d89f62009-07-28 10:29:18404
Jérémy Lalc93bab12010-03-11 21:15:32405
Ryan5a071ad2009-05-03 12:09:16406 ### http_parser
Ryan Dahl122e74b2009-10-27 21:26:53407 http_parser = bld.new_task_gen("cc")
Ryan5a071ad2009-05-03 12:09:16408 http_parser.source = "deps/http_parser/http_parser.c"
409 http_parser.includes = "deps/http_parser/"
410 http_parser.name = "http_parser"
411 http_parser.target = "http_parser"
412 http_parser.install_path = None
Ryan29b528c2009-04-23 15:29:31413 if bld.env["USE_DEBUG"]:
Ryan5a071ad2009-05-03 12:09:16414 http_parser.clone("debug")
Ryan1a126ed2009-04-04 12:50:15415
Ryan63a9cd32009-04-15 08:08:28416 ### src/native.cc
Zokab29f7872010-03-20 03:56:03417 def make_macros(loc, content):
418 f = open(loc, 'w')
419 f.write(content)
420 f.close
421
422 macros_loc_debug = join(
423 bld.srcnode.abspath(bld.env_of_name("debug")),
424 "macros.py"
425 )
426
427 macros_loc_default = join(
428 bld.srcnode.abspath(bld.env_of_name("default")),
429 "macros.py"
430 )
431
432 make_macros(macros_loc_debug, "") # leave debug(x) as is in debug build
433 # replace debug(x) with nothing in release build
434 make_macros(macros_loc_default, "macro debug(x) = ;\n")
435
Ryan63a9cd32009-04-15 08:08:28436 def javascript_in_c(task):
437 env = task.env
438 source = map(lambda x: x.srcpath(env), task.inputs)
439 targets = map(lambda x: x.srcpath(env), task.outputs)
Zokab29f7872010-03-20 03:56:03440 source.append(macros_loc_default)
441 js2c.JS2C(source, targets)
442
443 def javascript_in_c_debug(task):
444 env = task.env
445 source = map(lambda x: x.srcpath(env), task.inputs)
446 targets = map(lambda x: x.srcpath(env), task.outputs)
447 source.append(macros_loc_debug)
Ryan63a9cd32009-04-15 08:08:28448 js2c.JS2C(source, targets)
449
450 native_cc = bld.new_task_gen(
Ryan Dahl4ccdc502010-03-15 15:00:19451 source='src/node.js ' + bld.path.ant_glob('lib/*.js'),
Ryan Dahl53ebe752009-10-08 21:20:14452 target="src/node_natives.h",
Ryan Dahl4ccdc502010-03-15 15:00:19453 before="cxx",
454 install_path=None
Ryan63a9cd32009-04-15 08:08:28455 )
Ryan Dahl4bcb01c2009-10-16 20:53:44456
457 # Add the rule /after/ cloning the debug
458 # This is a work around for an error had in python 2.4.3 (I'll paste the
459 # error that was had into the git commit meessage. git-blame to find out
460 # where.)
Ryan29b528c2009-04-23 15:29:31461 if bld.env["USE_DEBUG"]:
Ryan Dahl4bcb01c2009-10-16 20:53:44462 native_cc_debug = native_cc.clone("debug")
Zokab29f7872010-03-20 03:56:03463 native_cc_debug.rule = javascript_in_c_debug
464
Ryan Dahl4bcb01c2009-10-16 20:53:44465 native_cc.rule = javascript_in_c
Ryan63a9cd32009-04-15 08:08:28466
Ryan2b6d7242009-06-20 13:07:10467 ### node lib
Ryan8152f9c2009-09-01 12:15:29468 node = bld.new_task_gen("cxx", "program")
469 node.name = "node"
470 node.target = "node"
Ryan Dahl9e8df0e2010-06-02 21:05:37471 node.uselib = 'RT EV OPENSSL CARES EXECINFO DL KVM SOCKET NSL'
472 node.add_objects = 'eio http_parser'
473 node.install_path = '${PREFIX}/lib'
474 node.install_path = '${PREFIX}/bin'
475 node.chmod = 0755
Ryan8152f9c2009-09-01 12:15:29476 node.source = """
Ryan Dahl124fbed2010-09-19 20:13:57477 src/node_main.cc
Ryan1a126ed2009-04-04 12:50:15478 src/node.cc
Ryan Dahl630bb7a2009-12-13 07:42:45479 src/node_buffer.cc
Paul Querna30dadfc2010-07-14 06:22:41480 src/node_extensions.cc
Ryan Dahl42ee1692010-01-24 19:21:45481 src/node_http_parser.cc
Ryan Dahl78e49f12010-05-29 20:08:05482 src/node_net.cc
Ryan Dahlf2199382009-12-13 14:43:58483 src/node_io_watcher.cc
Ryan Dahla5df0f62009-10-27 10:46:58484 src/node_child_process.cc
485 src/node_constants.cc
Krishna Rajendrandc1f4eb2010-04-06 10:28:37486 src/node_cares.cc
Ryan Dahla5df0f62009-10-27 10:46:58487 src/node_events.cc
488 src/node_file.cc
Ryan Dahl8492c522010-03-15 21:05:18489 src/node_signal_watcher.cc
490 src/node_stat_watcher.cc
Ryan17c6a672009-08-24 18:25:24491 src/node_stdio.cc
Ryan Dahla5df0f62009-10-27 10:46:58492 src/node_timer.cc
Herbert Vojcikc2a06722010-04-17 15:18:15493 src/node_script.cc
Ryan1a126ed2009-04-04 12:50:15494 """
Ryan Dahl01a8d272010-06-18 01:23:40495
496 platform_file = "src/platform_%s.cc" % bld.env['DEST_OS']
497 if os.path.exists(join(cwd, platform_file)):
498 node.source += platform_file
499 else:
500 node.source += "src/platform_none.cc "
501
502
503 if bld.env["USE_OPENSSL"]: node.source += " src/node_crypto.cc "
Rhys Jonesfb3a9cd2010-04-02 23:11:53504
Ryan Dahl9e8df0e2010-06-02 21:05:37505 node.includes = """
506 src/
507 deps/libeio
508 deps/http_parser
509 """
Ryan Dahle9a116f2010-04-06 10:41:32510
Ryan Dahl9e8df0e2010-06-02 21:05:37511 if not bld.env["USE_SHARED_V8"]: node.includes += ' deps/v8/include '
Vanilla Hsu067f4082010-04-07 16:05:37512
Ryan Dahl9e8df0e2010-06-02 21:05:37513 if not bld.env["USE_SHARED_LIBEV"]:
514 node.add_objects += ' ev '
515 node.includes += ' deps/libev '
Ryan Dahle9a116f2010-04-06 10:41:32516
Ryan Dahl9e8df0e2010-06-02 21:05:37517 if not bld.env["USE_SHARED_CARES"]:
518 node.add_objects += ' cares '
519 node.includes += ' deps/c-ares deps/c-ares/' + bld.env['DEST_OS'] + '-' + bld.env['DEST_CPU']
Ryan8e7bbf22009-04-23 17:26:56520
Brian McKenna431e72c2010-06-11 11:25:05521 if sys.platform.startswith('cygwin'):
522 bld.env.append_value('LINKFLAGS', '-Wl,--export-all-symbols')
523 bld.env.append_value('LINKFLAGS', '-Wl,--out-implib,default/libnode.dll.a')
524 bld.env.append_value('LINKFLAGS', '-Wl,--output-def,default/libnode.def')
525 bld.install_files('${PREFIX}/lib', "build/default/libnode.*")
526
Ryan4d921992009-08-26 23:11:16527 def subflags(program):
Ryan Dahl5bce8ed2010-08-18 20:16:32528 x = { 'CCFLAGS' : " ".join(program.env["CCFLAGS"]).replace('"', '\\"')
529 , 'CPPFLAGS' : " ".join(program.env["CPPFLAGS"]).replace('"', '\\"')
530 , 'LIBFLAGS' : " ".join(program.env["LIBFLAGS"]).replace('"', '\\"')
Ryanb73264d2009-08-27 00:15:11531 , 'PREFIX' : program.env["PREFIX"]
Ryan4d921992009-08-26 23:11:16532 }
Ryan Dahlbf0d2782009-10-03 20:42:03533 return x
Ryan4d921992009-08-26 23:11:16534
Ryan4d921992009-08-26 23:11:16535 # process file.pc.in -> file.pc
Ryan Dahld979ac92009-10-09 13:00:12536
Paul Querna480164f2010-07-13 06:59:57537 node_conf = bld.new_task_gen('subst', before="cxx")
538 node_conf.source = 'src/node_config.h.in'
539 node_conf.target = 'src/node_config.h'
540 node_conf.dict = subflags(node)
541 node_conf.install_path = '${PREFIX}/include/node'
Ryan4d921992009-08-26 23:11:16542
Ryan29b528c2009-04-23 15:29:31543 if bld.env["USE_DEBUG"]:
Ryan2b6d7242009-06-20 13:07:10544 node_g = node.clone("debug")
545 node_g.target = "node_g"
Ryan Dahl9e8df0e2010-06-02 21:05:37546 node_g.uselib += ' V8_G'
547
Paul Querna480164f2010-07-13 06:59:57548 node_conf_g = node_conf.clone("debug")
549 node_conf_g.dict = subflags(node_g)
550 node_conf_g.install_path = None
Ryan4d921992009-08-26 23:11:16551
Ryan Dahl9e8df0e2010-06-02 21:05:37552 # After creating the debug clone, append the V8 dep
553 node.uselib += ' V8'
Ryana97dce72009-08-31 09:14:34554
555 bld.install_files('${PREFIX}/include/node/', """
556 config.h
557 src/node.h
Ryan Dahl5f466c82009-10-27 19:17:03558 src/node_object_wrap.h
Ryan Dahld2415942010-05-06 21:14:52559 src/node_buffer.h
Ryan Dahl5f466c82009-10-27 19:17:03560 src/node_events.h
Samuel Shull24c6d262010-08-04 05:25:17561 src/node_version.h
Ryan Dahlbf0d2782009-10-03 20:42:03562 """)
563
Ryan Dahlef9f4042010-06-02 19:27:53564 # Only install the man page if it exists.
Ryan Dahlbf0d2782009-10-03 20:42:03565 # Do 'make doc install' to build and install it.
566 if os.path.exists('doc/node.1'):
567 bld.install_files('${PREFIX}/share/man/man1/', 'doc/node.1')
568
569 bld.install_files('${PREFIX}/bin/', 'bin/*', chmod=0755)
Ryan Dahlbf0d2782009-10-03 20:42:03570 bld.install_files('${PREFIX}/lib/node/wafadmin', 'tools/wafadmin/*.py')
571 bld.install_files('${PREFIX}/lib/node/wafadmin/Tools', 'tools/wafadmin/Tools/*.py')
Ryan Dahl6f17ca52009-10-03 17:08:05572
Ryan Dahl132d6852009-10-27 17:11:07573def shutdown():
574 Options.options.debug
575 # HACK to get binding.node out of build directory.
576 # better way to do this?
Ryan Dahla4906c72010-08-04 23:07:10577 if Options.commands['configure']:
578 if not Options.options.use_openssl:
579 print "WARNING WARNING WARNING"
580 print "OpenSSL not found. Will compile Node without crypto support!"
581 elif not Options.commands['clean']:
Ryan Dahl132d6852009-10-27 17:11:07582 if os.path.exists('build/default/node') and not os.path.exists('node'):
583 os.symlink('build/default/node', 'node')
584 if os.path.exists('build/debug/node_g') and not os.path.exists('node_g'):
585 os.symlink('build/debug/node_g', 'node_g')
586 else:
587 if os.path.exists('node'): os.unlink('node')
588 if os.path.exists('node_g'): os.unlink('node_g')