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