9 CC = os.environ.get('CC', 'cc')
11 root_dir = os.path.dirname(__file__)
12 sys.path.insert(0, os.path.join(root_dir, 'deps', 'v8', 'tools'))
15 parser = optparse.OptionParser()
17 parser.add_option("--debug",
20 help="Also build debug build")
22 parser.add_option("--prefix",
25 help="Select the install prefix (defaults to /usr/local)")
27 parser.add_option("--without-npm",
30 help="Don\'t install the bundled npm package manager")
32 parser.add_option("--without-ssl",
35 help="Build without SSL")
37 parser.add_option("--without-snapshot",
39 dest="without_snapshot",
40 help="Build without snapshotting V8 libraries. You might want to set"
41 " this for cross-compiling. [Default: False]")
43 parser.add_option("--shared-v8",
46 help="Link to a shared V8 DLL instead of static linking")
48 parser.add_option("--shared-v8-includes",
50 dest="shared_v8_includes",
51 help="Directory containing V8 header files")
53 parser.add_option("--shared-v8-libpath",
55 dest="shared_v8_libpath",
56 help="A directory to search for the shared V8 DLL")
58 parser.add_option("--shared-v8-libname",
60 dest="shared_v8_libname",
61 help="Alternative lib name to link to (default: 'v8')")
63 parser.add_option("--shared-openssl",
65 dest="shared_openssl",
66 help="Link to a shared OpenSSl DLL instead of static linking")
68 parser.add_option("--shared-openssl-includes",
70 dest="shared_openssl_includes",
71 help="Directory containing OpenSSL header files")
73 parser.add_option("--shared-openssl-libpath",
75 dest="shared_openssl_libpath",
76 help="A directory to search for the shared OpenSSL DLLs")
78 parser.add_option("--shared-openssl-libname",
80 dest="shared_openssl_libname",
81 help="Alternative lib name to link to (default: 'crypto,ssl')")
84 parser.add_option("--openssl-use-sys",
86 dest="shared_openssl",
87 help=optparse.SUPPRESS_HELP)
90 parser.add_option("--openssl-includes",
92 dest="shared_openssl_includes",
93 help=optparse.SUPPRESS_HELP)
96 parser.add_option("--openssl-libpath",
98 dest="shared_openssl_libpath",
99 help=optparse.SUPPRESS_HELP)
101 parser.add_option("--no-ssl2",
104 help="Disable OpenSSL v2")
106 parser.add_option("--shared-zlib",
109 help="Link to a shared zlib DLL instead of static linking")
111 parser.add_option("--shared-zlib-includes",
113 dest="shared_zlib_includes",
114 help="Directory containing zlib header files")
116 parser.add_option("--shared-zlib-libpath",
118 dest="shared_zlib_libpath",
119 help="A directory to search for the shared zlib DLL")
121 parser.add_option("--shared-zlib-libname",
123 dest="shared_zlib_libname",
124 help="Alternative lib name to link to (default: 'z')")
126 parser.add_option("--with-dtrace",
129 help="Build with DTrace (default is true on supported systems)")
131 parser.add_option("--without-dtrace",
133 dest="without_dtrace",
134 help="Build without DTrace")
136 parser.add_option("--with-etw",
139 help="Build with ETW (default is true on Windows)")
141 parser.add_option("--without-etw",
144 help="Build without ETW")
146 # CHECKME does this still work with recent releases of V8?
147 parser.add_option("--gdb",
150 help="add gdb support")
152 parser.add_option("--dest-cpu",
155 help="CPU architecture to build for. Valid values are: arm, ia32, x64")
157 parser.add_option("--no-ifaddrs",
160 help="Use on deprecated SunOS systems that do not support ifaddrs.h")
162 parser.add_option("--with-arm-float-abi",
164 dest="arm_float_abi",
165 help="Specifies which floating-point ABI to use. Valid values are: "
166 "soft, softfp, hard")
168 (options, args) = parser.parse_args()
172 """Returns the string 'true' if value is truthy, 'false' otherwise."""
180 cmd = os.popen('pkg-config --libs %s' % pkg, 'r')
181 libs = cmd.readline().strip()
183 if (ret): return None
185 cmd = os.popen('pkg-config --cflags %s' % pkg, 'r')
186 cflags = cmd.readline().strip()
188 if (ret): return None
190 return (libs, cflags)
194 """Checks predefined macros using the CC command."""
197 p = subprocess.Popen(CC.split() + ['-dM', '-E', '-'],
198 stdin=subprocess.PIPE,
199 stdout=subprocess.PIPE,
200 stderr=subprocess.PIPE)
202 print '''Node.js configure error: No acceptable C compiler found!
204 Please make sure you have a C compiler installed on your system and/or
205 consider adjusting the CC environment variable if you installed
206 it in a non-standard prefix.
211 out = p.communicate()[0]
213 out = str(out).split('\n')
218 lst = shlex.split(line)
227 """Check for ARMv7 instructions"""
228 cc_macros_cache = cc_macros()
229 return ('__ARM_ARCH_7__' in cc_macros_cache or
230 '__ARM_ARCH_7A__' in cc_macros_cache or
231 '__ARM_ARCH_7R__' in cc_macros_cache or
232 '__ARM_ARCH_7M__' in cc_macros_cache)
235 def arm_hard_float_abi():
236 """Check for hardfloat or softfloat eabi on ARM"""
237 # GCC versions 4.6 and above define __ARM_PCS or __ARM_PCS_VFP to specify
238 # the Floating Point ABI used (PCS stands for Procedure Call Standard).
239 # We use these as well as a couple of other defines to statically determine
241 # GCC versions 4.4 and below don't support hard-fp.
242 # GCC versions 4.5 may support hard-fp without defining __ARM_PCS or
245 if compiler_version() >= (4, 6, 0):
246 return '__ARM_PCS_VFP' in cc_macros()
247 elif compiler_version() < (4, 5, 0):
249 elif '__ARM_PCS_VFP' in cc_macros():
251 elif ('__ARM_PCS' in cc_macros() or
252 '__SOFTFP' in cc_macros() or
253 not '__VFP_FP__' in cc_macros()):
256 print '''Node.js configure error: Your version of GCC does not report
257 the Floating-Point ABI to compile for your hardware
259 Please manually specify which floating-point ABI to use with the
260 --with-arm-float-abi option.
266 """Host architecture check using the CC command."""
271 '__x86_64__' : 'x64',
276 rtn = 'ia32' # default
279 if i in k and k[i] != '0':
287 """Host architecture check using environ vars (better way to do this?)"""
289 arch = os.environ.get('PROCESSOR_ARCHITECTURE', 'x86')
297 return matchup.get(arch, 'ia32')
300 def compiler_version():
302 proc = subprocess.Popen(CC.split() + ['--version'], stdout=subprocess.PIPE)
306 is_clang = 'clang' in proc.communicate()[0].split('\n')[0]
308 proc = subprocess.Popen(CC.split() + ['-dumpversion'], stdout=subprocess.PIPE)
309 version = tuple(map(int, proc.communicate()[0].split('.')))
311 return (version, is_clang)
314 def configure_node(o):
316 o['variables']['v8_no_strict_aliasing'] = 1 # work around compiler bugs
317 o['variables']['node_prefix'] = os.path.expanduser(options.prefix or '')
318 o['variables']['node_install_npm'] = b(not options.without_npm)
319 o['default_configuration'] = 'Debug' if options.debug else 'Release'
321 host_arch = host_arch_win() if os.name == 'nt' else host_arch_cc()
322 target_arch = options.dest_cpu or host_arch
323 o['variables']['host_arch'] = host_arch
324 o['variables']['target_arch'] = target_arch
326 # V8 on ARM requires that armv7 is set. CPU Model detected by
327 # the presence of __ARM_ARCH_7__ and the like defines in compiler
328 if target_arch == 'arm':
329 if options.arm_float_abi:
330 hard_float = options.arm_float_abi == 'hard'
332 hard_float = arm_hard_float_abi()
333 o['variables']['v8_use_arm_eabi_hardfloat'] = b(hard_float)
334 o['variables']['armv7'] = 1 if is_arch_armv7() else 0
336 cc_version, is_clang = compiler_version()
337 o['variables']['clang'] = 1 if is_clang else 0
339 if not is_clang and cc_version != 0:
340 o['variables']['gcc_version'] = 10 * cc_version[0] + cc_version[1]
342 # clang has always supported -fvisibility=hidden, right?
343 if not is_clang and cc_version < (4,0,0):
344 o['variables']['visibility'] = ''
346 # By default, enable DTrace on SunOS systems. Don't allow it on other
347 # systems, since it won't work. (The MacOS build process is different than
348 # SunOS, and we haven't implemented it.)
349 if sys.platform.startswith('sunos'):
350 o['variables']['node_use_dtrace'] = b(not options.without_dtrace)
351 elif b(options.with_dtrace) == 'true':
352 raise Exception('DTrace is currently only supported on SunOS systems.')
354 o['variables']['node_use_dtrace'] = 'false'
356 if options.no_ifaddrs:
357 o['defines'] += ['SUNOS_NO_IFADDRS']
359 # By default, enable ETW on Windows.
360 if sys.platform.startswith('win32'):
361 o['variables']['node_use_etw'] = b(not options.without_etw);
362 elif b(options.with_etw) == 'true':
363 raise Exception('ETW is only supported on Windows.')
365 o['variables']['node_use_etw'] = 'false'
368 def configure_libz(o):
369 o['variables']['node_shared_zlib'] = b(options.shared_zlib)
371 # assume shared_zlib if one of these is set?
372 if options.shared_zlib_libpath:
373 o['libraries'] += ['-L%s' % options.shared_zlib_libpath]
374 if options.shared_zlib_libname:
375 o['libraries'] += ['-l%s' % options.shared_zlib_libname]
376 elif options.shared_zlib:
377 o['libraries'] += ['-lz']
378 if options.shared_zlib_includes:
379 o['include_dirs'] += [options.shared_zlib_includes]
383 o['variables']['v8_use_snapshot'] = b(not options.without_snapshot)
384 o['variables']['node_shared_v8'] = b(options.shared_v8)
386 # assume shared_v8 if one of these is set?
387 if options.shared_v8_libpath:
388 o['libraries'] += ['-L%s' % options.shared_v8_libpath]
389 if options.shared_v8_libname:
390 o['libraries'] += ['-l%s' % options.shared_v8_libname]
391 elif options.shared_v8:
392 o['libraries'] += ['-lv8']
393 if options.shared_v8_includes:
394 o['include_dirs'] += [options.shared_v8_includes]
397 def configure_openssl(o):
398 o['variables']['node_use_openssl'] = b(not options.without_ssl)
399 o['variables']['node_shared_openssl'] = b(options.shared_openssl)
401 if options.without_ssl:
405 o['defines'] += ['OPENSSL_NO_SSL2=1']
407 if options.shared_openssl:
408 (libs, cflags) = pkg_config('openssl') or ('-lssl -lcrypto', '')
410 if options.shared_openssl_libpath:
411 o['libraries'] += ['-L%s' % options.shared_openssl_libpath]
413 if options.shared_openssl_libname:
414 libnames = options.shared_openssl_libname.split(',')
415 o['libraries'] += ['-l%s' % s for s in libnames]
417 o['libraries'] += libs.split()
419 if options.shared_openssl_includes:
420 o['include_dirs'] += [options.shared_openssl_includes]
422 o['cflags'] += cflags.split()
433 configure_node(output)
434 configure_libz(output)
436 configure_openssl(output)
438 # variables should be a root level element,
439 # move everything else to target_defaults
440 variables = output['variables']
441 del output['variables']
443 'variables': variables,
444 'target_defaults': output
446 pprint.pprint(output, indent=2)
448 def write(filename, data):
449 filename = os.path.join(root_dir, filename)
450 print "creating ", filename
451 f = open(filename, 'w+')
454 write('config.gypi', "# Do not edit. Generated by the configure script.\n" +
455 pprint.pformat(output, indent=2) + "\n")
457 write('config.mk', "# Do not edit. Generated by the configure script.\n" +
458 ("BUILDTYPE=%s\n" % ('Debug' if options.debug else 'Release')))
461 gyp_args = ['-f', 'msvs', '-G', 'msvs_version=2010']
463 gyp_args = ['-f', 'make']
465 subprocess.call([sys.executable, 'tools/gyp_node'] + gyp_args)