9 root_dir = os.path.dirname(__file__)
10 sys.path.insert(0, os.path.join(root_dir, 'deps', 'v8', 'tools'))
13 parser = optparse.OptionParser()
15 parser.add_option("--debug",
18 help="Also build debug build")
20 parser.add_option("--prefix",
23 help="Select the install prefix (defaults to /usr/local)")
25 parser.add_option("--without-npm",
28 help="Don\'t install the bundled npm package manager")
30 parser.add_option("--without-isolates",
32 dest="without_isolates",
33 help="Build without isolates (no threads, single loop) [Default: False]")
35 parser.add_option("--without-ssl",
38 help="Build without SSL")
40 parser.add_option("--without-snapshot",
42 dest="without_snapshot",
43 help="Build without snapshotting V8 libraries. You might want to set"
44 " this for cross-compiling. [Default: False]")
46 parser.add_option("--shared-v8",
49 help="Link to a shared V8 DLL instead of static linking")
51 parser.add_option("--shared-v8-includes",
53 dest="shared_v8_includes",
54 help="Directory containing V8 header files")
56 parser.add_option("--shared-v8-libpath",
58 dest="shared_v8_libpath",
59 help="A directory to search for the shared V8 DLL")
61 parser.add_option("--shared-v8-libname",
63 dest="shared_v8_libname",
64 help="Alternative lib name to link to (default: 'v8')")
66 parser.add_option("--openssl-use-sys",
68 dest="openssl_use_sys",
69 help="Use the system OpenSSL instead of one included with Node")
71 parser.add_option("--openssl-includes",
73 dest="openssl_includes",
74 help="A directory to search for the OpenSSL includes")
76 parser.add_option("--openssl-libpath",
78 dest="openssl_libpath",
79 help="A directory to search for the OpenSSL libraries")
81 parser.add_option("--no-ssl2",
84 help="Disable OpenSSL v2")
86 parser.add_option("--shared-cares",
89 help="Link to a shared C-Ares DLL instead of static linking")
91 parser.add_option("--shared-cares-includes",
93 dest="shared_cares_includes",
94 help="Directory containing C-Ares header files")
96 parser.add_option("--shared-cares-libpath",
98 dest="shared_cares_libpath",
99 help="A directory to search for the shared C-Ares DLL")
101 parser.add_option("--with-dtrace",
104 help="Build with DTrace (experimental)")
106 # CHECKME does this still work with recent releases of V8?
107 parser.add_option("--gdb",
110 help="add gdb support")
112 parser.add_option("--dest-cpu",
115 help="CPU architecture to build for. Valid values are: arm, ia32, x64")
117 (options, args) = parser.parse_args()
121 """Returns the string 'true' if value is truthy, 'false' otherwise."""
129 cmd = os.popen('pkg-config --libs %s' % pkg, 'r')
130 libs = cmd.readline().strip()
132 if (ret): return None
134 cmd = os.popen('pkg-config --cflags %s' % pkg, 'r')
135 cflags = cmd.readline().strip()
137 if (ret): return None
139 return (libs, cflags)
143 f = os.popen('uname %s' % switch)
150 """Host architecture. One of arm, ia32 or x64."""
153 if arch == 'unknown':
165 # TODO act on options.dest_cpu
169 def configure_node(o):
170 # TODO add gdb and dest_cpu
171 o['variables']['node_use_isolates'] = b(not options.without_isolates)
172 o['variables']['node_debug'] = b(options.debug)
173 o['variables']['node_prefix'] = options.prefix if options.prefix else ''
174 o['variables']['node_use_dtrace'] = b(options.with_dtrace)
175 o['variables']['node_install_npm'] = b(not options.without_npm)
176 o['variables']['host_arch'] = host_arch()
177 o['variables']['target_arch'] = target_arch()
179 # TODO move to node.gyp
180 if sys.platform == 'sunos5':
181 o['variables']['visibility'] = '' # FIXME -fvisibility=hidden, should be a gcc check
184 def configure_libz(o):
185 o['libraries'] += ['-lz']
189 o['variables']['v8_use_snapshot'] = b(not options.without_snapshot)
190 o['variables']['node_shared_v8'] = b(options.shared_v8)
192 # assume shared_v8 if one of these is set?
193 if options.shared_v8_libpath:
194 o['libraries'] += ['-L%s' % options.shared_v8_libpath]
195 if options.shared_v8_libname:
196 o['libraries'] += ['-l%s' % options.shared_v8_libname]
197 if options.shared_v8_includes:
198 o['include_dirs'] += [options.shared_v8_includes]
201 def configure_cares(o):
202 o['variables']['node_shared_cares'] = b(options.shared_cares)
204 # assume shared_cares if one of these is set?
205 if options.shared_cares_libpath:
206 o['libraries'] += ['-L%s' % options.shared_cares_libpath]
207 if options.shared_cares_includes:
208 o['include_dirs'] += [options.shared_cares_includes]
211 def configure_openssl(o):
212 o['variables']['node_use_openssl'] = b(not options.without_ssl)
214 if options.without_ssl:
218 o['defines'] += ['OPENSSL_NO_SSL2=1']
220 if not options.openssl_use_sys:
221 o['variables']['node_use_system_openssl'] = b(False)
223 out = pkg_config('openssl')
224 (libs, cflags) = out if out else ('', '')
226 if options.openssl_libpath:
227 o['libraries'] += ['-L%s' % options.openssl_libpath, '-lssl', '-lcrypto']
229 o['libraries'] += libs.split()
231 if options.openssl_includes:
232 o['include_dirs'] += [options.openssl_includes]
234 o['cflags'] += cflags.split()
236 o['variables']['node_use_system_openssl'] = b(
237 libs or cflags or options.openssl_libpath or options.openssl_includes)
248 configure_node(output)
249 configure_libz(output)
251 configure_cares(output)
252 configure_openssl(output)
254 # variables should be a root level element,
255 # move everything else to target_defaults
256 variables = output['variables']
257 del output['variables']
259 'variables': variables,
260 'target_defaults': output
262 pprint.pprint(output, indent=2)
264 fn = os.path.join(root_dir, 'config.gypi')
265 print "creating ", fn
268 f.write("# Do not edit. Generated by the configure script.\n")
269 pprint.pprint(output, stream=f, indent=2)
273 subprocess.call(['tools/gyp_node','-f', 'make'])