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 | 0c1aa36 | 2010-05-30 02:32:33 | [diff] [blame] | 10 | VERSION="0.1.97" |
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 | |
Ryan Dahl | 311a62d | 2010-05-26 20:05:31 | [diff] [blame] | 18 | |
Ryan Dahl | ef9f404 | 2010-06-02 19:27:53 | [diff] [blame] | 19 | |
Ryan Dahl | 311a62d | 2010-05-26 20:05:31 | [diff] [blame] | 20 | jobs=1 |
| 21 | if os.environ.has_key('JOBS'): |
| 22 | jobs = int(os.environ['JOBS']) |
| 23 | |
Ryan | 1a126ed | 2009-04-04 12:50:15 | [diff] [blame] | 24 | def set_options(opt): |
| 25 | # the gcc module provides a --debug-level option |
| 26 | opt.tool_options('compiler_cxx') |
| 27 | opt.tool_options('compiler_cc') |
Ryan | 4d92199 | 2009-08-26 23:11:16 | [diff] [blame] | 28 | opt.tool_options('misc') |
Ryan | 29b528c | 2009-04-23 15:29:31 | [diff] [blame] | 29 | opt.add_option( '--debug' |
| 30 | , action='store_true' |
| 31 | , default=False |
| 32 | , help='Build debug variant [Default: False]' |
| 33 | , dest='debug' |
| 34 | ) |
Ryan | 7bad9de | 2009-06-16 13:47:57 | [diff] [blame] | 35 | opt.add_option( '--efence' |
| 36 | , action='store_true' |
| 37 | , default=False |
| 38 | , help='Build with -lefence for debugging [Default: False]' |
| 39 | , dest='efence' |
| 40 | ) |
Ryan Dahl | 9e8df0e | 2010-06-02 21:05:37 | [diff] [blame] | 41 | |
Ryan Dahl | a9b962a | 2010-05-14 23:34:47 | [diff] [blame] | 42 | opt.add_option( '--without-ssl' |
| 43 | , action='store_true' |
| 44 | , default=False |
| 45 | , help='Build without SSL' |
| 46 | , dest='without_ssl' |
| 47 | ) |
Ryan | 1a126ed | 2009-04-04 12:50:15 | [diff] [blame] | 48 | |
Ryan Dahl | 9e8df0e | 2010-06-02 21:05:37 | [diff] [blame] | 49 | |
| 50 | opt.add_option('--shared-v8' |
| 51 | , action='store_true' |
| 52 | , default=False |
| 53 | , help='Link to a shared V8 DLL instead of static linking' |
| 54 | , dest='shared_v8' |
| 55 | ) |
| 56 | |
| 57 | opt.add_option( '--shared-v8-includes' |
| 58 | , action='store' |
| 59 | , default=False |
| 60 | , help='Directory containing V8 header files' |
| 61 | , dest='shared_v8_includes' |
| 62 | ) |
| 63 | |
| 64 | opt.add_option( '--shared-v8-libpath' |
| 65 | , action='store' |
| 66 | , default=False |
| 67 | , help='A directory to search for the shared V8 DLL' |
| 68 | , dest='shared_v8_libpath' |
| 69 | ) |
| 70 | |
| 71 | opt.add_option( '--shared-v8-libname' |
| 72 | , action='store' |
| 73 | , default=False |
| 74 | , help="Alternative lib name to link to (default: 'v8')" |
| 75 | , dest='shared_v8_libname' |
| 76 | ) |
| 77 | |
| 78 | |
| 79 | opt.add_option('--shared-cares' |
| 80 | , action='store_true' |
| 81 | , default=False |
| 82 | , help='Link to a shared C-Ares DLL instead of static linking' |
| 83 | , dest='shared_cares' |
| 84 | ) |
| 85 | |
| 86 | opt.add_option( '--shared-cares-includes' |
| 87 | , action='store' |
| 88 | , default=False |
| 89 | , help='Directory containing C-Ares header files' |
| 90 | , dest='shared_cares_includes' |
| 91 | ) |
| 92 | |
| 93 | opt.add_option( '--shared-cares-libpath' |
| 94 | , action='store' |
| 95 | , default=False |
| 96 | , help='A directory to search for the shared C-Ares DLL' |
| 97 | , dest='shared_cares_libpath' |
| 98 | ) |
| 99 | |
| 100 | |
| 101 | opt.add_option('--shared-libev' |
| 102 | , action='store_true' |
| 103 | , default=False |
| 104 | , help='Link to a shared libev DLL instead of static linking' |
| 105 | , dest='shared_libev' |
| 106 | ) |
| 107 | |
| 108 | opt.add_option( '--shared-libev-includes' |
| 109 | , action='store' |
| 110 | , default=False |
| 111 | , help='Directory containing libev header files' |
| 112 | , dest='shared_libev_includes' |
| 113 | ) |
| 114 | |
| 115 | opt.add_option( '--shared-libev-libpath' |
| 116 | , action='store' |
| 117 | , default=False |
| 118 | , help='A directory to search for the shared libev DLL' |
| 119 | , dest='shared_libev_libpath' |
| 120 | ) |
| 121 | |
| 122 | |
| 123 | |
| 124 | |
Ryan | 1a126ed | 2009-04-04 12:50:15 | [diff] [blame] | 125 | def configure(conf): |
| 126 | conf.check_tool('compiler_cxx') |
Ryan Dahl | f379b77 | 2010-01-12 00:43:10 | [diff] [blame] | 127 | if not conf.env.CXX: conf.fatal('c++ compiler not found') |
Ryan | 1a126ed | 2009-04-04 12:50:15 | [diff] [blame] | 128 | conf.check_tool('compiler_cc') |
Ryan Dahl | f379b77 | 2010-01-12 00:43:10 | [diff] [blame] | 129 | if not conf.env.CC: conf.fatal('c compiler not found') |
Ryan | a4593e3 | 2009-04-23 11:18:38 | [diff] [blame] | 130 | |
Ryan Dahl | 9e8df0e | 2010-06-02 21:05:37 | [diff] [blame] | 131 | o = Options.options |
| 132 | |
| 133 | conf.env["USE_DEBUG"] = o.debug |
| 134 | |
| 135 | conf.env["USE_SHARED_V8"] = o.shared_v8 or o.shared_v8_includes or o.shared_v8_libpath or o.shared_v8_libname |
| 136 | conf.env["USE_SHARED_CARES"] = o.shared_cares or o.shared_cares_includes or o.shared_cares_libpath |
| 137 | conf.env["USE_SHARED_LIBEV"] = o.shared_libev or o.shared_libev_includes or o.shared_libev_libpath |
Ryan | 1a126ed | 2009-04-04 12:50:15 | [diff] [blame] | 138 | |
Ryan | 2b6d724 | 2009-06-20 13:07:10 | [diff] [blame] | 139 | conf.check(lib='dl', uselib_store='DL') |
Raffaele Sena | b3b81d6 | 2010-06-09 04:08:05 | [diff] [blame^] | 140 | if not sys.platform.startswith("sunos") and not sys.platform.startswith("cygwin"): |
Ryan Dahl | 0c12554 | 2010-01-19 23:38:20 | [diff] [blame] | 141 | conf.env.append_value("CCFLAGS", "-rdynamic") |
| 142 | conf.env.append_value("LINKFLAGS_DL", "-rdynamic") |
Ryan | a97dce7 | 2009-08-31 09:14:34 | [diff] [blame] | 143 | |
Vanilla Hsu | d22952b | 2010-01-07 07:37:27 | [diff] [blame] | 144 | if sys.platform.startswith("freebsd"): |
| 145 | conf.check(lib='kvm', uselib_store='KVM') |
| 146 | |
Ryan | 8152f9c | 2009-09-01 12:15:29 | [diff] [blame] | 147 | #if Options.options.debug: |
| 148 | # conf.check(lib='profiler', uselib_store='PROFILER') |
Ryan | 7bad9de | 2009-06-16 13:47:57 | [diff] [blame] | 149 | |
Ryan Dahl | b8c3d71 | 2010-01-27 02:34:42 | [diff] [blame] | 150 | if Options.options.efence: |
| 151 | conf.check(lib='efence', libpath=['/usr/lib', '/usr/local/lib'], uselib_store='EFENCE') |
Ryan | a3627c0 | 2009-05-27 14:29:55 | [diff] [blame] | 152 | |
Vanilla Hsu | d7a4501 | 2010-04-06 16:07:10 | [diff] [blame] | 153 | if not conf.check(lib="execinfo", includes=['/usr/include', '/usr/local/include'], libpath=['/usr/lib', '/usr/local/lib'], uselib_store="EXECINFO"): |
Rasmus Andersson | 6eb8bbc | 2009-12-15 22:37:49 | [diff] [blame] | 154 | # Note on Darwin/OS X: This will fail, but will still be used as the |
| 155 | # execinfo stuff are part of the standard library. |
Ryan Dahl | 8b62e86 | 2009-10-10 09:58:36 | [diff] [blame] | 156 | if sys.platform.startswith("freebsd"): |
Simon Cornelius P. Umacob | e801f42 | 2009-12-09 12:36:12 | [diff] [blame] | 157 | conf.fatal("Install the libexecinfo port from /usr/ports/devel/libexecinfo.") |
Ryan | a3627c0 | 2009-05-27 14:29:55 | [diff] [blame] | 158 | |
Ryan Dahl | a9b962a | 2010-05-14 23:34:47 | [diff] [blame] | 159 | if not Options.options.without_ssl: |
| 160 | if conf.check_cfg(package='openssl', |
| 161 | args='--cflags --libs', |
| 162 | uselib_store='OPENSSL'): |
Standa Opichal | fa514a9 | 2010-04-18 16:24:08 | [diff] [blame] | 163 | conf.env["USE_OPENSSL"] = True |
| 164 | conf.env.append_value("CXXFLAGS", "-DHAVE_OPENSSL=1") |
Ryan Dahl | a9b962a | 2010-05-14 23:34:47 | [diff] [blame] | 165 | else: |
| 166 | libssl = conf.check_cc(lib='ssl', |
| 167 | header_name='openssl/ssl.h', |
| 168 | function_name='SSL_library_init', |
| 169 | libpath=['/usr/lib', '/usr/local/lib', '/opt/local/lib', '/usr/sfw/lib'], |
| 170 | uselib_store='OPENSSL') |
| 171 | libcrypto = conf.check_cc(lib='crypto', |
| 172 | header_name='openssl/crypto.h', |
| 173 | uselib_store='OPENSSL') |
| 174 | if libcrypto and libssl: |
| 175 | conf.env["USE_OPENSSL"] = True |
| 176 | conf.env.append_value("CXXFLAGS", "-DHAVE_OPENSSL=1") |
Rhys Jones | fb3a9cd | 2010-04-02 23:11:53 | [diff] [blame] | 177 | |
Ryan Dahl | e9a116f | 2010-04-06 10:41:32 | [diff] [blame] | 178 | conf.check(lib='rt', uselib_store='RT') |
| 179 | |
Ryan Dahl | 0c12554 | 2010-01-19 23:38:20 | [diff] [blame] | 180 | if sys.platform.startswith("sunos"): |
| 181 | if not conf.check(lib='socket', uselib_store="SOCKET"): |
| 182 | conf.fatal("Cannot find socket library") |
| 183 | if not conf.check(lib='nsl', uselib_store="NSL"): |
| 184 | conf.fatal("Cannot find nsl library") |
| 185 | |
Ryan Dahl | 9e8df0e | 2010-06-02 21:05:37 | [diff] [blame] | 186 | |
| 187 | |
Ryan | 1a126ed | 2009-04-04 12:50:15 | [diff] [blame] | 188 | conf.sub_config('deps/libeio') |
Ryan Dahl | 9e8df0e | 2010-06-02 21:05:37 | [diff] [blame] | 189 | |
| 190 | |
| 191 | |
| 192 | if conf.env['USE_SHARED_V8']: |
| 193 | v8_includes = []; |
| 194 | if o.shared_v8_includes: v8_includes.append(o.shared_v8_includes); |
| 195 | |
| 196 | v8_libpath = []; |
| 197 | if o.shared_v8_libpath: v8_libpath.append(o.shared_v8_libpath); |
| 198 | |
| 199 | if not o.shared_v8_libname: o.shared_v8_libname = 'v8' |
| 200 | |
| 201 | if not conf.check_cxx(lib=o.shared_v8_libname, header_name='v8.h', |
| 202 | uselib_store='V8', |
| 203 | includes=v8_includes, |
| 204 | libpath=v8_libpath): |
| 205 | conf.fatal("Cannot find v8") |
| 206 | |
| 207 | if o.debug: |
| 208 | if not conf.check_cxx(lib=o.shared_v8_libname + '_g', header_name='v8.h', |
| 209 | uselib_store='V8_G', |
| 210 | includes=v8_includes, |
| 211 | libpath=v8_libpath): |
| 212 | conf.fatal("Cannot find v8_g") |
| 213 | |
| 214 | if conf.env['USE_SHARED_CARES']: |
| 215 | cares_includes = []; |
| 216 | if o.shared_cares_includes: cares_includes.append(o.shared_cares_includes); |
| 217 | cares_libpath = []; |
| 218 | if o.shared_cares_libpath: cares_libpath.append(o.shared_cares_libpath); |
| 219 | if not conf.check_cxx(lib='cares', |
| 220 | header_name='ares.h', |
| 221 | uselib_store='CARES', |
| 222 | includes=cares_includes, |
| 223 | libpath=cares_libpath): |
Ryan Dahl | 501136b | 2010-06-02 16:15:54 | [diff] [blame] | 224 | conf.fatal("Cannot find c-ares") |
Ryan Dahl | 9e8df0e | 2010-06-02 21:05:37 | [diff] [blame] | 225 | else: |
| 226 | conf.sub_config('deps/c-ares') |
| 227 | |
| 228 | |
| 229 | if conf.env['USE_SHARED_LIBEV']: |
| 230 | libev_includes = []; |
| 231 | if o.shared_libev_includes: libev_includes.append(o.shared_libev_includes); |
| 232 | libev_libpath = []; |
| 233 | if o.shared_libev_libpath: libev_libpath.append(o.shared_libev_libpath); |
| 234 | if not conf.check_cxx(lib='ev', header_name='ev.h', |
| 235 | uselib_store='EV', |
| 236 | includes=libev_includes, |
| 237 | libpath=libev_libpath): |
| 238 | conf.fatal("Cannot find libev") |
| 239 | else: |
| 240 | conf.sub_config('deps/libev') |
| 241 | |
| 242 | |
Ryan | 41d89f6 | 2009-07-28 10:29:18 | [diff] [blame] | 243 | |
Ryan | 1a126ed | 2009-04-04 12:50:15 | [diff] [blame] | 244 | conf.define("HAVE_CONFIG_H", 1) |
Ryan | c62b124 | 2009-04-22 17:55:08 | [diff] [blame] | 245 | |
Ryan Dahl | 4279725 | 2010-03-31 20:36:20 | [diff] [blame] | 246 | if sys.platform.startswith("sunos"): |
| 247 | conf.env.append_value ('CCFLAGS', '-threads') |
| 248 | conf.env.append_value ('CXXFLAGS', '-threads') |
| 249 | #conf.env.append_value ('LINKFLAGS', ' -threads') |
Raffaele Sena | b3b81d6 | 2010-06-09 04:08:05 | [diff] [blame^] | 250 | elif not sys.platform.startswith("cygwin"): |
Ryan Dahl | 4279725 | 2010-03-31 20:36:20 | [diff] [blame] | 251 | threadflags='-pthread' |
| 252 | conf.env.append_value ('CCFLAGS', threadflags) |
| 253 | conf.env.append_value ('CXXFLAGS', threadflags) |
| 254 | conf.env.append_value ('LINKFLAGS', threadflags) |
| 255 | |
Ryan Dahl | 1beb840 | 2009-12-30 08:01:28 | [diff] [blame] | 256 | conf.env.append_value("CCFLAGS", "-DX_STACKSIZE=%d" % (1024*64)) |
Ryan | 427e3f5 | 2009-05-14 11:16:45 | [diff] [blame] | 257 | |
Ryan Dahl | 2b743aa | 2009-10-27 11:05:38 | [diff] [blame] | 258 | # LFS |
| 259 | conf.env.append_value('CCFLAGS', '-D_LARGEFILE_SOURCE') |
| 260 | conf.env.append_value('CXXFLAGS', '-D_LARGEFILE_SOURCE') |
| 261 | conf.env.append_value('CCFLAGS', '-D_FILE_OFFSET_BITS=64') |
| 262 | conf.env.append_value('CXXFLAGS', '-D_FILE_OFFSET_BITS=64') |
| 263 | |
Andrew Johnston | 9599607 | 2010-03-22 07:25:24 | [diff] [blame] | 264 | ## needed for node_file.cc fdatasync |
| 265 | ## Strangely on OSX 10.6 the g++ doesn't see fdatasync but gcc does? |
| 266 | code = """ |
| 267 | #include <unistd.h> |
| 268 | int main(void) |
| 269 | { |
| 270 | int fd = 0; |
| 271 | fdatasync (fd); |
| 272 | return 0; |
| 273 | } |
| 274 | """ |
| 275 | if conf.check_cxx(msg="Checking for fdatasync(2) with c++", fragment=code): |
| 276 | conf.env.append_value('CXXFLAGS', '-DHAVE_FDATASYNC=1') |
| 277 | else: |
| 278 | conf.env.append_value('CXXFLAGS', '-DHAVE_FDATASYNC=0') |
| 279 | |
Ryan Dahl | f481183 | 2009-11-02 23:21:00 | [diff] [blame] | 280 | # platform |
| 281 | platform_def = '-DPLATFORM=' + sys.platform |
| 282 | conf.env.append_value('CCFLAGS', platform_def) |
| 283 | conf.env.append_value('CXXFLAGS', platform_def) |
| 284 | |
Ryan | 67af958 | 2009-04-18 13:35:42 | [diff] [blame] | 285 | # Split off debug variant before adding variant specific defines |
Ryan | 7e1350f | 2009-04-16 09:37:44 | [diff] [blame] | 286 | debug_env = conf.env.copy() |
| 287 | conf.set_env_name('debug', debug_env) |
Ryan | 7e1350f | 2009-04-16 09:37:44 | [diff] [blame] | 288 | |
Ryan | 67af958 | 2009-04-18 13:35:42 | [diff] [blame] | 289 | # Configure debug variant |
| 290 | conf.setenv('debug') |
| 291 | debug_env.set_variant('debug') |
Ryan | 8ddf930 | 2009-09-02 18:19:52 | [diff] [blame] | 292 | debug_env.append_value('CCFLAGS', ['-DDEBUG', '-g', '-O0', '-Wall', '-Wextra']) |
| 293 | debug_env.append_value('CXXFLAGS', ['-DDEBUG', '-g', '-O0', '-Wall', '-Wextra']) |
Ryan | 67af958 | 2009-04-18 13:35:42 | [diff] [blame] | 294 | conf.write_config_header("config.h") |
| 295 | |
| 296 | # Configure default variant |
| 297 | conf.setenv('default') |
Ryan Dahl | 48d58f9 | 2010-05-03 01:20:02 | [diff] [blame] | 298 | conf.env.append_value('CCFLAGS', ['-DNDEBUG', '-g', '-O3']) |
| 299 | conf.env.append_value('CXXFLAGS', ['-DNDEBUG', '-g', '-O3']) |
Ryan | 67af958 | 2009-04-18 13:35:42 | [diff] [blame] | 300 | conf.write_config_header("config.h") |
Ryan | 63a9cd3 | 2009-04-15 08:08:28 | [diff] [blame] | 301 | |
Ryan | 41d89f6 | 2009-07-28 10:29:18 | [diff] [blame] | 302 | |
Ryan Dahl | 53ebe75 | 2009-10-08 21:20:14 | [diff] [blame] | 303 | def v8_cmd(bld, variant): |
| 304 | scons = join(cwd, 'tools/scons/scons.py') |
Ryan | 1a126ed | 2009-04-04 12:50:15 | [diff] [blame] | 305 | deps_src = join(bld.path.abspath(),"deps") |
Ryan | 1a126ed | 2009-04-04 12:50:15 | [diff] [blame] | 306 | v8dir_src = join(deps_src,"v8") |
Ryan Dahl | 53ebe75 | 2009-10-08 21:20:14 | [diff] [blame] | 307 | |
Ryan Dahl | bc9b343 | 2009-10-02 12:10:40 | [diff] [blame] | 308 | # NOTE: We want to compile V8 to export its symbols. I.E. Do not want |
| 309 | # -fvisibility=hidden. When using dlopen() it seems that the loaded DSO |
| 310 | # cannot see symbols in the executable which are hidden, even if the |
| 311 | # executable is statically linked together... |
Ryan | 8ddf930 | 2009-09-02 18:19:52 | [diff] [blame] | 312 | |
Ryan Dahl | 7d9d881 | 2009-10-26 21:27:52 | [diff] [blame] | 313 | # XXX Remove this when v8 defaults x86_64 to native builds |
Ryan Dahl | d85724d | 2009-10-08 22:34:39 | [diff] [blame] | 314 | arch = "" |
Ryan Dahl | 7d9d881 | 2009-10-26 21:27:52 | [diff] [blame] | 315 | if bld.env['DEST_CPU'] == 'x86_64': |
Ryan Dahl | d85724d | 2009-10-08 22:34:39 | [diff] [blame] | 316 | arch = "arch=x64" |
| 317 | |
| 318 | if variant == "default": |
| 319 | mode = "release" |
| 320 | else: |
| 321 | mode = "debug" |
Ryan | a4593e3 | 2009-04-23 11:18:38 | [diff] [blame] | 322 | |
Ryan Dahl | 23d680b | 2010-05-13 23:24:05 | [diff] [blame] | 323 | cmd_R = 'python "%s" -j %d -C "%s" -Y "%s" visibility=default mode=%s %s library=static snapshot=on' |
Ryan Dahl | 53ebe75 | 2009-10-08 21:20:14 | [diff] [blame] | 324 | |
| 325 | cmd = cmd_R % ( scons |
Ryan Dahl | 23d680b | 2010-05-13 23:24:05 | [diff] [blame] | 326 | , Options.options.jobs |
Ryan Dahl | 53ebe75 | 2009-10-08 21:20:14 | [diff] [blame] | 327 | , bld.srcnode.abspath(bld.env_of_name(variant)) |
| 328 | , v8dir_src |
| 329 | , mode |
| 330 | , arch |
| 331 | ) |
| 332 | return cmd |
| 333 | |
| 334 | |
| 335 | def build_v8(bld): |
Ryan | 1a126ed | 2009-04-04 12:50:15 | [diff] [blame] | 336 | v8 = bld.new_task_gen( |
Ryan Dahl | 9e8df0e | 2010-06-02 21:05:37 | [diff] [blame] | 337 | source = 'deps/v8/SConstruct ' |
| 338 | + bld.path.ant_glob('v8/include/*') |
| 339 | + bld.path.ant_glob('v8/src/*'), |
Ryan Dahl | 53ebe75 | 2009-10-08 21:20:14 | [diff] [blame] | 340 | target = bld.env["staticlib_PATTERN"] % "v8", |
| 341 | rule = v8_cmd(bld, "default"), |
| 342 | before = "cxx", |
Ryan Dahl | 9e8df0e | 2010-06-02 21:05:37 | [diff] [blame] | 343 | install_path = None) |
Ryan Dahl | 8b62e86 | 2009-10-10 09:58:36 | [diff] [blame] | 344 | v8.uselib = "EXECINFO" |
Ryan | 1a126ed | 2009-04-04 12:50:15 | [diff] [blame] | 345 | bld.env["CPPPATH_V8"] = "deps/v8/include" |
Ryan Dahl | fc937aa | 2009-10-27 21:50:46 | [diff] [blame] | 346 | t = join(bld.srcnode.abspath(bld.env_of_name("default")), v8.target) |
Ryan Dahl | 4279725 | 2010-03-31 20:36:20 | [diff] [blame] | 347 | bld.env_of_name('default').append_value("LINKFLAGS_V8", t) |
| 348 | |
Ryan | a4593e3 | 2009-04-23 11:18:38 | [diff] [blame] | 349 | |
| 350 | ### v8 debug |
Ryan | 29b528c | 2009-04-23 15:29:31 | [diff] [blame] | 351 | if bld.env["USE_DEBUG"]: |
Ryan | 29b528c | 2009-04-23 15:29:31 | [diff] [blame] | 352 | v8_debug = v8.clone("debug") |
Ryan Dahl | 53ebe75 | 2009-10-08 21:20:14 | [diff] [blame] | 353 | v8_debug.rule = v8_cmd(bld, "debug") |
| 354 | v8_debug.target = bld.env["staticlib_PATTERN"] % "v8_g" |
Ryan Dahl | 8b62e86 | 2009-10-10 09:58:36 | [diff] [blame] | 355 | v8_debug.uselib = "EXECINFO" |
Ryan Dahl | 9e8df0e | 2010-06-02 21:05:37 | [diff] [blame] | 356 | bld.env["CPPPATH_V8_G"] = "deps/v8/include" |
Ryan Dahl | fc937aa | 2009-10-27 21:50:46 | [diff] [blame] | 357 | t = join(bld.srcnode.abspath(bld.env_of_name("debug")), v8_debug.target) |
Ryan Dahl | 9e8df0e | 2010-06-02 21:05:37 | [diff] [blame] | 358 | bld.env_of_name('debug').append_value("LINKFLAGS_V8_G", t) |
Ryan | 1a126ed | 2009-04-04 12:50:15 | [diff] [blame] | 359 | |
Ryan Dahl | 53ebe75 | 2009-10-08 21:20:14 | [diff] [blame] | 360 | bld.install_files('${PREFIX}/include/node/', 'deps/v8/include/*.h') |
Ryan | 2b6d724 | 2009-06-20 13:07:10 | [diff] [blame] | 361 | |
Ryan | 41d89f6 | 2009-07-28 10:29:18 | [diff] [blame] | 362 | def build(bld): |
Ryan Dahl | ef9f404 | 2010-06-02 19:27:53 | [diff] [blame] | 363 | ## This snippet is to show full commands as WAF executes |
| 364 | import Build |
| 365 | old = Build.BuildContext.exec_command |
| 366 | def exec_command(self, cmd, **kw): |
| 367 | if isinstance(cmd, list): print(" ".join(cmd)) |
| 368 | return old(self, cmd, **kw) |
| 369 | Build.BuildContext.exec_command = exec_command |
| 370 | |
Ryan Dahl | 501136b | 2010-06-02 16:15:54 | [diff] [blame] | 371 | Options.options.jobs=jobs |
Ryan Dahl | ef9f404 | 2010-06-02 19:27:53 | [diff] [blame] | 372 | |
Ryan Dahl | 9ea8c9f | 2010-04-07 20:34:40 | [diff] [blame] | 373 | print "DEST_OS: " + bld.env['DEST_OS'] |
| 374 | print "DEST_CPU: " + bld.env['DEST_CPU'] |
Ryan Dahl | 23d680b | 2010-05-13 23:24:05 | [diff] [blame] | 375 | print "Parallel Jobs: " + str(Options.options.jobs) |
Ryan Dahl | 9ea8c9f | 2010-04-07 20:34:40 | [diff] [blame] | 376 | |
Ryan Dahl | 9e8df0e | 2010-06-02 21:05:37 | [diff] [blame] | 377 | bld.add_subdirs('deps/libeio') |
| 378 | |
| 379 | if not bld.env['USE_SHARED_V8']: build_v8(bld) |
| 380 | if not bld.env['USE_SHARED_LIBEV']: bld.add_subdirs('deps/libev') |
| 381 | if not bld.env['USE_SHARED_CARES']: bld.add_subdirs('deps/c-ares') |
Ryan | 41d89f6 | 2009-07-28 10:29:18 | [diff] [blame] | 382 | |
Jérémy Lal | c93bab1 | 2010-03-11 21:15:32 | [diff] [blame] | 383 | |
Ryan | 5a071ad | 2009-05-03 12:09:16 | [diff] [blame] | 384 | ### http_parser |
Ryan Dahl | 122e74b | 2009-10-27 21:26:53 | [diff] [blame] | 385 | http_parser = bld.new_task_gen("cc") |
Ryan | 5a071ad | 2009-05-03 12:09:16 | [diff] [blame] | 386 | http_parser.source = "deps/http_parser/http_parser.c" |
| 387 | http_parser.includes = "deps/http_parser/" |
| 388 | http_parser.name = "http_parser" |
| 389 | http_parser.target = "http_parser" |
| 390 | http_parser.install_path = None |
Ryan | 29b528c | 2009-04-23 15:29:31 | [diff] [blame] | 391 | if bld.env["USE_DEBUG"]: |
Ryan | 5a071ad | 2009-05-03 12:09:16 | [diff] [blame] | 392 | http_parser.clone("debug") |
Ryan | 1a126ed | 2009-04-04 12:50:15 | [diff] [blame] | 393 | |
Ryan | 63a9cd3 | 2009-04-15 08:08:28 | [diff] [blame] | 394 | ### src/native.cc |
Zoka | b29f787 | 2010-03-20 03:56:03 | [diff] [blame] | 395 | def make_macros(loc, content): |
| 396 | f = open(loc, 'w') |
| 397 | f.write(content) |
| 398 | f.close |
| 399 | |
| 400 | macros_loc_debug = join( |
| 401 | bld.srcnode.abspath(bld.env_of_name("debug")), |
| 402 | "macros.py" |
| 403 | ) |
| 404 | |
| 405 | macros_loc_default = join( |
| 406 | bld.srcnode.abspath(bld.env_of_name("default")), |
| 407 | "macros.py" |
| 408 | ) |
| 409 | |
| 410 | make_macros(macros_loc_debug, "") # leave debug(x) as is in debug build |
| 411 | # replace debug(x) with nothing in release build |
| 412 | make_macros(macros_loc_default, "macro debug(x) = ;\n") |
| 413 | |
Ryan | 63a9cd3 | 2009-04-15 08:08:28 | [diff] [blame] | 414 | def javascript_in_c(task): |
| 415 | env = task.env |
| 416 | source = map(lambda x: x.srcpath(env), task.inputs) |
| 417 | targets = map(lambda x: x.srcpath(env), task.outputs) |
Zoka | b29f787 | 2010-03-20 03:56:03 | [diff] [blame] | 418 | source.append(macros_loc_default) |
| 419 | js2c.JS2C(source, targets) |
| 420 | |
| 421 | def javascript_in_c_debug(task): |
| 422 | env = task.env |
| 423 | source = map(lambda x: x.srcpath(env), task.inputs) |
| 424 | targets = map(lambda x: x.srcpath(env), task.outputs) |
| 425 | source.append(macros_loc_debug) |
Ryan | 63a9cd3 | 2009-04-15 08:08:28 | [diff] [blame] | 426 | js2c.JS2C(source, targets) |
| 427 | |
| 428 | native_cc = bld.new_task_gen( |
Ryan Dahl | 4ccdc50 | 2010-03-15 15:00:19 | [diff] [blame] | 429 | source='src/node.js ' + bld.path.ant_glob('lib/*.js'), |
Ryan Dahl | 53ebe75 | 2009-10-08 21:20:14 | [diff] [blame] | 430 | target="src/node_natives.h", |
Ryan Dahl | 4ccdc50 | 2010-03-15 15:00:19 | [diff] [blame] | 431 | before="cxx", |
| 432 | install_path=None |
Ryan | 63a9cd3 | 2009-04-15 08:08:28 | [diff] [blame] | 433 | ) |
Ryan Dahl | 4bcb01c | 2009-10-16 20:53:44 | [diff] [blame] | 434 | |
| 435 | # Add the rule /after/ cloning the debug |
| 436 | # This is a work around for an error had in python 2.4.3 (I'll paste the |
| 437 | # error that was had into the git commit meessage. git-blame to find out |
| 438 | # where.) |
Ryan | 29b528c | 2009-04-23 15:29:31 | [diff] [blame] | 439 | if bld.env["USE_DEBUG"]: |
Ryan Dahl | 4bcb01c | 2009-10-16 20:53:44 | [diff] [blame] | 440 | native_cc_debug = native_cc.clone("debug") |
Zoka | b29f787 | 2010-03-20 03:56:03 | [diff] [blame] | 441 | native_cc_debug.rule = javascript_in_c_debug |
| 442 | |
Ryan Dahl | 4bcb01c | 2009-10-16 20:53:44 | [diff] [blame] | 443 | native_cc.rule = javascript_in_c |
Ryan | 63a9cd3 | 2009-04-15 08:08:28 | [diff] [blame] | 444 | |
Ryan | 2b6d724 | 2009-06-20 13:07:10 | [diff] [blame] | 445 | ### node lib |
Ryan | 8152f9c | 2009-09-01 12:15:29 | [diff] [blame] | 446 | node = bld.new_task_gen("cxx", "program") |
| 447 | node.name = "node" |
| 448 | node.target = "node" |
Ryan Dahl | 9e8df0e | 2010-06-02 21:05:37 | [diff] [blame] | 449 | node.uselib = 'RT EV OPENSSL CARES EXECINFO DL KVM SOCKET NSL' |
| 450 | node.add_objects = 'eio http_parser' |
| 451 | node.install_path = '${PREFIX}/lib' |
| 452 | node.install_path = '${PREFIX}/bin' |
| 453 | node.chmod = 0755 |
Ryan | 8152f9c | 2009-09-01 12:15:29 | [diff] [blame] | 454 | node.source = """ |
Ryan | 1a126ed | 2009-04-04 12:50:15 | [diff] [blame] | 455 | src/node.cc |
Ryan Dahl | 630bb7a | 2009-12-13 07:42:45 | [diff] [blame] | 456 | src/node_buffer.cc |
Ryan Dahl | 42ee169 | 2010-01-24 19:21:45 | [diff] [blame] | 457 | src/node_http_parser.cc |
Ryan Dahl | 78e49f1 | 2010-05-29 20:08:05 | [diff] [blame] | 458 | src/node_net.cc |
Ryan Dahl | f219938 | 2009-12-13 14:43:58 | [diff] [blame] | 459 | src/node_io_watcher.cc |
Ryan Dahl | a5df0f6 | 2009-10-27 10:46:58 | [diff] [blame] | 460 | src/node_child_process.cc |
| 461 | src/node_constants.cc |
Krishna Rajendran | dc1f4eb | 2010-04-06 10:28:37 | [diff] [blame] | 462 | src/node_cares.cc |
Ryan Dahl | a5df0f6 | 2009-10-27 10:46:58 | [diff] [blame] | 463 | src/node_events.cc |
| 464 | src/node_file.cc |
Ryan Dahl | 8492c52 | 2010-03-15 21:05:18 | [diff] [blame] | 465 | src/node_signal_watcher.cc |
| 466 | src/node_stat_watcher.cc |
Ryan | 17c6a67 | 2009-08-24 18:25:24 | [diff] [blame] | 467 | src/node_stdio.cc |
Ryan Dahl | a5df0f6 | 2009-10-27 10:46:58 | [diff] [blame] | 468 | src/node_timer.cc |
Herbert Vojcik | c2a0672 | 2010-04-17 15:18:15 | [diff] [blame] | 469 | src/node_script.cc |
Ryan | 1a126ed | 2009-04-04 12:50:15 | [diff] [blame] | 470 | """ |
Ryan Dahl | 9e8df0e | 2010-06-02 21:05:37 | [diff] [blame] | 471 | if bld.env["USE_OPENSSL"]: node.source += "src/node_crypto.cc" |
Rhys Jones | fb3a9cd | 2010-04-02 23:11:53 | [diff] [blame] | 472 | |
Ryan Dahl | 9e8df0e | 2010-06-02 21:05:37 | [diff] [blame] | 473 | node.includes = """ |
| 474 | src/ |
| 475 | deps/libeio |
| 476 | deps/http_parser |
| 477 | """ |
Ryan Dahl | e9a116f | 2010-04-06 10:41:32 | [diff] [blame] | 478 | |
Ryan Dahl | 9e8df0e | 2010-06-02 21:05:37 | [diff] [blame] | 479 | if not bld.env["USE_SHARED_V8"]: node.includes += ' deps/v8/include ' |
Vanilla Hsu | 067f408 | 2010-04-07 16:05:37 | [diff] [blame] | 480 | |
Ryan Dahl | 9e8df0e | 2010-06-02 21:05:37 | [diff] [blame] | 481 | if not bld.env["USE_SHARED_LIBEV"]: |
| 482 | node.add_objects += ' ev ' |
| 483 | node.includes += ' deps/libev ' |
Ryan Dahl | e9a116f | 2010-04-06 10:41:32 | [diff] [blame] | 484 | |
Ryan Dahl | 9e8df0e | 2010-06-02 21:05:37 | [diff] [blame] | 485 | if not bld.env["USE_SHARED_CARES"]: |
| 486 | node.add_objects += ' cares ' |
| 487 | node.includes += ' deps/c-ares deps/c-ares/' + bld.env['DEST_OS'] + '-' + bld.env['DEST_CPU'] |
Ryan | 8e7bbf2 | 2009-04-23 17:26:56 | [diff] [blame] | 488 | |
Ryan | 4d92199 | 2009-08-26 23:11:16 | [diff] [blame] | 489 | def subflags(program): |
Ryan Dahl | d979ac9 | 2009-10-09 13:00:12 | [diff] [blame] | 490 | if os.path.exists(join(cwd, ".git")): |
Ryan Dahl | 962e929 | 2009-10-09 14:16:27 | [diff] [blame] | 491 | actual_version=cmd_output("git describe").strip() |
Ryan Dahl | d979ac9 | 2009-10-09 13:00:12 | [diff] [blame] | 492 | else: |
| 493 | actual_version=VERSION |
| 494 | |
Ryan | b73264d | 2009-08-27 00:15:11 | [diff] [blame] | 495 | x = { 'CCFLAGS' : " ".join(program.env["CCFLAGS"]) |
| 496 | , 'CPPFLAGS' : " ".join(program.env["CPPFLAGS"]) |
| 497 | , 'LIBFLAGS' : " ".join(program.env["LIBFLAGS"]) |
Ryan Dahl | d979ac9 | 2009-10-09 13:00:12 | [diff] [blame] | 498 | , 'VERSION' : actual_version |
Ryan | b73264d | 2009-08-27 00:15:11 | [diff] [blame] | 499 | , 'PREFIX' : program.env["PREFIX"] |
Ryan | 4d92199 | 2009-08-26 23:11:16 | [diff] [blame] | 500 | } |
Ryan Dahl | bf0d278 | 2009-10-03 20:42:03 | [diff] [blame] | 501 | return x |
Ryan | 4d92199 | 2009-08-26 23:11:16 | [diff] [blame] | 502 | |
Ryan | 4d92199 | 2009-08-26 23:11:16 | [diff] [blame] | 503 | # process file.pc.in -> file.pc |
Ryan Dahl | d979ac9 | 2009-10-09 13:00:12 | [diff] [blame] | 504 | |
Ryan | b73264d | 2009-08-27 00:15:11 | [diff] [blame] | 505 | node_version = bld.new_task_gen('subst', before="cxx") |
| 506 | node_version.source = 'src/node_version.h.in' |
| 507 | node_version.target = 'src/node_version.h' |
| 508 | node_version.dict = subflags(node) |
Ryan | a97dce7 | 2009-08-31 09:14:34 | [diff] [blame] | 509 | node_version.install_path = '${PREFIX}/include/node' |
Ryan | 4d92199 | 2009-08-26 23:11:16 | [diff] [blame] | 510 | |
Ryan | 29b528c | 2009-04-23 15:29:31 | [diff] [blame] | 511 | if bld.env["USE_DEBUG"]: |
Ryan | 2b6d724 | 2009-06-20 13:07:10 | [diff] [blame] | 512 | node_g = node.clone("debug") |
| 513 | node_g.target = "node_g" |
Ryan Dahl | 9e8df0e | 2010-06-02 21:05:37 | [diff] [blame] | 514 | node_g.uselib += ' V8_G' |
| 515 | |
Ryan | b73264d | 2009-08-27 00:15:11 | [diff] [blame] | 516 | node_version_g = node_version.clone("debug") |
| 517 | node_version_g.dict = subflags(node_g) |
Ryan | a97dce7 | 2009-08-31 09:14:34 | [diff] [blame] | 518 | node_version_g.install_path = None |
Ryan | 4d92199 | 2009-08-26 23:11:16 | [diff] [blame] | 519 | |
Ryan Dahl | 9e8df0e | 2010-06-02 21:05:37 | [diff] [blame] | 520 | # After creating the debug clone, append the V8 dep |
| 521 | node.uselib += ' V8' |
Ryan | a97dce7 | 2009-08-31 09:14:34 | [diff] [blame] | 522 | |
| 523 | bld.install_files('${PREFIX}/include/node/', """ |
| 524 | config.h |
| 525 | src/node.h |
Ryan Dahl | 5f466c8 | 2009-10-27 19:17:03 | [diff] [blame] | 526 | src/node_object_wrap.h |
Ryan Dahl | d241594 | 2010-05-06 21:14:52 | [diff] [blame] | 527 | src/node_buffer.h |
Ryan Dahl | 5f466c8 | 2009-10-27 19:17:03 | [diff] [blame] | 528 | src/node_events.h |
Ryan Dahl | bf0d278 | 2009-10-03 20:42:03 | [diff] [blame] | 529 | """) |
| 530 | |
Ryan Dahl | ef9f404 | 2010-06-02 19:27:53 | [diff] [blame] | 531 | # Only install the man page if it exists. |
Ryan Dahl | bf0d278 | 2009-10-03 20:42:03 | [diff] [blame] | 532 | # Do 'make doc install' to build and install it. |
| 533 | if os.path.exists('doc/node.1'): |
| 534 | bld.install_files('${PREFIX}/share/man/man1/', 'doc/node.1') |
| 535 | |
| 536 | bld.install_files('${PREFIX}/bin/', 'bin/*', chmod=0755) |
Ryan Dahl | bf0d278 | 2009-10-03 20:42:03 | [diff] [blame] | 537 | bld.install_files('${PREFIX}/lib/node/wafadmin', 'tools/wafadmin/*.py') |
| 538 | bld.install_files('${PREFIX}/lib/node/wafadmin/Tools', 'tools/wafadmin/Tools/*.py') |
Ryan Dahl | 6f17ca5 | 2009-10-03 17:08:05 | [diff] [blame] | 539 | |
Ryan Dahl | 132d685 | 2009-10-27 17:11:07 | [diff] [blame] | 540 | def shutdown(): |
| 541 | Options.options.debug |
| 542 | # HACK to get binding.node out of build directory. |
| 543 | # better way to do this? |
| 544 | if not Options.commands['clean']: |
| 545 | if os.path.exists('build/default/node') and not os.path.exists('node'): |
| 546 | os.symlink('build/default/node', 'node') |
| 547 | if os.path.exists('build/debug/node_g') and not os.path.exists('node_g'): |
| 548 | os.symlink('build/debug/node_g', 'node_g') |
| 549 | else: |
| 550 | if os.path.exists('node'): os.unlink('node') |
| 551 | if os.path.exists('node_g'): os.unlink('node_g') |