Skip to content

HTTPS clone URL

Subversion checkout URL

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