blob: 4129088a64895c30ab0f67577a941daad714e161 [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 Dahl2f56ccb2009-09-24 11:51:109VERSION="0.1.12"
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
40def conf_subproject (conf, subdir, command=None):
41 print("---- %s ----" % subdir)
42 src = join(conf.srcdir, subdir)
43 if not os.path.exists (src): fatal("no such subproject " + subdir)
44
45 default_tgt = join(conf.blddir, "default", subdir)
46
47 if not os.path.exists(default_tgt):
48 shutil.copytree(src, default_tgt)
49
50 if command:
51 if os.system("cd %s && %s" % (default_tgt, command)) != 0:
52 fatal("Configuring %s failed." % (subdir))
53
54 debug_tgt = join(conf.blddir, "debug", subdir)
55
56 if not os.path.exists(debug_tgt):
57 shutil.copytree(default_tgt, debug_tgt)
58
Ryan1a126ed2009-04-04 12:50:1559def configure(conf):
60 conf.check_tool('compiler_cxx')
61 conf.check_tool('compiler_cc')
Ryana4593e32009-04-23 11:18:3862
Ryan8e7bbf22009-04-23 17:26:5663 conf.env["USE_DEBUG"] = Options.options.debug
Ryan1a126ed2009-04-04 12:50:1564
Ryan2b6d7242009-06-20 13:07:1065 conf.check(lib='dl', uselib_store='DL')
Ryan8152f9c2009-09-01 12:15:2966 conf.env.append_value("CCFLAGS", "-rdynamic")
Ryana97dce72009-08-31 09:14:3467 conf.env.append_value("LINKFLAGS_DL", "-rdynamic")
68
Ryan8152f9c2009-09-01 12:15:2969 #if Options.options.debug:
70 # conf.check(lib='profiler', uselib_store='PROFILER')
Ryan7bad9de2009-06-16 13:47:5771
Ryan8152f9c2009-09-01 12:15:2972 #if Options.options.efence:
73 # conf.check(lib='efence', libpath=['/usr/lib', '/usr/local/lib'], uselib_store='EFENCE')
Ryana3627c02009-05-27 14:29:5574
75 if sys.platform.startswith("freebsd"):
76 if not conf.check(lib="execinfo", libpath=['/usr/lib', '/usr/local/lib'], uselib_store="EXECINFO"):
Ryan7bad9de2009-06-16 13:47:5777 fatal("Install the libexecinfo port from /usr/ports/devel/libexecinfo.")
Ryana3627c02009-05-27 14:29:5578
Ryan1a126ed2009-04-04 12:50:1579 conf.sub_config('deps/libeio')
80 conf.sub_config('deps/libev')
81
Ryan41d89f62009-07-28 10:29:1882 conf_subproject(conf, 'deps/udns', './configure')
83 conf_subproject(conf, 'deps/v8')
84
Ryan452d3f12009-06-11 11:40:1485 # Not using TLS yet
86 # if conf.check_cfg(package='gnutls', args='--cflags --libs', uselib_store="GNUTLS"):
87 # conf.define("HAVE_GNUTLS", 1)
Ryan1a126ed2009-04-04 12:50:1588
89 conf.define("HAVE_CONFIG_H", 1)
Ryanc62b1242009-04-22 17:55:0890
Ryan1df6d612009-09-03 13:59:4891 conf.env.append_value("CCFLAGS", "-DX_STACKSIZE=%d" % (1024*64))
Ryan427e3f52009-05-14 11:16:4592
Ryan67af9582009-04-18 13:35:4293 # Split off debug variant before adding variant specific defines
Ryan7e1350f2009-04-16 09:37:4494 debug_env = conf.env.copy()
95 conf.set_env_name('debug', debug_env)
Ryan7e1350f2009-04-16 09:37:4496
Ryan67af9582009-04-18 13:35:4297 # Configure debug variant
98 conf.setenv('debug')
99 debug_env.set_variant('debug')
Ryan8ddf9302009-09-02 18:19:52100 debug_env.append_value('CCFLAGS', ['-DDEBUG', '-g', '-O0', '-Wall', '-Wextra'])
101 debug_env.append_value('CXXFLAGS', ['-DDEBUG', '-g', '-O0', '-Wall', '-Wextra'])
Ryan67af9582009-04-18 13:35:42102 conf.write_config_header("config.h")
103
104 # Configure default variant
105 conf.setenv('default')
Ryan8ddf9302009-09-02 18:19:52106 conf.env.append_value('CCFLAGS', ['-DNDEBUG', '-O3'])
107 conf.env.append_value('CXXFLAGS', ['-DNDEBUG', '-O3'])
Ryan67af9582009-04-18 13:35:42108 conf.write_config_header("config.h")
Ryan63a9cd32009-04-15 08:08:28109
Ryan41d89f62009-07-28 10:29:18110def build_udns(bld):
111 default_build_dir = bld.srcnode.abspath(bld.env_of_name("default"))
Ryan1a126ed2009-04-04 12:50:15112
Ryan41d89f62009-07-28 10:29:18113 default_dir = join(default_build_dir, "deps/udns")
114
115 static_lib = bld.env["staticlib_PATTERN"] % "udns"
116
117 rule = 'cd %s && make'
118
119 default = bld.new_task_gen(
120 target= join("deps/udns", static_lib),
121 rule= rule % default_dir,
122 before= "cxx",
123 install_path= None
124 )
125
126 bld.env["CPPPATH_UDNS"] = "deps/udns"
127 bld.env["STATICLIB_UDNS"] = "udns"
128
129 bld.env_of_name('default')["STATICLIB_UDNS"] = "udns"
130 bld.env_of_name('default')["LIBPATH_UDNS"] = default_dir
131
132 if bld.env["USE_DEBUG"]:
133 debug_build_dir = bld.srcnode.abspath(bld.env_of_name("debug"))
134 debug_dir = join(debug_build_dir, "deps/udns")
135 debug = default.clone("debug")
136 debug.rule = rule % debug_dir
137 #debug.target = join(debug_dir, static_lib)
138 bld.env_of_name('debug')["STATICLIB_UDNS"] = "udns"
139 bld.env_of_name('debug')["LIBPATH_UDNS"] = debug_dir
Ryan2b6d7242009-06-20 13:07:10140 bld.install_files('${PREFIX}/include/node/', 'deps/udns/udns.h');
Ryan41d89f62009-07-28 10:29:18141
Ryan8ddf9302009-09-02 18:19:52142# XXX Remove this when v8 defaults x86_64 to native builds
143def GuessArchitecture():
144 id = platform.machine()
Jeff Smickbc6f3812009-09-12 10:40:27145 arch = platform.architecture()[0]
Ryan8ddf9302009-09-02 18:19:52146 if id.startswith('arm'):
147 return 'arm'
Jeff Smickbc6f3812009-09-12 10:40:27148 elif ('64' in id) or ('64' in arch):
Ryan8ddf9302009-09-02 18:19:52149 return 'x64'
150 elif (not id) or (not re.match('(x|i[3-6])86', id) is None):
151 return 'ia32'
152 else:
153 return None
154
Ryan41d89f62009-07-28 10:29:18155
156def build_v8(bld):
Ryan1a126ed2009-04-04 12:50:15157 deps_src = join(bld.path.abspath(),"deps")
Ryana4593e32009-04-23 11:18:38158 deps_tgt = join(bld.srcnode.abspath(bld.env_of_name("default")),"deps")
Ryan1a126ed2009-04-04 12:50:15159 v8dir_src = join(deps_src,"v8")
160 v8dir_tgt = join(deps_tgt, "v8")
Ryan115c4942009-06-22 11:08:32161 scons = os.path.join(cwd, 'tools/scons/scons.py')
Ryana4593e32009-04-23 11:18:38162
Ryan41d89f62009-07-28 10:29:18163 v8rule = 'cd %s && ' \
Ryan Dahl45ea62a2009-09-26 13:10:56164 'python %s -Q visibility=default mode=%s %s library=static snapshot=on'
Ryan8ddf9302009-09-02 18:19:52165
166 arch = ""
167 if GuessArchitecture() == "x64":
168 arch = "arch=x64"
Ryana4593e32009-04-23 11:18:38169
Ryan1a126ed2009-04-04 12:50:15170 v8 = bld.new_task_gen(
Ryana4593e32009-04-23 11:18:38171 target = join("deps/v8", bld.env["staticlib_PATTERN"] % "v8"),
Ryan8ddf9302009-09-02 18:19:52172 rule=v8rule % (v8dir_tgt, scons, "release", arch),
Ryan8e7bbf22009-04-23 17:26:56173 before="cxx",
174 install_path = None
Ryan1a126ed2009-04-04 12:50:15175 )
176 bld.env["CPPPATH_V8"] = "deps/v8/include"
Ryana4593e32009-04-23 11:18:38177 bld.env_of_name('default')["STATICLIB_V8"] = "v8"
178 bld.env_of_name('default')["LIBPATH_V8"] = v8dir_tgt
Ryan8ddf9302009-09-02 18:19:52179 bld.env_of_name('default')["LINKFLAGS_V8"] = ["-pthread"]
Ryana4593e32009-04-23 11:18:38180
181 ### v8 debug
Ryan29b528c2009-04-23 15:29:31182 if bld.env["USE_DEBUG"]:
183 deps_tgt = join(bld.srcnode.abspath(bld.env_of_name("debug")),"deps")
184 v8dir_tgt = join(deps_tgt, "v8")
Ryana4593e32009-04-23 11:18:38185
Ryan29b528c2009-04-23 15:29:31186 v8_debug = v8.clone("debug")
187 bld.env_of_name('debug')["STATICLIB_V8"] = "v8_g"
188 bld.env_of_name('debug')["LIBPATH_V8"] = v8dir_tgt
Ryan8ddf9302009-09-02 18:19:52189 bld.env_of_name('debug')["LINKFLAGS_V8"] = ["-pthread"]
190 v8_debug.rule = v8rule % (v8dir_tgt, scons, "debug", arch)
Ryan29b528c2009-04-23 15:29:31191 v8_debug.target = join("deps/v8", bld.env["staticlib_PATTERN"] % "v8_g")
Ryan1a126ed2009-04-04 12:50:15192
Ryan2b6d7242009-06-20 13:07:10193 bld.install_files('${PREFIX}/include/node/', 'deps/v8/include/v8*');
194
Ryan41d89f62009-07-28 10:29:18195def build(bld):
196 bld.add_subdirs('deps/libeio deps/libev')
197
198 build_udns(bld)
199 build_v8(bld)
200
Ryan0fb0af32009-07-25 15:52:21201 ### evcom
202 evcom = bld.new_task_gen("cc", "staticlib")
203 evcom.source = "deps/evcom/evcom.c"
204 evcom.includes = "deps/evcom/ deps/libev/"
205 evcom.name = "evcom"
206 evcom.target = "evcom"
207 # evcom.uselib = "GNUTLS"
208 evcom.install_path = None
Ryan29b528c2009-04-23 15:29:31209 if bld.env["USE_DEBUG"]:
Ryan0fb0af32009-07-25 15:52:21210 evcom.clone("debug")
Ryan2b6d7242009-06-20 13:07:10211 bld.install_files('${PREFIX}/include/node/', 'deps/evcom/evcom.h');
Ryan1a126ed2009-04-04 12:50:15212
Ryan5a071ad2009-05-03 12:09:16213 ### http_parser
214 http_parser = bld.new_task_gen("cc", "staticlib")
215 http_parser.source = "deps/http_parser/http_parser.c"
216 http_parser.includes = "deps/http_parser/"
217 http_parser.name = "http_parser"
218 http_parser.target = "http_parser"
219 http_parser.install_path = None
Ryan29b528c2009-04-23 15:29:31220 if bld.env["USE_DEBUG"]:
Ryan5a071ad2009-05-03 12:09:16221 http_parser.clone("debug")
Ryan1a126ed2009-04-04 12:50:15222
Ryan17c6a672009-08-24 18:25:24223 ### coupling
224 coupling = bld.new_task_gen("cc", "staticlib")
225 coupling.source = "deps/coupling/coupling.c"
226 coupling.includes = "deps/coupling/"
227 coupling.name = "coupling"
228 coupling.target = "coupling"
229 coupling.install_path = None
230 if bld.env["USE_DEBUG"]:
231 coupling.clone("debug")
232
Ryan63a9cd32009-04-15 08:08:28233 ### src/native.cc
234 def javascript_in_c(task):
235 env = task.env
236 source = map(lambda x: x.srcpath(env), task.inputs)
237 targets = map(lambda x: x.srcpath(env), task.outputs)
238 js2c.JS2C(source, targets)
239
240 native_cc = bld.new_task_gen(
Ryan2ecd7ff2009-06-25 17:13:20241 source = """
Ryaneb105532009-07-16 15:19:02242 src/util.js
Ryan2ecd7ff2009-06-25 17:13:20243 src/events.js
244 src/http.js
245 src/file.js
246 src/node.js
247 """,
Ryan63a9cd32009-04-15 08:08:28248 target="src/natives.h",
249 rule=javascript_in_c,
250 before="cxx"
251 )
Ryan8e7bbf22009-04-23 17:26:56252 native_cc.install_path = None
Ryan29b528c2009-04-23 15:29:31253 if bld.env["USE_DEBUG"]:
254 native_cc.clone("debug")
Ryan63a9cd32009-04-15 08:08:28255
Ryan2b6d7242009-06-20 13:07:10256 ### node lib
Ryan8152f9c2009-09-01 12:15:29257 node = bld.new_task_gen("cxx", "program")
258 node.name = "node"
259 node.target = "node"
260 node.source = """
Ryan1a126ed2009-04-04 12:50:15261 src/node.cc
Ryan2ecd7ff2009-06-25 17:13:20262 src/events.cc
Ryan67af9582009-04-18 13:35:42263 src/http.cc
Ryan707f2442009-04-21 17:56:30264 src/net.cc
Ryan17c6a672009-08-24 18:25:24265 src/node_stdio.cc
Ryan41d89f62009-07-28 10:29:18266 src/dns.cc
Ryan63a9cd32009-04-15 08:08:28267 src/file.cc
Ryanf213a272009-04-29 09:00:46268 src/timer.cc
Ryanad9d6832009-08-26 20:11:51269 src/child_process.cc
Ryanb260a912009-05-26 17:48:49270 src/constants.cc
Ryan1a126ed2009-04-04 12:50:15271 """
Ryan8152f9c2009-09-01 12:15:29272 node.includes = """
Ryan1a126ed2009-04-04 12:50:15273 src/
274 deps/v8/include
275 deps/libev
Ryan41d89f62009-07-28 10:29:18276 deps/udns
Ryan1a126ed2009-04-04 12:50:15277 deps/libeio
Ryan0fb0af32009-07-25 15:52:21278 deps/evcom
Ryan5a071ad2009-05-03 12:09:16279 deps/http_parser
Ryan17c6a672009-08-24 18:25:24280 deps/coupling
Ryan1a126ed2009-04-04 12:50:15281 """
Ryan8152f9c2009-09-01 12:15:29282 node.uselib_local = "evcom ev eio http_parser coupling"
283 node.uselib = "UDNS V8 EXECINFO DL"
284 node.install_path = '${PREFIX}/lib'
Ryan8e7bbf22009-04-23 17:26:56285 node.install_path = '${PREFIX}/bin'
286 node.chmod = 0755
287
Ryan4d921992009-08-26 23:11:16288 def subflags(program):
Ryanb73264d2009-08-27 00:15:11289 x = { 'CCFLAGS' : " ".join(program.env["CCFLAGS"])
290 , 'CPPFLAGS' : " ".join(program.env["CPPFLAGS"])
291 , 'LIBFLAGS' : " ".join(program.env["LIBFLAGS"])
292 , 'VERSION' : VERSION
293 , 'PREFIX' : program.env["PREFIX"]
Ryan4d921992009-08-26 23:11:16294 }
295 return x;
296
Ryan4d921992009-08-26 23:11:16297 # process file.pc.in -> file.pc
298 pkgconfig = bld.new_task_gen('subst', before="cxx")
299 pkgconfig.source = 'src/node.pc.in'
300 pkgconfig.target = 'node.pc'
301 pkgconfig.install_path = '${PREFIX}/lib/pkgconfig'
302 pkgconfig.dict = subflags(node)
303
Ryanb73264d2009-08-27 00:15:11304 # process file.pc.in -> file.pc
305 node_version = bld.new_task_gen('subst', before="cxx")
306 node_version.source = 'src/node_version.h.in'
307 node_version.target = 'src/node_version.h'
308 node_version.dict = subflags(node)
Ryana97dce72009-08-31 09:14:34309 node_version.install_path = '${PREFIX}/include/node'
Ryan4d921992009-08-26 23:11:16310
Ryan29b528c2009-04-23 15:29:31311 if bld.env["USE_DEBUG"]:
Ryan2b6d7242009-06-20 13:07:10312 node_g = node.clone("debug")
313 node_g.target = "node_g"
Ryan4d921992009-08-26 23:11:16314
Ryanb73264d2009-08-27 00:15:11315 node_version_g = node_version.clone("debug")
316 node_version_g.dict = subflags(node_g)
Ryana97dce72009-08-31 09:14:34317 node_version_g.install_path = None
Ryan4d921992009-08-26 23:11:16318
Ryana97dce72009-08-31 09:14:34319
320 bld.install_files('${PREFIX}/include/node/', """
321 config.h
322 src/node.h
323 src/object_wrap.h
324 src/events.h
325 src/net.h
326 """);
Ryan68dda0a2009-09-10 11:40:38327 bld.install_files('${PREFIX}/share/man/man1/', 'doc/node.1');
Ryan Dahl2db7d672009-09-20 18:54:19328 bld.install_files('${PREFIX}/bin/', 'bin/*', chmod=0755);
Ryan Dahl4b8f5032009-09-20 16:19:33329 bld.install_files('${PREFIX}/lib/node_libraries/', 'lib/*.js');