10 CC = os.environ.get('CC', 'cc')
12 root_dir = os.path.dirname(__file__)
13 sys.path.insert(0, os.path.join(root_dir, 'tools', 'gyp', 'pylib'))
14 from gyp.common import GetFlavor
17 parser = optparse.OptionParser()
19 parser.add_option("--debug",
22 help="Also build debug build")
24 parser.add_option("--prefix",
27 help="Select the install prefix (defaults to /usr/local)")
29 parser.add_option("--without-npm",
32 help="Don\'t install the bundled npm package manager")
34 parser.add_option("--without-ssl",
37 help="Build without SSL")
39 parser.add_option("--without-snapshot",
41 dest="without_snapshot",
42 help="Build without snapshotting V8 libraries. You might want to set"
43 " this for cross-compiling. [Default: False]")
45 parser.add_option("--shared-v8",
48 help="Link to a shared V8 DLL instead of static linking")
50 parser.add_option("--shared-v8-includes",
52 dest="shared_v8_includes",
53 help="Directory containing V8 header files")
55 parser.add_option("--shared-v8-libpath",
57 dest="shared_v8_libpath",
58 help="A directory to search for the shared V8 DLL")
60 parser.add_option("--shared-v8-libname",
62 dest="shared_v8_libname",
63 help="Alternative lib name to link to (default: 'v8')")
65 parser.add_option("--shared-openssl",
67 dest="shared_openssl",
68 help="Link to a shared OpenSSl DLL instead of static linking")
70 parser.add_option("--shared-openssl-includes",
72 dest="shared_openssl_includes",
73 help="Directory containing OpenSSL header files")
75 parser.add_option("--shared-openssl-libpath",
77 dest="shared_openssl_libpath",
78 help="A directory to search for the shared OpenSSL DLLs")
80 parser.add_option("--shared-openssl-libname",
82 dest="shared_openssl_libname",
83 help="Alternative lib name to link to (default: 'crypto,ssl')")
86 parser.add_option("--openssl-use-sys",
88 dest="shared_openssl",
89 help=optparse.SUPPRESS_HELP)
92 parser.add_option("--openssl-includes",
94 dest="shared_openssl_includes",
95 help=optparse.SUPPRESS_HELP)
98 parser.add_option("--openssl-libpath",
100 dest="shared_openssl_libpath",
101 help=optparse.SUPPRESS_HELP)
103 # TODO document when we've decided on what the tracing API and its options will
105 parser.add_option("--systemtap-includes",
107 dest="systemtap_includes",
108 help=optparse.SUPPRESS_HELP)
110 parser.add_option("--no-ssl2",
113 help="Disable OpenSSL v2")
115 parser.add_option("--shared-zlib",
118 help="Link to a shared zlib DLL instead of static linking")
120 parser.add_option("--shared-zlib-includes",
122 dest="shared_zlib_includes",
123 help="Directory containing zlib header files")
125 parser.add_option("--shared-zlib-libpath",
127 dest="shared_zlib_libpath",
128 help="A directory to search for the shared zlib DLL")
130 parser.add_option("--shared-zlib-libname",
132 dest="shared_zlib_libname",
133 help="Alternative lib name to link to (default: 'z')")
135 parser.add_option("--shared-http-parser",
137 dest="shared_http_parser",
138 help="Link to a shared http_parser DLL instead of static linking")
140 parser.add_option("--shared-http-parser-includes",
142 dest="shared_http_parser_includes",
143 help="Directory containing http_parser header files")
145 parser.add_option("--shared-http-parser-libpath",
147 dest="shared_http_parser_libpath",
148 help="A directory to search for the shared http_parser DLL")
150 parser.add_option("--shared-http-parser-libname",
152 dest="shared_http_parser_libname",
153 help="Alternative lib name to link to (default: 'http_parser')")
155 parser.add_option("--shared-cares",
158 help="Link to a shared cares DLL instead of static linking")
160 parser.add_option("--shared-cares-includes",
162 dest="shared_cares_includes",
163 help="Directory containing cares header files")
165 parser.add_option("--shared-cares-libpath",
167 dest="shared_cares_libpath",
168 help="A directory to search for the shared cares DLL")
170 parser.add_option("--shared-cares-libname",
172 dest="shared_cares_libname",
173 help="Alternative lib name to link to (default: 'cares')")
175 parser.add_option("--shared-libuv",
178 help="Link to a shared libuv DLL instead of static linking")
180 parser.add_option("--shared-libuv-includes",
182 dest="shared_libuv_includes",
183 help="Directory containing libuv header files")
185 parser.add_option("--shared-libuv-libpath",
187 dest="shared_libuv_libpath",
188 help="A directory to search for the shared libuv DLL")
190 parser.add_option("--shared-libuv-libname",
192 dest="shared_libuv_libname",
193 help="Alternative lib name to link to (default: 'uv')")
195 parser.add_option("--with-dtrace",
198 help="Build with DTrace (default is true on sunos)")
200 parser.add_option("--without-dtrace",
202 dest="without_dtrace",
203 help="Build without DTrace")
205 parser.add_option("--with-etw",
208 help="Build with ETW (default is true on Windows)")
210 parser.add_option("--without-etw",
213 help="Build without ETW")
215 parser.add_option("--with-perfctr",
218 help="Build with performance counters (default is true on Windows)")
220 parser.add_option("--without-perfctr",
222 dest="without_perfctr",
223 help="Build without performance counters")
225 # CHECKME does this still work with recent releases of V8?
226 parser.add_option("--gdb",
229 help="add gdb support")
231 parser.add_option("--dest-cpu",
234 help="CPU architecture to build for. Valid values are: arm, ia32, x64")
236 parser.add_option("--dest-os",
239 help="Operating system to build for. Valid values are: "
240 "win, mac, solaris, freebsd, openbsd, linux, android")
242 parser.add_option("--no-ifaddrs",
245 help="Use on deprecated SunOS systems that do not support ifaddrs.h")
247 parser.add_option("--with-arm-float-abi",
249 dest="arm_float_abi",
250 help="Specifies which floating-point ABI to use. Valid values are: "
251 "soft, softfp, hard")
253 parser.add_option("--ninja",
256 help="Generate files for the ninja build system")
258 # Using --unsafe-optimizations voids your warranty.
259 parser.add_option("--unsafe-optimizations",
261 dest="unsafe_optimizations",
262 help=optparse.SUPPRESS_HELP)
264 parser.add_option("--xcode",
267 help="Generate build files for use with xcode")
269 parser.add_option("--tag",
272 help="Custom build tag")
274 (options, args) = parser.parse_args()
278 """Returns the string 'true' if value is truthy, 'false' otherwise."""
286 cmd = os.popen('pkg-config --libs %s' % pkg, 'r')
287 libs = cmd.readline().strip()
289 if (ret): return None
291 cmd = os.popen('pkg-config --cflags %s' % pkg, 'r')
292 cflags = cmd.readline().strip()
294 if (ret): return None
296 return (libs, cflags)
299 def cc_macros(cc=None):
300 """Checks predefined macros using the C compiler command."""
306 p = subprocess.Popen(shlex.split(cc) + ['-dM', '-E', '-'],
307 stdin=subprocess.PIPE,
308 stdout=subprocess.PIPE,
309 stderr=subprocess.PIPE)
311 print '''Node.js configure error: No acceptable C compiler found!
313 Please make sure you have a C compiler installed on your system and/or
314 consider adjusting the CC environment variable if you installed
315 it in a non-standard prefix.
320 out = p.communicate()[0]
322 out = str(out).split('\n')
326 lst = shlex.split(line)
335 """Check for ARMv7 instructions"""
336 cc_macros_cache = cc_macros()
337 return ('__ARM_ARCH_7__' in cc_macros_cache or
338 '__ARM_ARCH_7A__' in cc_macros_cache or
339 '__ARM_ARCH_7R__' in cc_macros_cache or
340 '__ARM_ARCH_7M__' in cc_macros_cache)
344 """Check for ARM NEON support"""
345 return '__ARM_NEON__' in cc_macros()
348 def is_arm_hard_float_abi():
349 """Check for hardfloat or softfloat eabi on ARM"""
350 # GCC versions 4.6 and above define __ARM_PCS or __ARM_PCS_VFP to specify
351 # the Floating Point ABI used (PCS stands for Procedure Call Standard).
352 # We use these as well as a couple of other defines to statically determine
354 # GCC versions 4.4 and below don't support hard-fp.
355 # GCC versions 4.5 may support hard-fp without defining __ARM_PCS or
358 if compiler_version() >= (4, 6, 0):
359 return '__ARM_PCS_VFP' in cc_macros()
360 elif compiler_version() < (4, 5, 0):
362 elif '__ARM_PCS_VFP' in cc_macros():
364 elif ('__ARM_PCS' in cc_macros() or
365 '__SOFTFP' in cc_macros() or
366 not '__VFP_FP__' in cc_macros()):
369 print '''Node.js configure error: Your version of GCC does not report
370 the Floating-Point ABI to compile for your hardware
372 Please manually specify which floating-point ABI to use with the
373 --with-arm-float-abi option.
379 """Host architecture check using the CC command."""
381 # use 'cc', as CC may be set to a target arch compiler command
382 # in case of cross-compilation
386 '__x86_64__' : 'x64',
392 rtn = 'ia32' # default
395 if i in k and k[i] != '0':
403 """Host architecture check using environ vars (better way to do this?)"""
405 arch = os.environ.get('PROCESSOR_ARCHITECTURE', 'x86')
414 return matchup.get(arch, 'ia32')
417 def compiler_version():
419 proc = subprocess.Popen(shlex.split(CC) + ['--version'], stdout=subprocess.PIPE)
423 is_clang = 'clang' in proc.communicate()[0].split('\n')[0]
425 proc = subprocess.Popen(shlex.split(CC) + ['-dumpversion'], stdout=subprocess.PIPE)
426 version = tuple(map(int, proc.communicate()[0].split('.')))
428 return (version, is_clang)
431 def configure_arm(o):
432 if options.arm_float_abi:
433 arm_float_abi = options.arm_float_abi
435 arm_float_abi = 'hard' if is_arm_hard_float_abi() else 'default'
436 o['variables']['armv7'] = int(is_arch_armv7())
437 o['variables']['arm_fpu'] = 'vfpv3' # V8 3.18 no longer supports VFP2.
438 o['variables']['arm_neon'] = int(is_arm_neon())
439 o['variables']['arm_thumb'] = 0 # -marm
440 o['variables']['arm_float_abi'] = arm_float_abi
443 def configure_node(o):
444 if options.dest_os == 'android':
445 o['variables']['OS'] = "android"
446 o['variables']['v8_enable_gdbjit'] = 1 if options.gdb else 0
447 o['variables']['v8_no_strict_aliasing'] = 1 # work around compiler bugs
448 o['variables']['node_prefix'] = os.path.expanduser(options.prefix or '')
449 o['variables']['node_install_npm'] = b(not options.without_npm)
450 o['variables']['node_unsafe_optimizations'] = (
451 1 if options.unsafe_optimizations else 0)
452 o['default_configuration'] = 'Debug' if options.debug else 'Release'
454 host_arch = host_arch_win() if os.name == 'nt' else host_arch_cc()
455 target_arch = options.dest_cpu or host_arch
456 o['variables']['host_arch'] = host_arch
457 o['variables']['target_arch'] = target_arch
459 if target_arch == 'arm':
462 cc_version, is_clang = compiler_version()
463 o['variables']['clang'] = 1 if is_clang else 0
465 if not is_clang and cc_version != 0:
466 o['variables']['gcc_version'] = 10 * cc_version[0] + cc_version[1]
468 # clang has always supported -fvisibility=hidden, right?
469 if not is_clang and cc_version < (4,0,0):
470 o['variables']['visibility'] = ''
472 # By default, enable DTrace on SunOS systems. Don't allow it on other
473 # systems, since it won't work. (The MacOS build process is different than
474 # SunOS, and we haven't implemented it.)
475 if flavor in ('solaris', 'mac'):
476 o['variables']['node_use_dtrace'] = b(not options.without_dtrace)
477 o['variables']['uv_use_dtrace'] = o['variables']['node_use_dtrace']
478 o['variables']['uv_parent_path'] = '/deps/uv/'
479 elif flavor == 'linux':
480 o['variables']['node_use_dtrace'] = 'false'
481 o['variables']['node_use_systemtap'] = b(options.with_dtrace)
482 if options.systemtap_includes:
483 o['include_dirs'] += [options.systemtap_includes]
484 elif options.with_dtrace:
486 'DTrace is currently only supported on SunOS, MacOS or Linux systems.')
488 o['variables']['node_use_dtrace'] = 'false'
489 o['variables']['node_use_systemtap'] = 'false'
491 if options.no_ifaddrs:
492 o['defines'] += ['SUNOS_NO_IFADDRS']
494 # By default, enable ETW on Windows.
496 o['variables']['node_use_etw'] = b(not options.without_etw);
497 elif options.with_etw:
498 raise Exception('ETW is only supported on Windows.')
500 o['variables']['node_use_etw'] = 'false'
502 # By default, enable Performance counters on Windows.
504 o['variables']['node_use_perfctr'] = b(not options.without_perfctr);
505 elif options.with_perfctr:
506 raise Exception('Performance counter is only supported on Windows.')
508 o['variables']['node_use_perfctr'] = 'false'
511 o['variables']['node_tag'] = '-' + options.tag
513 o['variables']['node_tag'] = ''
516 def configure_libz(o):
517 o['variables']['node_shared_zlib'] = b(options.shared_zlib)
519 # assume shared_zlib if one of these is set?
520 if options.shared_zlib_libpath:
521 o['libraries'] += ['-L%s' % options.shared_zlib_libpath]
522 if options.shared_zlib_libname:
523 o['libraries'] += ['-l%s' % options.shared_zlib_libname]
524 elif options.shared_zlib:
525 o['libraries'] += ['-lz']
526 if options.shared_zlib_includes:
527 o['include_dirs'] += [options.shared_zlib_includes]
530 def configure_http_parser(o):
531 o['variables']['node_shared_http_parser'] = b(options.shared_http_parser)
533 # assume shared http_parser if one of these is set?
534 if options.shared_http_parser_libpath:
535 o['libraries'] += ['-L%s' % options.shared_http_parser_libpath]
536 if options.shared_http_parser_libname:
537 o['libraries'] += ['-l%s' % options.shared_http_parser_libname]
538 elif options.shared_http_parser:
539 o['libraries'] += ['-lhttp_parser']
540 if options.shared_http_parser_includes:
541 o['include_dirs'] += [options.shared_http_parser_includes]
544 def configure_cares(o):
545 o['variables']['node_shared_cares'] = b(options.shared_cares)
547 # assume shared cares if one of these is set?
548 if options.shared_cares_libpath:
549 o['libraries'] += ['-L%s' % options.shared_cares_libpath]
550 if options.shared_cares_libname:
551 o['libraries'] += ['-l%s' % options.shared_cares_libname]
552 elif options.shared_cares:
553 o['libraries'] += ['-lcares']
554 if options.shared_cares_includes:
555 o['include_dirs'] += [options.shared_cares_includes]
558 def configure_libuv(o):
559 o['variables']['node_shared_libuv'] = b(options.shared_libuv)
561 # assume shared libuv if one of these is set?
562 if options.shared_libuv_libpath:
563 o['libraries'] += ['-L%s' % options.shared_libuv_libpath]
564 if options.shared_libuv_libname:
565 o['libraries'] += ['-l%s' % options.shared_libuv_libname]
566 elif options.shared_libuv:
567 o['libraries'] += ['-luv']
568 if options.shared_libuv_includes:
569 o['include_dirs'] += [options.shared_libuv_includes]
573 o['variables']['v8_use_snapshot'] = b(not options.without_snapshot)
574 o['variables']['node_shared_v8'] = b(options.shared_v8)
576 # assume shared_v8 if one of these is set?
577 if options.shared_v8_libpath:
578 o['libraries'] += ['-L%s' % options.shared_v8_libpath]
579 if options.shared_v8_libname:
580 o['libraries'] += ['-l%s' % options.shared_v8_libname]
581 elif options.shared_v8:
582 o['libraries'] += ['-lv8']
583 if options.shared_v8_includes:
584 o['include_dirs'] += [options.shared_v8_includes]
587 def configure_openssl(o):
588 o['variables']['node_use_openssl'] = b(not options.without_ssl)
589 o['variables']['node_shared_openssl'] = b(options.shared_openssl)
591 if options.without_ssl:
595 o['defines'] += ['OPENSSL_NO_SSL2=1']
597 if options.shared_openssl:
598 (libs, cflags) = pkg_config('openssl') or ('-lssl -lcrypto', '')
600 if options.shared_openssl_libpath:
601 o['libraries'] += ['-L%s' % options.shared_openssl_libpath]
603 if options.shared_openssl_libname:
604 libnames = options.shared_openssl_libname.split(',')
605 o['libraries'] += ['-l%s' % s for s in libnames]
607 o['libraries'] += libs.split()
609 if options.shared_openssl_includes:
610 o['include_dirs'] += [options.shared_openssl_includes]
612 o['cflags'] += cflags.split()
615 def configure_winsdk(o):
619 winsdk_dir = os.environ.get("WindowsSdkDir")
621 if winsdk_dir and os.path.isfile(winsdk_dir + '\\bin\\ctrpp.exe'):
622 print "Found ctrpp in WinSDK--will build generated files into tools/msvs/genfiles."
623 o['variables']['node_has_winsdk'] = 'true'
626 print "ctrpp not found in WinSDK path--using pre-gen files from tools/msvs/genfiles."
629 # determine the "flavor" (operating system) we're building for,
630 # leveraging gyp's GetFlavor function
632 if (options.dest_os):
633 flavor_params['flavor'] = options.dest_os;
634 flavor = GetFlavor(flavor_params);
637 'variables': { 'python': sys.executable },
644 configure_node(output)
645 configure_libz(output)
646 configure_http_parser(output)
647 configure_cares(output)
648 configure_libuv(output)
650 configure_openssl(output)
651 configure_winsdk(output)
654 # variables should be a root level element,
655 # move everything else to target_defaults
656 variables = output['variables']
657 del output['variables']
659 'variables': variables,
660 'target_defaults': output
662 pprint.pprint(output, indent=2)
664 def write(filename, data):
665 filename = os.path.join(root_dir, filename)
666 print "creating ", filename
667 f = open(filename, 'w+')
670 write('config.gypi', "# Do not edit. Generated by the configure script.\n" +
671 pprint.pformat(output, indent=2) + "\n")
674 'BUILDTYPE': 'Debug' if options.debug else 'Release',
675 'USE_NINJA': str(int(options.use_ninja or 0)),
676 'USE_XCODE': str(int(options.use_xcode or 0)),
677 'PYTHON': sys.executable,
681 config['PREFIX'] = options.prefix
683 config = '\n'.join(map('='.join, config.iteritems())) + '\n'
686 '# Do not edit. Generated by the configure script.\n' + config)
688 if options.use_ninja:
689 gyp_args = ['-f', 'ninja-' + flavor]
690 elif options.use_xcode:
691 gyp_args = ['-f', 'xcode']
692 elif flavor == 'win':
693 gyp_args = ['-f', 'msvs', '-G', 'msvs_version=auto']
695 gyp_args = ['-f', 'make-' + flavor]
697 subprocess.call([sys.executable, 'tools/gyp_node'] + gyp_args)