blob: 93e82c2b6cd6d774c00a71d3ebf2a08cdeda48b9 [file] [log] [blame]
Ryana3627c02009-05-27 14:29:551# /usr/bin/env python
Ryan1a126ed2009-04-04 12:50:152import Options
Ryan41d89f62009-07-28 10:29:183import sys, os, shutil
Ryan1a126ed2009-04-04 12:50:154from os.path import join, dirname, abspath
Ryana4593e32009-04-23 11:18:385from logging import fatal
6
Ryanb73264d2009-08-27 00:15:117VERSION="0.1.7"
Ryan4d921992009-08-26 23:11:168APPNAME="node.js"
9
Ryan63a9cd32009-04-15 08:08:2810import js2c
11
Ryan1a126ed2009-04-04 12:50:1512srcdir = '.'
13blddir = 'build'
Ryan115c4942009-06-22 11:08:3214cwd = os.getcwd()
Ryan1a126ed2009-04-04 12:50:1515
16def set_options(opt):
17 # the gcc module provides a --debug-level option
18 opt.tool_options('compiler_cxx')
19 opt.tool_options('compiler_cc')
Ryan4d921992009-08-26 23:11:1620 opt.tool_options('misc')
Ryan29b528c2009-04-23 15:29:3121 opt.add_option( '--debug'
22 , action='store_true'
23 , default=False
24 , help='Build debug variant [Default: False]'
25 , dest='debug'
26 )
Ryan7bad9de2009-06-16 13:47:5727 opt.add_option( '--efence'
28 , action='store_true'
29 , default=False
30 , help='Build with -lefence for debugging [Default: False]'
31 , dest='efence'
32 )
Ryan1a126ed2009-04-04 12:50:1533
Ryan41d89f62009-07-28 10:29:1834def mkdir_p(dir):
35 if not os.path.exists (dir):
36 os.makedirs (dir)
37
38def conf_subproject (conf, subdir, command=None):
39 print("---- %s ----" % subdir)
40 src = join(conf.srcdir, subdir)
41 if not os.path.exists (src): fatal("no such subproject " + subdir)
42
43 default_tgt = join(conf.blddir, "default", subdir)
44
45 if not os.path.exists(default_tgt):
46 shutil.copytree(src, default_tgt)
47
48 if command:
49 if os.system("cd %s && %s" % (default_tgt, command)) != 0:
50 fatal("Configuring %s failed." % (subdir))
51
52 debug_tgt = join(conf.blddir, "debug", subdir)
53
54 if not os.path.exists(debug_tgt):
55 shutil.copytree(default_tgt, debug_tgt)
56
Ryan1a126ed2009-04-04 12:50:1557def configure(conf):
58 conf.check_tool('compiler_cxx')
59 conf.check_tool('compiler_cc')
Ryana4593e32009-04-23 11:18:3860
Ryan8e7bbf22009-04-23 17:26:5661 conf.env["USE_DEBUG"] = Options.options.debug
Ryan1a126ed2009-04-04 12:50:1562
Ryan2b6d7242009-06-20 13:07:1063 conf.check(lib='dl', uselib_store='DL')
Ryana97dce72009-08-31 09:14:3464 conf.env.append_value("LINKFLAGS_DL", "-rdynamic")
65
Ryan7bad9de2009-06-16 13:47:5766 if Options.options.debug:
67 conf.check(lib='profiler', uselib_store='PROFILER')
68
69 if Options.options.efence:
70 conf.check(lib='efence', libpath=['/usr/lib', '/usr/local/lib'], uselib_store='EFENCE')
Ryana3627c02009-05-27 14:29:5571
72 if sys.platform.startswith("freebsd"):
73 if not conf.check(lib="execinfo", libpath=['/usr/lib', '/usr/local/lib'], uselib_store="EXECINFO"):
Ryan7bad9de2009-06-16 13:47:5774 fatal("Install the libexecinfo port from /usr/ports/devel/libexecinfo.")
Ryana3627c02009-05-27 14:29:5575
Ryan1a126ed2009-04-04 12:50:1576 conf.sub_config('deps/libeio')
77 conf.sub_config('deps/libev')
78
Ryan41d89f62009-07-28 10:29:1879 conf_subproject(conf, 'deps/udns', './configure')
80 conf_subproject(conf, 'deps/v8')
81
Ryan452d3f12009-06-11 11:40:1482 # Not using TLS yet
83 # if conf.check_cfg(package='gnutls', args='--cflags --libs', uselib_store="GNUTLS"):
84 # conf.define("HAVE_GNUTLS", 1)
Ryan1a126ed2009-04-04 12:50:1585
86 conf.define("HAVE_CONFIG_H", 1)
Ryanc62b1242009-04-22 17:55:0887
Ryan7703ad52009-04-22 15:19:0888 conf.env.append_value("CCFLAGS", "-DEIO_STACKSIZE=%d" % (4096*8))
Ryan427e3f52009-05-14 11:16:4589
Ryan67af9582009-04-18 13:35:4290 # Split off debug variant before adding variant specific defines
Ryan7e1350f2009-04-16 09:37:4491 debug_env = conf.env.copy()
92 conf.set_env_name('debug', debug_env)
Ryan7e1350f2009-04-16 09:37:4493
Ryan67af9582009-04-18 13:35:4294 # Configure debug variant
95 conf.setenv('debug')
96 debug_env.set_variant('debug')
Ryana623d762009-06-29 19:17:0697 debug_env.append_value('CCFLAGS', ['-DDEBUG', '-g', '-O0', '-Wall', '-Wextra', '-m32'])
98 debug_env.append_value('CXXFLAGS', ['-DDEBUG', '-g', '-O0', '-Wall', '-Wextra', '-m32'])
Ryan67af9582009-04-18 13:35:4299 conf.write_config_header("config.h")
100
101 # Configure default variant
102 conf.setenv('default')
Ryana623d762009-06-29 19:17:06103 conf.env.append_value('CCFLAGS', ['-DNDEBUG', '-O3', '-m32'])
104 conf.env.append_value('CXXFLAGS', ['-DNDEBUG', '-O3', '-m32'])
Ryan67af9582009-04-18 13:35:42105 conf.write_config_header("config.h")
Ryan63a9cd32009-04-15 08:08:28106
Ryan41d89f62009-07-28 10:29:18107def build_udns(bld):
108 default_build_dir = bld.srcnode.abspath(bld.env_of_name("default"))
Ryan1a126ed2009-04-04 12:50:15109
Ryan41d89f62009-07-28 10:29:18110 default_dir = join(default_build_dir, "deps/udns")
111
112 static_lib = bld.env["staticlib_PATTERN"] % "udns"
113
114 rule = 'cd %s && make'
115
116 default = bld.new_task_gen(
117 target= join("deps/udns", static_lib),
118 rule= rule % default_dir,
119 before= "cxx",
120 install_path= None
121 )
122
123 bld.env["CPPPATH_UDNS"] = "deps/udns"
124 bld.env["STATICLIB_UDNS"] = "udns"
125
126 bld.env_of_name('default')["STATICLIB_UDNS"] = "udns"
127 bld.env_of_name('default')["LIBPATH_UDNS"] = default_dir
128
129 if bld.env["USE_DEBUG"]:
130 debug_build_dir = bld.srcnode.abspath(bld.env_of_name("debug"))
131 debug_dir = join(debug_build_dir, "deps/udns")
132 debug = default.clone("debug")
133 debug.rule = rule % debug_dir
134 #debug.target = join(debug_dir, static_lib)
135 bld.env_of_name('debug')["STATICLIB_UDNS"] = "udns"
136 bld.env_of_name('debug')["LIBPATH_UDNS"] = debug_dir
Ryan2b6d7242009-06-20 13:07:10137 bld.install_files('${PREFIX}/include/node/', 'deps/udns/udns.h');
Ryan41d89f62009-07-28 10:29:18138
139
140def build_v8(bld):
Ryan1a126ed2009-04-04 12:50:15141 deps_src = join(bld.path.abspath(),"deps")
Ryana4593e32009-04-23 11:18:38142 deps_tgt = join(bld.srcnode.abspath(bld.env_of_name("default")),"deps")
Ryan1a126ed2009-04-04 12:50:15143 v8dir_src = join(deps_src,"v8")
144 v8dir_tgt = join(deps_tgt, "v8")
Ryan115c4942009-06-22 11:08:32145 scons = os.path.join(cwd, 'tools/scons/scons.py')
Ryana4593e32009-04-23 11:18:38146
Ryan41d89f62009-07-28 10:29:18147 v8rule = 'cd %s && ' \
Ryan115c4942009-06-22 11:08:32148 'python %s -Q mode=%s library=static snapshot=on'
Ryana4593e32009-04-23 11:18:38149
Ryan1a126ed2009-04-04 12:50:15150 v8 = bld.new_task_gen(
Ryana4593e32009-04-23 11:18:38151 target = join("deps/v8", bld.env["staticlib_PATTERN"] % "v8"),
Ryan41d89f62009-07-28 10:29:18152 rule=v8rule % (v8dir_tgt, scons, "release"),
Ryan8e7bbf22009-04-23 17:26:56153 before="cxx",
154 install_path = None
Ryan1a126ed2009-04-04 12:50:15155 )
156 bld.env["CPPPATH_V8"] = "deps/v8/include"
Ryana4593e32009-04-23 11:18:38157 bld.env_of_name('default')["STATICLIB_V8"] = "v8"
158 bld.env_of_name('default')["LIBPATH_V8"] = v8dir_tgt
Ryan41d89f62009-07-28 10:29:18159 bld.env_of_name('default')["LINKFLAGS_V8"] = ["-pthread", "-m32"]
Ryana4593e32009-04-23 11:18:38160
161 ### v8 debug
Ryan29b528c2009-04-23 15:29:31162 if bld.env["USE_DEBUG"]:
163 deps_tgt = join(bld.srcnode.abspath(bld.env_of_name("debug")),"deps")
164 v8dir_tgt = join(deps_tgt, "v8")
Ryana4593e32009-04-23 11:18:38165
Ryan29b528c2009-04-23 15:29:31166 v8_debug = v8.clone("debug")
167 bld.env_of_name('debug')["STATICLIB_V8"] = "v8_g"
168 bld.env_of_name('debug')["LIBPATH_V8"] = v8dir_tgt
Ryana623d762009-06-29 19:17:06169 bld.env_of_name('debug')["LINKFLAGS_V8"] = ["-pthread", "-m32"]
Ryan41d89f62009-07-28 10:29:18170 v8_debug.rule = v8rule % (v8dir_tgt, scons, "debug")
Ryan29b528c2009-04-23 15:29:31171 v8_debug.target = join("deps/v8", bld.env["staticlib_PATTERN"] % "v8_g")
Ryan1a126ed2009-04-04 12:50:15172
Ryan2b6d7242009-06-20 13:07:10173 bld.install_files('${PREFIX}/include/node/', 'deps/v8/include/v8*');
174
Ryan41d89f62009-07-28 10:29:18175def build(bld):
176 bld.add_subdirs('deps/libeio deps/libev')
177
178 build_udns(bld)
179 build_v8(bld)
180
Ryan0fb0af32009-07-25 15:52:21181 ### evcom
182 evcom = bld.new_task_gen("cc", "staticlib")
183 evcom.source = "deps/evcom/evcom.c"
184 evcom.includes = "deps/evcom/ deps/libev/"
185 evcom.name = "evcom"
186 evcom.target = "evcom"
187 # evcom.uselib = "GNUTLS"
188 evcom.install_path = None
Ryan29b528c2009-04-23 15:29:31189 if bld.env["USE_DEBUG"]:
Ryan0fb0af32009-07-25 15:52:21190 evcom.clone("debug")
Ryan2b6d7242009-06-20 13:07:10191 bld.install_files('${PREFIX}/include/node/', 'deps/evcom/evcom.h');
Ryan1a126ed2009-04-04 12:50:15192
Ryan5a071ad2009-05-03 12:09:16193 ### http_parser
194 http_parser = bld.new_task_gen("cc", "staticlib")
195 http_parser.source = "deps/http_parser/http_parser.c"
196 http_parser.includes = "deps/http_parser/"
197 http_parser.name = "http_parser"
198 http_parser.target = "http_parser"
199 http_parser.install_path = None
Ryan29b528c2009-04-23 15:29:31200 if bld.env["USE_DEBUG"]:
Ryan5a071ad2009-05-03 12:09:16201 http_parser.clone("debug")
Ryan1a126ed2009-04-04 12:50:15202
Ryan17c6a672009-08-24 18:25:24203 ### coupling
204 coupling = bld.new_task_gen("cc", "staticlib")
205 coupling.source = "deps/coupling/coupling.c"
206 coupling.includes = "deps/coupling/"
207 coupling.name = "coupling"
208 coupling.target = "coupling"
209 coupling.install_path = None
210 if bld.env["USE_DEBUG"]:
211 coupling.clone("debug")
212
Ryan63a9cd32009-04-15 08:08:28213 ### src/native.cc
214 def javascript_in_c(task):
215 env = task.env
216 source = map(lambda x: x.srcpath(env), task.inputs)
217 targets = map(lambda x: x.srcpath(env), task.outputs)
218 js2c.JS2C(source, targets)
219
220 native_cc = bld.new_task_gen(
Ryan2ecd7ff2009-06-25 17:13:20221 source = """
Ryaneb105532009-07-16 15:19:02222 src/util.js
Ryan2ecd7ff2009-06-25 17:13:20223 src/events.js
224 src/http.js
225 src/file.js
226 src/node.js
227 """,
Ryan63a9cd32009-04-15 08:08:28228 target="src/natives.h",
229 rule=javascript_in_c,
230 before="cxx"
231 )
Ryan8e7bbf22009-04-23 17:26:56232 native_cc.install_path = None
Ryan29b528c2009-04-23 15:29:31233 if bld.env["USE_DEBUG"]:
234 native_cc.clone("debug")
Ryan63a9cd32009-04-15 08:08:28235
Ryan2b6d7242009-06-20 13:07:10236 ### node lib
237 libnode = bld.new_task_gen("cxx", "shlib")
238 libnode.name = "node"
239 libnode.target = "node"
240 libnode.source = """
Ryan1a126ed2009-04-04 12:50:15241 src/node.cc
Ryan2ecd7ff2009-06-25 17:13:20242 src/events.cc
Ryan67af9582009-04-18 13:35:42243 src/http.cc
Ryan707f2442009-04-21 17:56:30244 src/net.cc
Ryan17c6a672009-08-24 18:25:24245 src/node_stdio.cc
Ryan41d89f62009-07-28 10:29:18246 src/dns.cc
Ryan63a9cd32009-04-15 08:08:28247 src/file.cc
Ryanf213a272009-04-29 09:00:46248 src/timer.cc
Ryanad9d6832009-08-26 20:11:51249 src/child_process.cc
Ryanb260a912009-05-26 17:48:49250 src/constants.cc
Ryan1a126ed2009-04-04 12:50:15251 """
Ryan2b6d7242009-06-20 13:07:10252 libnode.includes = """
Ryan1a126ed2009-04-04 12:50:15253 src/
254 deps/v8/include
255 deps/libev
Ryan41d89f62009-07-28 10:29:18256 deps/udns
Ryan1a126ed2009-04-04 12:50:15257 deps/libeio
Ryan0fb0af32009-07-25 15:52:21258 deps/evcom
Ryan5a071ad2009-05-03 12:09:16259 deps/http_parser
Ryan17c6a672009-08-24 18:25:24260 deps/coupling
Ryan1a126ed2009-04-04 12:50:15261 """
Ryan2b6d7242009-06-20 13:07:10262 libnode.uselib_local = "evcom ev eio http_parser coupling"
263 libnode.uselib = "UDNS V8 EXECINFO PROFILER EFENCE DL"
264 libnode.install_path = '${PREFIX}/lib'
Ryana97dce72009-08-31 09:14:34265
266
267 libnode_static = bld.new_task_gen("cxx", "staticlib")
268 libnode_static.name = "node-static"
269 libnode_static.target = libnode.target
270 libnode_static.source = libnode.source
271 libnode_static.includes = libnode.includes
272 libnode_static.uselib_local = libnode.uselib_local
273 libnode_static.uselib = libnode.uselib
Ryan2b6d7242009-06-20 13:07:10274
275 ### node
276 node = bld.new_task_gen("cxx", "program")
277 node.target = 'node'
278 node.source = "src/main.cc"
279 node.includes = libnode.includes
Ryana97dce72009-08-31 09:14:34280 node.uselib_local = "node-static"
Ryan8e7bbf22009-04-23 17:26:56281 node.install_path = '${PREFIX}/bin'
282 node.chmod = 0755
283
Ryan4d921992009-08-26 23:11:16284 def subflags(program):
Ryanb73264d2009-08-27 00:15:11285 x = { 'CCFLAGS' : " ".join(program.env["CCFLAGS"])
286 , 'CPPFLAGS' : " ".join(program.env["CPPFLAGS"])
287 , 'LIBFLAGS' : " ".join(program.env["LIBFLAGS"])
288 , 'VERSION' : VERSION
289 , 'PREFIX' : program.env["PREFIX"]
Ryan4d921992009-08-26 23:11:16290 }
291 return x;
292
Ryan4d921992009-08-26 23:11:16293 # process file.pc.in -> file.pc
294 pkgconfig = bld.new_task_gen('subst', before="cxx")
295 pkgconfig.source = 'src/node.pc.in'
296 pkgconfig.target = 'node.pc'
297 pkgconfig.install_path = '${PREFIX}/lib/pkgconfig'
298 pkgconfig.dict = subflags(node)
299
Ryanb73264d2009-08-27 00:15:11300 # process file.pc.in -> file.pc
301 node_version = bld.new_task_gen('subst', before="cxx")
302 node_version.source = 'src/node_version.h.in'
303 node_version.target = 'src/node_version.h'
304 node_version.dict = subflags(node)
Ryana97dce72009-08-31 09:14:34305 node_version.install_path = '${PREFIX}/include/node'
Ryan4d921992009-08-26 23:11:16306
Ryan29b528c2009-04-23 15:29:31307 if bld.env["USE_DEBUG"]:
Ryan2b6d7242009-06-20 13:07:10308 node_g = node.clone("debug")
309 node_g.target = "node_g"
310
311 libnode_g = libnode.clone("debug")
312 libnode_g.target = "node_g"
Ryan67af9582009-04-18 13:35:42313
Ryana97dce72009-08-31 09:14:34314 libnode_static_g = libnode_static.clone("debug")
315 libnode_static_g.target = "node_g"
Ryan4d921992009-08-26 23:11:16316
Ryanb73264d2009-08-27 00:15:11317 node_version_g = node_version.clone("debug")
318 node_version_g.dict = subflags(node_g)
Ryana97dce72009-08-31 09:14:34319 node_version_g.install_path = None
Ryan4d921992009-08-26 23:11:16320
Ryana97dce72009-08-31 09:14:34321
322 bld.install_files('${PREFIX}/include/node/', """
323 config.h
324 src/node.h
325 src/object_wrap.h
326 src/events.h
327 src/net.h
328 """);