blob: 00c529befad882842d7255e0f1144b2bb8b1163d [file] [log] [blame]
Ryana3627c02009-05-27 14:29:551# /usr/bin/env python
Ryan8ddf9302009-09-02 18:19:522import platform
3import re
Ryan1a126ed2009-04-04 12:50:154import Options
Ryan41d89f62009-07-28 10:29:185import sys, os, shutil
Ryan1a126ed2009-04-04 12:50:156from os.path import join, dirname, abspath
Ryana4593e32009-04-23 11:18:387from logging import fatal
8
Ryan Dahl9c9d67e2009-09-30 21:21:259VERSION="0.1.13"
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'
Ryan115c4942009-06-22 11:08:3216cwd = os.getcwd()
Ryan1a126ed2009-04-04 12:50:1517
18def set_options(opt):
19 # the gcc module provides a --debug-level option
20 opt.tool_options('compiler_cxx')
21 opt.tool_options('compiler_cc')
Ryan4d921992009-08-26 23:11:1622 opt.tool_options('misc')
Ryan29b528c2009-04-23 15:29:3123 opt.add_option( '--debug'
24 , action='store_true'
25 , default=False
26 , help='Build debug variant [Default: False]'
27 , dest='debug'
28 )
Ryan7bad9de2009-06-16 13:47:5729 opt.add_option( '--efence'
30 , action='store_true'
31 , default=False
32 , help='Build with -lefence for debugging [Default: False]'
33 , dest='efence'
34 )
Ryan1a126ed2009-04-04 12:50:1535
Ryan41d89f62009-07-28 10:29:1836def mkdir_p(dir):
37 if not os.path.exists (dir):
38 os.makedirs (dir)
39
Ryan Dahl18da8ff2009-09-28 20:39:0040# Copied from Python 2.6 because 2.4.4 at least is broken by not using
41# mkdirs
42# http://mail.python.org/pipermail/python-bugs-list/2005-January/027118.html
43def copytree(src, dst, symlinks=False, ignore=None):
44 names = os.listdir(src)
45 if ignore is not None:
46 ignored_names = ignore(src, names)
47 else:
48 ignored_names = set()
49
50 os.makedirs(dst)
51 errors = []
52 for name in names:
53 if name in ignored_names:
54 continue
55 srcname = os.path.join(src, name)
56 dstname = os.path.join(dst, name)
57 try:
58 if symlinks and os.path.islink(srcname):
59 linkto = os.readlink(srcname)
60 os.symlink(linkto, dstname)
61 elif os.path.isdir(srcname):
62 copytree(srcname, dstname, symlinks, ignore)
63 else:
64 shutil.copy2(srcname, dstname)
65 # XXX What about devices, sockets etc.?
66 except (IOError, os.error), why:
67 errors.append((srcname, dstname, str(why)))
68 # catch the Error from the recursive copytree so that we can
69 # continue with other files
70 except Error, err:
71 errors.extend(err.args[0])
72 try:
73 shutil.copystat(src, dst)
74 except OSError, why:
75 if WindowsError is not None and isinstance(why, WindowsError):
76 # Copying file access times may fail on Windows
77 pass
78 else:
79 errors.extend((src, dst, str(why)))
80 if errors:
81 raise Error, errors
82
Ryan41d89f62009-07-28 10:29:1883def conf_subproject (conf, subdir, command=None):
84 print("---- %s ----" % subdir)
85 src = join(conf.srcdir, subdir)
86 if not os.path.exists (src): fatal("no such subproject " + subdir)
87
88 default_tgt = join(conf.blddir, "default", subdir)
89
90 if not os.path.exists(default_tgt):
Ryan Dahl18da8ff2009-09-28 20:39:0091 copytree(src, default_tgt, True)
Ryan41d89f62009-07-28 10:29:1892
93 if command:
94 if os.system("cd %s && %s" % (default_tgt, command)) != 0:
95 fatal("Configuring %s failed." % (subdir))
96
97 debug_tgt = join(conf.blddir, "debug", subdir)
98
99 if not os.path.exists(debug_tgt):
Ryan Dahl18da8ff2009-09-28 20:39:00100 copytree(default_tgt, debug_tgt, True)
Ryan41d89f62009-07-28 10:29:18101
Ryan1a126ed2009-04-04 12:50:15102def configure(conf):
103 conf.check_tool('compiler_cxx')
104 conf.check_tool('compiler_cc')
Ryana4593e32009-04-23 11:18:38105
Ryan8e7bbf22009-04-23 17:26:56106 conf.env["USE_DEBUG"] = Options.options.debug
Ryan1a126ed2009-04-04 12:50:15107
Ryan2b6d7242009-06-20 13:07:10108 conf.check(lib='dl', uselib_store='DL')
Ryan8152f9c2009-09-01 12:15:29109 conf.env.append_value("CCFLAGS", "-rdynamic")
Ryana97dce72009-08-31 09:14:34110 conf.env.append_value("LINKFLAGS_DL", "-rdynamic")
111
Ryan8152f9c2009-09-01 12:15:29112 #if Options.options.debug:
113 # conf.check(lib='profiler', uselib_store='PROFILER')
Ryan7bad9de2009-06-16 13:47:57114
Ryan8152f9c2009-09-01 12:15:29115 #if Options.options.efence:
116 # conf.check(lib='efence', libpath=['/usr/lib', '/usr/local/lib'], uselib_store='EFENCE')
Ryana3627c02009-05-27 14:29:55117
118 if sys.platform.startswith("freebsd"):
119 if not conf.check(lib="execinfo", libpath=['/usr/lib', '/usr/local/lib'], uselib_store="EXECINFO"):
Ryan7bad9de2009-06-16 13:47:57120 fatal("Install the libexecinfo port from /usr/ports/devel/libexecinfo.")
Ryana3627c02009-05-27 14:29:55121
Ryan1a126ed2009-04-04 12:50:15122 conf.sub_config('deps/libeio')
123 conf.sub_config('deps/libev')
124
Ryan41d89f62009-07-28 10:29:18125 conf_subproject(conf, 'deps/udns', './configure')
126 conf_subproject(conf, 'deps/v8')
127
Ryan452d3f12009-06-11 11:40:14128 # Not using TLS yet
129 # if conf.check_cfg(package='gnutls', args='--cflags --libs', uselib_store="GNUTLS"):
130 # conf.define("HAVE_GNUTLS", 1)
Ryan1a126ed2009-04-04 12:50:15131
132 conf.define("HAVE_CONFIG_H", 1)
Ryanc62b1242009-04-22 17:55:08133
Ryan1df6d612009-09-03 13:59:48134 conf.env.append_value("CCFLAGS", "-DX_STACKSIZE=%d" % (1024*64))
Ryan427e3f52009-05-14 11:16:45135
Ryan67af9582009-04-18 13:35:42136 # Split off debug variant before adding variant specific defines
Ryan7e1350f2009-04-16 09:37:44137 debug_env = conf.env.copy()
138 conf.set_env_name('debug', debug_env)
Ryan7e1350f2009-04-16 09:37:44139
Ryan67af9582009-04-18 13:35:42140 # Configure debug variant
141 conf.setenv('debug')
142 debug_env.set_variant('debug')
Ryan8ddf9302009-09-02 18:19:52143 debug_env.append_value('CCFLAGS', ['-DDEBUG', '-g', '-O0', '-Wall', '-Wextra'])
144 debug_env.append_value('CXXFLAGS', ['-DDEBUG', '-g', '-O0', '-Wall', '-Wextra'])
Ryan67af9582009-04-18 13:35:42145 conf.write_config_header("config.h")
146
147 # Configure default variant
148 conf.setenv('default')
Ryan8ddf9302009-09-02 18:19:52149 conf.env.append_value('CCFLAGS', ['-DNDEBUG', '-O3'])
150 conf.env.append_value('CXXFLAGS', ['-DNDEBUG', '-O3'])
Ryan67af9582009-04-18 13:35:42151 conf.write_config_header("config.h")
Ryan63a9cd32009-04-15 08:08:28152
Ryan41d89f62009-07-28 10:29:18153def build_udns(bld):
154 default_build_dir = bld.srcnode.abspath(bld.env_of_name("default"))
Ryan1a126ed2009-04-04 12:50:15155
Ryan41d89f62009-07-28 10:29:18156 default_dir = join(default_build_dir, "deps/udns")
157
158 static_lib = bld.env["staticlib_PATTERN"] % "udns"
159
160 rule = 'cd %s && make'
161
162 default = bld.new_task_gen(
163 target= join("deps/udns", static_lib),
164 rule= rule % default_dir,
165 before= "cxx",
166 install_path= None
167 )
168
169 bld.env["CPPPATH_UDNS"] = "deps/udns"
170 bld.env["STATICLIB_UDNS"] = "udns"
171
172 bld.env_of_name('default')["STATICLIB_UDNS"] = "udns"
173 bld.env_of_name('default')["LIBPATH_UDNS"] = default_dir
174
175 if bld.env["USE_DEBUG"]:
176 debug_build_dir = bld.srcnode.abspath(bld.env_of_name("debug"))
177 debug_dir = join(debug_build_dir, "deps/udns")
178 debug = default.clone("debug")
179 debug.rule = rule % debug_dir
180 #debug.target = join(debug_dir, static_lib)
181 bld.env_of_name('debug')["STATICLIB_UDNS"] = "udns"
182 bld.env_of_name('debug')["LIBPATH_UDNS"] = debug_dir
Ryan2b6d7242009-06-20 13:07:10183 bld.install_files('${PREFIX}/include/node/', 'deps/udns/udns.h');
Ryan41d89f62009-07-28 10:29:18184
Ryan8ddf9302009-09-02 18:19:52185# XXX Remove this when v8 defaults x86_64 to native builds
186def GuessArchitecture():
187 id = platform.machine()
Jeff Smickbc6f3812009-09-12 10:40:27188 arch = platform.architecture()[0]
Ryan8ddf9302009-09-02 18:19:52189 if id.startswith('arm'):
190 return 'arm'
Jeff Smickbc6f3812009-09-12 10:40:27191 elif ('64' in id) or ('64' in arch):
Ryan8ddf9302009-09-02 18:19:52192 return 'x64'
193 elif (not id) or (not re.match('(x|i[3-6])86', id) is None):
194 return 'ia32'
195 else:
196 return None
197
Ryan41d89f62009-07-28 10:29:18198
199def build_v8(bld):
Ryan1a126ed2009-04-04 12:50:15200 deps_src = join(bld.path.abspath(),"deps")
Ryana4593e32009-04-23 11:18:38201 deps_tgt = join(bld.srcnode.abspath(bld.env_of_name("default")),"deps")
Ryan1a126ed2009-04-04 12:50:15202 v8dir_src = join(deps_src,"v8")
203 v8dir_tgt = join(deps_tgt, "v8")
Ryan115c4942009-06-22 11:08:32204 scons = os.path.join(cwd, 'tools/scons/scons.py')
Ryana4593e32009-04-23 11:18:38205
Ryan Dahlbc9b3432009-10-02 12:10:40206 # NOTE: We want to compile V8 to export its symbols. I.E. Do not want
207 # -fvisibility=hidden. When using dlopen() it seems that the loaded DSO
208 # cannot see symbols in the executable which are hidden, even if the
209 # executable is statically linked together...
Ryan41d89f62009-07-28 10:29:18210 v8rule = 'cd %s && ' \
Ryan Dahl45ea62a2009-09-26 13:10:56211 'python %s -Q visibility=default mode=%s %s library=static snapshot=on'
Ryan8ddf9302009-09-02 18:19:52212
213 arch = ""
214 if GuessArchitecture() == "x64":
215 arch = "arch=x64"
Ryana4593e32009-04-23 11:18:38216
Ryan1a126ed2009-04-04 12:50:15217 v8 = bld.new_task_gen(
Ryana4593e32009-04-23 11:18:38218 target = join("deps/v8", bld.env["staticlib_PATTERN"] % "v8"),
Ryan8ddf9302009-09-02 18:19:52219 rule=v8rule % (v8dir_tgt, scons, "release", arch),
Ryan8e7bbf22009-04-23 17:26:56220 before="cxx",
221 install_path = None
Ryan1a126ed2009-04-04 12:50:15222 )
223 bld.env["CPPPATH_V8"] = "deps/v8/include"
Ryana4593e32009-04-23 11:18:38224 bld.env_of_name('default')["STATICLIB_V8"] = "v8"
225 bld.env_of_name('default')["LIBPATH_V8"] = v8dir_tgt
Ryan8ddf9302009-09-02 18:19:52226 bld.env_of_name('default')["LINKFLAGS_V8"] = ["-pthread"]
Ryana4593e32009-04-23 11:18:38227
228 ### v8 debug
Ryan29b528c2009-04-23 15:29:31229 if bld.env["USE_DEBUG"]:
230 deps_tgt = join(bld.srcnode.abspath(bld.env_of_name("debug")),"deps")
231 v8dir_tgt = join(deps_tgt, "v8")
Ryana4593e32009-04-23 11:18:38232
Ryan29b528c2009-04-23 15:29:31233 v8_debug = v8.clone("debug")
234 bld.env_of_name('debug')["STATICLIB_V8"] = "v8_g"
235 bld.env_of_name('debug')["LIBPATH_V8"] = v8dir_tgt
Ryan8ddf9302009-09-02 18:19:52236 bld.env_of_name('debug')["LINKFLAGS_V8"] = ["-pthread"]
237 v8_debug.rule = v8rule % (v8dir_tgt, scons, "debug", arch)
Ryan29b528c2009-04-23 15:29:31238 v8_debug.target = join("deps/v8", bld.env["staticlib_PATTERN"] % "v8_g")
Ryan1a126ed2009-04-04 12:50:15239
Ryan2b6d7242009-06-20 13:07:10240 bld.install_files('${PREFIX}/include/node/', 'deps/v8/include/v8*');
241
Ryan41d89f62009-07-28 10:29:18242def build(bld):
243 bld.add_subdirs('deps/libeio deps/libev')
244
245 build_udns(bld)
246 build_v8(bld)
247
Ryan0fb0af32009-07-25 15:52:21248 ### evcom
249 evcom = bld.new_task_gen("cc", "staticlib")
250 evcom.source = "deps/evcom/evcom.c"
251 evcom.includes = "deps/evcom/ deps/libev/"
252 evcom.name = "evcom"
253 evcom.target = "evcom"
254 # evcom.uselib = "GNUTLS"
255 evcom.install_path = None
Ryan29b528c2009-04-23 15:29:31256 if bld.env["USE_DEBUG"]:
Ryan0fb0af32009-07-25 15:52:21257 evcom.clone("debug")
Ryan2b6d7242009-06-20 13:07:10258 bld.install_files('${PREFIX}/include/node/', 'deps/evcom/evcom.h');
Ryan1a126ed2009-04-04 12:50:15259
Ryan5a071ad2009-05-03 12:09:16260 ### http_parser
261 http_parser = bld.new_task_gen("cc", "staticlib")
262 http_parser.source = "deps/http_parser/http_parser.c"
263 http_parser.includes = "deps/http_parser/"
264 http_parser.name = "http_parser"
265 http_parser.target = "http_parser"
266 http_parser.install_path = None
Ryan29b528c2009-04-23 15:29:31267 if bld.env["USE_DEBUG"]:
Ryan5a071ad2009-05-03 12:09:16268 http_parser.clone("debug")
Ryan1a126ed2009-04-04 12:50:15269
Ryan17c6a672009-08-24 18:25:24270 ### coupling
271 coupling = bld.new_task_gen("cc", "staticlib")
272 coupling.source = "deps/coupling/coupling.c"
273 coupling.includes = "deps/coupling/"
274 coupling.name = "coupling"
275 coupling.target = "coupling"
276 coupling.install_path = None
277 if bld.env["USE_DEBUG"]:
278 coupling.clone("debug")
279
Ryan63a9cd32009-04-15 08:08:28280 ### src/native.cc
281 def javascript_in_c(task):
282 env = task.env
283 source = map(lambda x: x.srcpath(env), task.inputs)
284 targets = map(lambda x: x.srcpath(env), task.outputs)
285 js2c.JS2C(source, targets)
286
287 native_cc = bld.new_task_gen(
Ryan2ecd7ff2009-06-25 17:13:20288 source = """
Ryaneb105532009-07-16 15:19:02289 src/util.js
Ryan2ecd7ff2009-06-25 17:13:20290 src/events.js
Ryan2ecd7ff2009-06-25 17:13:20291 src/file.js
292 src/node.js
293 """,
Ryan63a9cd32009-04-15 08:08:28294 target="src/natives.h",
295 rule=javascript_in_c,
296 before="cxx"
297 )
Ryan8e7bbf22009-04-23 17:26:56298 native_cc.install_path = None
Ryan29b528c2009-04-23 15:29:31299 if bld.env["USE_DEBUG"]:
300 native_cc.clone("debug")
Ryan63a9cd32009-04-15 08:08:28301
Ryan2b6d7242009-06-20 13:07:10302 ### node lib
Ryan8152f9c2009-09-01 12:15:29303 node = bld.new_task_gen("cxx", "program")
304 node.name = "node"
305 node.target = "node"
306 node.source = """
Ryan1a126ed2009-04-04 12:50:15307 src/node.cc
Ryan2ecd7ff2009-06-25 17:13:20308 src/events.cc
Ryan67af9582009-04-18 13:35:42309 src/http.cc
Ryan707f2442009-04-21 17:56:30310 src/net.cc
Ryan17c6a672009-08-24 18:25:24311 src/node_stdio.cc
Ryan41d89f62009-07-28 10:29:18312 src/dns.cc
Ryan63a9cd32009-04-15 08:08:28313 src/file.cc
Ryanf213a272009-04-29 09:00:46314 src/timer.cc
Ryanad9d6832009-08-26 20:11:51315 src/child_process.cc
Ryanb260a912009-05-26 17:48:49316 src/constants.cc
Ryan1a126ed2009-04-04 12:50:15317 """
Ryan8152f9c2009-09-01 12:15:29318 node.includes = """
Ryan1a126ed2009-04-04 12:50:15319 src/
320 deps/v8/include
321 deps/libev
Ryan41d89f62009-07-28 10:29:18322 deps/udns
Ryan1a126ed2009-04-04 12:50:15323 deps/libeio
Ryan0fb0af32009-07-25 15:52:21324 deps/evcom
Ryan5a071ad2009-05-03 12:09:16325 deps/http_parser
Ryan17c6a672009-08-24 18:25:24326 deps/coupling
Ryan1a126ed2009-04-04 12:50:15327 """
Ryan8152f9c2009-09-01 12:15:29328 node.uselib_local = "evcom ev eio http_parser coupling"
329 node.uselib = "UDNS V8 EXECINFO DL"
330 node.install_path = '${PREFIX}/lib'
Ryan8e7bbf22009-04-23 17:26:56331 node.install_path = '${PREFIX}/bin'
332 node.chmod = 0755
333
Ryan4d921992009-08-26 23:11:16334 def subflags(program):
Ryanb73264d2009-08-27 00:15:11335 x = { 'CCFLAGS' : " ".join(program.env["CCFLAGS"])
336 , 'CPPFLAGS' : " ".join(program.env["CPPFLAGS"])
337 , 'LIBFLAGS' : " ".join(program.env["LIBFLAGS"])
338 , 'VERSION' : VERSION
339 , 'PREFIX' : program.env["PREFIX"]
Ryan4d921992009-08-26 23:11:16340 }
341 return x;
342
Ryan4d921992009-08-26 23:11:16343 # process file.pc.in -> file.pc
344 pkgconfig = bld.new_task_gen('subst', before="cxx")
345 pkgconfig.source = 'src/node.pc.in'
346 pkgconfig.target = 'node.pc'
347 pkgconfig.install_path = '${PREFIX}/lib/pkgconfig'
348 pkgconfig.dict = subflags(node)
349
Ryanb73264d2009-08-27 00:15:11350 # process file.pc.in -> file.pc
351 node_version = bld.new_task_gen('subst', before="cxx")
352 node_version.source = 'src/node_version.h.in'
353 node_version.target = 'src/node_version.h'
354 node_version.dict = subflags(node)
Ryana97dce72009-08-31 09:14:34355 node_version.install_path = '${PREFIX}/include/node'
Ryan4d921992009-08-26 23:11:16356
Ryan29b528c2009-04-23 15:29:31357 if bld.env["USE_DEBUG"]:
Ryan2b6d7242009-06-20 13:07:10358 node_g = node.clone("debug")
359 node_g.target = "node_g"
Ryan4d921992009-08-26 23:11:16360
Ryanb73264d2009-08-27 00:15:11361 node_version_g = node_version.clone("debug")
362 node_version_g.dict = subflags(node_g)
Ryana97dce72009-08-31 09:14:34363 node_version_g.install_path = None
Ryan4d921992009-08-26 23:11:16364
Ryana97dce72009-08-31 09:14:34365
366 bld.install_files('${PREFIX}/include/node/', """
367 config.h
368 src/node.h
369 src/object_wrap.h
370 src/events.h
371 src/net.h
372 """);
Ryan68dda0a2009-09-10 11:40:38373 bld.install_files('${PREFIX}/share/man/man1/', 'doc/node.1');
Ryan Dahl2db7d672009-09-20 18:54:19374 bld.install_files('${PREFIX}/bin/', 'bin/*', chmod=0755);
Ryan Dahl6f17ca52009-10-03 17:08:05375
376 # Why am I using two lines? Because WAF SUCKS.
377 bld.install_files('${PREFIX}/lib/node/wafadmin', 'tools/wafadmin/*.py');
378 bld.install_files('${PREFIX}/lib/node/wafadmin/Tools', 'tools/wafadmin/Tools/*.py');
379
380 bld.install_files('${PREFIX}/lib/node/libraries/', 'lib/*.js');