blob: 090611f888e928c8db7fbdb97b6b7e2ab41032a1 [file] [log] [blame]
Ryana3627c02009-05-27 14:29:551# /usr/bin/env python
Ryan1a126ed2009-04-04 12:50:152import Options
Ryan63a9cd32009-04-15 08:08:283import sys
Ryan1a126ed2009-04-04 12:50:154import os
5from os.path import join, dirname, abspath
Ryana4593e32009-04-23 11:18:386from logging import fatal
7
Ryan1a126ed2009-04-04 12:50:158
Ryan63a9cd32009-04-15 08:08:289import js2c
10
Ryan1a126ed2009-04-04 12:50:1511VERSION='0.0.1'
12APPNAME='node'
13
14srcdir = '.'
15blddir = 'build'
16
17def set_options(opt):
18 # the gcc module provides a --debug-level option
19 opt.tool_options('compiler_cxx')
20 opt.tool_options('compiler_cc')
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 )
Ryan1a126ed2009-04-04 12:50:1527
28def configure(conf):
29 conf.check_tool('compiler_cxx')
30 conf.check_tool('compiler_cc')
Ryana4593e32009-04-23 11:18:3831
Ryan8e7bbf22009-04-23 17:26:5632 conf.env["USE_DEBUG"] = Options.options.debug
Ryan1a126ed2009-04-04 12:50:1533
Ryana3627c02009-05-27 14:29:5534
35 if sys.platform.startswith("freebsd"):
36 if not conf.check(lib="execinfo", libpath=['/usr/lib', '/usr/local/lib'], uselib_store="EXECINFO"):
37 fatal("install the libexecinfo port. devel/libexecinfo")
38
Ryan1a126ed2009-04-04 12:50:1539 conf.sub_config('deps/libeio')
40 conf.sub_config('deps/libev')
41
Ryan1a126ed2009-04-04 12:50:1542 # liboi config
43 print "--- liboi ---"
44 if conf.check_cfg(package='gnutls', args='--cflags --libs', uselib_store="GNUTLS"):
45 conf.define("HAVE_GNUTLS", 1)
46
47 conf.define("HAVE_CONFIG_H", 1)
Ryanc62b1242009-04-22 17:55:0848
Ryan7703ad52009-04-22 15:19:0849 conf.env.append_value("CCFLAGS", "-DEIO_STACKSIZE=%d" % (4096*8))
Ryan427e3f52009-05-14 11:16:4550
Ryan0bb12be2009-05-05 19:16:1951 conf.check(lib='profiler', uselib_store='PROFILER')
52
Ryan67af9582009-04-18 13:35:4253 # Split off debug variant before adding variant specific defines
Ryan7e1350f2009-04-16 09:37:4454 debug_env = conf.env.copy()
55 conf.set_env_name('debug', debug_env)
Ryan7e1350f2009-04-16 09:37:4456
Ryan67af9582009-04-18 13:35:4257 # Configure debug variant
58 conf.setenv('debug')
59 debug_env.set_variant('debug')
60 debug_env.append_value('CCFLAGS', ['-DDEBUG', '-g', '-O0', '-Wall', '-Wextra'])
61 debug_env.append_value('CXXFLAGS', ['-DDEBUG', '-g', '-O0', '-Wall', '-Wextra'])
62 conf.write_config_header("config.h")
63
64 # Configure default variant
65 conf.setenv('default')
Ryan0bb12be2009-05-05 19:16:1966 conf.env.append_value('CCFLAGS', ['-DNDEBUG', '-O3'])
67 conf.env.append_value('CXXFLAGS', ['-DNDEBUG', '-O3'])
Ryan67af9582009-04-18 13:35:4268 conf.write_config_header("config.h")
Ryan63a9cd32009-04-15 08:08:2869
Ryan1a126ed2009-04-04 12:50:1570def build(bld):
Ryan1a126ed2009-04-04 12:50:1571 bld.add_subdirs('deps/libeio deps/libev')
72
73 ### v8
74 deps_src = join(bld.path.abspath(),"deps")
Ryana4593e32009-04-23 11:18:3875 deps_tgt = join(bld.srcnode.abspath(bld.env_of_name("default")),"deps")
Ryan1a126ed2009-04-04 12:50:1576 v8dir_src = join(deps_src,"v8")
77 v8dir_tgt = join(deps_tgt, "v8")
Ryana4593e32009-04-23 11:18:3878
79 v8rule = 'cp -rf %s %s && ' \
80 'cd %s && ' \
81 'python scons.py -Q mode=%s library=static snapshot=on'
82
Ryan1a126ed2009-04-04 12:50:1583 v8 = bld.new_task_gen(
Ryana4593e32009-04-23 11:18:3884 target = join("deps/v8", bld.env["staticlib_PATTERN"] % "v8"),
85 rule=v8rule % ( v8dir_src , deps_tgt , v8dir_tgt, "release"),
Ryan8e7bbf22009-04-23 17:26:5686 before="cxx",
87 install_path = None
Ryan1a126ed2009-04-04 12:50:1588 )
89 bld.env["CPPPATH_V8"] = "deps/v8/include"
Ryanc62b1242009-04-22 17:55:0890 bld.env["LINKFLAGS_V8"] = "-pthread"
Ryana4593e32009-04-23 11:18:3891 bld.env_of_name('default')["STATICLIB_V8"] = "v8"
92 bld.env_of_name('default')["LIBPATH_V8"] = v8dir_tgt
93
94 ### v8 debug
Ryan29b528c2009-04-23 15:29:3195 if bld.env["USE_DEBUG"]:
96 deps_tgt = join(bld.srcnode.abspath(bld.env_of_name("debug")),"deps")
97 v8dir_tgt = join(deps_tgt, "v8")
Ryana4593e32009-04-23 11:18:3898
Ryan29b528c2009-04-23 15:29:3199 v8_debug = v8.clone("debug")
100 bld.env_of_name('debug')["STATICLIB_V8"] = "v8_g"
101 bld.env_of_name('debug')["LIBPATH_V8"] = v8dir_tgt
102 bld.env_of_name('debug')["LINKFLAGS_V8"] = "-pthread"
103 v8_debug.rule = v8rule % ( v8dir_src , deps_tgt , v8dir_tgt, "debug")
104 v8_debug.target = join("deps/v8", bld.env["staticlib_PATTERN"] % "v8_g")
Ryan1a126ed2009-04-04 12:50:15105
106 ### oi
107 oi = bld.new_task_gen("cc", "staticlib")
Ryan30450382009-05-05 10:52:18108 oi.source = "deps/liboi/oi_socket.c"
Ryan94a182a2009-05-12 01:46:30109 oi.includes = "deps/liboi/ deps/libev/"
Ryan1a126ed2009-04-04 12:50:15110 oi.name = "oi"
111 oi.target = "oi"
112 oi.uselib = "GNUTLS"
Ryan8e7bbf22009-04-23 17:26:56113 oi.install_path = None
Ryan29b528c2009-04-23 15:29:31114 if bld.env["USE_DEBUG"]:
115 oi.clone("debug")
Ryan1a126ed2009-04-04 12:50:15116
Ryan5a071ad2009-05-03 12:09:16117 ### http_parser
118 http_parser = bld.new_task_gen("cc", "staticlib")
119 http_parser.source = "deps/http_parser/http_parser.c"
120 http_parser.includes = "deps/http_parser/"
121 http_parser.name = "http_parser"
122 http_parser.target = "http_parser"
123 http_parser.install_path = None
Ryan29b528c2009-04-23 15:29:31124 if bld.env["USE_DEBUG"]:
Ryan5a071ad2009-05-03 12:09:16125 http_parser.clone("debug")
Ryan1a126ed2009-04-04 12:50:15126
Ryan63a9cd32009-04-15 08:08:28127 ### src/native.cc
128 def javascript_in_c(task):
129 env = task.env
130 source = map(lambda x: x.srcpath(env), task.inputs)
131 targets = map(lambda x: x.srcpath(env), task.outputs)
132 js2c.JS2C(source, targets)
133
134 native_cc = bld.new_task_gen(
Ryan3212b312009-05-13 19:43:24135 source="src/http.js src/file.js src/node.js",
Ryan63a9cd32009-04-15 08:08:28136 target="src/natives.h",
137 rule=javascript_in_c,
138 before="cxx"
139 )
Ryan8e7bbf22009-04-23 17:26:56140 native_cc.install_path = None
Ryan29b528c2009-04-23 15:29:31141 if bld.env["USE_DEBUG"]:
142 native_cc.clone("debug")
Ryan63a9cd32009-04-15 08:08:28143
Ryan1a126ed2009-04-04 12:50:15144 ### node
145 node = bld.new_task_gen("cxx", "program")
146 node.target = 'node'
147 node.source = """
148 src/node.cc
Ryan67af9582009-04-18 13:35:42149 src/http.cc
Ryan707f2442009-04-21 17:56:30150 src/net.cc
Ryan63a9cd32009-04-15 08:08:28151 src/file.cc
Ryanf213a272009-04-29 09:00:46152 src/timer.cc
Ryanb260a912009-05-26 17:48:49153 src/constants.cc
Ryan1a126ed2009-04-04 12:50:15154 """
155 node.includes = """
156 src/
157 deps/v8/include
158 deps/libev
159 deps/libeio
Ryan40c0f752009-04-22 17:35:47160 deps/liboi
Ryan5a071ad2009-05-03 12:09:16161 deps/http_parser
Ryan1a126ed2009-04-04 12:50:15162 """
Ryan5a071ad2009-05-03 12:09:16163 node.uselib_local = "oi ev eio http_parser"
Ryana3627c02009-05-27 14:29:55164 node.uselib = "V8 EXECINFO PROFILER"
Ryan8e7bbf22009-04-23 17:26:56165 node.install_path = '${PREFIX}/bin'
166 node.chmod = 0755
167
Ryan29b528c2009-04-23 15:29:31168 if bld.env["USE_DEBUG"]:
169 node.clone("debug")
Ryan67af9582009-04-18 13:35:42170