Ryan Dahl | 14b04b0 | 2011-11-15 03:02:44 | [diff] [blame] | 1 | #!/usr/bin/env python |
Ryan Dahl | 5cf4cef | 2010-10-26 01:17:19 | [diff] [blame] | 2 | |
Ryan Dahl | 14b04b0 | 2011-11-15 03:02:44 | [diff] [blame] | 3 | import optparse |
| 4 | import os |
jbergstroem | 45605c9 | 2011-12-18 22:53:07 | [diff] [blame] | 5 | import pprint |
Ben Noordhuis | b9e1bb3 | 2011-11-15 16:17:05 | [diff] [blame] | 6 | import subprocess |
Ryan Dahl | 14b04b0 | 2011-11-15 03:02:44 | [diff] [blame] | 7 | import sys |
Ryan Dahl | 5cf4cef | 2010-10-26 01:17:19 | [diff] [blame] | 8 | |
Ryan Dahl | 14b04b0 | 2011-11-15 03:02:44 | [diff] [blame] | 9 | root_dir = os.path.dirname(__file__) |
| 10 | sys.path.insert(0, os.path.join(root_dir, 'deps', 'v8', 'tools')) |
Ryan Dahl | 97c9745 | 2010-11-01 23:03:32 | [diff] [blame] | 11 | |
Ryan Dahl | 14b04b0 | 2011-11-15 03:02:44 | [diff] [blame] | 12 | # parse our options |
| 13 | parser = optparse.OptionParser() |
Ryan Dahl | 97c9745 | 2010-11-01 23:03:32 | [diff] [blame] | 14 | |
Ryan Dahl | 14b04b0 | 2011-11-15 03:02:44 | [diff] [blame] | 15 | parser.add_option("--debug", |
| 16 | action="store_true", |
| 17 | dest="debug", |
| 18 | help="Also build debug build") |
Ryan Dahl | 97c9745 | 2010-11-01 23:03:32 | [diff] [blame] | 19 | |
Ryan Dahl | 14b04b0 | 2011-11-15 03:02:44 | [diff] [blame] | 20 | parser.add_option("--prefix", |
| 21 | action="store", |
| 22 | dest="prefix", |
| 23 | help="Select the install prefix (defaults to /usr/local)") |
| 24 | |
Fedor Indutny | a9f2c4a | 2011-12-17 08:09:14 | [diff] [blame] | 25 | parser.add_option("--without-npm", |
| 26 | action="store_true", |
| 27 | dest="without_npm", |
| 28 | help="Don\'t install the bundled npm package manager") |
| 29 | |
Ben Noordhuis | b3d4938 | 2011-11-29 15:41:41 | [diff] [blame] | 30 | parser.add_option("--without-isolates", |
| 31 | action="store_true", |
| 32 | dest="without_isolates", |
| 33 | help="Build without isolates (no threads, single loop) [Default: False]") |
| 34 | |
Ryan Dahl | 14b04b0 | 2011-11-15 03:02:44 | [diff] [blame] | 35 | parser.add_option("--without-ssl", |
| 36 | action="store_true", |
| 37 | dest="without_ssl", |
| 38 | help="Build without SSL") |
| 39 | |
| 40 | parser.add_option("--without-snapshot", |
| 41 | action="store_true", |
| 42 | dest="without_snapshot", |
| 43 | help="Build without snapshotting V8 libraries. You might want to set" |
| 44 | " this for cross-compiling. [Default: False]") |
| 45 | |
| 46 | parser.add_option("--shared-v8", |
| 47 | action="store_true", |
| 48 | dest="shared_v8", |
| 49 | help="Link to a shared V8 DLL instead of static linking") |
| 50 | |
| 51 | parser.add_option("--shared-v8-includes", |
| 52 | action="store", |
| 53 | dest="shared_v8_includes", |
| 54 | help="Directory containing V8 header files") |
| 55 | |
| 56 | parser.add_option("--shared-v8-libpath", |
| 57 | action="store", |
| 58 | dest="shared_v8_libpath", |
| 59 | help="A directory to search for the shared V8 DLL") |
| 60 | |
| 61 | parser.add_option("--shared-v8-libname", |
| 62 | action="store", |
| 63 | dest="shared_v8_libname", |
| 64 | help="Alternative lib name to link to (default: 'v8')") |
| 65 | |
Ryan Dahl | e61de70 | 2011-12-16 23:00:23 | [diff] [blame] | 66 | parser.add_option("--openssl-use-sys", |
| 67 | action="store", |
| 68 | dest="openssl_use_sys", |
| 69 | help="Use the system OpenSSL instead of one included with Node") |
| 70 | |
Ryan Dahl | 14b04b0 | 2011-11-15 03:02:44 | [diff] [blame] | 71 | parser.add_option("--openssl-includes", |
| 72 | action="store", |
| 73 | dest="openssl_includes", |
| 74 | help="A directory to search for the OpenSSL includes") |
| 75 | |
| 76 | parser.add_option("--openssl-libpath", |
| 77 | action="store", |
| 78 | dest="openssl_libpath", |
| 79 | help="A directory to search for the OpenSSL libraries") |
| 80 | |
| 81 | parser.add_option("--no-ssl2", |
| 82 | action="store_true", |
| 83 | dest="no_ssl2", |
| 84 | help="Disable OpenSSL v2") |
| 85 | |
| 86 | parser.add_option("--shared-cares", |
| 87 | action="store_true", |
| 88 | dest="shared_cares", |
| 89 | help="Link to a shared C-Ares DLL instead of static linking") |
| 90 | |
| 91 | parser.add_option("--shared-cares-includes", |
| 92 | action="store", |
| 93 | dest="shared_cares_includes", |
| 94 | help="Directory containing C-Ares header files") |
| 95 | |
| 96 | parser.add_option("--shared-cares-libpath", |
| 97 | action="store", |
| 98 | dest="shared_cares_libpath", |
| 99 | help="A directory to search for the shared C-Ares DLL") |
| 100 | |
| 101 | parser.add_option("--with-dtrace", |
| 102 | action="store_true", |
| 103 | dest="with_dtrace", |
| 104 | help="Build with DTrace (experimental)") |
| 105 | |
| 106 | # CHECKME does this still work with recent releases of V8? |
| 107 | parser.add_option("--gdb", |
| 108 | action="store_true", |
| 109 | dest="gdb", |
| 110 | help="add gdb support") |
| 111 | |
| 112 | parser.add_option("--dest-cpu", |
| 113 | action="store", |
| 114 | dest="dest_cpu", |
| 115 | help="CPU architecture to build for. Valid values are: arm, ia32, x64") |
| 116 | |
| 117 | (options, args) = parser.parse_args() |
| 118 | |
| 119 | |
Ben Noordhuis | a033261 | 2011-11-29 15:27:52 | [diff] [blame] | 120 | def b(value): |
| 121 | """Returns the string 'true' if value is truthy, 'false' otherwise.""" |
| 122 | if value: |
| 123 | return 'true' |
| 124 | else: |
| 125 | return 'false' |
| 126 | |
| 127 | |
Ryan Dahl | 14b04b0 | 2011-11-15 03:02:44 | [diff] [blame] | 128 | def pkg_config(pkg): |
| 129 | cmd = os.popen('pkg-config --libs %s' % pkg, 'r') |
| 130 | libs = cmd.readline().strip() |
| 131 | ret = cmd.close() |
| 132 | if (ret): return None |
| 133 | |
| 134 | cmd = os.popen('pkg-config --cflags %s' % pkg, 'r') |
| 135 | cflags = cmd.readline().strip() |
| 136 | ret = cmd.close() |
| 137 | if (ret): return None |
| 138 | |
| 139 | return (libs, cflags) |
| 140 | |
| 141 | |
| 142 | def uname(switch): |
| 143 | f = os.popen('uname %s' % switch) |
| 144 | s = f.read().strip() |
| 145 | f.close() |
| 146 | return s |
| 147 | |
| 148 | |
| 149 | def host_arch(): |
| 150 | """Host architecture. One of arm, ia32 or x64.""" |
| 151 | arch = uname('-p') |
| 152 | |
| 153 | if arch == 'unknown': |
| 154 | arch = uname('-m') |
| 155 | |
| 156 | return { |
| 157 | 'arm': 'arm', |
| 158 | 'x86': 'ia32', |
| 159 | 'i386': 'ia32', |
| 160 | 'x86_64': 'x64', |
| 161 | }.get(arch, 'ia32') |
| 162 | |
| 163 | |
| 164 | def target_arch(): |
Ryan Dahl | 14b04b0 | 2011-11-15 03:02:44 | [diff] [blame] | 165 | return host_arch() |
| 166 | |
| 167 | |
| 168 | def configure_node(o): |
Ben Noordhuis | 93465d3 | 2012-01-15 15:50:58 | [diff] [blame^] | 169 | # TODO add gdb |
Ben Noordhuis | b3d4938 | 2011-11-29 15:41:41 | [diff] [blame] | 170 | o['variables']['node_use_isolates'] = b(not options.without_isolates) |
Ben Noordhuis | a033261 | 2011-11-29 15:27:52 | [diff] [blame] | 171 | o['variables']['node_debug'] = b(options.debug) |
Ryan Dahl | 14b04b0 | 2011-11-15 03:02:44 | [diff] [blame] | 172 | o['variables']['node_prefix'] = options.prefix if options.prefix else '' |
Ben Noordhuis | a033261 | 2011-11-29 15:27:52 | [diff] [blame] | 173 | o['variables']['node_use_dtrace'] = b(options.with_dtrace) |
Fedor Indutny | a9f2c4a | 2011-12-17 08:09:14 | [diff] [blame] | 174 | o['variables']['node_install_npm'] = b(not options.without_npm) |
Ryan Dahl | 14b04b0 | 2011-11-15 03:02:44 | [diff] [blame] | 175 | o['variables']['host_arch'] = host_arch() |
Ben Noordhuis | 93465d3 | 2012-01-15 15:50:58 | [diff] [blame^] | 176 | o['variables']['target_arch'] = options.dest_cpu or target_arch() |
Ryan Dahl | 14b04b0 | 2011-11-15 03:02:44 | [diff] [blame] | 177 | |
| 178 | # TODO move to node.gyp |
| 179 | if sys.platform == 'sunos5': |
| 180 | o['variables']['visibility'] = '' # FIXME -fvisibility=hidden, should be a gcc check |
| 181 | |
| 182 | |
| 183 | def configure_libz(o): |
| 184 | o['libraries'] += ['-lz'] |
| 185 | |
| 186 | |
| 187 | def configure_v8(o): |
Ben Noordhuis | a033261 | 2011-11-29 15:27:52 | [diff] [blame] | 188 | o['variables']['v8_use_snapshot'] = b(not options.without_snapshot) |
| 189 | o['variables']['node_shared_v8'] = b(options.shared_v8) |
Ryan Dahl | 14b04b0 | 2011-11-15 03:02:44 | [diff] [blame] | 190 | |
| 191 | # assume shared_v8 if one of these is set? |
| 192 | if options.shared_v8_libpath: |
| 193 | o['libraries'] += ['-L%s' % options.shared_v8_libpath] |
| 194 | if options.shared_v8_libname: |
| 195 | o['libraries'] += ['-l%s' % options.shared_v8_libname] |
| 196 | if options.shared_v8_includes: |
| 197 | o['include_dirs'] += [options.shared_v8_includes] |
| 198 | |
| 199 | |
| 200 | def configure_cares(o): |
Ben Noordhuis | a033261 | 2011-11-29 15:27:52 | [diff] [blame] | 201 | o['variables']['node_shared_cares'] = b(options.shared_cares) |
Ryan Dahl | 14b04b0 | 2011-11-15 03:02:44 | [diff] [blame] | 202 | |
| 203 | # assume shared_cares if one of these is set? |
| 204 | if options.shared_cares_libpath: |
| 205 | o['libraries'] += ['-L%s' % options.shared_cares_libpath] |
| 206 | if options.shared_cares_includes: |
| 207 | o['include_dirs'] += [options.shared_cares_includes] |
| 208 | |
| 209 | |
| 210 | def configure_openssl(o): |
Ben Noordhuis | a033261 | 2011-11-29 15:27:52 | [diff] [blame] | 211 | o['variables']['node_use_openssl'] = b(not options.without_ssl) |
Ryan Dahl | 14b04b0 | 2011-11-15 03:02:44 | [diff] [blame] | 212 | |
| 213 | if options.without_ssl: |
| 214 | return |
| 215 | |
| 216 | if options.no_ssl2: |
| 217 | o['defines'] += ['OPENSSL_NO_SSL2=1'] |
| 218 | |
Ryan Dahl | e61de70 | 2011-12-16 23:00:23 | [diff] [blame] | 219 | if not options.openssl_use_sys: |
| 220 | o['variables']['node_use_system_openssl'] = b(False) |
Ryan Dahl | 14b04b0 | 2011-11-15 03:02:44 | [diff] [blame] | 221 | else: |
Ryan Dahl | e61de70 | 2011-12-16 23:00:23 | [diff] [blame] | 222 | out = pkg_config('openssl') |
| 223 | (libs, cflags) = out if out else ('', '') |
Ryan Dahl | 14b04b0 | 2011-11-15 03:02:44 | [diff] [blame] | 224 | |
Ryan Dahl | e61de70 | 2011-12-16 23:00:23 | [diff] [blame] | 225 | if options.openssl_libpath: |
| 226 | o['libraries'] += ['-L%s' % options.openssl_libpath, '-lssl', '-lcrypto'] |
| 227 | else: |
| 228 | o['libraries'] += libs.split() |
Ryan Dahl | 14b04b0 | 2011-11-15 03:02:44 | [diff] [blame] | 229 | |
Ryan Dahl | e61de70 | 2011-12-16 23:00:23 | [diff] [blame] | 230 | if options.openssl_includes: |
| 231 | o['include_dirs'] += [options.openssl_includes] |
| 232 | else: |
| 233 | o['cflags'] += cflags.split() |
| 234 | |
| 235 | o['variables']['node_use_system_openssl'] = b( |
| 236 | libs or cflags or options.openssl_libpath or options.openssl_includes) |
Ryan Dahl | 14b04b0 | 2011-11-15 03:02:44 | [diff] [blame] | 237 | |
| 238 | |
Ryan Dahl | 14b04b0 | 2011-11-15 03:02:44 | [diff] [blame] | 239 | output = { |
| 240 | 'variables': {}, |
| 241 | 'include_dirs': [], |
| 242 | 'libraries': [], |
| 243 | 'defines': [], |
| 244 | 'cflags': [], |
| 245 | } |
| 246 | |
| 247 | configure_node(output) |
| 248 | configure_libz(output) |
| 249 | configure_v8(output) |
| 250 | configure_cares(output) |
| 251 | configure_openssl(output) |
| 252 | |
| 253 | # variables should be a root level element, |
| 254 | # move everything else to target_defaults |
| 255 | variables = output['variables'] |
| 256 | del output['variables'] |
| 257 | output = { |
| 258 | 'variables': variables, |
| 259 | 'target_defaults': output |
| 260 | } |
Ryan Dahl | 624f70e | 2011-12-23 22:24:50 | [diff] [blame] | 261 | pprint.pprint(output, indent=2) |
Ryan Dahl | 14b04b0 | 2011-11-15 03:02:44 | [diff] [blame] | 262 | |
Ryan Dahl | 624f70e | 2011-12-23 22:24:50 | [diff] [blame] | 263 | fn = os.path.join(root_dir, 'config.gypi') |
Ryan Dahl | 14b04b0 | 2011-11-15 03:02:44 | [diff] [blame] | 264 | print "creating ", fn |
| 265 | |
| 266 | f = open(fn, 'w+') |
| 267 | f.write("# Do not edit. Generated by the configure script.\n") |
jbergstroem | 45605c9 | 2011-12-18 22:53:07 | [diff] [blame] | 268 | pprint.pprint(output, stream=f, indent=2) |
Ryan Dahl | 14b04b0 | 2011-11-15 03:02:44 | [diff] [blame] | 269 | f.write("\n") |
| 270 | f.close() |
| 271 | |
Ryan Dahl | 48d21dd | 2011-11-18 01:18:29 | [diff] [blame] | 272 | subprocess.call(['tools/gyp_node','-f', 'make']) |