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