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