blob: 815dc897159bfdfc643cfd615a4968df20d8ce73 [file] [log] [blame]
Ryan1a126ed2009-04-04 12:50:151#! /usr/bin/env python
2import 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')
Ryan63a9cd32009-04-15 08:08:2821 opt.tool_options('ragel', tdir=".")
Ryan29b528c2009-04-23 15:29:3122 opt.add_option( '--debug'
23 , action='store_true'
24 , default=False
25 , help='Build debug variant [Default: False]'
26 , dest='debug'
27 )
Ryan1a126ed2009-04-04 12:50:1528
29def configure(conf):
30 conf.check_tool('compiler_cxx')
31 conf.check_tool('compiler_cc')
Ryan63a9cd32009-04-15 08:08:2832 conf.check_tool('ragel', tooldir=".")
Ryana4593e32009-04-23 11:18:3833 if not conf.env['RAGEL']:
34 fatal('ragel not found')
35 exit(1)
36
Ryan29b528c2009-04-23 15:29:3137 conf.env["USE_DEBUG"] = bld.env["USE_DEBUG"]
Ryan1a126ed2009-04-04 12:50:1538
39 conf.sub_config('deps/libeio')
40 conf.sub_config('deps/libev')
41
42 # needs to match the symbols found in libeio and libev
43 # __solaris
44 # __linux
45 # __freebsd
46 # __hpux
47 # __solaris
48 platform_string = "__" + Options.platform
49 if Options.platform == "linux2":
50 platform_string = "__linux"
51 conf.define(platform_string, 1)
52
53 # liboi config
54 print "--- liboi ---"
55 if conf.check_cfg(package='gnutls', args='--cflags --libs', uselib_store="GNUTLS"):
56 conf.define("HAVE_GNUTLS", 1)
57
58 conf.define("HAVE_CONFIG_H", 1)
Ryanc62b1242009-04-22 17:55:0859
Ryan7703ad52009-04-22 15:19:0860 conf.env.append_value("CCFLAGS", "-DEIO_STACKSIZE=%d" % (4096*8))
Ryanc62b1242009-04-22 17:55:0861 conf.check(lib='rt', uselib_store='RT')
Ryan1a126ed2009-04-04 12:50:1562
Ryan67af9582009-04-18 13:35:4263 # Split off debug variant before adding variant specific defines
Ryan7e1350f2009-04-16 09:37:4464 debug_env = conf.env.copy()
65 conf.set_env_name('debug', debug_env)
Ryan7e1350f2009-04-16 09:37:4466
Ryan67af9582009-04-18 13:35:4267 # Configure debug variant
68 conf.setenv('debug')
69 debug_env.set_variant('debug')
70 debug_env.append_value('CCFLAGS', ['-DDEBUG', '-g', '-O0', '-Wall', '-Wextra'])
71 debug_env.append_value('CXXFLAGS', ['-DDEBUG', '-g', '-O0', '-Wall', '-Wextra'])
72 conf.write_config_header("config.h")
73
74 # Configure default variant
75 conf.setenv('default')
Ryana4593e32009-04-23 11:18:3876 conf.env.append_value('CCFLAGS', ['-DNDEBUG', '-O2'])
77 conf.env.append_value('CXXFLAGS', ['-DNDEBUG', '-O2'])
Ryan67af9582009-04-18 13:35:4278 conf.write_config_header("config.h")
Ryan63a9cd32009-04-15 08:08:2879
Ryan1a126ed2009-04-04 12:50:1580def build(bld):
Ryan1a126ed2009-04-04 12:50:1581 bld.add_subdirs('deps/libeio deps/libev')
82
83 ### v8
84 deps_src = join(bld.path.abspath(),"deps")
Ryana4593e32009-04-23 11:18:3885 deps_tgt = join(bld.srcnode.abspath(bld.env_of_name("default")),"deps")
Ryan1a126ed2009-04-04 12:50:1586 v8dir_src = join(deps_src,"v8")
87 v8dir_tgt = join(deps_tgt, "v8")
Ryana4593e32009-04-23 11:18:3888
89 v8rule = 'cp -rf %s %s && ' \
90 'cd %s && ' \
91 'python scons.py -Q mode=%s library=static snapshot=on'
92
Ryan1a126ed2009-04-04 12:50:1593 v8 = bld.new_task_gen(
Ryana4593e32009-04-23 11:18:3894 target = join("deps/v8", bld.env["staticlib_PATTERN"] % "v8"),
95 rule=v8rule % ( v8dir_src , deps_tgt , v8dir_tgt, "release"),
Ryan1a126ed2009-04-04 12:50:1596 before="cxx"
97 )
98 bld.env["CPPPATH_V8"] = "deps/v8/include"
Ryanc62b1242009-04-22 17:55:0899 bld.env["LINKFLAGS_V8"] = "-pthread"
Ryana4593e32009-04-23 11:18:38100 bld.env_of_name('default')["STATICLIB_V8"] = "v8"
101 bld.env_of_name('default')["LIBPATH_V8"] = v8dir_tgt
102
103 ### v8 debug
Ryan29b528c2009-04-23 15:29:31104 if bld.env["USE_DEBUG"]:
105 deps_tgt = join(bld.srcnode.abspath(bld.env_of_name("debug")),"deps")
106 v8dir_tgt = join(deps_tgt, "v8")
Ryana4593e32009-04-23 11:18:38107
Ryan29b528c2009-04-23 15:29:31108 v8_debug = v8.clone("debug")
109 bld.env_of_name('debug')["STATICLIB_V8"] = "v8_g"
110 bld.env_of_name('debug')["LIBPATH_V8"] = v8dir_tgt
111 bld.env_of_name('debug')["LINKFLAGS_V8"] = "-pthread"
112 v8_debug.rule = v8rule % ( v8dir_src , deps_tgt , v8dir_tgt, "debug")
113 v8_debug.target = join("deps/v8", bld.env["staticlib_PATTERN"] % "v8_g")
Ryan1a126ed2009-04-04 12:50:15114
115 ### oi
116 oi = bld.new_task_gen("cc", "staticlib")
Ryan40c0f752009-04-22 17:35:47117 oi.source = "deps/liboi/oi_socket.c deps/liboi/oi_buf.c"
118 oi.includes = "deps/liboi/"
Ryan1a126ed2009-04-04 12:50:15119 oi.name = "oi"
120 oi.target = "oi"
121 oi.uselib = "GNUTLS"
Ryan29b528c2009-04-23 15:29:31122 if bld.env["USE_DEBUG"]:
123 oi.clone("debug")
Ryan1a126ed2009-04-04 12:50:15124
125 ### ebb
126 ebb = bld.new_task_gen("cc", "staticlib")
Ryan40c0f752009-04-22 17:35:47127 ebb.source = "deps/libebb/ebb_request_parser.rl"
128 ebb.includes = "deps/libebb/"
Ryan1a126ed2009-04-04 12:50:15129 ebb.name = "ebb"
130 ebb.target = "ebb"
Ryan29b528c2009-04-23 15:29:31131 if bld.env["USE_DEBUG"]:
132 ebb.clone("debug")
Ryan1a126ed2009-04-04 12:50:15133
Ryan63a9cd32009-04-15 08:08:28134 ### src/native.cc
135 def javascript_in_c(task):
136 env = task.env
137 source = map(lambda x: x.srcpath(env), task.inputs)
138 targets = map(lambda x: x.srcpath(env), task.outputs)
139 js2c.JS2C(source, targets)
140
141 native_cc = bld.new_task_gen(
Ryan12d31dd2009-04-16 18:09:55142 source="src/file.js src/main.js",
Ryan63a9cd32009-04-15 08:08:28143 target="src/natives.h",
144 rule=javascript_in_c,
145 before="cxx"
146 )
Ryan29b528c2009-04-23 15:29:31147 if bld.env["USE_DEBUG"]:
148 native_cc.clone("debug")
Ryan63a9cd32009-04-15 08:08:28149
Ryan1a126ed2009-04-04 12:50:15150 ### node
151 node = bld.new_task_gen("cxx", "program")
152 node.target = 'node'
153 node.source = """
154 src/node.cc
Ryan67af9582009-04-18 13:35:42155 src/http.cc
Ryan707f2442009-04-21 17:56:30156 src/net.cc
Ryan63a9cd32009-04-15 08:08:28157 src/process.cc
158 src/file.cc
Ryan67af9582009-04-18 13:35:42159 src/timers.cc
Ryan1a126ed2009-04-04 12:50:15160 """
161 node.includes = """
162 src/
163 deps/v8/include
164 deps/libev
165 deps/libeio
Ryan40c0f752009-04-22 17:35:47166 deps/liboi
167 deps/libebb
Ryan1a126ed2009-04-04 12:50:15168 """
169 node.uselib_local = "oi ev eio ebb"
Ryanc62b1242009-04-22 17:55:08170 node.uselib = "V8 RT"
Ryan29b528c2009-04-23 15:29:31171 if bld.env["USE_DEBUG"]:
172 node.clone("debug")
Ryan67af9582009-04-18 13:35:42173