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