Ryan Dahl | 7a251f3 | 2010-03-01 22:39:31 | [diff] [blame] | 1 | #!/usr/bin/env python |
Ryan | 8ddf930 | 2009-09-02 18:19:52 | [diff] [blame] | 2 | import re |
Ryan | 1a126ed | 2009-04-04 12:50:15 | [diff] [blame] | 3 | import Options |
Ryan | 41d89f6 | 2009-07-28 10:29:18 | [diff] [blame] | 4 | import sys, os, shutil |
Ryan Dahl | d979ac9 | 2009-10-09 13:00:12 | [diff] [blame] | 5 | from Utils import cmd_output |
Ryan | 1a126ed | 2009-04-04 12:50:15 | [diff] [blame] | 6 | from os.path import join, dirname, abspath |
Ryan | a4593e3 | 2009-04-23 11:18:38 | [diff] [blame] | 7 | from logging import fatal |
| 8 | |
Ryan Dahl | d979ac9 | 2009-10-09 13:00:12 | [diff] [blame] | 9 | cwd = os.getcwd() |
Ryan Dahl | 61c8014 | 2010-03-13 02:50:46 | [diff] [blame] | 10 | VERSION="0.1.32" |
Ryan | 4d92199 | 2009-08-26 23:11:16 | [diff] [blame] | 11 | APPNAME="node.js" |
| 12 | |
Ryan | 63a9cd3 | 2009-04-15 08:08:28 | [diff] [blame] | 13 | import js2c |
| 14 | |
Ryan | 1a126ed | 2009-04-04 12:50:15 | [diff] [blame] | 15 | srcdir = '.' |
| 16 | blddir = 'build' |
| 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') |
Ryan | 4d92199 | 2009-08-26 23:11:16 | [diff] [blame] | 22 | opt.tool_options('misc') |
Ryan | 29b528c | 2009-04-23 15:29:31 | [diff] [blame] | 23 | opt.add_option( '--debug' |
| 24 | , action='store_true' |
| 25 | , default=False |
| 26 | , help='Build debug variant [Default: False]' |
| 27 | , dest='debug' |
| 28 | ) |
Ryan | 7bad9de | 2009-06-16 13:47:57 | [diff] [blame] | 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 | ) |
Jérémy Lal | c93bab1 | 2010-03-11 21:15:32 | [diff] [blame] | 35 | opt.add_option( '--system' |
| 36 | , action='store_true' |
| 37 | , default=False |
| 38 | , help='Build using system libraries and headers (like a debian build) [Default: False]' |
| 39 | , dest='system' |
| 40 | ) |
Ryan | 1a126ed | 2009-04-04 12:50:15 | [diff] [blame] | 41 | |
Ryan | 41d89f6 | 2009-07-28 10:29:18 | [diff] [blame] | 42 | def mkdir_p(dir): |
| 43 | if not os.path.exists (dir): |
| 44 | os.makedirs (dir) |
| 45 | |
Ryan Dahl | 18da8ff | 2009-09-28 20:39:00 | [diff] [blame] | 46 | # Copied from Python 2.6 because 2.4.4 at least is broken by not using |
| 47 | # mkdirs |
| 48 | # http://mail.python.org/pipermail/python-bugs-list/2005-January/027118.html |
| 49 | def copytree(src, dst, symlinks=False, ignore=None): |
| 50 | names = os.listdir(src) |
| 51 | if ignore is not None: |
| 52 | ignored_names = ignore(src, names) |
| 53 | else: |
| 54 | ignored_names = set() |
| 55 | |
| 56 | os.makedirs(dst) |
| 57 | errors = [] |
| 58 | for name in names: |
| 59 | if name in ignored_names: |
| 60 | continue |
Ryan Dahl | 53ebe75 | 2009-10-08 21:20:14 | [diff] [blame] | 61 | srcname = join(src, name) |
| 62 | dstname = join(dst, name) |
Ryan Dahl | 18da8ff | 2009-09-28 20:39:00 | [diff] [blame] | 63 | try: |
| 64 | if symlinks and os.path.islink(srcname): |
| 65 | linkto = os.readlink(srcname) |
| 66 | os.symlink(linkto, dstname) |
| 67 | elif os.path.isdir(srcname): |
| 68 | copytree(srcname, dstname, symlinks, ignore) |
| 69 | else: |
| 70 | shutil.copy2(srcname, dstname) |
| 71 | # XXX What about devices, sockets etc.? |
| 72 | except (IOError, os.error), why: |
| 73 | errors.append((srcname, dstname, str(why))) |
| 74 | # catch the Error from the recursive copytree so that we can |
| 75 | # continue with other files |
| 76 | except Error, err: |
| 77 | errors.extend(err.args[0]) |
| 78 | try: |
| 79 | shutil.copystat(src, dst) |
| 80 | except OSError, why: |
| 81 | if WindowsError is not None and isinstance(why, WindowsError): |
| 82 | # Copying file access times may fail on Windows |
| 83 | pass |
| 84 | else: |
| 85 | errors.extend((src, dst, str(why))) |
| 86 | if errors: |
| 87 | raise Error, errors |
| 88 | |
Ryan | 41d89f6 | 2009-07-28 10:29:18 | [diff] [blame] | 89 | def conf_subproject (conf, subdir, command=None): |
| 90 | print("---- %s ----" % subdir) |
| 91 | src = join(conf.srcdir, subdir) |
Simon Cornelius P. Umacob | e801f42 | 2009-12-09 12:36:12 | [diff] [blame] | 92 | if not os.path.exists (src): conf.fatal("no such subproject " + subdir) |
Ryan | 41d89f6 | 2009-07-28 10:29:18 | [diff] [blame] | 93 | |
| 94 | default_tgt = join(conf.blddir, "default", subdir) |
| 95 | |
| 96 | if not os.path.exists(default_tgt): |
Ryan Dahl | 18da8ff | 2009-09-28 20:39:00 | [diff] [blame] | 97 | copytree(src, default_tgt, True) |
Ryan | 41d89f6 | 2009-07-28 10:29:18 | [diff] [blame] | 98 | |
| 99 | if command: |
masuidrive | 3337e9d | 2010-02-10 10:21:54 | [diff] [blame] | 100 | if os.system("cd \"%s\" && %s" % (default_tgt, command)) != 0: |
Simon Cornelius P. Umacob | e801f42 | 2009-12-09 12:36:12 | [diff] [blame] | 101 | conf.fatal("Configuring %s failed." % (subdir)) |
Ryan | 41d89f6 | 2009-07-28 10:29:18 | [diff] [blame] | 102 | |
| 103 | debug_tgt = join(conf.blddir, "debug", subdir) |
| 104 | |
| 105 | if not os.path.exists(debug_tgt): |
Ryan Dahl | 18da8ff | 2009-09-28 20:39:00 | [diff] [blame] | 106 | copytree(default_tgt, debug_tgt, True) |
Ryan | 41d89f6 | 2009-07-28 10:29:18 | [diff] [blame] | 107 | |
Ryan | 1a126ed | 2009-04-04 12:50:15 | [diff] [blame] | 108 | def configure(conf): |
| 109 | conf.check_tool('compiler_cxx') |
Ryan Dahl | f379b77 | 2010-01-12 00:43:10 | [diff] [blame] | 110 | if not conf.env.CXX: conf.fatal('c++ compiler not found') |
Ryan | 1a126ed | 2009-04-04 12:50:15 | [diff] [blame] | 111 | conf.check_tool('compiler_cc') |
Ryan Dahl | f379b77 | 2010-01-12 00:43:10 | [diff] [blame] | 112 | if not conf.env.CC: conf.fatal('c compiler not found') |
Ryan | a4593e3 | 2009-04-23 11:18:38 | [diff] [blame] | 113 | |
Ryan | 8e7bbf2 | 2009-04-23 17:26:56 | [diff] [blame] | 114 | conf.env["USE_DEBUG"] = Options.options.debug |
Jérémy Lal | c93bab1 | 2010-03-11 21:15:32 | [diff] [blame] | 115 | conf.env["USE_SYSTEM"] = Options.options.system |
Ryan | 1a126ed | 2009-04-04 12:50:15 | [diff] [blame] | 116 | |
Ryan | 2b6d724 | 2009-06-20 13:07:10 | [diff] [blame] | 117 | conf.check(lib='dl', uselib_store='DL') |
Ryan Dahl | 0c12554 | 2010-01-19 23:38:20 | [diff] [blame] | 118 | if not sys.platform.startswith("sunos"): |
| 119 | conf.env.append_value("CCFLAGS", "-rdynamic") |
| 120 | conf.env.append_value("LINKFLAGS_DL", "-rdynamic") |
Ryan | a97dce7 | 2009-08-31 09:14:34 | [diff] [blame] | 121 | |
Vanilla Hsu | d22952b | 2010-01-07 07:37:27 | [diff] [blame] | 122 | if sys.platform.startswith("freebsd"): |
| 123 | conf.check(lib='kvm', uselib_store='KVM') |
| 124 | |
Ryan | 8152f9c | 2009-09-01 12:15:29 | [diff] [blame] | 125 | #if Options.options.debug: |
| 126 | # conf.check(lib='profiler', uselib_store='PROFILER') |
Ryan | 7bad9de | 2009-06-16 13:47:57 | [diff] [blame] | 127 | |
Ryan | 8152f9c | 2009-09-01 12:15:29 | [diff] [blame] | 128 | #if Options.options.efence: |
| 129 | # conf.check(lib='efence', libpath=['/usr/lib', '/usr/local/lib'], uselib_store='EFENCE') |
Ryan | a3627c0 | 2009-05-27 14:29:55 | [diff] [blame] | 130 | |
Ryan Dahl | 8b62e86 | 2009-10-10 09:58:36 | [diff] [blame] | 131 | if not conf.check(lib="execinfo", libpath=['/usr/lib', '/usr/local/lib'], uselib_store="EXECINFO"): |
Rasmus Andersson | 6eb8bbc | 2009-12-15 22:37:49 | [diff] [blame] | 132 | # Note on Darwin/OS X: This will fail, but will still be used as the |
| 133 | # execinfo stuff are part of the standard library. |
Ryan Dahl | 8b62e86 | 2009-10-10 09:58:36 | [diff] [blame] | 134 | if sys.platform.startswith("freebsd"): |
Simon Cornelius P. Umacob | e801f42 | 2009-12-09 12:36:12 | [diff] [blame] | 135 | conf.fatal("Install the libexecinfo port from /usr/ports/devel/libexecinfo.") |
Ryan | a3627c0 | 2009-05-27 14:29:55 | [diff] [blame] | 136 | |
Rhys Jones | b6dda61 | 2009-11-22 02:58:08 | [diff] [blame] | 137 | if conf.check_cfg(package='gnutls', |
| 138 | args='--cflags --libs', |
Ryan Dahl | 8a58e83 | 2009-11-28 14:25:10 | [diff] [blame] | 139 | atleast_version='2.5.0', |
Rhys Jones | b6dda61 | 2009-11-22 02:58:08 | [diff] [blame] | 140 | #libpath=['/usr/lib', '/usr/local/lib'], |
| 141 | uselib_store='GNUTLS'): |
| 142 | if conf.check(lib='gpg-error', |
Ryan Dahl | 0b823dc | 2010-02-17 21:56:44 | [diff] [blame] | 143 | libpath=['/usr/lib', '/usr/local/lib', '/opt/local/lib'], |
Rhys Jones | b6dda61 | 2009-11-22 02:58:08 | [diff] [blame] | 144 | uselib_store='GPGERROR'): |
| 145 | conf.env.append_value("CCFLAGS", "-DEVCOM_HAVE_GNUTLS=1") |
| 146 | conf.env.append_value("CXXFLAGS", "-DEVCOM_HAVE_GNUTLS=1") |
| 147 | |
Ryan Dahl | 0c12554 | 2010-01-19 23:38:20 | [diff] [blame] | 148 | if sys.platform.startswith("sunos"): |
| 149 | if not conf.check(lib='socket', uselib_store="SOCKET"): |
| 150 | conf.fatal("Cannot find socket library") |
| 151 | if not conf.check(lib='nsl', uselib_store="NSL"): |
| 152 | conf.fatal("Cannot find nsl library") |
| 153 | |
Ryan | 1a126ed | 2009-04-04 12:50:15 | [diff] [blame] | 154 | conf.sub_config('deps/libeio') |
Jérémy Lal | c93bab1 | 2010-03-11 21:15:32 | [diff] [blame] | 155 | if not Options.options.system: |
| 156 | conf.sub_config('deps/libev') |
| 157 | if sys.platform.startswith("sunos"): |
| 158 | conf_subproject(conf, 'deps/udns', 'LIBS="-lsocket -lnsl" ./configure') |
| 159 | else: |
| 160 | conf_subproject(conf, 'deps/udns', './configure') |
Ryan Dahl | 0c12554 | 2010-01-19 23:38:20 | [diff] [blame] | 161 | else: |
Jérémy Lal | c93bab1 | 2010-03-11 21:15:32 | [diff] [blame] | 162 | if not conf.check(lib='v8', uselib_store='V8'): |
| 163 | conf.fatal("Cannot find V8") |
| 164 | if not conf.check(lib='ev', uselib_store='EV'): |
| 165 | conf.fatal("Cannot find libev") |
Ryan Dahl | ffeb472 | 2010-03-13 20:20:09 | [diff] [blame^] | 166 | if not conf.check(lib='udns', uselib_store='UDNS'): |
Jérémy Lal | c93bab1 | 2010-03-11 21:15:32 | [diff] [blame] | 167 | conf.fatal("Cannot find udns") |
Ryan | 41d89f6 | 2009-07-28 10:29:18 | [diff] [blame] | 168 | |
Ryan | 1a126ed | 2009-04-04 12:50:15 | [diff] [blame] | 169 | conf.define("HAVE_CONFIG_H", 1) |
Ryan | c62b124 | 2009-04-22 17:55:08 | [diff] [blame] | 170 | |
Ryan | 1df6d61 | 2009-09-03 13:59:48 | [diff] [blame] | 171 | conf.env.append_value("CCFLAGS", "-DX_STACKSIZE=%d" % (1024*64)) |
Ryan | 427e3f5 | 2009-05-14 11:16:45 | [diff] [blame] | 172 | |
Ryan Dahl | 2b743aa | 2009-10-27 11:05:38 | [diff] [blame] | 173 | # LFS |
| 174 | conf.env.append_value('CCFLAGS', '-D_LARGEFILE_SOURCE') |
| 175 | conf.env.append_value('CXXFLAGS', '-D_LARGEFILE_SOURCE') |
| 176 | conf.env.append_value('CCFLAGS', '-D_FILE_OFFSET_BITS=64') |
| 177 | conf.env.append_value('CXXFLAGS', '-D_FILE_OFFSET_BITS=64') |
| 178 | |
Ryan Dahl | f481183 | 2009-11-02 23:21:00 | [diff] [blame] | 179 | # platform |
| 180 | platform_def = '-DPLATFORM=' + sys.platform |
| 181 | conf.env.append_value('CCFLAGS', platform_def) |
| 182 | conf.env.append_value('CXXFLAGS', platform_def) |
| 183 | |
Ryan | 67af958 | 2009-04-18 13:35:42 | [diff] [blame] | 184 | # Split off debug variant before adding variant specific defines |
Ryan | 7e1350f | 2009-04-16 09:37:44 | [diff] [blame] | 185 | debug_env = conf.env.copy() |
| 186 | conf.set_env_name('debug', debug_env) |
Ryan | 7e1350f | 2009-04-16 09:37:44 | [diff] [blame] | 187 | |
Ryan | 67af958 | 2009-04-18 13:35:42 | [diff] [blame] | 188 | # Configure debug variant |
| 189 | conf.setenv('debug') |
| 190 | debug_env.set_variant('debug') |
Ryan | 8ddf930 | 2009-09-02 18:19:52 | [diff] [blame] | 191 | debug_env.append_value('CCFLAGS', ['-DDEBUG', '-g', '-O0', '-Wall', '-Wextra']) |
| 192 | debug_env.append_value('CXXFLAGS', ['-DDEBUG', '-g', '-O0', '-Wall', '-Wextra']) |
Ryan | 67af958 | 2009-04-18 13:35:42 | [diff] [blame] | 193 | conf.write_config_header("config.h") |
| 194 | |
| 195 | # Configure default variant |
| 196 | conf.setenv('default') |
Ryan | 8ddf930 | 2009-09-02 18:19:52 | [diff] [blame] | 197 | conf.env.append_value('CCFLAGS', ['-DNDEBUG', '-O3']) |
| 198 | conf.env.append_value('CXXFLAGS', ['-DNDEBUG', '-O3']) |
Ryan | 67af958 | 2009-04-18 13:35:42 | [diff] [blame] | 199 | conf.write_config_header("config.h") |
Ryan | 63a9cd3 | 2009-04-15 08:08:28 | [diff] [blame] | 200 | |
Ryan | 41d89f6 | 2009-07-28 10:29:18 | [diff] [blame] | 201 | def build_udns(bld): |
| 202 | default_build_dir = bld.srcnode.abspath(bld.env_of_name("default")) |
Ryan | 1a126ed | 2009-04-04 12:50:15 | [diff] [blame] | 203 | |
Ryan | 41d89f6 | 2009-07-28 10:29:18 | [diff] [blame] | 204 | default_dir = join(default_build_dir, "deps/udns") |
| 205 | |
| 206 | static_lib = bld.env["staticlib_PATTERN"] % "udns" |
| 207 | |
masuidrive | 3337e9d | 2010-02-10 10:21:54 | [diff] [blame] | 208 | rule = 'cd "%s" && make' |
Ryan | 41d89f6 | 2009-07-28 10:29:18 | [diff] [blame] | 209 | |
| 210 | default = bld.new_task_gen( |
| 211 | target= join("deps/udns", static_lib), |
| 212 | rule= rule % default_dir, |
| 213 | before= "cxx", |
| 214 | install_path= None |
| 215 | ) |
| 216 | |
| 217 | bld.env["CPPPATH_UDNS"] = "deps/udns" |
Ryan Dahl | fc937aa | 2009-10-27 21:50:46 | [diff] [blame] | 218 | t = join(bld.srcnode.abspath(bld.env_of_name("default")), default.target) |
| 219 | bld.env_of_name('default')["LINKFLAGS_UDNS"] = [t] |
Ryan | 41d89f6 | 2009-07-28 10:29:18 | [diff] [blame] | 220 | |
| 221 | if bld.env["USE_DEBUG"]: |
| 222 | debug_build_dir = bld.srcnode.abspath(bld.env_of_name("debug")) |
| 223 | debug_dir = join(debug_build_dir, "deps/udns") |
| 224 | debug = default.clone("debug") |
| 225 | debug.rule = rule % debug_dir |
Ryan Dahl | fc937aa | 2009-10-27 21:50:46 | [diff] [blame] | 226 | t = join(bld.srcnode.abspath(bld.env_of_name("debug")), debug.target) |
| 227 | bld.env_of_name('debug')["LINKFLAGS_UDNS"] = [t] |
Ryan Dahl | 0c12554 | 2010-01-19 23:38:20 | [diff] [blame] | 228 | |
Ryan Dahl | bf0d278 | 2009-10-03 20:42:03 | [diff] [blame] | 229 | bld.install_files('${PREFIX}/include/node/', 'deps/udns/udns.h') |
Ryan | 41d89f6 | 2009-07-28 10:29:18 | [diff] [blame] | 230 | |
Ryan Dahl | 53ebe75 | 2009-10-08 21:20:14 | [diff] [blame] | 231 | def v8_cmd(bld, variant): |
| 232 | scons = join(cwd, 'tools/scons/scons.py') |
Ryan | 1a126ed | 2009-04-04 12:50:15 | [diff] [blame] | 233 | deps_src = join(bld.path.abspath(),"deps") |
Ryan | 1a126ed | 2009-04-04 12:50:15 | [diff] [blame] | 234 | v8dir_src = join(deps_src,"v8") |
Ryan Dahl | 53ebe75 | 2009-10-08 21:20:14 | [diff] [blame] | 235 | |
Ryan Dahl | bc9b343 | 2009-10-02 12:10:40 | [diff] [blame] | 236 | # NOTE: We want to compile V8 to export its symbols. I.E. Do not want |
| 237 | # -fvisibility=hidden. When using dlopen() it seems that the loaded DSO |
| 238 | # cannot see symbols in the executable which are hidden, even if the |
| 239 | # executable is statically linked together... |
Ryan | 8ddf930 | 2009-09-02 18:19:52 | [diff] [blame] | 240 | |
Ryan Dahl | 7d9d881 | 2009-10-26 21:27:52 | [diff] [blame] | 241 | # XXX Remove this when v8 defaults x86_64 to native builds |
Ryan Dahl | d85724d | 2009-10-08 22:34:39 | [diff] [blame] | 242 | arch = "" |
Ryan Dahl | 7d9d881 | 2009-10-26 21:27:52 | [diff] [blame] | 243 | if bld.env['DEST_CPU'] == 'x86_64': |
Ryan Dahl | d85724d | 2009-10-08 22:34:39 | [diff] [blame] | 244 | arch = "arch=x64" |
| 245 | |
| 246 | if variant == "default": |
| 247 | mode = "release" |
| 248 | else: |
| 249 | mode = "debug" |
Ryan | a4593e3 | 2009-04-23 11:18:38 | [diff] [blame] | 250 | |
masuidrive | 3337e9d | 2010-02-10 10:21:54 | [diff] [blame] | 251 | cmd_R = 'python "%s" -C "%s" -Y "%s" visibility=default mode=%s %s library=static snapshot=on' |
Ryan Dahl | 53ebe75 | 2009-10-08 21:20:14 | [diff] [blame] | 252 | |
| 253 | cmd = cmd_R % ( scons |
| 254 | , bld.srcnode.abspath(bld.env_of_name(variant)) |
| 255 | , v8dir_src |
| 256 | , mode |
| 257 | , arch |
| 258 | ) |
| 259 | return cmd |
| 260 | |
| 261 | |
| 262 | def build_v8(bld): |
Ryan | 1a126ed | 2009-04-04 12:50:15 | [diff] [blame] | 263 | v8 = bld.new_task_gen( |
Ryan Dahl | 59b7a1b | 2009-10-09 10:49:48 | [diff] [blame] | 264 | source = 'deps/v8/SConstruct ' |
| 265 | + bld.path.ant_glob('v8/include/*') |
| 266 | + bld.path.ant_glob('v8/src/*'), |
Ryan Dahl | 53ebe75 | 2009-10-08 21:20:14 | [diff] [blame] | 267 | target = bld.env["staticlib_PATTERN"] % "v8", |
| 268 | rule = v8_cmd(bld, "default"), |
| 269 | before = "cxx", |
| 270 | install_path = None |
Ryan | 1a126ed | 2009-04-04 12:50:15 | [diff] [blame] | 271 | ) |
Ryan Dahl | 8b62e86 | 2009-10-10 09:58:36 | [diff] [blame] | 272 | v8.uselib = "EXECINFO" |
Ryan | 1a126ed | 2009-04-04 12:50:15 | [diff] [blame] | 273 | bld.env["CPPPATH_V8"] = "deps/v8/include" |
Ryan Dahl | fc937aa | 2009-10-27 21:50:46 | [diff] [blame] | 274 | t = join(bld.srcnode.abspath(bld.env_of_name("default")), v8.target) |
Ryan Dahl | 0c12554 | 2010-01-19 23:38:20 | [diff] [blame] | 275 | if sys.platform.startswith("sunos"): |
| 276 | bld.env_of_name('default')["LINKFLAGS_V8"] = ["-mt", t] |
| 277 | else: |
| 278 | bld.env_of_name('default')["LINKFLAGS_V8"] = ["-pthread", t] |
Ryan | a4593e3 | 2009-04-23 11:18:38 | [diff] [blame] | 279 | |
| 280 | ### v8 debug |
Ryan | 29b528c | 2009-04-23 15:29:31 | [diff] [blame] | 281 | if bld.env["USE_DEBUG"]: |
Ryan | 29b528c | 2009-04-23 15:29:31 | [diff] [blame] | 282 | v8_debug = v8.clone("debug") |
Ryan Dahl | 53ebe75 | 2009-10-08 21:20:14 | [diff] [blame] | 283 | v8_debug.rule = v8_cmd(bld, "debug") |
| 284 | v8_debug.target = bld.env["staticlib_PATTERN"] % "v8_g" |
Ryan Dahl | 8b62e86 | 2009-10-10 09:58:36 | [diff] [blame] | 285 | v8_debug.uselib = "EXECINFO" |
Ryan Dahl | fc937aa | 2009-10-27 21:50:46 | [diff] [blame] | 286 | t = join(bld.srcnode.abspath(bld.env_of_name("debug")), v8_debug.target) |
Ryan Dahl | 0c12554 | 2010-01-19 23:38:20 | [diff] [blame] | 287 | if sys.platform.startswith("sunos"): |
| 288 | bld.env_of_name('debug')["LINKFLAGS_V8"] = ["-mt", t] |
| 289 | else: |
| 290 | bld.env_of_name('debug')["LINKFLAGS_V8"] = ["-pthread", t] |
Ryan | 1a126ed | 2009-04-04 12:50:15 | [diff] [blame] | 291 | |
Ryan Dahl | 53ebe75 | 2009-10-08 21:20:14 | [diff] [blame] | 292 | bld.install_files('${PREFIX}/include/node/', 'deps/v8/include/*.h') |
Ryan | 2b6d724 | 2009-06-20 13:07:10 | [diff] [blame] | 293 | |
Ryan | 41d89f6 | 2009-07-28 10:29:18 | [diff] [blame] | 294 | def build(bld): |
Jérémy Lal | c93bab1 | 2010-03-11 21:15:32 | [diff] [blame] | 295 | if not bld.env["USE_SYSTEM"]: |
| 296 | bld.add_subdirs('deps/libeio deps/libev') |
| 297 | build_udns(bld) |
| 298 | build_v8(bld) |
| 299 | else: |
| 300 | bld.add_subdirs('deps/libeio') |
Ryan | 41d89f6 | 2009-07-28 10:29:18 | [diff] [blame] | 301 | |
Jérémy Lal | c93bab1 | 2010-03-11 21:15:32 | [diff] [blame] | 302 | |
Ryan | 41d89f6 | 2009-07-28 10:29:18 | [diff] [blame] | 303 | |
Ryan | 0fb0af3 | 2009-07-25 15:52:21 | [diff] [blame] | 304 | ### evcom |
Ryan Dahl | 122e74b | 2009-10-27 21:26:53 | [diff] [blame] | 305 | evcom = bld.new_task_gen("cc") |
Ryan | 0fb0af3 | 2009-07-25 15:52:21 | [diff] [blame] | 306 | evcom.source = "deps/evcom/evcom.c" |
Jérémy Lal | c93bab1 | 2010-03-11 21:15:32 | [diff] [blame] | 307 | if not bld.env["USE_SYSTEM"]: |
| 308 | evcom.includes = "deps/evcom/ deps/libev/" |
| 309 | else: |
| 310 | evcom.includes = "deps/evcom/" |
Ryan | 0fb0af3 | 2009-07-25 15:52:21 | [diff] [blame] | 311 | evcom.name = "evcom" |
| 312 | evcom.target = "evcom" |
Rhys Jones | b6dda61 | 2009-11-22 02:58:08 | [diff] [blame] | 313 | evcom.uselib = "GPGERROR GNUTLS" |
Ryan | 0fb0af3 | 2009-07-25 15:52:21 | [diff] [blame] | 314 | evcom.install_path = None |
Ryan | 29b528c | 2009-04-23 15:29:31 | [diff] [blame] | 315 | if bld.env["USE_DEBUG"]: |
Ryan | 0fb0af3 | 2009-07-25 15:52:21 | [diff] [blame] | 316 | evcom.clone("debug") |
Ryan Dahl | bf0d278 | 2009-10-03 20:42:03 | [diff] [blame] | 317 | bld.install_files('${PREFIX}/include/node/', 'deps/evcom/evcom.h') |
Ryan | 1a126ed | 2009-04-04 12:50:15 | [diff] [blame] | 318 | |
Ryan | 5a071ad | 2009-05-03 12:09:16 | [diff] [blame] | 319 | ### http_parser |
Ryan Dahl | 122e74b | 2009-10-27 21:26:53 | [diff] [blame] | 320 | http_parser = bld.new_task_gen("cc") |
Ryan | 5a071ad | 2009-05-03 12:09:16 | [diff] [blame] | 321 | http_parser.source = "deps/http_parser/http_parser.c" |
| 322 | http_parser.includes = "deps/http_parser/" |
| 323 | http_parser.name = "http_parser" |
| 324 | http_parser.target = "http_parser" |
| 325 | http_parser.install_path = None |
Ryan | 29b528c | 2009-04-23 15:29:31 | [diff] [blame] | 326 | if bld.env["USE_DEBUG"]: |
Ryan | 5a071ad | 2009-05-03 12:09:16 | [diff] [blame] | 327 | http_parser.clone("debug") |
Ryan | 1a126ed | 2009-04-04 12:50:15 | [diff] [blame] | 328 | |
Ryan | 17c6a67 | 2009-08-24 18:25:24 | [diff] [blame] | 329 | ### coupling |
Ryan Dahl | 122e74b | 2009-10-27 21:26:53 | [diff] [blame] | 330 | coupling = bld.new_task_gen("cc") |
Ryan | 17c6a67 | 2009-08-24 18:25:24 | [diff] [blame] | 331 | coupling.source = "deps/coupling/coupling.c" |
| 332 | coupling.includes = "deps/coupling/" |
| 333 | coupling.name = "coupling" |
| 334 | coupling.target = "coupling" |
| 335 | coupling.install_path = None |
| 336 | if bld.env["USE_DEBUG"]: |
| 337 | coupling.clone("debug") |
| 338 | |
Ryan | 63a9cd3 | 2009-04-15 08:08:28 | [diff] [blame] | 339 | ### src/native.cc |
| 340 | def javascript_in_c(task): |
| 341 | env = task.env |
| 342 | source = map(lambda x: x.srcpath(env), task.inputs) |
| 343 | targets = map(lambda x: x.srcpath(env), task.outputs) |
| 344 | js2c.JS2C(source, targets) |
| 345 | |
| 346 | native_cc = bld.new_task_gen( |
Ryan Dahl | d737a06 | 2009-11-07 13:37:22 | [diff] [blame] | 347 | source='src/node.js', |
Ryan Dahl | 53ebe75 | 2009-10-08 21:20:14 | [diff] [blame] | 348 | target="src/node_natives.h", |
Ryan | 63a9cd3 | 2009-04-15 08:08:28 | [diff] [blame] | 349 | before="cxx" |
| 350 | ) |
Ryan | 8e7bbf2 | 2009-04-23 17:26:56 | [diff] [blame] | 351 | native_cc.install_path = None |
Ryan Dahl | 4bcb01c | 2009-10-16 20:53:44 | [diff] [blame] | 352 | |
| 353 | # Add the rule /after/ cloning the debug |
| 354 | # This is a work around for an error had in python 2.4.3 (I'll paste the |
| 355 | # error that was had into the git commit meessage. git-blame to find out |
| 356 | # where.) |
Ryan | 29b528c | 2009-04-23 15:29:31 | [diff] [blame] | 357 | if bld.env["USE_DEBUG"]: |
Ryan Dahl | 4bcb01c | 2009-10-16 20:53:44 | [diff] [blame] | 358 | native_cc_debug = native_cc.clone("debug") |
| 359 | native_cc_debug.rule = javascript_in_c |
| 360 | native_cc.rule = javascript_in_c |
Ryan | 63a9cd3 | 2009-04-15 08:08:28 | [diff] [blame] | 361 | |
Ryan | 2b6d724 | 2009-06-20 13:07:10 | [diff] [blame] | 362 | ### node lib |
Ryan | 8152f9c | 2009-09-01 12:15:29 | [diff] [blame] | 363 | node = bld.new_task_gen("cxx", "program") |
| 364 | node.name = "node" |
| 365 | node.target = "node" |
| 366 | node.source = """ |
Ryan | 1a126ed | 2009-04-04 12:50:15 | [diff] [blame] | 367 | src/node.cc |
Ryan Dahl | a5df0f6 | 2009-10-27 10:46:58 | [diff] [blame] | 368 | src/node_child_process.cc |
| 369 | src/node_constants.cc |
| 370 | src/node_dns.cc |
| 371 | src/node_events.cc |
| 372 | src/node_file.cc |
| 373 | src/node_http.cc |
| 374 | src/node_net.cc |
| 375 | src/node_signal_handler.cc |
Ryan Dahl | 8d2f9e8 | 2009-11-17 13:07:48 | [diff] [blame] | 376 | src/node_stat.cc |
Ryan | 17c6a67 | 2009-08-24 18:25:24 | [diff] [blame] | 377 | src/node_stdio.cc |
Ryan Dahl | a5df0f6 | 2009-10-27 10:46:58 | [diff] [blame] | 378 | src/node_timer.cc |
Ryan Dahl | aeb7d6d | 2010-01-18 18:12:04 | [diff] [blame] | 379 | src/node_idle_watcher.cc |
Ryan | 1a126ed | 2009-04-04 12:50:15 | [diff] [blame] | 380 | """ |
Jérémy Lal | c93bab1 | 2010-03-11 21:15:32 | [diff] [blame] | 381 | if not bld.env["USE_SYSTEM"]: |
| 382 | node.includes = """ |
| 383 | src/ |
| 384 | deps/v8/include |
| 385 | deps/libev |
| 386 | deps/udns |
| 387 | deps/libeio |
| 388 | deps/evcom |
| 389 | deps/http_parser |
| 390 | deps/coupling |
| 391 | """ |
| 392 | node.add_objects = 'ev eio evcom http_parser coupling' |
| 393 | node.uselib_local = '' |
| 394 | node.uselib = 'GNUTLS GPGERROR UDNS V8 EXECINFO DL KVM SOCKET NSL' |
| 395 | else: |
| 396 | node.includes = """ |
| 397 | src/ |
| 398 | deps/libeio |
| 399 | deps/evcom |
| 400 | deps/http_parser |
| 401 | deps/coupling |
| 402 | """ |
| 403 | node.add_objects = 'eio evcom http_parser coupling' |
| 404 | node.uselib_local = 'eio' |
| 405 | node.uselib = 'EV GNUTLS GPGERROR UDNS V8 EXECINFO DL KVM SOCKET NSL' |
Rhys Jones | b6dda61 | 2009-11-22 02:58:08 | [diff] [blame] | 406 | |
Ryan | 8152f9c | 2009-09-01 12:15:29 | [diff] [blame] | 407 | node.install_path = '${PREFIX}/lib' |
Ryan | 8e7bbf2 | 2009-04-23 17:26:56 | [diff] [blame] | 408 | node.install_path = '${PREFIX}/bin' |
| 409 | node.chmod = 0755 |
| 410 | |
Ryan | 4d92199 | 2009-08-26 23:11:16 | [diff] [blame] | 411 | def subflags(program): |
Ryan Dahl | d979ac9 | 2009-10-09 13:00:12 | [diff] [blame] | 412 | if os.path.exists(join(cwd, ".git")): |
Ryan Dahl | 962e929 | 2009-10-09 14:16:27 | [diff] [blame] | 413 | actual_version=cmd_output("git describe").strip() |
Ryan Dahl | d979ac9 | 2009-10-09 13:00:12 | [diff] [blame] | 414 | else: |
| 415 | actual_version=VERSION |
| 416 | |
Ryan | b73264d | 2009-08-27 00:15:11 | [diff] [blame] | 417 | x = { 'CCFLAGS' : " ".join(program.env["CCFLAGS"]) |
| 418 | , 'CPPFLAGS' : " ".join(program.env["CPPFLAGS"]) |
| 419 | , 'LIBFLAGS' : " ".join(program.env["LIBFLAGS"]) |
Ryan Dahl | d979ac9 | 2009-10-09 13:00:12 | [diff] [blame] | 420 | , 'VERSION' : actual_version |
Ryan | b73264d | 2009-08-27 00:15:11 | [diff] [blame] | 421 | , 'PREFIX' : program.env["PREFIX"] |
Ryan | 4d92199 | 2009-08-26 23:11:16 | [diff] [blame] | 422 | } |
Ryan Dahl | bf0d278 | 2009-10-03 20:42:03 | [diff] [blame] | 423 | return x |
Ryan | 4d92199 | 2009-08-26 23:11:16 | [diff] [blame] | 424 | |
Ryan | 4d92199 | 2009-08-26 23:11:16 | [diff] [blame] | 425 | # process file.pc.in -> file.pc |
Ryan Dahl | d979ac9 | 2009-10-09 13:00:12 | [diff] [blame] | 426 | |
Ryan | b73264d | 2009-08-27 00:15:11 | [diff] [blame] | 427 | node_version = bld.new_task_gen('subst', before="cxx") |
| 428 | node_version.source = 'src/node_version.h.in' |
| 429 | node_version.target = 'src/node_version.h' |
| 430 | node_version.dict = subflags(node) |
Ryan | a97dce7 | 2009-08-31 09:14:34 | [diff] [blame] | 431 | node_version.install_path = '${PREFIX}/include/node' |
Ryan | 4d92199 | 2009-08-26 23:11:16 | [diff] [blame] | 432 | |
Ryan | 29b528c | 2009-04-23 15:29:31 | [diff] [blame] | 433 | if bld.env["USE_DEBUG"]: |
Ryan | 2b6d724 | 2009-06-20 13:07:10 | [diff] [blame] | 434 | node_g = node.clone("debug") |
| 435 | node_g.target = "node_g" |
Ryan | 4d92199 | 2009-08-26 23:11:16 | [diff] [blame] | 436 | |
Ryan | b73264d | 2009-08-27 00:15:11 | [diff] [blame] | 437 | node_version_g = node_version.clone("debug") |
| 438 | node_version_g.dict = subflags(node_g) |
Ryan | a97dce7 | 2009-08-31 09:14:34 | [diff] [blame] | 439 | node_version_g.install_path = None |
Ryan | 4d92199 | 2009-08-26 23:11:16 | [diff] [blame] | 440 | |
Ryan | a97dce7 | 2009-08-31 09:14:34 | [diff] [blame] | 441 | |
| 442 | bld.install_files('${PREFIX}/include/node/', """ |
| 443 | config.h |
| 444 | src/node.h |
Ryan Dahl | 5f466c8 | 2009-10-27 19:17:03 | [diff] [blame] | 445 | src/node_object_wrap.h |
| 446 | src/node_events.h |
| 447 | src/node_net.h |
Ryan Dahl | bf0d278 | 2009-10-03 20:42:03 | [diff] [blame] | 448 | """) |
| 449 | |
| 450 | # Only install the man page if it exists. |
| 451 | # Do 'make doc install' to build and install it. |
| 452 | if os.path.exists('doc/node.1'): |
| 453 | bld.install_files('${PREFIX}/share/man/man1/', 'doc/node.1') |
| 454 | |
| 455 | bld.install_files('${PREFIX}/bin/', 'bin/*', chmod=0755) |
Ryan Dahl | 6f17ca5 | 2009-10-03 17:08:05 | [diff] [blame] | 456 | |
| 457 | # Why am I using two lines? Because WAF SUCKS. |
Ryan Dahl | bf0d278 | 2009-10-03 20:42:03 | [diff] [blame] | 458 | bld.install_files('${PREFIX}/lib/node/wafadmin', 'tools/wafadmin/*.py') |
| 459 | bld.install_files('${PREFIX}/lib/node/wafadmin/Tools', 'tools/wafadmin/Tools/*.py') |
Ryan Dahl | 6f17ca5 | 2009-10-03 17:08:05 | [diff] [blame] | 460 | |
Ryan Dahl | bf0d278 | 2009-10-03 20:42:03 | [diff] [blame] | 461 | bld.install_files('${PREFIX}/lib/node/libraries/', 'lib/*.js') |
Ryan Dahl | 132d685 | 2009-10-27 17:11:07 | [diff] [blame] | 462 | |
| 463 | def shutdown(): |
| 464 | Options.options.debug |
| 465 | # HACK to get binding.node out of build directory. |
| 466 | # better way to do this? |
| 467 | if not Options.commands['clean']: |
| 468 | if os.path.exists('build/default/node') and not os.path.exists('node'): |
| 469 | os.symlink('build/default/node', 'node') |
| 470 | if os.path.exists('build/debug/node_g') and not os.path.exists('node_g'): |
| 471 | os.symlink('build/debug/node_g', 'node_g') |
| 472 | else: |
| 473 | if os.path.exists('node'): os.unlink('node') |
| 474 | if os.path.exists('node_g'): os.unlink('node_g') |