blob: 232bf47accbe043f253abae76aa07dd8986d1bfb [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
Ryanba6c5e32009-09-05 12:47:569VERSION="0.1.9"
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'])
Ryanea29e132009-09-05 12:13:06102
103 # HACK FIXME - use 32bit on Mac
104 if platform.system() == "Darwin":
105 debug_env.append_value('CCFLAGS', '-m32')
106 debug_env.append_value('CXXFLAGS', '-m32')
107
Ryan67af9582009-04-18 13:35:42108 conf.write_config_header("config.h")
109
110 # Configure default variant
111 conf.setenv('default')
Ryan8ddf9302009-09-02 18:19:52112 conf.env.append_value('CCFLAGS', ['-DNDEBUG', '-O3'])
113 conf.env.append_value('CXXFLAGS', ['-DNDEBUG', '-O3'])
Ryanea29e132009-09-05 12:13:06114
115 # HACK FIXME - use 32bit on Mac
116 if platform.system() == "Darwin":
117 conf.env.append_value('CCFLAGS', '-m32')
118 conf.env.append_value('CXXFLAGS', '-m32')
119
Ryan67af9582009-04-18 13:35:42120 conf.write_config_header("config.h")
Ryan63a9cd32009-04-15 08:08:28121
Ryan41d89f62009-07-28 10:29:18122def build_udns(bld):
123 default_build_dir = bld.srcnode.abspath(bld.env_of_name("default"))
Ryan1a126ed2009-04-04 12:50:15124
Ryan41d89f62009-07-28 10:29:18125 default_dir = join(default_build_dir, "deps/udns")
126
127 static_lib = bld.env["staticlib_PATTERN"] % "udns"
128
129 rule = 'cd %s && make'
130
131 default = bld.new_task_gen(
132 target= join("deps/udns", static_lib),
133 rule= rule % default_dir,
134 before= "cxx",
135 install_path= None
136 )
137
138 bld.env["CPPPATH_UDNS"] = "deps/udns"
139 bld.env["STATICLIB_UDNS"] = "udns"
140
141 bld.env_of_name('default')["STATICLIB_UDNS"] = "udns"
142 bld.env_of_name('default')["LIBPATH_UDNS"] = default_dir
143
144 if bld.env["USE_DEBUG"]:
145 debug_build_dir = bld.srcnode.abspath(bld.env_of_name("debug"))
146 debug_dir = join(debug_build_dir, "deps/udns")
147 debug = default.clone("debug")
148 debug.rule = rule % debug_dir
149 #debug.target = join(debug_dir, static_lib)
150 bld.env_of_name('debug')["STATICLIB_UDNS"] = "udns"
151 bld.env_of_name('debug')["LIBPATH_UDNS"] = debug_dir
Ryan2b6d7242009-06-20 13:07:10152 bld.install_files('${PREFIX}/include/node/', 'deps/udns/udns.h');
Ryan41d89f62009-07-28 10:29:18153
Ryan8ddf9302009-09-02 18:19:52154# XXX Remove this when v8 defaults x86_64 to native builds
155def GuessArchitecture():
156 id = platform.machine()
157 if id.startswith('arm'):
158 return 'arm'
159 elif '64' in id:
160 return 'x64'
161 elif (not id) or (not re.match('(x|i[3-6])86', id) is None):
162 return 'ia32'
163 else:
164 return None
165
Ryan41d89f62009-07-28 10:29:18166
167def build_v8(bld):
Ryan1a126ed2009-04-04 12:50:15168 deps_src = join(bld.path.abspath(),"deps")
Ryana4593e32009-04-23 11:18:38169 deps_tgt = join(bld.srcnode.abspath(bld.env_of_name("default")),"deps")
Ryan1a126ed2009-04-04 12:50:15170 v8dir_src = join(deps_src,"v8")
171 v8dir_tgt = join(deps_tgt, "v8")
Ryan115c4942009-06-22 11:08:32172 scons = os.path.join(cwd, 'tools/scons/scons.py')
Ryana4593e32009-04-23 11:18:38173
Ryan41d89f62009-07-28 10:29:18174 v8rule = 'cd %s && ' \
Ryan8ddf9302009-09-02 18:19:52175 'python %s -Q mode=%s %s library=static snapshot=on'
176
177 arch = ""
178 if GuessArchitecture() == "x64":
179 arch = "arch=x64"
Ryana4593e32009-04-23 11:18:38180
Ryanea29e132009-09-05 12:13:06181 # HACK FIXME - use 32bit on Mac
182 if platform.system() == "Darwin": arch = "arch=ia32";
183
Ryan1a126ed2009-04-04 12:50:15184 v8 = bld.new_task_gen(
Ryana4593e32009-04-23 11:18:38185 target = join("deps/v8", bld.env["staticlib_PATTERN"] % "v8"),
Ryan8ddf9302009-09-02 18:19:52186 rule=v8rule % (v8dir_tgt, scons, "release", arch),
Ryan8e7bbf22009-04-23 17:26:56187 before="cxx",
188 install_path = None
Ryan1a126ed2009-04-04 12:50:15189 )
190 bld.env["CPPPATH_V8"] = "deps/v8/include"
Ryana4593e32009-04-23 11:18:38191 bld.env_of_name('default')["STATICLIB_V8"] = "v8"
192 bld.env_of_name('default')["LIBPATH_V8"] = v8dir_tgt
Ryan8ddf9302009-09-02 18:19:52193 bld.env_of_name('default')["LINKFLAGS_V8"] = ["-pthread"]
Ryana4593e32009-04-23 11:18:38194
Ryanea29e132009-09-05 12:13:06195 # HACK FIXME - use 32bit on Mac
196 if platform.system() == "Darwin":
197 bld.env_of_name('default')["LINKFLAGS_V8"] = ["-pthread", "-m32"]
198
Ryana4593e32009-04-23 11:18:38199 ### v8 debug
Ryan29b528c2009-04-23 15:29:31200 if bld.env["USE_DEBUG"]:
201 deps_tgt = join(bld.srcnode.abspath(bld.env_of_name("debug")),"deps")
202 v8dir_tgt = join(deps_tgt, "v8")
Ryana4593e32009-04-23 11:18:38203
Ryan29b528c2009-04-23 15:29:31204 v8_debug = v8.clone("debug")
205 bld.env_of_name('debug')["STATICLIB_V8"] = "v8_g"
206 bld.env_of_name('debug')["LIBPATH_V8"] = v8dir_tgt
Ryan8ddf9302009-09-02 18:19:52207 bld.env_of_name('debug')["LINKFLAGS_V8"] = ["-pthread"]
Ryanea29e132009-09-05 12:13:06208
209 # HACK FIXME - use 32bit on Mac
210 if platform.system() == "Darwin":
211 bld.env_of_name('debug')["LINKFLAGS_V8"] = ["-pthread", "-m32"]
212
Ryan8ddf9302009-09-02 18:19:52213 v8_debug.rule = v8rule % (v8dir_tgt, scons, "debug", arch)
Ryan29b528c2009-04-23 15:29:31214 v8_debug.target = join("deps/v8", bld.env["staticlib_PATTERN"] % "v8_g")
Ryan1a126ed2009-04-04 12:50:15215
Ryan2b6d7242009-06-20 13:07:10216 bld.install_files('${PREFIX}/include/node/', 'deps/v8/include/v8*');
217
Ryan41d89f62009-07-28 10:29:18218def build(bld):
219 bld.add_subdirs('deps/libeio deps/libev')
220
221 build_udns(bld)
222 build_v8(bld)
223
Ryan0fb0af32009-07-25 15:52:21224 ### evcom
225 evcom = bld.new_task_gen("cc", "staticlib")
226 evcom.source = "deps/evcom/evcom.c"
227 evcom.includes = "deps/evcom/ deps/libev/"
228 evcom.name = "evcom"
229 evcom.target = "evcom"
230 # evcom.uselib = "GNUTLS"
231 evcom.install_path = None
Ryan29b528c2009-04-23 15:29:31232 if bld.env["USE_DEBUG"]:
Ryan0fb0af32009-07-25 15:52:21233 evcom.clone("debug")
Ryan2b6d7242009-06-20 13:07:10234 bld.install_files('${PREFIX}/include/node/', 'deps/evcom/evcom.h');
Ryan1a126ed2009-04-04 12:50:15235
Ryan5a071ad2009-05-03 12:09:16236 ### http_parser
237 http_parser = bld.new_task_gen("cc", "staticlib")
238 http_parser.source = "deps/http_parser/http_parser.c"
239 http_parser.includes = "deps/http_parser/"
240 http_parser.name = "http_parser"
241 http_parser.target = "http_parser"
242 http_parser.install_path = None
Ryan29b528c2009-04-23 15:29:31243 if bld.env["USE_DEBUG"]:
Ryan5a071ad2009-05-03 12:09:16244 http_parser.clone("debug")
Ryan1a126ed2009-04-04 12:50:15245
Ryan17c6a672009-08-24 18:25:24246 ### coupling
247 coupling = bld.new_task_gen("cc", "staticlib")
248 coupling.source = "deps/coupling/coupling.c"
249 coupling.includes = "deps/coupling/"
250 coupling.name = "coupling"
251 coupling.target = "coupling"
252 coupling.install_path = None
253 if bld.env["USE_DEBUG"]:
254 coupling.clone("debug")
255
Ryan63a9cd32009-04-15 08:08:28256 ### src/native.cc
257 def javascript_in_c(task):
258 env = task.env
259 source = map(lambda x: x.srcpath(env), task.inputs)
260 targets = map(lambda x: x.srcpath(env), task.outputs)
261 js2c.JS2C(source, targets)
262
263 native_cc = bld.new_task_gen(
Ryan2ecd7ff2009-06-25 17:13:20264 source = """
Ryaneb105532009-07-16 15:19:02265 src/util.js
Ryan2ecd7ff2009-06-25 17:13:20266 src/events.js
267 src/http.js
268 src/file.js
269 src/node.js
270 """,
Ryan63a9cd32009-04-15 08:08:28271 target="src/natives.h",
272 rule=javascript_in_c,
273 before="cxx"
274 )
Ryan8e7bbf22009-04-23 17:26:56275 native_cc.install_path = None
Ryan29b528c2009-04-23 15:29:31276 if bld.env["USE_DEBUG"]:
277 native_cc.clone("debug")
Ryan63a9cd32009-04-15 08:08:28278
Ryan2b6d7242009-06-20 13:07:10279 ### node lib
Ryan8152f9c2009-09-01 12:15:29280 node = bld.new_task_gen("cxx", "program")
281 node.name = "node"
282 node.target = "node"
283 node.source = """
Ryan1a126ed2009-04-04 12:50:15284 src/node.cc
Ryan2ecd7ff2009-06-25 17:13:20285 src/events.cc
Ryan67af9582009-04-18 13:35:42286 src/http.cc
Ryan707f2442009-04-21 17:56:30287 src/net.cc
Ryan17c6a672009-08-24 18:25:24288 src/node_stdio.cc
Ryan41d89f62009-07-28 10:29:18289 src/dns.cc
Ryan63a9cd32009-04-15 08:08:28290 src/file.cc
Ryanf213a272009-04-29 09:00:46291 src/timer.cc
Ryanad9d6832009-08-26 20:11:51292 src/child_process.cc
Ryanb260a912009-05-26 17:48:49293 src/constants.cc
Ryan1a126ed2009-04-04 12:50:15294 """
Ryan8152f9c2009-09-01 12:15:29295 node.includes = """
Ryan1a126ed2009-04-04 12:50:15296 src/
297 deps/v8/include
298 deps/libev
Ryan41d89f62009-07-28 10:29:18299 deps/udns
Ryan1a126ed2009-04-04 12:50:15300 deps/libeio
Ryan0fb0af32009-07-25 15:52:21301 deps/evcom
Ryan5a071ad2009-05-03 12:09:16302 deps/http_parser
Ryan17c6a672009-08-24 18:25:24303 deps/coupling
Ryan1a126ed2009-04-04 12:50:15304 """
Ryan8152f9c2009-09-01 12:15:29305 node.uselib_local = "evcom ev eio http_parser coupling"
306 node.uselib = "UDNS V8 EXECINFO DL"
307 node.install_path = '${PREFIX}/lib'
Ryan8e7bbf22009-04-23 17:26:56308 node.install_path = '${PREFIX}/bin'
309 node.chmod = 0755
310
Ryan4d921992009-08-26 23:11:16311 def subflags(program):
Ryanb73264d2009-08-27 00:15:11312 x = { 'CCFLAGS' : " ".join(program.env["CCFLAGS"])
313 , 'CPPFLAGS' : " ".join(program.env["CPPFLAGS"])
314 , 'LIBFLAGS' : " ".join(program.env["LIBFLAGS"])
315 , 'VERSION' : VERSION
316 , 'PREFIX' : program.env["PREFIX"]
Ryan4d921992009-08-26 23:11:16317 }
318 return x;
319
Ryan4d921992009-08-26 23:11:16320 # process file.pc.in -> file.pc
321 pkgconfig = bld.new_task_gen('subst', before="cxx")
322 pkgconfig.source = 'src/node.pc.in'
323 pkgconfig.target = 'node.pc'
324 pkgconfig.install_path = '${PREFIX}/lib/pkgconfig'
325 pkgconfig.dict = subflags(node)
326
Ryanb73264d2009-08-27 00:15:11327 # process file.pc.in -> file.pc
328 node_version = bld.new_task_gen('subst', before="cxx")
329 node_version.source = 'src/node_version.h.in'
330 node_version.target = 'src/node_version.h'
331 node_version.dict = subflags(node)
Ryana97dce72009-08-31 09:14:34332 node_version.install_path = '${PREFIX}/include/node'
Ryan4d921992009-08-26 23:11:16333
Ryan29b528c2009-04-23 15:29:31334 if bld.env["USE_DEBUG"]:
Ryan2b6d7242009-06-20 13:07:10335 node_g = node.clone("debug")
336 node_g.target = "node_g"
Ryan4d921992009-08-26 23:11:16337
Ryanb73264d2009-08-27 00:15:11338 node_version_g = node_version.clone("debug")
339 node_version_g.dict = subflags(node_g)
Ryana97dce72009-08-31 09:14:34340 node_version_g.install_path = None
Ryan4d921992009-08-26 23:11:16341
Ryana97dce72009-08-31 09:14:34342
343 bld.install_files('${PREFIX}/include/node/', """
344 config.h
345 src/node.h
346 src/object_wrap.h
347 src/events.h
348 src/net.h
349 """);
Ryan68dda0a2009-09-10 11:40:38350 bld.install_files('${PREFIX}/share/man/man1/', 'doc/node.1');