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 | 618296e | 2010-03-20 04:07:03 | [diff] [blame] | 10 | VERSION="0.1.33" |
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 Dahl | b8c3d71 | 2010-01-27 02:34:42 | [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 Dahl | 4279725 | 2010-03-31 20:36:20 | [diff] [blame^] | 171 | if sys.platform.startswith("sunos"): |
| 172 | conf.env.append_value ('CCFLAGS', '-threads') |
| 173 | conf.env.append_value ('CXXFLAGS', '-threads') |
| 174 | #conf.env.append_value ('LINKFLAGS', ' -threads') |
| 175 | else: |
| 176 | threadflags='-pthread' |
| 177 | conf.env.append_value ('CCFLAGS', threadflags) |
| 178 | conf.env.append_value ('CXXFLAGS', threadflags) |
| 179 | conf.env.append_value ('LINKFLAGS', threadflags) |
| 180 | |
Ryan Dahl | 1beb840 | 2009-12-30 08:01:28 | [diff] [blame] | 181 | conf.env.append_value("CCFLAGS", "-DX_STACKSIZE=%d" % (1024*64)) |
Ryan | 427e3f5 | 2009-05-14 11:16:45 | [diff] [blame] | 182 | |
Ryan Dahl | 2b743aa | 2009-10-27 11:05:38 | [diff] [blame] | 183 | # LFS |
| 184 | conf.env.append_value('CCFLAGS', '-D_LARGEFILE_SOURCE') |
| 185 | conf.env.append_value('CXXFLAGS', '-D_LARGEFILE_SOURCE') |
| 186 | conf.env.append_value('CCFLAGS', '-D_FILE_OFFSET_BITS=64') |
| 187 | conf.env.append_value('CXXFLAGS', '-D_FILE_OFFSET_BITS=64') |
| 188 | |
Ryan Dahl | f481183 | 2009-11-02 23:21:00 | [diff] [blame] | 189 | # platform |
| 190 | platform_def = '-DPLATFORM=' + sys.platform |
| 191 | conf.env.append_value('CCFLAGS', platform_def) |
| 192 | conf.env.append_value('CXXFLAGS', platform_def) |
| 193 | |
Ryan | 67af958 | 2009-04-18 13:35:42 | [diff] [blame] | 194 | # Split off debug variant before adding variant specific defines |
Ryan | 7e1350f | 2009-04-16 09:37:44 | [diff] [blame] | 195 | debug_env = conf.env.copy() |
| 196 | conf.set_env_name('debug', debug_env) |
Ryan | 7e1350f | 2009-04-16 09:37:44 | [diff] [blame] | 197 | |
Ryan | 67af958 | 2009-04-18 13:35:42 | [diff] [blame] | 198 | # Configure debug variant |
| 199 | conf.setenv('debug') |
| 200 | debug_env.set_variant('debug') |
Ryan | 8ddf930 | 2009-09-02 18:19:52 | [diff] [blame] | 201 | debug_env.append_value('CCFLAGS', ['-DDEBUG', '-g', '-O0', '-Wall', '-Wextra']) |
| 202 | debug_env.append_value('CXXFLAGS', ['-DDEBUG', '-g', '-O0', '-Wall', '-Wextra']) |
Ryan | 67af958 | 2009-04-18 13:35:42 | [diff] [blame] | 203 | conf.write_config_header("config.h") |
| 204 | |
| 205 | # Configure default variant |
| 206 | conf.setenv('default') |
Ryan | 8ddf930 | 2009-09-02 18:19:52 | [diff] [blame] | 207 | conf.env.append_value('CCFLAGS', ['-DNDEBUG', '-O3']) |
| 208 | conf.env.append_value('CXXFLAGS', ['-DNDEBUG', '-O3']) |
Ryan | 67af958 | 2009-04-18 13:35:42 | [diff] [blame] | 209 | conf.write_config_header("config.h") |
Ryan | 63a9cd3 | 2009-04-15 08:08:28 | [diff] [blame] | 210 | |
Ryan | 41d89f6 | 2009-07-28 10:29:18 | [diff] [blame] | 211 | def build_udns(bld): |
| 212 | default_build_dir = bld.srcnode.abspath(bld.env_of_name("default")) |
Ryan | 1a126ed | 2009-04-04 12:50:15 | [diff] [blame] | 213 | |
Ryan | 41d89f6 | 2009-07-28 10:29:18 | [diff] [blame] | 214 | default_dir = join(default_build_dir, "deps/udns") |
| 215 | |
| 216 | static_lib = bld.env["staticlib_PATTERN"] % "udns" |
| 217 | |
masuidrive | 3337e9d | 2010-02-10 10:21:54 | [diff] [blame] | 218 | rule = 'cd "%s" && make' |
Ryan | 41d89f6 | 2009-07-28 10:29:18 | [diff] [blame] | 219 | |
| 220 | default = bld.new_task_gen( |
| 221 | target= join("deps/udns", static_lib), |
| 222 | rule= rule % default_dir, |
| 223 | before= "cxx", |
| 224 | install_path= None |
| 225 | ) |
| 226 | |
| 227 | bld.env["CPPPATH_UDNS"] = "deps/udns" |
Ryan Dahl | fc937aa | 2009-10-27 21:50:46 | [diff] [blame] | 228 | t = join(bld.srcnode.abspath(bld.env_of_name("default")), default.target) |
| 229 | bld.env_of_name('default')["LINKFLAGS_UDNS"] = [t] |
Ryan | 41d89f6 | 2009-07-28 10:29:18 | [diff] [blame] | 230 | |
| 231 | if bld.env["USE_DEBUG"]: |
| 232 | debug_build_dir = bld.srcnode.abspath(bld.env_of_name("debug")) |
| 233 | debug_dir = join(debug_build_dir, "deps/udns") |
| 234 | debug = default.clone("debug") |
| 235 | debug.rule = rule % debug_dir |
Ryan Dahl | fc937aa | 2009-10-27 21:50:46 | [diff] [blame] | 236 | t = join(bld.srcnode.abspath(bld.env_of_name("debug")), debug.target) |
| 237 | bld.env_of_name('debug')["LINKFLAGS_UDNS"] = [t] |
Ryan Dahl | 0c12554 | 2010-01-19 23:38:20 | [diff] [blame] | 238 | |
Ryan Dahl | bf0d278 | 2009-10-03 20:42:03 | [diff] [blame] | 239 | bld.install_files('${PREFIX}/include/node/', 'deps/udns/udns.h') |
Ryan | 41d89f6 | 2009-07-28 10:29:18 | [diff] [blame] | 240 | |
Ryan Dahl | 53ebe75 | 2009-10-08 21:20:14 | [diff] [blame] | 241 | def v8_cmd(bld, variant): |
| 242 | scons = join(cwd, 'tools/scons/scons.py') |
Ryan | 1a126ed | 2009-04-04 12:50:15 | [diff] [blame] | 243 | deps_src = join(bld.path.abspath(),"deps") |
Ryan | 1a126ed | 2009-04-04 12:50:15 | [diff] [blame] | 244 | v8dir_src = join(deps_src,"v8") |
Ryan Dahl | 53ebe75 | 2009-10-08 21:20:14 | [diff] [blame] | 245 | |
Ryan Dahl | bc9b343 | 2009-10-02 12:10:40 | [diff] [blame] | 246 | # NOTE: We want to compile V8 to export its symbols. I.E. Do not want |
| 247 | # -fvisibility=hidden. When using dlopen() it seems that the loaded DSO |
| 248 | # cannot see symbols in the executable which are hidden, even if the |
| 249 | # executable is statically linked together... |
Ryan | 8ddf930 | 2009-09-02 18:19:52 | [diff] [blame] | 250 | |
Ryan Dahl | 7d9d881 | 2009-10-26 21:27:52 | [diff] [blame] | 251 | # XXX Remove this when v8 defaults x86_64 to native builds |
Ryan Dahl | d85724d | 2009-10-08 22:34:39 | [diff] [blame] | 252 | arch = "" |
Ryan Dahl | 7d9d881 | 2009-10-26 21:27:52 | [diff] [blame] | 253 | if bld.env['DEST_CPU'] == 'x86_64': |
Ryan Dahl | d85724d | 2009-10-08 22:34:39 | [diff] [blame] | 254 | arch = "arch=x64" |
| 255 | |
| 256 | if variant == "default": |
| 257 | mode = "release" |
| 258 | else: |
| 259 | mode = "debug" |
Ryan | a4593e3 | 2009-04-23 11:18:38 | [diff] [blame] | 260 | |
masuidrive | 3337e9d | 2010-02-10 10:21:54 | [diff] [blame] | 261 | 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] | 262 | |
| 263 | cmd = cmd_R % ( scons |
| 264 | , bld.srcnode.abspath(bld.env_of_name(variant)) |
| 265 | , v8dir_src |
| 266 | , mode |
| 267 | , arch |
| 268 | ) |
| 269 | return cmd |
| 270 | |
| 271 | |
| 272 | def build_v8(bld): |
Ryan | 1a126ed | 2009-04-04 12:50:15 | [diff] [blame] | 273 | v8 = bld.new_task_gen( |
Ryan Dahl | 59b7a1b | 2009-10-09 10:49:48 | [diff] [blame] | 274 | source = 'deps/v8/SConstruct ' |
| 275 | + bld.path.ant_glob('v8/include/*') |
| 276 | + bld.path.ant_glob('v8/src/*'), |
Ryan Dahl | 53ebe75 | 2009-10-08 21:20:14 | [diff] [blame] | 277 | target = bld.env["staticlib_PATTERN"] % "v8", |
| 278 | rule = v8_cmd(bld, "default"), |
| 279 | before = "cxx", |
| 280 | install_path = None |
Ryan | 1a126ed | 2009-04-04 12:50:15 | [diff] [blame] | 281 | ) |
Ryan Dahl | 8b62e86 | 2009-10-10 09:58:36 | [diff] [blame] | 282 | v8.uselib = "EXECINFO" |
Ryan | 1a126ed | 2009-04-04 12:50:15 | [diff] [blame] | 283 | bld.env["CPPPATH_V8"] = "deps/v8/include" |
Ryan Dahl | fc937aa | 2009-10-27 21:50:46 | [diff] [blame] | 284 | t = join(bld.srcnode.abspath(bld.env_of_name("default")), v8.target) |
Ryan Dahl | 4279725 | 2010-03-31 20:36:20 | [diff] [blame^] | 285 | bld.env_of_name('default').append_value("LINKFLAGS_V8", t) |
| 286 | |
Ryan | a4593e3 | 2009-04-23 11:18:38 | [diff] [blame] | 287 | |
| 288 | ### v8 debug |
Ryan | 29b528c | 2009-04-23 15:29:31 | [diff] [blame] | 289 | if bld.env["USE_DEBUG"]: |
Ryan | 29b528c | 2009-04-23 15:29:31 | [diff] [blame] | 290 | v8_debug = v8.clone("debug") |
Ryan Dahl | 53ebe75 | 2009-10-08 21:20:14 | [diff] [blame] | 291 | v8_debug.rule = v8_cmd(bld, "debug") |
| 292 | v8_debug.target = bld.env["staticlib_PATTERN"] % "v8_g" |
Ryan Dahl | 8b62e86 | 2009-10-10 09:58:36 | [diff] [blame] | 293 | v8_debug.uselib = "EXECINFO" |
Ryan Dahl | fc937aa | 2009-10-27 21:50:46 | [diff] [blame] | 294 | t = join(bld.srcnode.abspath(bld.env_of_name("debug")), v8_debug.target) |
Ryan Dahl | 4279725 | 2010-03-31 20:36:20 | [diff] [blame^] | 295 | bld.env_of_name('debug').append_value("LINKFLAGS_V8", t) |
Ryan | 1a126ed | 2009-04-04 12:50:15 | [diff] [blame] | 296 | |
Ryan Dahl | 53ebe75 | 2009-10-08 21:20:14 | [diff] [blame] | 297 | bld.install_files('${PREFIX}/include/node/', 'deps/v8/include/*.h') |
Ryan | 2b6d724 | 2009-06-20 13:07:10 | [diff] [blame] | 298 | |
Ryan | 41d89f6 | 2009-07-28 10:29:18 | [diff] [blame] | 299 | def build(bld): |
Jérémy Lal | c93bab1 | 2010-03-11 21:15:32 | [diff] [blame] | 300 | if not bld.env["USE_SYSTEM"]: |
| 301 | bld.add_subdirs('deps/libeio deps/libev') |
| 302 | build_udns(bld) |
| 303 | build_v8(bld) |
| 304 | else: |
| 305 | bld.add_subdirs('deps/libeio') |
Ryan | 41d89f6 | 2009-07-28 10:29:18 | [diff] [blame] | 306 | |
Jérémy Lal | c93bab1 | 2010-03-11 21:15:32 | [diff] [blame] | 307 | |
Ryan | 41d89f6 | 2009-07-28 10:29:18 | [diff] [blame] | 308 | |
Ryan | 0fb0af3 | 2009-07-25 15:52:21 | [diff] [blame] | 309 | ### evcom |
Ryan Dahl | 122e74b | 2009-10-27 21:26:53 | [diff] [blame] | 310 | evcom = bld.new_task_gen("cc") |
Ryan | 0fb0af3 | 2009-07-25 15:52:21 | [diff] [blame] | 311 | evcom.source = "deps/evcom/evcom.c" |
Jérémy Lal | c93bab1 | 2010-03-11 21:15:32 | [diff] [blame] | 312 | if not bld.env["USE_SYSTEM"]: |
| 313 | evcom.includes = "deps/evcom/ deps/libev/" |
| 314 | else: |
| 315 | evcom.includes = "deps/evcom/" |
Ryan | 0fb0af3 | 2009-07-25 15:52:21 | [diff] [blame] | 316 | evcom.name = "evcom" |
| 317 | evcom.target = "evcom" |
Rhys Jones | b6dda61 | 2009-11-22 02:58:08 | [diff] [blame] | 318 | evcom.uselib = "GPGERROR GNUTLS" |
Ryan | 0fb0af3 | 2009-07-25 15:52:21 | [diff] [blame] | 319 | evcom.install_path = None |
Ryan | 29b528c | 2009-04-23 15:29:31 | [diff] [blame] | 320 | if bld.env["USE_DEBUG"]: |
Ryan | 0fb0af3 | 2009-07-25 15:52:21 | [diff] [blame] | 321 | evcom.clone("debug") |
Ryan Dahl | bf0d278 | 2009-10-03 20:42:03 | [diff] [blame] | 322 | bld.install_files('${PREFIX}/include/node/', 'deps/evcom/evcom.h') |
Ryan | 1a126ed | 2009-04-04 12:50:15 | [diff] [blame] | 323 | |
Ryan | 5a071ad | 2009-05-03 12:09:16 | [diff] [blame] | 324 | ### http_parser |
Ryan Dahl | 122e74b | 2009-10-27 21:26:53 | [diff] [blame] | 325 | http_parser = bld.new_task_gen("cc") |
Ryan | 5a071ad | 2009-05-03 12:09:16 | [diff] [blame] | 326 | http_parser.source = "deps/http_parser/http_parser.c" |
| 327 | http_parser.includes = "deps/http_parser/" |
| 328 | http_parser.name = "http_parser" |
| 329 | http_parser.target = "http_parser" |
| 330 | http_parser.install_path = None |
Ryan | 29b528c | 2009-04-23 15:29:31 | [diff] [blame] | 331 | if bld.env["USE_DEBUG"]: |
Ryan | 5a071ad | 2009-05-03 12:09:16 | [diff] [blame] | 332 | http_parser.clone("debug") |
Ryan | 1a126ed | 2009-04-04 12:50:15 | [diff] [blame] | 333 | |
Ryan | 17c6a67 | 2009-08-24 18:25:24 | [diff] [blame] | 334 | ### coupling |
Ryan Dahl | 122e74b | 2009-10-27 21:26:53 | [diff] [blame] | 335 | coupling = bld.new_task_gen("cc") |
Ryan | 17c6a67 | 2009-08-24 18:25:24 | [diff] [blame] | 336 | coupling.source = "deps/coupling/coupling.c" |
| 337 | coupling.includes = "deps/coupling/" |
| 338 | coupling.name = "coupling" |
| 339 | coupling.target = "coupling" |
| 340 | coupling.install_path = None |
| 341 | if bld.env["USE_DEBUG"]: |
| 342 | coupling.clone("debug") |
| 343 | |
Ryan | 63a9cd3 | 2009-04-15 08:08:28 | [diff] [blame] | 344 | ### src/native.cc |
Zoka | b29f787 | 2010-03-20 03:56:03 | [diff] [blame] | 345 | def make_macros(loc, content): |
| 346 | f = open(loc, 'w') |
| 347 | f.write(content) |
| 348 | f.close |
| 349 | |
| 350 | macros_loc_debug = join( |
| 351 | bld.srcnode.abspath(bld.env_of_name("debug")), |
| 352 | "macros.py" |
| 353 | ) |
| 354 | |
| 355 | macros_loc_default = join( |
| 356 | bld.srcnode.abspath(bld.env_of_name("default")), |
| 357 | "macros.py" |
| 358 | ) |
| 359 | |
| 360 | make_macros(macros_loc_debug, "") # leave debug(x) as is in debug build |
| 361 | # replace debug(x) with nothing in release build |
| 362 | make_macros(macros_loc_default, "macro debug(x) = ;\n") |
| 363 | |
Ryan | 63a9cd3 | 2009-04-15 08:08:28 | [diff] [blame] | 364 | def javascript_in_c(task): |
| 365 | env = task.env |
| 366 | source = map(lambda x: x.srcpath(env), task.inputs) |
| 367 | targets = map(lambda x: x.srcpath(env), task.outputs) |
Zoka | b29f787 | 2010-03-20 03:56:03 | [diff] [blame] | 368 | source.append(macros_loc_default) |
| 369 | js2c.JS2C(source, targets) |
| 370 | |
| 371 | def javascript_in_c_debug(task): |
| 372 | env = task.env |
| 373 | source = map(lambda x: x.srcpath(env), task.inputs) |
| 374 | targets = map(lambda x: x.srcpath(env), task.outputs) |
| 375 | source.append(macros_loc_debug) |
Ryan | 63a9cd3 | 2009-04-15 08:08:28 | [diff] [blame] | 376 | js2c.JS2C(source, targets) |
| 377 | |
| 378 | native_cc = bld.new_task_gen( |
Ryan Dahl | 4ccdc50 | 2010-03-15 15:00:19 | [diff] [blame] | 379 | source='src/node.js ' + bld.path.ant_glob('lib/*.js'), |
Ryan Dahl | 53ebe75 | 2009-10-08 21:20:14 | [diff] [blame] | 380 | target="src/node_natives.h", |
Ryan Dahl | 4ccdc50 | 2010-03-15 15:00:19 | [diff] [blame] | 381 | before="cxx", |
| 382 | install_path=None |
Ryan | 63a9cd3 | 2009-04-15 08:08:28 | [diff] [blame] | 383 | ) |
Ryan Dahl | 4bcb01c | 2009-10-16 20:53:44 | [diff] [blame] | 384 | |
| 385 | # Add the rule /after/ cloning the debug |
| 386 | # This is a work around for an error had in python 2.4.3 (I'll paste the |
| 387 | # error that was had into the git commit meessage. git-blame to find out |
| 388 | # where.) |
Ryan | 29b528c | 2009-04-23 15:29:31 | [diff] [blame] | 389 | if bld.env["USE_DEBUG"]: |
Ryan Dahl | 4bcb01c | 2009-10-16 20:53:44 | [diff] [blame] | 390 | native_cc_debug = native_cc.clone("debug") |
Zoka | b29f787 | 2010-03-20 03:56:03 | [diff] [blame] | 391 | native_cc_debug.rule = javascript_in_c_debug |
| 392 | |
Ryan Dahl | 4bcb01c | 2009-10-16 20:53:44 | [diff] [blame] | 393 | native_cc.rule = javascript_in_c |
Ryan | 63a9cd3 | 2009-04-15 08:08:28 | [diff] [blame] | 394 | |
Ryan | 2b6d724 | 2009-06-20 13:07:10 | [diff] [blame] | 395 | ### node lib |
Ryan | 8152f9c | 2009-09-01 12:15:29 | [diff] [blame] | 396 | node = bld.new_task_gen("cxx", "program") |
| 397 | node.name = "node" |
| 398 | node.target = "node" |
| 399 | node.source = """ |
Ryan | 1a126ed | 2009-04-04 12:50:15 | [diff] [blame] | 400 | src/node.cc |
Ryan Dahl | 630bb7a | 2009-12-13 07:42:45 | [diff] [blame] | 401 | src/node_buffer.cc |
Ryan Dahl | 42ee169 | 2010-01-24 19:21:45 | [diff] [blame] | 402 | src/node_http_parser.cc |
Ryan Dahl | bf803f4 | 2010-01-27 23:40:09 | [diff] [blame] | 403 | src/node_net2.cc |
Ryan Dahl | f219938 | 2009-12-13 14:43:58 | [diff] [blame] | 404 | src/node_io_watcher.cc |
Ryan Dahl | a5df0f6 | 2009-10-27 10:46:58 | [diff] [blame] | 405 | src/node_child_process.cc |
| 406 | src/node_constants.cc |
| 407 | src/node_dns.cc |
| 408 | src/node_events.cc |
| 409 | src/node_file.cc |
| 410 | src/node_http.cc |
| 411 | src/node_net.cc |
Ryan Dahl | 8492c52 | 2010-03-15 21:05:18 | [diff] [blame] | 412 | src/node_signal_watcher.cc |
| 413 | src/node_stat_watcher.cc |
Ryan | 17c6a67 | 2009-08-24 18:25:24 | [diff] [blame] | 414 | src/node_stdio.cc |
Ryan Dahl | a5df0f6 | 2009-10-27 10:46:58 | [diff] [blame] | 415 | src/node_timer.cc |
Ryan Dahl | aeb7d6d | 2010-01-18 18:12:04 | [diff] [blame] | 416 | src/node_idle_watcher.cc |
Ryan | 1a126ed | 2009-04-04 12:50:15 | [diff] [blame] | 417 | """ |
Jérémy Lal | c93bab1 | 2010-03-11 21:15:32 | [diff] [blame] | 418 | if not bld.env["USE_SYSTEM"]: |
| 419 | node.includes = """ |
| 420 | src/ |
| 421 | deps/v8/include |
| 422 | deps/libev |
| 423 | deps/udns |
| 424 | deps/libeio |
| 425 | deps/evcom |
| 426 | deps/http_parser |
| 427 | deps/coupling |
| 428 | """ |
| 429 | node.add_objects = 'ev eio evcom http_parser coupling' |
| 430 | node.uselib_local = '' |
| 431 | node.uselib = 'GNUTLS GPGERROR UDNS V8 EXECINFO DL KVM SOCKET NSL' |
| 432 | else: |
| 433 | node.includes = """ |
| 434 | src/ |
| 435 | deps/libeio |
| 436 | deps/evcom |
| 437 | deps/http_parser |
| 438 | deps/coupling |
| 439 | """ |
| 440 | node.add_objects = 'eio evcom http_parser coupling' |
| 441 | node.uselib_local = 'eio' |
| 442 | node.uselib = 'EV GNUTLS GPGERROR UDNS V8 EXECINFO DL KVM SOCKET NSL' |
Rhys Jones | b6dda61 | 2009-11-22 02:58:08 | [diff] [blame] | 443 | |
Ryan | 8152f9c | 2009-09-01 12:15:29 | [diff] [blame] | 444 | node.install_path = '${PREFIX}/lib' |
Ryan | 8e7bbf2 | 2009-04-23 17:26:56 | [diff] [blame] | 445 | node.install_path = '${PREFIX}/bin' |
| 446 | node.chmod = 0755 |
| 447 | |
Ryan | 4d92199 | 2009-08-26 23:11:16 | [diff] [blame] | 448 | def subflags(program): |
Ryan Dahl | d979ac9 | 2009-10-09 13:00:12 | [diff] [blame] | 449 | if os.path.exists(join(cwd, ".git")): |
Ryan Dahl | 962e929 | 2009-10-09 14:16:27 | [diff] [blame] | 450 | actual_version=cmd_output("git describe").strip() |
Ryan Dahl | d979ac9 | 2009-10-09 13:00:12 | [diff] [blame] | 451 | else: |
| 452 | actual_version=VERSION |
| 453 | |
Ryan | b73264d | 2009-08-27 00:15:11 | [diff] [blame] | 454 | x = { 'CCFLAGS' : " ".join(program.env["CCFLAGS"]) |
| 455 | , 'CPPFLAGS' : " ".join(program.env["CPPFLAGS"]) |
| 456 | , 'LIBFLAGS' : " ".join(program.env["LIBFLAGS"]) |
Ryan Dahl | d979ac9 | 2009-10-09 13:00:12 | [diff] [blame] | 457 | , 'VERSION' : actual_version |
Ryan | b73264d | 2009-08-27 00:15:11 | [diff] [blame] | 458 | , 'PREFIX' : program.env["PREFIX"] |
Ryan | 4d92199 | 2009-08-26 23:11:16 | [diff] [blame] | 459 | } |
Ryan Dahl | bf0d278 | 2009-10-03 20:42:03 | [diff] [blame] | 460 | return x |
Ryan | 4d92199 | 2009-08-26 23:11:16 | [diff] [blame] | 461 | |
Ryan | 4d92199 | 2009-08-26 23:11:16 | [diff] [blame] | 462 | # process file.pc.in -> file.pc |
Ryan Dahl | d979ac9 | 2009-10-09 13:00:12 | [diff] [blame] | 463 | |
Ryan | b73264d | 2009-08-27 00:15:11 | [diff] [blame] | 464 | node_version = bld.new_task_gen('subst', before="cxx") |
| 465 | node_version.source = 'src/node_version.h.in' |
| 466 | node_version.target = 'src/node_version.h' |
| 467 | node_version.dict = subflags(node) |
Ryan | a97dce7 | 2009-08-31 09:14:34 | [diff] [blame] | 468 | node_version.install_path = '${PREFIX}/include/node' |
Ryan | 4d92199 | 2009-08-26 23:11:16 | [diff] [blame] | 469 | |
Ryan | 29b528c | 2009-04-23 15:29:31 | [diff] [blame] | 470 | if bld.env["USE_DEBUG"]: |
Ryan | 2b6d724 | 2009-06-20 13:07:10 | [diff] [blame] | 471 | node_g = node.clone("debug") |
| 472 | node_g.target = "node_g" |
Ryan | 4d92199 | 2009-08-26 23:11:16 | [diff] [blame] | 473 | |
Ryan | b73264d | 2009-08-27 00:15:11 | [diff] [blame] | 474 | node_version_g = node_version.clone("debug") |
| 475 | node_version_g.dict = subflags(node_g) |
Ryan | a97dce7 | 2009-08-31 09:14:34 | [diff] [blame] | 476 | node_version_g.install_path = None |
Ryan | 4d92199 | 2009-08-26 23:11:16 | [diff] [blame] | 477 | |
Ryan | a97dce7 | 2009-08-31 09:14:34 | [diff] [blame] | 478 | |
| 479 | bld.install_files('${PREFIX}/include/node/', """ |
| 480 | config.h |
| 481 | src/node.h |
Ryan Dahl | 5f466c8 | 2009-10-27 19:17:03 | [diff] [blame] | 482 | src/node_object_wrap.h |
| 483 | src/node_events.h |
| 484 | src/node_net.h |
Ryan Dahl | bf0d278 | 2009-10-03 20:42:03 | [diff] [blame] | 485 | """) |
| 486 | |
| 487 | # Only install the man page if it exists. |
| 488 | # Do 'make doc install' to build and install it. |
| 489 | if os.path.exists('doc/node.1'): |
| 490 | bld.install_files('${PREFIX}/share/man/man1/', 'doc/node.1') |
| 491 | |
| 492 | bld.install_files('${PREFIX}/bin/', 'bin/*', chmod=0755) |
Ryan Dahl | 6f17ca5 | 2009-10-03 17:08:05 | [diff] [blame] | 493 | |
| 494 | # Why am I using two lines? Because WAF SUCKS. |
Ryan Dahl | bf0d278 | 2009-10-03 20:42:03 | [diff] [blame] | 495 | bld.install_files('${PREFIX}/lib/node/wafadmin', 'tools/wafadmin/*.py') |
| 496 | bld.install_files('${PREFIX}/lib/node/wafadmin/Tools', 'tools/wafadmin/Tools/*.py') |
Ryan Dahl | 6f17ca5 | 2009-10-03 17:08:05 | [diff] [blame] | 497 | |
Ryan Dahl | 132d685 | 2009-10-27 17:11:07 | [diff] [blame] | 498 | def shutdown(): |
| 499 | Options.options.debug |
| 500 | # HACK to get binding.node out of build directory. |
| 501 | # better way to do this? |
| 502 | if not Options.commands['clean']: |
| 503 | if os.path.exists('build/default/node') and not os.path.exists('node'): |
| 504 | os.symlink('build/default/node', 'node') |
| 505 | if os.path.exists('build/debug/node_g') and not os.path.exists('node_g'): |
| 506 | os.symlink('build/debug/node_g', 'node_g') |
| 507 | else: |
| 508 | if os.path.exists('node'): os.unlink('node') |
| 509 | if os.path.exists('node_g'): os.unlink('node_g') |