Ryan | a3627c0 | 2009-05-27 14:29:55 | [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 | 027829d | 2009-11-17 13:30:40 | [diff] [blame] | 10 | VERSION="0.1.18" |
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 | ) |
Ryan | 1a126ed | 2009-04-04 12:50:15 | [diff] [blame] | 35 | |
Ryan | 41d89f6 | 2009-07-28 10:29:18 | [diff] [blame] | 36 | def mkdir_p(dir): |
| 37 | if not os.path.exists (dir): |
| 38 | os.makedirs (dir) |
| 39 | |
Ryan Dahl | 18da8ff | 2009-09-28 20:39:00 | [diff] [blame] | 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 |
Ryan Dahl | 53ebe75 | 2009-10-08 21:20:14 | [diff] [blame] | 55 | srcname = join(src, name) |
| 56 | dstname = join(dst, name) |
Ryan Dahl | 18da8ff | 2009-09-28 20:39:00 | [diff] [blame] | 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 | |
Ryan | 41d89f6 | 2009-07-28 10:29:18 | [diff] [blame] | 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): |
Ryan Dahl | 18da8ff | 2009-09-28 20:39:00 | [diff] [blame] | 91 | copytree(src, default_tgt, True) |
Ryan | 41d89f6 | 2009-07-28 10:29:18 | [diff] [blame] | 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): |
Ryan Dahl | 18da8ff | 2009-09-28 20:39:00 | [diff] [blame] | 100 | copytree(default_tgt, debug_tgt, True) |
Ryan | 41d89f6 | 2009-07-28 10:29:18 | [diff] [blame] | 101 | |
Ryan | 1a126ed | 2009-04-04 12:50:15 | [diff] [blame] | 102 | def configure(conf): |
| 103 | conf.check_tool('compiler_cxx') |
| 104 | conf.check_tool('compiler_cc') |
Ryan | a4593e3 | 2009-04-23 11:18:38 | [diff] [blame] | 105 | |
Ryan | 8e7bbf2 | 2009-04-23 17:26:56 | [diff] [blame] | 106 | conf.env["USE_DEBUG"] = Options.options.debug |
Ryan | 1a126ed | 2009-04-04 12:50:15 | [diff] [blame] | 107 | |
Ryan | 2b6d724 | 2009-06-20 13:07:10 | [diff] [blame] | 108 | conf.check(lib='dl', uselib_store='DL') |
Ryan | 8152f9c | 2009-09-01 12:15:29 | [diff] [blame] | 109 | conf.env.append_value("CCFLAGS", "-rdynamic") |
Ryan | a97dce7 | 2009-08-31 09:14:34 | [diff] [blame] | 110 | conf.env.append_value("LINKFLAGS_DL", "-rdynamic") |
| 111 | |
Ryan | 8152f9c | 2009-09-01 12:15:29 | [diff] [blame] | 112 | #if Options.options.debug: |
| 113 | # conf.check(lib='profiler', uselib_store='PROFILER') |
Ryan | 7bad9de | 2009-06-16 13:47:57 | [diff] [blame] | 114 | |
Ryan | 8152f9c | 2009-09-01 12:15:29 | [diff] [blame] | 115 | #if Options.options.efence: |
| 116 | # conf.check(lib='efence', libpath=['/usr/lib', '/usr/local/lib'], uselib_store='EFENCE') |
Ryan | a3627c0 | 2009-05-27 14:29:55 | [diff] [blame] | 117 | |
Ryan Dahl | 8b62e86 | 2009-10-10 09:58:36 | [diff] [blame] | 118 | if not conf.check(lib="execinfo", libpath=['/usr/lib', '/usr/local/lib'], uselib_store="EXECINFO"): |
| 119 | if sys.platform.startswith("freebsd"): |
Ryan | 7bad9de | 2009-06-16 13:47:57 | [diff] [blame] | 120 | fatal("Install the libexecinfo port from /usr/ports/devel/libexecinfo.") |
Ryan | a3627c0 | 2009-05-27 14:29:55 | [diff] [blame] | 121 | |
Rhys Jones | b6dda61 | 2009-11-22 02:58:08 | [diff] [blame^] | 122 | if conf.check_cfg(package='gnutls', |
| 123 | args='--cflags --libs', |
| 124 | #libpath=['/usr/lib', '/usr/local/lib'], |
| 125 | uselib_store='GNUTLS'): |
| 126 | if conf.check(lib='gpg-error', |
| 127 | #libpath=['/usr/lib', '/usr/local/lib'], |
| 128 | uselib_store='GPGERROR'): |
| 129 | conf.env.append_value("CCFLAGS", "-DEVCOM_HAVE_GNUTLS=1") |
| 130 | conf.env.append_value("CXXFLAGS", "-DEVCOM_HAVE_GNUTLS=1") |
| 131 | |
Ryan | 1a126ed | 2009-04-04 12:50:15 | [diff] [blame] | 132 | conf.sub_config('deps/libeio') |
| 133 | conf.sub_config('deps/libev') |
| 134 | |
Ryan | 41d89f6 | 2009-07-28 10:29:18 | [diff] [blame] | 135 | conf_subproject(conf, 'deps/udns', './configure') |
Ryan | 41d89f6 | 2009-07-28 10:29:18 | [diff] [blame] | 136 | |
Ryan | 1a126ed | 2009-04-04 12:50:15 | [diff] [blame] | 137 | conf.define("HAVE_CONFIG_H", 1) |
Ryan | c62b124 | 2009-04-22 17:55:08 | [diff] [blame] | 138 | |
Ryan | 1df6d61 | 2009-09-03 13:59:48 | [diff] [blame] | 139 | conf.env.append_value("CCFLAGS", "-DX_STACKSIZE=%d" % (1024*64)) |
Ryan | 427e3f5 | 2009-05-14 11:16:45 | [diff] [blame] | 140 | |
Ryan Dahl | 2b743aa | 2009-10-27 11:05:38 | [diff] [blame] | 141 | # LFS |
| 142 | conf.env.append_value('CCFLAGS', '-D_LARGEFILE_SOURCE') |
| 143 | conf.env.append_value('CXXFLAGS', '-D_LARGEFILE_SOURCE') |
| 144 | conf.env.append_value('CCFLAGS', '-D_FILE_OFFSET_BITS=64') |
| 145 | conf.env.append_value('CXXFLAGS', '-D_FILE_OFFSET_BITS=64') |
| 146 | |
Ryan Dahl | f481183 | 2009-11-02 23:21:00 | [diff] [blame] | 147 | # platform |
| 148 | platform_def = '-DPLATFORM=' + sys.platform |
| 149 | conf.env.append_value('CCFLAGS', platform_def) |
| 150 | conf.env.append_value('CXXFLAGS', platform_def) |
| 151 | |
Ryan | 67af958 | 2009-04-18 13:35:42 | [diff] [blame] | 152 | # Split off debug variant before adding variant specific defines |
Ryan | 7e1350f | 2009-04-16 09:37:44 | [diff] [blame] | 153 | debug_env = conf.env.copy() |
| 154 | conf.set_env_name('debug', debug_env) |
Ryan | 7e1350f | 2009-04-16 09:37:44 | [diff] [blame] | 155 | |
Ryan | 67af958 | 2009-04-18 13:35:42 | [diff] [blame] | 156 | # Configure debug variant |
| 157 | conf.setenv('debug') |
| 158 | debug_env.set_variant('debug') |
Ryan | 8ddf930 | 2009-09-02 18:19:52 | [diff] [blame] | 159 | debug_env.append_value('CCFLAGS', ['-DDEBUG', '-g', '-O0', '-Wall', '-Wextra']) |
| 160 | debug_env.append_value('CXXFLAGS', ['-DDEBUG', '-g', '-O0', '-Wall', '-Wextra']) |
Ryan | 67af958 | 2009-04-18 13:35:42 | [diff] [blame] | 161 | conf.write_config_header("config.h") |
| 162 | |
| 163 | # Configure default variant |
| 164 | conf.setenv('default') |
Ryan | 8ddf930 | 2009-09-02 18:19:52 | [diff] [blame] | 165 | conf.env.append_value('CCFLAGS', ['-DNDEBUG', '-O3']) |
| 166 | conf.env.append_value('CXXFLAGS', ['-DNDEBUG', '-O3']) |
Ryan | 67af958 | 2009-04-18 13:35:42 | [diff] [blame] | 167 | conf.write_config_header("config.h") |
Ryan | 63a9cd3 | 2009-04-15 08:08:28 | [diff] [blame] | 168 | |
Ryan | 41d89f6 | 2009-07-28 10:29:18 | [diff] [blame] | 169 | def build_udns(bld): |
| 170 | default_build_dir = bld.srcnode.abspath(bld.env_of_name("default")) |
Ryan | 1a126ed | 2009-04-04 12:50:15 | [diff] [blame] | 171 | |
Ryan | 41d89f6 | 2009-07-28 10:29:18 | [diff] [blame] | 172 | default_dir = join(default_build_dir, "deps/udns") |
| 173 | |
| 174 | static_lib = bld.env["staticlib_PATTERN"] % "udns" |
| 175 | |
| 176 | rule = 'cd %s && make' |
| 177 | |
| 178 | default = bld.new_task_gen( |
| 179 | target= join("deps/udns", static_lib), |
| 180 | rule= rule % default_dir, |
| 181 | before= "cxx", |
| 182 | install_path= None |
| 183 | ) |
| 184 | |
| 185 | bld.env["CPPPATH_UDNS"] = "deps/udns" |
Ryan Dahl | fc937aa | 2009-10-27 21:50:46 | [diff] [blame] | 186 | t = join(bld.srcnode.abspath(bld.env_of_name("default")), default.target) |
| 187 | bld.env_of_name('default')["LINKFLAGS_UDNS"] = [t] |
Ryan | 41d89f6 | 2009-07-28 10:29:18 | [diff] [blame] | 188 | |
| 189 | if bld.env["USE_DEBUG"]: |
| 190 | debug_build_dir = bld.srcnode.abspath(bld.env_of_name("debug")) |
| 191 | debug_dir = join(debug_build_dir, "deps/udns") |
| 192 | debug = default.clone("debug") |
| 193 | debug.rule = rule % debug_dir |
Ryan Dahl | fc937aa | 2009-10-27 21:50:46 | [diff] [blame] | 194 | t = join(bld.srcnode.abspath(bld.env_of_name("debug")), debug.target) |
| 195 | bld.env_of_name('debug')["LINKFLAGS_UDNS"] = [t] |
Ryan Dahl | bf0d278 | 2009-10-03 20:42:03 | [diff] [blame] | 196 | bld.install_files('${PREFIX}/include/node/', 'deps/udns/udns.h') |
Ryan | 41d89f6 | 2009-07-28 10:29:18 | [diff] [blame] | 197 | |
Ryan Dahl | 53ebe75 | 2009-10-08 21:20:14 | [diff] [blame] | 198 | def v8_cmd(bld, variant): |
| 199 | scons = join(cwd, 'tools/scons/scons.py') |
Ryan | 1a126ed | 2009-04-04 12:50:15 | [diff] [blame] | 200 | deps_src = join(bld.path.abspath(),"deps") |
Ryan | 1a126ed | 2009-04-04 12:50:15 | [diff] [blame] | 201 | v8dir_src = join(deps_src,"v8") |
Ryan Dahl | 53ebe75 | 2009-10-08 21:20:14 | [diff] [blame] | 202 | |
Ryan Dahl | bc9b343 | 2009-10-02 12:10:40 | [diff] [blame] | 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... |
Ryan | 8ddf930 | 2009-09-02 18:19:52 | [diff] [blame] | 207 | |
Ryan Dahl | 7d9d881 | 2009-10-26 21:27:52 | [diff] [blame] | 208 | # XXX Remove this when v8 defaults x86_64 to native builds |
Ryan Dahl | d85724d | 2009-10-08 22:34:39 | [diff] [blame] | 209 | arch = "" |
Ryan Dahl | 7d9d881 | 2009-10-26 21:27:52 | [diff] [blame] | 210 | if bld.env['DEST_CPU'] == 'x86_64': |
Ryan Dahl | d85724d | 2009-10-08 22:34:39 | [diff] [blame] | 211 | arch = "arch=x64" |
| 212 | |
| 213 | if variant == "default": |
| 214 | mode = "release" |
| 215 | else: |
| 216 | mode = "debug" |
Ryan | a4593e3 | 2009-04-23 11:18:38 | [diff] [blame] | 217 | |
Ryan Dahl | 53ebe75 | 2009-10-08 21:20:14 | [diff] [blame] | 218 | cmd_R = 'python %s -C %s -Y %s visibility=default mode=%s %s library=static snapshot=on' |
| 219 | |
| 220 | cmd = cmd_R % ( scons |
| 221 | , bld.srcnode.abspath(bld.env_of_name(variant)) |
| 222 | , v8dir_src |
| 223 | , mode |
| 224 | , arch |
| 225 | ) |
| 226 | return cmd |
| 227 | |
| 228 | |
| 229 | def build_v8(bld): |
Ryan | 1a126ed | 2009-04-04 12:50:15 | [diff] [blame] | 230 | v8 = bld.new_task_gen( |
Ryan Dahl | 59b7a1b | 2009-10-09 10:49:48 | [diff] [blame] | 231 | source = 'deps/v8/SConstruct ' |
| 232 | + bld.path.ant_glob('v8/include/*') |
| 233 | + bld.path.ant_glob('v8/src/*'), |
Ryan Dahl | 53ebe75 | 2009-10-08 21:20:14 | [diff] [blame] | 234 | target = bld.env["staticlib_PATTERN"] % "v8", |
| 235 | rule = v8_cmd(bld, "default"), |
| 236 | before = "cxx", |
| 237 | install_path = None |
Ryan | 1a126ed | 2009-04-04 12:50:15 | [diff] [blame] | 238 | ) |
Ryan Dahl | 8b62e86 | 2009-10-10 09:58:36 | [diff] [blame] | 239 | v8.uselib = "EXECINFO" |
Ryan | 1a126ed | 2009-04-04 12:50:15 | [diff] [blame] | 240 | bld.env["CPPPATH_V8"] = "deps/v8/include" |
Ryan Dahl | fc937aa | 2009-10-27 21:50:46 | [diff] [blame] | 241 | t = join(bld.srcnode.abspath(bld.env_of_name("default")), v8.target) |
| 242 | bld.env_of_name('default')["LINKFLAGS_V8"] = ["-pthread", t] |
Ryan | a4593e3 | 2009-04-23 11:18:38 | [diff] [blame] | 243 | |
| 244 | ### v8 debug |
Ryan | 29b528c | 2009-04-23 15:29:31 | [diff] [blame] | 245 | if bld.env["USE_DEBUG"]: |
Ryan | 29b528c | 2009-04-23 15:29:31 | [diff] [blame] | 246 | v8_debug = v8.clone("debug") |
Ryan Dahl | 53ebe75 | 2009-10-08 21:20:14 | [diff] [blame] | 247 | v8_debug.rule = v8_cmd(bld, "debug") |
| 248 | v8_debug.target = bld.env["staticlib_PATTERN"] % "v8_g" |
Ryan Dahl | 8b62e86 | 2009-10-10 09:58:36 | [diff] [blame] | 249 | v8_debug.uselib = "EXECINFO" |
Ryan Dahl | fc937aa | 2009-10-27 21:50:46 | [diff] [blame] | 250 | t = join(bld.srcnode.abspath(bld.env_of_name("debug")), v8_debug.target) |
| 251 | bld.env_of_name('debug')["LINKFLAGS_V8"] = ["-pthread", t] |
Ryan | 1a126ed | 2009-04-04 12:50:15 | [diff] [blame] | 252 | |
Ryan Dahl | 53ebe75 | 2009-10-08 21:20:14 | [diff] [blame] | 253 | bld.install_files('${PREFIX}/include/node/', 'deps/v8/include/*.h') |
Ryan | 2b6d724 | 2009-06-20 13:07:10 | [diff] [blame] | 254 | |
Ryan | 41d89f6 | 2009-07-28 10:29:18 | [diff] [blame] | 255 | def build(bld): |
| 256 | bld.add_subdirs('deps/libeio deps/libev') |
| 257 | |
| 258 | build_udns(bld) |
| 259 | build_v8(bld) |
| 260 | |
Ryan | 0fb0af3 | 2009-07-25 15:52:21 | [diff] [blame] | 261 | ### evcom |
Ryan Dahl | 122e74b | 2009-10-27 21:26:53 | [diff] [blame] | 262 | evcom = bld.new_task_gen("cc") |
Ryan | 0fb0af3 | 2009-07-25 15:52:21 | [diff] [blame] | 263 | evcom.source = "deps/evcom/evcom.c" |
| 264 | evcom.includes = "deps/evcom/ deps/libev/" |
| 265 | evcom.name = "evcom" |
| 266 | evcom.target = "evcom" |
Rhys Jones | b6dda61 | 2009-11-22 02:58:08 | [diff] [blame^] | 267 | evcom.uselib = "GPGERROR GNUTLS" |
Ryan | 0fb0af3 | 2009-07-25 15:52:21 | [diff] [blame] | 268 | evcom.install_path = None |
Ryan | 29b528c | 2009-04-23 15:29:31 | [diff] [blame] | 269 | if bld.env["USE_DEBUG"]: |
Ryan | 0fb0af3 | 2009-07-25 15:52:21 | [diff] [blame] | 270 | evcom.clone("debug") |
Ryan Dahl | bf0d278 | 2009-10-03 20:42:03 | [diff] [blame] | 271 | bld.install_files('${PREFIX}/include/node/', 'deps/evcom/evcom.h') |
Ryan | 1a126ed | 2009-04-04 12:50:15 | [diff] [blame] | 272 | |
Ryan | 5a071ad | 2009-05-03 12:09:16 | [diff] [blame] | 273 | ### http_parser |
Ryan Dahl | 122e74b | 2009-10-27 21:26:53 | [diff] [blame] | 274 | http_parser = bld.new_task_gen("cc") |
Ryan | 5a071ad | 2009-05-03 12:09:16 | [diff] [blame] | 275 | http_parser.source = "deps/http_parser/http_parser.c" |
| 276 | http_parser.includes = "deps/http_parser/" |
| 277 | http_parser.name = "http_parser" |
| 278 | http_parser.target = "http_parser" |
| 279 | http_parser.install_path = None |
Ryan | 29b528c | 2009-04-23 15:29:31 | [diff] [blame] | 280 | if bld.env["USE_DEBUG"]: |
Ryan | 5a071ad | 2009-05-03 12:09:16 | [diff] [blame] | 281 | http_parser.clone("debug") |
Ryan | 1a126ed | 2009-04-04 12:50:15 | [diff] [blame] | 282 | |
Ryan | 17c6a67 | 2009-08-24 18:25:24 | [diff] [blame] | 283 | ### coupling |
Ryan Dahl | 122e74b | 2009-10-27 21:26:53 | [diff] [blame] | 284 | coupling = bld.new_task_gen("cc") |
Ryan | 17c6a67 | 2009-08-24 18:25:24 | [diff] [blame] | 285 | coupling.source = "deps/coupling/coupling.c" |
| 286 | coupling.includes = "deps/coupling/" |
| 287 | coupling.name = "coupling" |
| 288 | coupling.target = "coupling" |
| 289 | coupling.install_path = None |
| 290 | if bld.env["USE_DEBUG"]: |
| 291 | coupling.clone("debug") |
| 292 | |
Ryan | 63a9cd3 | 2009-04-15 08:08:28 | [diff] [blame] | 293 | ### src/native.cc |
| 294 | def javascript_in_c(task): |
| 295 | env = task.env |
| 296 | source = map(lambda x: x.srcpath(env), task.inputs) |
| 297 | targets = map(lambda x: x.srcpath(env), task.outputs) |
| 298 | js2c.JS2C(source, targets) |
| 299 | |
| 300 | native_cc = bld.new_task_gen( |
Ryan Dahl | d737a06 | 2009-11-07 13:37:22 | [diff] [blame] | 301 | source='src/node.js', |
Ryan Dahl | 53ebe75 | 2009-10-08 21:20:14 | [diff] [blame] | 302 | target="src/node_natives.h", |
Ryan | 63a9cd3 | 2009-04-15 08:08:28 | [diff] [blame] | 303 | before="cxx" |
| 304 | ) |
Ryan | 8e7bbf2 | 2009-04-23 17:26:56 | [diff] [blame] | 305 | native_cc.install_path = None |
Ryan Dahl | 4bcb01c | 2009-10-16 20:53:44 | [diff] [blame] | 306 | |
| 307 | # Add the rule /after/ cloning the debug |
| 308 | # This is a work around for an error had in python 2.4.3 (I'll paste the |
| 309 | # error that was had into the git commit meessage. git-blame to find out |
| 310 | # where.) |
Ryan | 29b528c | 2009-04-23 15:29:31 | [diff] [blame] | 311 | if bld.env["USE_DEBUG"]: |
Ryan Dahl | 4bcb01c | 2009-10-16 20:53:44 | [diff] [blame] | 312 | native_cc_debug = native_cc.clone("debug") |
| 313 | native_cc_debug.rule = javascript_in_c |
| 314 | native_cc.rule = javascript_in_c |
Ryan | 63a9cd3 | 2009-04-15 08:08:28 | [diff] [blame] | 315 | |
Ryan | 2b6d724 | 2009-06-20 13:07:10 | [diff] [blame] | 316 | ### node lib |
Ryan | 8152f9c | 2009-09-01 12:15:29 | [diff] [blame] | 317 | node = bld.new_task_gen("cxx", "program") |
| 318 | node.name = "node" |
| 319 | node.target = "node" |
| 320 | node.source = """ |
Ryan | 1a126ed | 2009-04-04 12:50:15 | [diff] [blame] | 321 | src/node.cc |
Ryan Dahl | a5df0f6 | 2009-10-27 10:46:58 | [diff] [blame] | 322 | src/node_child_process.cc |
| 323 | src/node_constants.cc |
| 324 | src/node_dns.cc |
| 325 | src/node_events.cc |
| 326 | src/node_file.cc |
| 327 | src/node_http.cc |
| 328 | src/node_net.cc |
| 329 | src/node_signal_handler.cc |
Ryan Dahl | 8d2f9e8 | 2009-11-17 13:07:48 | [diff] [blame] | 330 | src/node_stat.cc |
Ryan | 17c6a67 | 2009-08-24 18:25:24 | [diff] [blame] | 331 | src/node_stdio.cc |
Ryan Dahl | a5df0f6 | 2009-10-27 10:46:58 | [diff] [blame] | 332 | src/node_timer.cc |
Ryan | 1a126ed | 2009-04-04 12:50:15 | [diff] [blame] | 333 | """ |
Ryan | 8152f9c | 2009-09-01 12:15:29 | [diff] [blame] | 334 | node.includes = """ |
Ryan | 1a126ed | 2009-04-04 12:50:15 | [diff] [blame] | 335 | src/ |
| 336 | deps/v8/include |
| 337 | deps/libev |
Ryan | 41d89f6 | 2009-07-28 10:29:18 | [diff] [blame] | 338 | deps/udns |
Ryan | 1a126ed | 2009-04-04 12:50:15 | [diff] [blame] | 339 | deps/libeio |
Ryan | 0fb0af3 | 2009-07-25 15:52:21 | [diff] [blame] | 340 | deps/evcom |
Ryan | 5a071ad | 2009-05-03 12:09:16 | [diff] [blame] | 341 | deps/http_parser |
Ryan | 17c6a67 | 2009-08-24 18:25:24 | [diff] [blame] | 342 | deps/coupling |
Ryan | 1a126ed | 2009-04-04 12:50:15 | [diff] [blame] | 343 | """ |
Ryan Dahl | 122e74b | 2009-10-27 21:26:53 | [diff] [blame] | 344 | node.add_objects = 'ev eio evcom http_parser coupling' |
| 345 | node.uselib_local = '' |
Rhys Jones | b6dda61 | 2009-11-22 02:58:08 | [diff] [blame^] | 346 | node.uselib = 'UDNS V8 EXECINFO DL GPGERROR GNUTLS' |
| 347 | |
Ryan | 8152f9c | 2009-09-01 12:15:29 | [diff] [blame] | 348 | node.install_path = '${PREFIX}/lib' |
Ryan | 8e7bbf2 | 2009-04-23 17:26:56 | [diff] [blame] | 349 | node.install_path = '${PREFIX}/bin' |
| 350 | node.chmod = 0755 |
| 351 | |
Ryan | 4d92199 | 2009-08-26 23:11:16 | [diff] [blame] | 352 | def subflags(program): |
Ryan Dahl | d979ac9 | 2009-10-09 13:00:12 | [diff] [blame] | 353 | if os.path.exists(join(cwd, ".git")): |
Ryan Dahl | 962e929 | 2009-10-09 14:16:27 | [diff] [blame] | 354 | actual_version=cmd_output("git describe").strip() |
Ryan Dahl | d979ac9 | 2009-10-09 13:00:12 | [diff] [blame] | 355 | else: |
| 356 | actual_version=VERSION |
| 357 | |
Ryan | b73264d | 2009-08-27 00:15:11 | [diff] [blame] | 358 | x = { 'CCFLAGS' : " ".join(program.env["CCFLAGS"]) |
| 359 | , 'CPPFLAGS' : " ".join(program.env["CPPFLAGS"]) |
| 360 | , 'LIBFLAGS' : " ".join(program.env["LIBFLAGS"]) |
Ryan Dahl | d979ac9 | 2009-10-09 13:00:12 | [diff] [blame] | 361 | , 'VERSION' : actual_version |
Ryan | b73264d | 2009-08-27 00:15:11 | [diff] [blame] | 362 | , 'PREFIX' : program.env["PREFIX"] |
Ryan | 4d92199 | 2009-08-26 23:11:16 | [diff] [blame] | 363 | } |
Ryan Dahl | bf0d278 | 2009-10-03 20:42:03 | [diff] [blame] | 364 | return x |
Ryan | 4d92199 | 2009-08-26 23:11:16 | [diff] [blame] | 365 | |
Ryan | 4d92199 | 2009-08-26 23:11:16 | [diff] [blame] | 366 | # process file.pc.in -> file.pc |
Ryan Dahl | d979ac9 | 2009-10-09 13:00:12 | [diff] [blame] | 367 | |
Ryan | b73264d | 2009-08-27 00:15:11 | [diff] [blame] | 368 | node_version = bld.new_task_gen('subst', before="cxx") |
| 369 | node_version.source = 'src/node_version.h.in' |
| 370 | node_version.target = 'src/node_version.h' |
| 371 | node_version.dict = subflags(node) |
Ryan | a97dce7 | 2009-08-31 09:14:34 | [diff] [blame] | 372 | node_version.install_path = '${PREFIX}/include/node' |
Ryan | 4d92199 | 2009-08-26 23:11:16 | [diff] [blame] | 373 | |
Ryan | 29b528c | 2009-04-23 15:29:31 | [diff] [blame] | 374 | if bld.env["USE_DEBUG"]: |
Ryan | 2b6d724 | 2009-06-20 13:07:10 | [diff] [blame] | 375 | node_g = node.clone("debug") |
| 376 | node_g.target = "node_g" |
Ryan | 4d92199 | 2009-08-26 23:11:16 | [diff] [blame] | 377 | |
Ryan | b73264d | 2009-08-27 00:15:11 | [diff] [blame] | 378 | node_version_g = node_version.clone("debug") |
| 379 | node_version_g.dict = subflags(node_g) |
Ryan | a97dce7 | 2009-08-31 09:14:34 | [diff] [blame] | 380 | node_version_g.install_path = None |
Ryan | 4d92199 | 2009-08-26 23:11:16 | [diff] [blame] | 381 | |
Ryan | a97dce7 | 2009-08-31 09:14:34 | [diff] [blame] | 382 | |
| 383 | bld.install_files('${PREFIX}/include/node/', """ |
| 384 | config.h |
| 385 | src/node.h |
Ryan Dahl | 5f466c8 | 2009-10-27 19:17:03 | [diff] [blame] | 386 | src/node_object_wrap.h |
| 387 | src/node_events.h |
| 388 | src/node_net.h |
Ryan Dahl | bf0d278 | 2009-10-03 20:42:03 | [diff] [blame] | 389 | """) |
| 390 | |
| 391 | # Only install the man page if it exists. |
| 392 | # Do 'make doc install' to build and install it. |
| 393 | if os.path.exists('doc/node.1'): |
| 394 | bld.install_files('${PREFIX}/share/man/man1/', 'doc/node.1') |
| 395 | |
| 396 | bld.install_files('${PREFIX}/bin/', 'bin/*', chmod=0755) |
Ryan Dahl | 6f17ca5 | 2009-10-03 17:08:05 | [diff] [blame] | 397 | |
| 398 | # Why am I using two lines? Because WAF SUCKS. |
Ryan Dahl | bf0d278 | 2009-10-03 20:42:03 | [diff] [blame] | 399 | bld.install_files('${PREFIX}/lib/node/wafadmin', 'tools/wafadmin/*.py') |
| 400 | bld.install_files('${PREFIX}/lib/node/wafadmin/Tools', 'tools/wafadmin/Tools/*.py') |
Ryan Dahl | 6f17ca5 | 2009-10-03 17:08:05 | [diff] [blame] | 401 | |
Ryan Dahl | bf0d278 | 2009-10-03 20:42:03 | [diff] [blame] | 402 | bld.install_files('${PREFIX}/lib/node/libraries/', 'lib/*.js') |
Ryan Dahl | 132d685 | 2009-10-27 17:11:07 | [diff] [blame] | 403 | |
| 404 | def shutdown(): |
| 405 | Options.options.debug |
| 406 | # HACK to get binding.node out of build directory. |
| 407 | # better way to do this? |
| 408 | if not Options.commands['clean']: |
| 409 | if os.path.exists('build/default/node') and not os.path.exists('node'): |
| 410 | os.symlink('build/default/node', 'node') |
| 411 | if os.path.exists('build/debug/node_g') and not os.path.exists('node_g'): |
| 412 | os.symlink('build/debug/node_g', 'node_g') |
| 413 | else: |
| 414 | if os.path.exists('node'): os.unlink('node') |
| 415 | if os.path.exists('node_g'): os.unlink('node_g') |