Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 381 lines (316 sloc) 11.42 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
9c9d67e @ry bump version
ry authored
9 VERSION="0.1.13"
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
18da8ff @ry Copy Python's shutil.copytree into wscript.
ry authored
40 # Copied from Python 2.6 because 2.4.4 at least is broken by not using
41 # mkdirs
42 # http://mail.python.org/pipermail/python-bugs-list/2005-January/027118.html
43 def copytree(src, dst, symlinks=False, ignore=None):
44 names = os.listdir(src)
45 if ignore is not None:
46 ignored_names = ignore(src, names)
47 else:
48 ignored_names = set()
49
50 os.makedirs(dst)
51 errors = []
52 for name in names:
53 if name in ignored_names:
54 continue
53ebe75 @ry Improve build for V8
ry authored
55 srcname = join(src, name)
56 dstname = join(dst, name)
18da8ff @ry Copy Python's shutil.copytree into wscript.
ry authored
57 try:
58 if symlinks and os.path.islink(srcname):
59 linkto = os.readlink(srcname)
60 os.symlink(linkto, dstname)
61 elif os.path.isdir(srcname):
62 copytree(srcname, dstname, symlinks, ignore)
63 else:
64 shutil.copy2(srcname, dstname)
65 # XXX What about devices, sockets etc.?
66 except (IOError, os.error), why:
67 errors.append((srcname, dstname, str(why)))
68 # catch the Error from the recursive copytree so that we can
69 # continue with other files
70 except Error, err:
71 errors.extend(err.args[0])
72 try:
73 shutil.copystat(src, dst)
74 except OSError, why:
75 if WindowsError is not None and isinstance(why, WindowsError):
76 # Copying file access times may fail on Windows
77 pass
78 else:
79 errors.extend((src, dst, str(why)))
80 if errors:
81 raise Error, errors
82
41d89f6 @ry Add DNS API.
ry authored
83 def conf_subproject (conf, subdir, command=None):
84 print("---- %s ----" % subdir)
85 src = join(conf.srcdir, subdir)
86 if not os.path.exists (src): fatal("no such subproject " + subdir)
87
88 default_tgt = join(conf.blddir, "default", subdir)
89
90 if not os.path.exists(default_tgt):
18da8ff @ry Copy Python's shutil.copytree into wscript.
ry authored
91 copytree(src, default_tgt, True)
41d89f6 @ry Add DNS API.
ry authored
92
93 if command:
94 if os.system("cd %s && %s" % (default_tgt, command)) != 0:
95 fatal("Configuring %s failed." % (subdir))
96
97 debug_tgt = join(conf.blddir, "debug", subdir)
98
99 if not os.path.exists(debug_tgt):
18da8ff @ry Copy Python's shutil.copytree into wscript.
ry authored
100 copytree(default_tgt, debug_tgt, True)
41d89f6 @ry Add DNS API.
ry authored
101
1a126ed @ry use the WAF build system
ry authored
102 def configure(conf):
103 conf.check_tool('compiler_cxx')
104 conf.check_tool('compiler_cc')
a4593e3 @ry WAF: fix the debug variant.
ry authored
105
8e7bbf2 @ry get 'make install' working
ry authored
106 conf.env["USE_DEBUG"] = Options.options.debug
1a126ed @ry use the WAF build system
ry authored
107
2b6d724 @ry First attempt at node.dlopen
ry authored
108 conf.check(lib='dl', uselib_store='DL')
8152f9c @ry Revert static library build.
ry authored
109 conf.env.append_value("CCFLAGS", "-rdynamic")
a97dce7 @ry Build static executable.
ry authored
110 conf.env.append_value("LINKFLAGS_DL", "-rdynamic")
111
8152f9c @ry Revert static library build.
ry authored
112 #if Options.options.debug:
113 # conf.check(lib='profiler', uselib_store='PROFILER')
7bad9de @ry Add electric fence option to configure process
ry authored
114
8152f9c @ry Revert static library build.
ry authored
115 #if Options.options.efence:
116 # conf.check(lib='efence', libpath=['/usr/lib', '/usr/local/lib'], uselib_store='EFENCE')
a3627c0 @ry Change to build on FreeBSD
ry authored
117
118 if sys.platform.startswith("freebsd"):
119 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
120 fatal("Install the libexecinfo port from /usr/ports/devel/libexecinfo.")
a3627c0 @ry Change to build on FreeBSD
ry authored
121
1a126ed @ry use the WAF build system
ry authored
122 conf.sub_config('deps/libeio')
123 conf.sub_config('deps/libev')
124
41d89f6 @ry Add DNS API.
ry authored
125 conf_subproject(conf, 'deps/udns', './configure')
126
452d3f1 @ry comment out gnutls check in wscript until it's used
ry authored
127 # Not using TLS yet
128 # if conf.check_cfg(package='gnutls', args='--cflags --libs', uselib_store="GNUTLS"):
129 # conf.define("HAVE_GNUTLS", 1)
1a126ed @ry use the WAF build system
ry authored
130
131 conf.define("HAVE_CONFIG_H", 1)
c62b124 @ry add scons local for v8. check for librt in wscript
ry authored
132
1df6d61 @ry Upgrade libeio, increase xthread stacksize to 64kb.
ry authored
133 conf.env.append_value("CCFLAGS", "-DX_STACKSIZE=%d" % (1024*64))
427e3f5 @ry Introduce NODE_SET_PROTOTYPE_METHOD which properly sets the signature.
ry authored
134
67af958 @ry rename a few files to remove node_ prefix
ry authored
135 # Split off debug variant before adding variant specific defines
7e1350f @ry add file.write()
ry authored
136 debug_env = conf.env.copy()
137 conf.set_env_name('debug', debug_env)
67af958 @ry rename a few files to remove node_ prefix
ry authored
138
139 # Configure debug variant
7e1350f @ry add file.write()
ry authored
140 conf.setenv('debug')
67af958 @ry rename a few files to remove node_ prefix
ry authored
141 debug_env.set_variant('debug')
8ddf930 @ry Build natively on x64.
ry authored
142 debug_env.append_value('CCFLAGS', ['-DDEBUG', '-g', '-O0', '-Wall', '-Wextra'])
143 debug_env.append_value('CXXFLAGS', ['-DDEBUG', '-g', '-O0', '-Wall', '-Wextra'])
67af958 @ry rename a few files to remove node_ prefix
ry authored
144 conf.write_config_header("config.h")
7e1350f @ry add file.write()
ry authored
145
67af958 @ry rename a few files to remove node_ prefix
ry authored
146 # Configure default variant
147 conf.setenv('default')
8ddf930 @ry Build natively on x64.
ry authored
148 conf.env.append_value('CCFLAGS', ['-DNDEBUG', '-O3'])
149 conf.env.append_value('CXXFLAGS', ['-DNDEBUG', '-O3'])
67af958 @ry rename a few files to remove node_ prefix
ry authored
150 conf.write_config_header("config.h")
63a9cd3 @ry everything is changed. i've waited much too long to commit.
ry authored
151
41d89f6 @ry Add DNS API.
ry authored
152 def build_udns(bld):
153 default_build_dir = bld.srcnode.abspath(bld.env_of_name("default"))
154
155 default_dir = join(default_build_dir, "deps/udns")
156
157 static_lib = bld.env["staticlib_PATTERN"] % "udns"
1a126ed @ry use the WAF build system
ry authored
158
41d89f6 @ry Add DNS API.
ry authored
159 rule = 'cd %s && make'
160
161 default = bld.new_task_gen(
162 target= join("deps/udns", static_lib),
163 rule= rule % default_dir,
164 before= "cxx",
165 install_path= None
166 )
167
168 bld.env["CPPPATH_UDNS"] = "deps/udns"
169 bld.env["STATICLIB_UDNS"] = "udns"
170
171 bld.env_of_name('default')["STATICLIB_UDNS"] = "udns"
172 bld.env_of_name('default')["LIBPATH_UDNS"] = default_dir
173
174 if bld.env["USE_DEBUG"]:
175 debug_build_dir = bld.srcnode.abspath(bld.env_of_name("debug"))
176 debug_dir = join(debug_build_dir, "deps/udns")
177 debug = default.clone("debug")
178 debug.rule = rule % debug_dir
179 #debug.target = join(debug_dir, static_lib)
180 bld.env_of_name('debug')["STATICLIB_UDNS"] = "udns"
181 bld.env_of_name('debug')["LIBPATH_UDNS"] = debug_dir
bf0d278 @ry Improve "make dist" remove generated doc from repo.
ry authored
182 bld.install_files('${PREFIX}/include/node/', 'deps/udns/udns.h')
41d89f6 @ry Add DNS API.
ry authored
183
8ddf930 @ry Build natively on x64.
ry authored
184 # XXX Remove this when v8 defaults x86_64 to native builds
185 def GuessArchitecture():
186 id = platform.machine()
bc6f381 @sprsquish Use "platform.architecture()" to find the proper architecture.
sprsquish authored
187 arch = platform.architecture()[0]
8ddf930 @ry Build natively on x64.
ry authored
188 if id.startswith('arm'):
189 return 'arm'
bc6f381 @sprsquish Use "platform.architecture()" to find the proper architecture.
sprsquish authored
190 elif ('64' in id) or ('64' in arch):
8ddf930 @ry Build natively on x64.
ry authored
191 return 'x64'
192 elif (not id) or (not re.match('(x|i[3-6])86', id) is None):
193 return 'ia32'
194 else:
195 return None
196
53ebe75 @ry Improve build for V8
ry authored
197 def v8_cmd(bld, variant):
198 scons = join(cwd, 'tools/scons/scons.py')
1a126ed @ry use the WAF build system
ry authored
199 deps_src = join(bld.path.abspath(),"deps")
200 v8dir_src = join(deps_src,"v8")
53ebe75 @ry Improve build for V8
ry authored
201
a4593e3 @ry WAF: fix the debug variant.
ry authored
202
bc9b343 @ry Add note about symbol visibility in V8 to wscript
ry authored
203 # NOTE: We want to compile V8 to export its symbols. I.E. Do not want
204 # -fvisibility=hidden. When using dlopen() it seems that the loaded DSO
205 # cannot see symbols in the executable which are hidden, even if the
206 # executable is statically linked together...
8ddf930 @ry Build natively on x64.
ry authored
207
53ebe75 @ry Improve build for V8
ry authored
208 arch = "arch=x64" if GuessArchitecture() == "x64" else ""
209 mode = "release" if variant == "default" else "debug"
a4593e3 @ry WAF: fix the debug variant.
ry authored
210
53ebe75 @ry Improve build for V8
ry authored
211 cmd_R = 'python %s -C %s -Y %s visibility=default mode=%s %s library=static snapshot=on'
212
213 cmd = cmd_R % ( scons
214 , bld.srcnode.abspath(bld.env_of_name(variant))
215 , v8dir_src
216 , mode
217 , arch
218 )
219 return cmd
220
221
222 def build_v8(bld):
1a126ed @ry use the WAF build system
ry authored
223 v8 = bld.new_task_gen(
53ebe75 @ry Improve build for V8
ry authored
224 target = bld.env["staticlib_PATTERN"] % "v8",
225 rule = v8_cmd(bld, "default"),
226 before = "cxx",
227 install_path = None
1a126ed @ry use the WAF build system
ry authored
228 )
229 bld.env["CPPPATH_V8"] = "deps/v8/include"
a4593e3 @ry WAF: fix the debug variant.
ry authored
230 bld.env_of_name('default')["STATICLIB_V8"] = "v8"
8ddf930 @ry Build natively on x64.
ry authored
231 bld.env_of_name('default')["LINKFLAGS_V8"] = ["-pthread"]
a4593e3 @ry WAF: fix the debug variant.
ry authored
232
233 ### v8 debug
29b528c @ry fix the waf configure --debug options. seems to work now.
ry authored
234 if bld.env["USE_DEBUG"]:
235 v8_debug = v8.clone("debug")
53ebe75 @ry Improve build for V8
ry authored
236 v8_debug.rule = v8_cmd(bld, "debug")
237 v8_debug.target = bld.env["staticlib_PATTERN"] % "v8_g"
29b528c @ry fix the waf configure --debug options. seems to work now.
ry authored
238 bld.env_of_name('debug')["STATICLIB_V8"] = "v8_g"
8ddf930 @ry Build natively on x64.
ry authored
239 bld.env_of_name('debug')["LINKFLAGS_V8"] = ["-pthread"]
1a126ed @ry use the WAF build system
ry authored
240
53ebe75 @ry Improve build for V8
ry authored
241 bld.install_files('${PREFIX}/include/node/', 'deps/v8/include/*.h')
2b6d724 @ry First attempt at node.dlopen
ry authored
242
41d89f6 @ry Add DNS API.
ry authored
243 def build(bld):
244 bld.add_subdirs('deps/libeio deps/libev')
245
246 build_udns(bld)
247 build_v8(bld)
248
0fb0af3 @ry Rename evnet to evcom.
ry authored
249 ### evcom
250 evcom = bld.new_task_gen("cc", "staticlib")
251 evcom.source = "deps/evcom/evcom.c"
252 evcom.includes = "deps/evcom/ deps/libev/"
253 evcom.name = "evcom"
254 evcom.target = "evcom"
255 # evcom.uselib = "GNUTLS"
256 evcom.install_path = None
29b528c @ry fix the waf configure --debug options. seems to work now.
ry authored
257 if bld.env["USE_DEBUG"]:
0fb0af3 @ry Rename evnet to evcom.
ry authored
258 evcom.clone("debug")
bf0d278 @ry Improve "make dist" remove generated doc from repo.
ry authored
259 bld.install_files('${PREFIX}/include/node/', 'deps/evcom/evcom.h')
1a126ed @ry use the WAF build system
ry authored
260
5a071ad @ry Begin refactor of http.cc. Remove libebb add http_parser.
ry authored
261 ### http_parser
262 http_parser = bld.new_task_gen("cc", "staticlib")
263 http_parser.source = "deps/http_parser/http_parser.c"
264 http_parser.includes = "deps/http_parser/"
265 http_parser.name = "http_parser"
266 http_parser.target = "http_parser"
267 http_parser.install_path = None
29b528c @ry fix the waf configure --debug options. seems to work now.
ry authored
268 if bld.env["USE_DEBUG"]:
5a071ad @ry Begin refactor of http.cc. Remove libebb add http_parser.
ry authored
269 http_parser.clone("debug")
1a126ed @ry use the WAF build system
ry authored
270
17c6a67 @ry Introduce node.stdio
ry authored
271 ### coupling
272 coupling = bld.new_task_gen("cc", "staticlib")
273 coupling.source = "deps/coupling/coupling.c"
274 coupling.includes = "deps/coupling/"
275 coupling.name = "coupling"
276 coupling.target = "coupling"
277 coupling.install_path = None
278 if bld.env["USE_DEBUG"]:
279 coupling.clone("debug")
280
63a9cd3 @ry everything is changed. i've waited much too long to commit.
ry authored
281 ### src/native.cc
282 def javascript_in_c(task):
283 env = task.env
284 source = map(lambda x: x.srcpath(env), task.inputs)
285 targets = map(lambda x: x.srcpath(env), task.outputs)
286 js2c.JS2C(source, targets)
287
288 native_cc = bld.new_task_gen(
2ecd7ff @ry in the middle putting in event code. broken.
ry authored
289 source = """
eb10553 @ry Move node.inherit, node.path, node.cat to new file: util.js
ry authored
290 src/util.js
2ecd7ff @ry in the middle putting in event code. broken.
ry authored
291 src/events.js
292 src/file.js
293 src/node.js
294 """,
53ebe75 @ry Improve build for V8
ry authored
295 target="src/node_natives.h",
63a9cd3 @ry everything is changed. i've waited much too long to commit.
ry authored
296 rule=javascript_in_c,
297 before="cxx"
298 )
8e7bbf2 @ry get 'make install' working
ry authored
299 native_cc.install_path = None
29b528c @ry fix the waf configure --debug options. seems to work now.
ry authored
300 if bld.env["USE_DEBUG"]:
301 native_cc.clone("debug")
63a9cd3 @ry everything is changed. i've waited much too long to commit.
ry authored
302
2b6d724 @ry First attempt at node.dlopen
ry authored
303 ### node lib
8152f9c @ry Revert static library build.
ry authored
304 node = bld.new_task_gen("cxx", "program")
305 node.name = "node"
306 node.target = "node"
307 node.source = """
1a126ed @ry use the WAF build system
ry authored
308 src/node.cc
2ecd7ff @ry in the middle putting in event code. broken.
ry authored
309 src/events.cc
67af958 @ry rename a few files to remove node_ prefix
ry authored
310 src/http.cc
707f244 @ry begin clean up of Socket
ry authored
311 src/net.cc
17c6a67 @ry Introduce node.stdio
ry authored
312 src/node_stdio.cc
41d89f6 @ry Add DNS API.
ry authored
313 src/dns.cc
63a9cd3 @ry everything is changed. i've waited much too long to commit.
ry authored
314 src/file.cc
f068251 @brandon-beacher Added signal handler.
brandon-beacher authored
315 src/signal_handler.cc
f213a27 @ry Refactor setTimeout to be a Timer object.
ry authored
316 src/timer.cc
ad9d683 @ry API: rename node.Process to node.ChildProcess
ry authored
317 src/child_process.cc
b260a91 @ry Add errno constants. Move all constants to `node.constants` namespace.
ry authored
318 src/constants.cc
1a126ed @ry use the WAF build system
ry authored
319 """
8152f9c @ry Revert static library build.
ry authored
320 node.includes = """
1a126ed @ry use the WAF build system
ry authored
321 src/
322 deps/v8/include
323 deps/libev
41d89f6 @ry Add DNS API.
ry authored
324 deps/udns
1a126ed @ry use the WAF build system
ry authored
325 deps/libeio
0fb0af3 @ry Rename evnet to evcom.
ry authored
326 deps/evcom
5a071ad @ry Begin refactor of http.cc. Remove libebb add http_parser.
ry authored
327 deps/http_parser
17c6a67 @ry Introduce node.stdio
ry authored
328 deps/coupling
1a126ed @ry use the WAF build system
ry authored
329 """
8152f9c @ry Revert static library build.
ry authored
330 node.uselib_local = "evcom ev eio http_parser coupling"
331 node.uselib = "UDNS V8 EXECINFO DL"
332 node.install_path = '${PREFIX}/lib'
8e7bbf2 @ry get 'make install' working
ry authored
333 node.install_path = '${PREFIX}/bin'
334 node.chmod = 0755
335
4d92199 @ry Add pkgconfig files to help with dll builds.
ry authored
336 def subflags(program):
b73264d @ry Add command line arguments for accessing build flags.
ry authored
337 x = { 'CCFLAGS' : " ".join(program.env["CCFLAGS"])
338 , 'CPPFLAGS' : " ".join(program.env["CPPFLAGS"])
339 , 'LIBFLAGS' : " ".join(program.env["LIBFLAGS"])
340 , 'VERSION' : VERSION
341 , 'PREFIX' : program.env["PREFIX"]
4d92199 @ry Add pkgconfig files to help with dll builds.
ry authored
342 }
bf0d278 @ry Improve "make dist" remove generated doc from repo.
ry authored
343 return x
4d92199 @ry Add pkgconfig files to help with dll builds.
ry authored
344
345 # process file.pc.in -> file.pc
b73264d @ry Add command line arguments for accessing build flags.
ry authored
346 node_version = bld.new_task_gen('subst', before="cxx")
347 node_version.source = 'src/node_version.h.in'
348 node_version.target = 'src/node_version.h'
349 node_version.dict = subflags(node)
a97dce7 @ry Build static executable.
ry authored
350 node_version.install_path = '${PREFIX}/include/node'
4d92199 @ry Add pkgconfig files to help with dll builds.
ry authored
351
29b528c @ry fix the waf configure --debug options. seems to work now.
ry authored
352 if bld.env["USE_DEBUG"]:
2b6d724 @ry First attempt at node.dlopen
ry authored
353 node_g = node.clone("debug")
354 node_g.target = "node_g"
4d92199 @ry Add pkgconfig files to help with dll builds.
ry authored
355
b73264d @ry Add command line arguments for accessing build flags.
ry authored
356 node_version_g = node_version.clone("debug")
357 node_version_g.dict = subflags(node_g)
a97dce7 @ry Build static executable.
ry authored
358 node_version_g.install_path = None
359
4d92199 @ry Add pkgconfig files to help with dll builds.
ry authored
360
a97dce7 @ry Build static executable.
ry authored
361 bld.install_files('${PREFIX}/include/node/', """
362 config.h
363 src/node.h
364 src/object_wrap.h
365 src/events.h
366 src/net.h
bf0d278 @ry Improve "make dist" remove generated doc from repo.
ry authored
367 """)
368
369 # Only install the man page if it exists.
370 # Do 'make doc install' to build and install it.
371 if os.path.exists('doc/node.1'):
372 bld.install_files('${PREFIX}/share/man/man1/', 'doc/node.1')
373
374 bld.install_files('${PREFIX}/bin/', 'bin/*', chmod=0755)
6f17ca5 @ry Install wafadmin into $PREFIX/lib/node/wafadmin
ry authored
375
376 # Why am I using two lines? Because WAF SUCKS.
bf0d278 @ry Improve "make dist" remove generated doc from repo.
ry authored
377 bld.install_files('${PREFIX}/lib/node/wafadmin', 'tools/wafadmin/*.py')
378 bld.install_files('${PREFIX}/lib/node/wafadmin/Tools', 'tools/wafadmin/Tools/*.py')
6f17ca5 @ry Install wafadmin into $PREFIX/lib/node/wafadmin
ry authored
379
bf0d278 @ry Improve "make dist" remove generated doc from repo.
ry authored
380 bld.install_files('${PREFIX}/lib/node/libraries/', 'lib/*.js')
Something went wrong with that request. Please try again.