Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 326 lines (268 sloc) 9.459 kb
a3627c0 ry Change to build on FreeBSD
ry authored
1 # /usr/bin/env python
8ddf930 ry Build natively on x64.
ry authored
2 import platform
3 import re
1a126ed ry use the WAF build system
ry authored
4 import Options
41d89f6 ry Add DNS API.
ry authored
5 import sys, os, shutil
1a126ed ry use the WAF build system
ry authored
6 from os.path import join, dirname, abspath
a4593e3 ry WAF: fix the debug variant.
ry authored
7 from logging import fatal
8
b73264d ry Add command line arguments for accessing build flags.
ry authored
9 VERSION="0.1.7"
4d92199 ry Add pkgconfig files to help with dll builds.
ry authored
10 APPNAME="node.js"
11
63a9cd3 ry everything is changed. i've waited much too long to commit.
ry authored
12 import js2c
13
1a126ed ry use the WAF build system
ry authored
14 srcdir = '.'
15 blddir = 'build'
115c494 ry Create tools directory
ry authored
16 cwd = os.getcwd()
1a126ed ry use the WAF build system
ry authored
17
18 def set_options(opt):
19 # the gcc module provides a --debug-level option
20 opt.tool_options('compiler_cxx')
21 opt.tool_options('compiler_cc')
4d92199 ry Add pkgconfig files to help with dll builds.
ry authored
22 opt.tool_options('misc')
29b528c ry fix the waf configure --debug options. seems to work now.
ry authored
23 opt.add_option( '--debug'
24 , action='store_true'
25 , default=False
26 , help='Build debug variant [Default: False]'
27 , dest='debug'
28 )
7bad9de ry Add electric fence option to configure process
ry authored
29 opt.add_option( '--efence'
30 , action='store_true'
31 , default=False
32 , help='Build with -lefence for debugging [Default: False]'
33 , dest='efence'
34 )
1a126ed ry use the WAF build system
ry authored
35
41d89f6 ry Add DNS API.
ry authored
36 def mkdir_p(dir):
37 if not os.path.exists (dir):
38 os.makedirs (dir)
39
40 def 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
1a126ed ry use the WAF build system
ry authored
59 def configure(conf):
60 conf.check_tool('compiler_cxx')
61 conf.check_tool('compiler_cc')
a4593e3 ry WAF: fix the debug variant.
ry authored
62
8e7bbf2 ry get 'make install' working
ry authored
63 conf.env["USE_DEBUG"] = Options.options.debug
1a126ed ry use the WAF build system
ry authored
64
2b6d724 ry First attempt at node.dlopen
ry authored
65 conf.check(lib='dl', uselib_store='DL')
8152f9c ry Revert static library build.
ry authored
66 conf.env.append_value("CCFLAGS", "-rdynamic")
a97dce7 ry Build static executable.
ry authored
67 conf.env.append_value("LINKFLAGS_DL", "-rdynamic")
68
8152f9c ry Revert static library build.
ry authored
69 #if Options.options.debug:
70 # conf.check(lib='profiler', uselib_store='PROFILER')
7bad9de ry Add electric fence option to configure process
ry authored
71
8152f9c ry Revert static library build.
ry authored
72 #if Options.options.efence:
73 # conf.check(lib='efence', libpath=['/usr/lib', '/usr/local/lib'], uselib_store='EFENCE')
a3627c0 ry Change to build on FreeBSD
ry authored
74
75 if sys.platform.startswith("freebsd"):
76 if not conf.check(lib="execinfo", libpath=['/usr/lib', '/usr/local/lib'], uselib_store="EXECINFO"):
7bad9de ry Add electric fence option to configure process
ry authored
77 fatal("Install the libexecinfo port from /usr/ports/devel/libexecinfo.")
a3627c0 ry Change to build on FreeBSD
ry authored
78
1a126ed ry use the WAF build system
ry authored
79 conf.sub_config('deps/libeio')
80 conf.sub_config('deps/libev')
81
41d89f6 ry Add DNS API.
ry authored
82 conf_subproject(conf, 'deps/udns', './configure')
83 conf_subproject(conf, 'deps/v8')
84
452d3f1 ry comment out gnutls check in wscript until it's used
ry authored
85 # Not using TLS yet
86 # if conf.check_cfg(package='gnutls', args='--cflags --libs', uselib_store="GNUTLS"):
87 # conf.define("HAVE_GNUTLS", 1)
1a126ed ry use the WAF build system
ry authored
88
89 conf.define("HAVE_CONFIG_H", 1)
c62b124 ry add scons local for v8. check for librt in wscript
ry authored
90
7703ad5 ry update eio. add EIO_STACKSIZE define for getaddrinfo problem
ry authored
91 conf.env.append_value("CCFLAGS", "-DEIO_STACKSIZE=%d" % (4096*8))
427e3f5 ry Introduce NODE_SET_PROTOTYPE_METHOD which properly sets the signature.
ry authored
92
67af958 ry rename a few files to remove node_ prefix
ry authored
93 # Split off debug variant before adding variant specific defines
7e1350f ry add file.write()
ry authored
94 debug_env = conf.env.copy()
95 conf.set_env_name('debug', debug_env)
67af958 ry rename a few files to remove node_ prefix
ry authored
96
97 # Configure debug variant
7e1350f ry add file.write()
ry authored
98 conf.setenv('debug')
67af958 ry rename a few files to remove node_ prefix
ry authored
99 debug_env.set_variant('debug')
8ddf930 ry Build natively on x64.
ry authored
100 debug_env.append_value('CCFLAGS', ['-DDEBUG', '-g', '-O0', '-Wall', '-Wextra'])
101 debug_env.append_value('CXXFLAGS', ['-DDEBUG', '-g', '-O0', '-Wall', '-Wextra'])
67af958 ry rename a few files to remove node_ prefix
ry authored
102 conf.write_config_header("config.h")
7e1350f ry add file.write()
ry authored
103
67af958 ry rename a few files to remove node_ prefix
ry authored
104 # Configure default variant
105 conf.setenv('default')
8ddf930 ry Build natively on x64.
ry authored
106 conf.env.append_value('CCFLAGS', ['-DNDEBUG', '-O3'])
107 conf.env.append_value('CXXFLAGS', ['-DNDEBUG', '-O3'])
67af958 ry rename a few files to remove node_ prefix
ry authored
108 conf.write_config_header("config.h")
63a9cd3 ry everything is changed. i've waited much too long to commit.
ry authored
109
41d89f6 ry Add DNS API.
ry authored
110 def build_udns(bld):
111 default_build_dir = bld.srcnode.abspath(bld.env_of_name("default"))
112
113 default_dir = join(default_build_dir, "deps/udns")
114
115 static_lib = bld.env["staticlib_PATTERN"] % "udns"
1a126ed ry use the WAF build system
ry authored
116
41d89f6 ry Add DNS API.
ry authored
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
2b6d724 ry First attempt at node.dlopen
ry authored
140 bld.install_files('${PREFIX}/include/node/', 'deps/udns/udns.h');
41d89f6 ry Add DNS API.
ry authored
141
8ddf930 ry Build natively on x64.
ry authored
142 # XXX Remove this when v8 defaults x86_64 to native builds
143 def GuessArchitecture():
144 id = platform.machine()
145 if id.startswith('arm'):
146 return 'arm'
147 elif '64' in id:
148 return 'x64'
149 elif (not id) or (not re.match('(x|i[3-6])86', id) is None):
150 return 'ia32'
151 else:
152 return None
153
41d89f6 ry Add DNS API.
ry authored
154
155 def build_v8(bld):
1a126ed ry use the WAF build system
ry authored
156 deps_src = join(bld.path.abspath(),"deps")
a4593e3 ry WAF: fix the debug variant.
ry authored
157 deps_tgt = join(bld.srcnode.abspath(bld.env_of_name("default")),"deps")
1a126ed ry use the WAF build system
ry authored
158 v8dir_src = join(deps_src,"v8")
159 v8dir_tgt = join(deps_tgt, "v8")
115c494 ry Create tools directory
ry authored
160 scons = os.path.join(cwd, 'tools/scons/scons.py')
a4593e3 ry WAF: fix the debug variant.
ry authored
161
41d89f6 ry Add DNS API.
ry authored
162 v8rule = 'cd %s && ' \
8ddf930 ry Build natively on x64.
ry authored
163 'python %s -Q mode=%s %s library=static snapshot=on'
164
165 arch = ""
166 if GuessArchitecture() == "x64":
167 arch = "arch=x64"
a4593e3 ry WAF: fix the debug variant.
ry authored
168
1a126ed ry use the WAF build system
ry authored
169 v8 = bld.new_task_gen(
a4593e3 ry WAF: fix the debug variant.
ry authored
170 target = join("deps/v8", bld.env["staticlib_PATTERN"] % "v8"),
8ddf930 ry Build natively on x64.
ry authored
171 rule=v8rule % (v8dir_tgt, scons, "release", arch),
8e7bbf2 ry get 'make install' working
ry authored
172 before="cxx",
173 install_path = None
1a126ed ry use the WAF build system
ry authored
174 )
175 bld.env["CPPPATH_V8"] = "deps/v8/include"
a4593e3 ry WAF: fix the debug variant.
ry authored
176 bld.env_of_name('default')["STATICLIB_V8"] = "v8"
177 bld.env_of_name('default')["LIBPATH_V8"] = v8dir_tgt
8ddf930 ry Build natively on x64.
ry authored
178 bld.env_of_name('default')["LINKFLAGS_V8"] = ["-pthread"]
a4593e3 ry WAF: fix the debug variant.
ry authored
179
180 ### v8 debug
29b528c ry fix the waf configure --debug options. seems to work now.
ry authored
181 if bld.env["USE_DEBUG"]:
182 deps_tgt = join(bld.srcnode.abspath(bld.env_of_name("debug")),"deps")
183 v8dir_tgt = join(deps_tgt, "v8")
a4593e3 ry WAF: fix the debug variant.
ry authored
184
29b528c ry fix the waf configure --debug options. seems to work now.
ry authored
185 v8_debug = v8.clone("debug")
186 bld.env_of_name('debug')["STATICLIB_V8"] = "v8_g"
187 bld.env_of_name('debug')["LIBPATH_V8"] = v8dir_tgt
8ddf930 ry Build natively on x64.
ry authored
188 bld.env_of_name('debug')["LINKFLAGS_V8"] = ["-pthread"]
189 v8_debug.rule = v8rule % (v8dir_tgt, scons, "debug", arch)
29b528c ry fix the waf configure --debug options. seems to work now.
ry authored
190 v8_debug.target = join("deps/v8", bld.env["staticlib_PATTERN"] % "v8_g")
1a126ed ry use the WAF build system
ry authored
191
2b6d724 ry First attempt at node.dlopen
ry authored
192 bld.install_files('${PREFIX}/include/node/', 'deps/v8/include/v8*');
193
41d89f6 ry Add DNS API.
ry authored
194 def build(bld):
195 bld.add_subdirs('deps/libeio deps/libev')
196
197 build_udns(bld)
198 build_v8(bld)
199
0fb0af3 ry Rename evnet to evcom.
ry authored
200 ### evcom
201 evcom = bld.new_task_gen("cc", "staticlib")
202 evcom.source = "deps/evcom/evcom.c"
203 evcom.includes = "deps/evcom/ deps/libev/"
204 evcom.name = "evcom"
205 evcom.target = "evcom"
206 # evcom.uselib = "GNUTLS"
207 evcom.install_path = None
29b528c ry fix the waf configure --debug options. seems to work now.
ry authored
208 if bld.env["USE_DEBUG"]:
0fb0af3 ry Rename evnet to evcom.
ry authored
209 evcom.clone("debug")
2b6d724 ry First attempt at node.dlopen
ry authored
210 bld.install_files('${PREFIX}/include/node/', 'deps/evcom/evcom.h');
1a126ed ry use the WAF build system
ry authored
211
5a071ad ry Begin refactor of http.cc. Remove libebb add http_parser.
ry authored
212 ### http_parser
213 http_parser = bld.new_task_gen("cc", "staticlib")
214 http_parser.source = "deps/http_parser/http_parser.c"
215 http_parser.includes = "deps/http_parser/"
216 http_parser.name = "http_parser"
217 http_parser.target = "http_parser"
218 http_parser.install_path = None
29b528c ry fix the waf configure --debug options. seems to work now.
ry authored
219 if bld.env["USE_DEBUG"]:
5a071ad ry Begin refactor of http.cc. Remove libebb add http_parser.
ry authored
220 http_parser.clone("debug")
1a126ed ry use the WAF build system
ry authored
221
17c6a67 ry Introduce node.stdio
ry authored
222 ### coupling
223 coupling = bld.new_task_gen("cc", "staticlib")
224 coupling.source = "deps/coupling/coupling.c"
225 coupling.includes = "deps/coupling/"
226 coupling.name = "coupling"
227 coupling.target = "coupling"
228 coupling.install_path = None
229 if bld.env["USE_DEBUG"]:
230 coupling.clone("debug")
231
63a9cd3 ry everything is changed. i've waited much too long to commit.
ry authored
232 ### src/native.cc
233 def javascript_in_c(task):
234 env = task.env
235 source = map(lambda x: x.srcpath(env), task.inputs)
236 targets = map(lambda x: x.srcpath(env), task.outputs)
237 js2c.JS2C(source, targets)
238
239 native_cc = bld.new_task_gen(
2ecd7ff ry in the middle putting in event code. broken.
ry authored
240 source = """
eb10553 ry Move node.inherit, node.path, node.cat to new file: util.js
ry authored
241 src/util.js
2ecd7ff ry in the middle putting in event code. broken.
ry authored
242 src/events.js
243 src/http.js
244 src/file.js
245 src/node.js
246 """,
63a9cd3 ry everything is changed. i've waited much too long to commit.
ry authored
247 target="src/natives.h",
248 rule=javascript_in_c,
249 before="cxx"
250 )
8e7bbf2 ry get 'make install' working
ry authored
251 native_cc.install_path = None
29b528c ry fix the waf configure --debug options. seems to work now.
ry authored
252 if bld.env["USE_DEBUG"]:
253 native_cc.clone("debug")
63a9cd3 ry everything is changed. i've waited much too long to commit.
ry authored
254
2b6d724 ry First attempt at node.dlopen
ry authored
255 ### node lib
8152f9c ry Revert static library build.
ry authored
256 node = bld.new_task_gen("cxx", "program")
257 node.name = "node"
258 node.target = "node"
259 node.source = """
1a126ed ry use the WAF build system
ry authored
260 src/node.cc
2ecd7ff ry in the middle putting in event code. broken.
ry authored
261 src/events.cc
67af958 ry rename a few files to remove node_ prefix
ry authored
262 src/http.cc
707f244 ry begin clean up of Socket
ry authored
263 src/net.cc
17c6a67 ry Introduce node.stdio
ry authored
264 src/node_stdio.cc
41d89f6 ry Add DNS API.
ry authored
265 src/dns.cc
63a9cd3 ry everything is changed. i've waited much too long to commit.
ry authored
266 src/file.cc
f213a27 ry Refactor setTimeout to be a Timer object.
ry authored
267 src/timer.cc
ad9d683 ry API: rename node.Process to node.ChildProcess
ry authored
268 src/child_process.cc
b260a91 ry Add errno constants. Move all constants to `node.constants` namespace.
ry authored
269 src/constants.cc
1a126ed ry use the WAF build system
ry authored
270 """
8152f9c ry Revert static library build.
ry authored
271 node.includes = """
1a126ed ry use the WAF build system
ry authored
272 src/
273 deps/v8/include
274 deps/libev
41d89f6 ry Add DNS API.
ry authored
275 deps/udns
1a126ed ry use the WAF build system
ry authored
276 deps/libeio
0fb0af3 ry Rename evnet to evcom.
ry authored
277 deps/evcom
5a071ad ry Begin refactor of http.cc. Remove libebb add http_parser.
ry authored
278 deps/http_parser
17c6a67 ry Introduce node.stdio
ry authored
279 deps/coupling
1a126ed ry use the WAF build system
ry authored
280 """
8152f9c ry Revert static library build.
ry authored
281 node.uselib_local = "evcom ev eio http_parser coupling"
282 node.uselib = "UDNS V8 EXECINFO DL"
283 node.install_path = '${PREFIX}/lib'
8e7bbf2 ry get 'make install' working
ry authored
284 node.install_path = '${PREFIX}/bin'
285 node.chmod = 0755
286
4d92199 ry Add pkgconfig files to help with dll builds.
ry authored
287 def subflags(program):
b73264d ry Add command line arguments for accessing build flags.
ry authored
288 x = { 'CCFLAGS' : " ".join(program.env["CCFLAGS"])
289 , 'CPPFLAGS' : " ".join(program.env["CPPFLAGS"])
290 , 'LIBFLAGS' : " ".join(program.env["LIBFLAGS"])
291 , 'VERSION' : VERSION
292 , 'PREFIX' : program.env["PREFIX"]
4d92199 ry Add pkgconfig files to help with dll builds.
ry authored
293 }
294 return x;
295
296 # process file.pc.in -> file.pc
297 pkgconfig = bld.new_task_gen('subst', before="cxx")
298 pkgconfig.source = 'src/node.pc.in'
299 pkgconfig.target = 'node.pc'
300 pkgconfig.install_path = '${PREFIX}/lib/pkgconfig'
301 pkgconfig.dict = subflags(node)
302
b73264d ry Add command line arguments for accessing build flags.
ry authored
303 # process file.pc.in -> file.pc
304 node_version = bld.new_task_gen('subst', before="cxx")
305 node_version.source = 'src/node_version.h.in'
306 node_version.target = 'src/node_version.h'
307 node_version.dict = subflags(node)
a97dce7 ry Build static executable.
ry authored
308 node_version.install_path = '${PREFIX}/include/node'
4d92199 ry Add pkgconfig files to help with dll builds.
ry authored
309
29b528c ry fix the waf configure --debug options. seems to work now.
ry authored
310 if bld.env["USE_DEBUG"]:
2b6d724 ry First attempt at node.dlopen
ry authored
311 node_g = node.clone("debug")
312 node_g.target = "node_g"
4d92199 ry Add pkgconfig files to help with dll builds.
ry authored
313
b73264d ry Add command line arguments for accessing build flags.
ry authored
314 node_version_g = node_version.clone("debug")
315 node_version_g.dict = subflags(node_g)
a97dce7 ry Build static executable.
ry authored
316 node_version_g.install_path = None
317
4d92199 ry Add pkgconfig files to help with dll builds.
ry authored
318
a97dce7 ry Build static executable.
ry authored
319 bld.install_files('${PREFIX}/include/node/', """
320 config.h
321 src/node.h
322 src/object_wrap.h
323 src/events.h
324 src/net.h
325 """);
Something went wrong with that request. Please try again.