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 # Options should be in alphabetical order but keep --prefix at the top,
20 # that's arguably the one people will be looking for most.
21 parser.add_option('--prefix',
24 help='select the install prefix (defaults to /usr/local)')
26 parser.add_option('--debug',
29 help='also build debug build')
31 parser.add_option('--dest-cpu',
34 help='CPU architecture to build for. Valid values are: arm, ia32, x64')
36 parser.add_option('--dest-os',
39 help='operating system to build for. Valid values are: '
40 'win, mac, solaris, freebsd, openbsd, linux, android')
42 parser.add_option('--gdb',
45 help='add gdb support')
47 parser.add_option('--ninja',
50 help='generate files for the ninja build system')
52 parser.add_option('--no-ifaddrs',
55 help='use on deprecated SunOS systems that do not support ifaddrs.h')
58 parser.add_option('--openssl-includes',
60 dest='shared_openssl_includes',
61 help=optparse.SUPPRESS_HELP)
64 parser.add_option('--openssl-libpath',
66 dest='shared_openssl_libpath',
67 help=optparse.SUPPRESS_HELP)
70 parser.add_option('--openssl-use-sys',
72 dest='shared_openssl',
73 help=optparse.SUPPRESS_HELP)
75 parser.add_option('--shared-cares',
78 help='link to a shared cares DLL instead of static linking')
80 parser.add_option('--shared-cares-includes',
82 dest='shared_cares_includes',
83 help='directory containing cares header files')
85 parser.add_option('--shared-cares-libname',
87 dest='shared_cares_libname',
88 help='alternative lib name to link to (default: \'cares\')')
90 parser.add_option('--shared-cares-libpath',
92 dest='shared_cares_libpath',
93 help='a directory to search for the shared cares DLL')
95 parser.add_option('--shared-http-parser',
97 dest='shared_http_parser',
98 help='link to a shared http_parser DLL instead of static linking')
100 parser.add_option('--shared-http-parser-includes',
102 dest='shared_http_parser_includes',
103 help='directory containing http_parser header files')
105 parser.add_option('--shared-http-parser-libname',
107 dest='shared_http_parser_libname',
108 help='alternative lib name to link to (default: \'http_parser\')')
110 parser.add_option('--shared-http-parser-libpath',
112 dest='shared_http_parser_libpath',
113 help='a directory to search for the shared http_parser DLL')
115 parser.add_option('--shared-libuv',
118 help='link to a shared libuv DLL instead of static linking')
120 parser.add_option('--shared-libuv-includes',
122 dest='shared_libuv_includes',
123 help='directory containing libuv header files')
125 parser.add_option('--shared-libuv-libname',
127 dest='shared_libuv_libname',
128 help='alternative lib name to link to (default: \'uv\')')
130 parser.add_option('--shared-libuv-libpath',
132 dest='shared_libuv_libpath',
133 help='a directory to search for the shared libuv DLL')
135 parser.add_option('--shared-openssl',
137 dest='shared_openssl',
138 help='link to a shared OpenSSl DLL instead of static linking')
140 parser.add_option('--shared-openssl-includes',
142 dest='shared_openssl_includes',
143 help='directory containing OpenSSL header files')
145 parser.add_option('--shared-openssl-libname',
147 dest='shared_openssl_libname',
148 help='alternative lib name to link to (default: \'crypto,ssl\')')
150 parser.add_option('--shared-openssl-libpath',
152 dest='shared_openssl_libpath',
153 help='a directory to search for the shared OpenSSL DLLs')
155 parser.add_option('--shared-v8',
158 help='link to a shared V8 DLL instead of static linking')
160 parser.add_option('--shared-v8-includes',
162 dest='shared_v8_includes',
163 help='directory containing V8 header files')
165 parser.add_option('--shared-v8-libname',
167 dest='shared_v8_libname',
168 help='alternative lib name to link to (default: \'v8\')')
170 parser.add_option('--shared-v8-libpath',
172 dest='shared_v8_libpath',
173 help='a directory to search for the shared V8 DLL')
175 parser.add_option('--shared-zlib',
178 help='link to a shared zlib DLL instead of static linking')
180 parser.add_option('--shared-zlib-includes',
182 dest='shared_zlib_includes',
183 help='directory containing zlib header files')
185 parser.add_option('--shared-zlib-libname',
187 dest='shared_zlib_libname',
188 help='alternative lib name to link to (default: \'z\')')
190 parser.add_option('--shared-zlib-libpath',
192 dest='shared_zlib_libpath',
193 help='a directory to search for the shared zlib DLL')
195 # TODO document when we've decided on what the tracing API and its options will
197 parser.add_option('--systemtap-includes',
199 dest='systemtap_includes',
200 help=optparse.SUPPRESS_HELP)
202 parser.add_option('--tag',
205 help='custom build tag')
207 parser.add_option('--with-arm-float-abi',
209 dest='arm_float_abi',
210 help='specifies which floating-point ABI to use. Valid values are: '
211 'soft, softfp, hard')
213 parser.add_option('--with-dtrace',
216 help='build with DTrace (default is true on sunos)')
218 parser.add_option('--with-etw',
221 help='build with ETW (default is true on Windows)')
223 parser.add_option('--with-icu-path',
225 dest='with_icu_path',
226 help='Path to icu.gyp (ICU i18n, Chromium version only.)')
228 parser.add_option('--with-perfctr',
231 help='build with performance counters (default is true on Windows)')
233 parser.add_option('--with-sslv2',
236 help='enable SSL v2')
238 parser.add_option('--without-dtrace',
240 dest='without_dtrace',
241 help='build without DTrace')
243 parser.add_option('--without-etw',
246 help='build without ETW')
248 parser.add_option('--without-npm',
251 help='don\'t install the bundled npm package manager')
253 parser.add_option('--without-perfctr',
255 dest='without_perfctr',
256 help='build without performance counters')
258 parser.add_option('--without-snapshot',
260 dest='without_snapshot',
261 help='build without snapshotting V8 libraries. You might want to set'
262 ' this for cross-compiling. [Default: False]')
264 parser.add_option('--without-ssl',
267 help='build without SSL')
269 parser.add_option('--xcode',
272 help='generate build files for use with xcode')
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)
300 """Checks predefined macros using the CC command."""
303 p = subprocess.Popen(shlex.split(CC) + ['-dM', '-E', '-'],
304 stdin=subprocess.PIPE,
305 stdout=subprocess.PIPE,
306 stderr=subprocess.PIPE)
308 print '''Node.js configure error: No acceptable C compiler found!
310 Please make sure you have a C compiler installed on your system and/or
311 consider adjusting the CC environment variable if you installed
312 it in a non-standard prefix.
317 out = p.communicate()[0]
319 out = str(out).split('\n')
323 lst = shlex.split(line)
332 """Check for ARMv7 instructions"""
333 cc_macros_cache = cc_macros()
334 return ('__ARM_ARCH_7__' in cc_macros_cache or
335 '__ARM_ARCH_7A__' in cc_macros_cache or
336 '__ARM_ARCH_7R__' in cc_macros_cache or
337 '__ARM_ARCH_7M__' in cc_macros_cache)
341 """Check for ARM NEON support"""
342 return '__ARM_NEON__' in cc_macros()
345 def is_arm_hard_float_abi():
346 """Check for hardfloat or softfloat eabi on ARM"""
347 # GCC versions 4.6 and above define __ARM_PCS or __ARM_PCS_VFP to specify
348 # the Floating Point ABI used (PCS stands for Procedure Call Standard).
349 # We use these as well as a couple of other defines to statically determine
351 # GCC versions 4.4 and below don't support hard-fp.
352 # GCC versions 4.5 may support hard-fp without defining __ARM_PCS or
355 if compiler_version() >= (4, 6, 0):
356 return '__ARM_PCS_VFP' in cc_macros()
357 elif compiler_version() < (4, 5, 0):
359 elif '__ARM_PCS_VFP' in cc_macros():
361 elif ('__ARM_PCS' in cc_macros() or
362 '__SOFTFP' in cc_macros() or
363 not '__VFP_FP__' in cc_macros()):
366 print '''Node.js configure error: Your version of GCC does not report
367 the Floating-Point ABI to compile for your hardware
369 Please manually specify which floating-point ABI to use with the
370 --with-arm-float-abi option.
376 """Host architecture check using the CC command."""
381 '__x86_64__' : 'x64',
387 rtn = 'ia32' # default
390 if i in k and k[i] != '0':
398 """Host architecture check using environ vars (better way to do this?)"""
400 arch = os.environ.get('PROCESSOR_ARCHITECTURE', 'x86')
409 return matchup.get(arch, 'ia32')
412 def compiler_version():
414 proc = subprocess.Popen(shlex.split(CC) + ['--version'],
415 stdout=subprocess.PIPE)
419 is_clang = 'clang' in proc.communicate()[0].split('\n')[0]
421 proc = subprocess.Popen(shlex.split(CC) + ['-dumpversion'],
422 stdout=subprocess.PIPE)
423 version = tuple(map(int, proc.communicate()[0].split('.')))
425 return (version, is_clang)
428 def configure_arm(o):
429 if options.arm_float_abi:
430 arm_float_abi = options.arm_float_abi
431 elif is_arm_hard_float_abi():
432 arm_float_abi = 'hard'
434 arm_float_abi = 'default'
435 o['variables']['armv7'] = int(is_arch_armv7())
436 o['variables']['arm_fpu'] = 'vfpv3' # V8 3.18 no longer supports VFP2.
437 o['variables']['arm_neon'] = int(is_arm_neon())
438 o['variables']['arm_thumb'] = 0 # -marm
439 o['variables']['arm_float_abi'] = arm_float_abi
442 def configure_node(o):
443 if options.dest_os == 'android':
444 o['variables']['OS'] = 'android'
445 o['variables']['node_prefix'] = os.path.expanduser(options.prefix or '')
446 o['variables']['node_install_npm'] = b(not options.without_npm)
447 o['default_configuration'] = 'Debug' if options.debug else 'Release'
449 host_arch = host_arch_win() if os.name == 'nt' else host_arch_cc()
450 target_arch = options.dest_cpu or host_arch
451 o['variables']['host_arch'] = host_arch
452 o['variables']['target_arch'] = target_arch
454 if target_arch == 'arm':
457 cc_version, is_clang = compiler_version()
458 o['variables']['clang'] = 1 if is_clang else 0
460 if not is_clang and cc_version != 0:
461 o['variables']['gcc_version'] = 10 * cc_version[0] + cc_version[1]
463 # clang has always supported -fvisibility=hidden, right?
464 if not is_clang and cc_version < (4,0,0):
465 o['variables']['visibility'] = ''
467 if flavor in ('solaris', 'mac', 'linux', 'freebsd'):
468 use_dtrace = not options.without_dtrace
469 # Don't enable by default on linux and freebsd
470 if flavor in ('linux', 'freebsd'):
471 use_dtrace = options.with_dtrace
473 if flavor == 'linux':
474 if options.systemtap_includes:
475 o['include_dirs'] += [options.systemtap_includes]
476 o['variables']['node_use_dtrace'] = b(use_dtrace)
477 o['variables']['uv_use_dtrace'] = b(use_dtrace)
478 o['variables']['uv_parent_path'] = '/deps/uv/'
479 elif options.with_dtrace:
481 'DTrace is currently only supported on SunOS, MacOS or Linux systems.')
483 o['variables']['node_use_dtrace'] = 'false'
485 # if we're on illumos based systems wrap the helper library into the
487 if flavor == 'solaris':
488 o['variables']['node_use_mdb'] = 'true'
490 o['variables']['node_use_mdb'] = 'false'
492 if options.no_ifaddrs:
493 o['defines'] += ['SUNOS_NO_IFADDRS']
495 # By default, enable ETW on Windows.
497 o['variables']['node_use_etw'] = b(not options.without_etw)
498 elif options.with_etw:
499 raise Exception('ETW is only supported on Windows.')
501 o['variables']['node_use_etw'] = 'false'
503 # By default, enable Performance counters on Windows.
505 o['variables']['node_use_perfctr'] = b(not options.without_perfctr)
506 elif options.with_perfctr:
507 raise Exception('Performance counter is only supported on Windows.')
509 o['variables']['node_use_perfctr'] = 'false'
512 o['variables']['node_tag'] = '-' + options.tag
514 o['variables']['node_tag'] = ''
517 def configure_libz(o):
518 o['variables']['node_shared_zlib'] = b(options.shared_zlib)
520 # assume shared_zlib if one of these is set?
521 if options.shared_zlib_libpath:
522 o['libraries'] += ['-L%s' % options.shared_zlib_libpath]
523 if options.shared_zlib_libname:
524 o['libraries'] += ['-l%s' % options.shared_zlib_libname]
525 elif options.shared_zlib:
526 o['libraries'] += ['-lz']
527 if options.shared_zlib_includes:
528 o['include_dirs'] += [options.shared_zlib_includes]
531 def configure_http_parser(o):
532 o['variables']['node_shared_http_parser'] = b(options.shared_http_parser)
534 # assume shared http_parser if one of these is set?
535 if options.shared_http_parser_libpath:
536 o['libraries'] += ['-L%s' % options.shared_http_parser_libpath]
537 if options.shared_http_parser_libname:
538 o['libraries'] += ['-l%s' % options.shared_http_parser_libname]
539 elif options.shared_http_parser:
540 o['libraries'] += ['-lhttp_parser']
541 if options.shared_http_parser_includes:
542 o['include_dirs'] += [options.shared_http_parser_includes]
545 def configure_cares(o):
546 o['variables']['node_shared_cares'] = b(options.shared_cares)
548 # assume shared cares if one of these is set?
549 if options.shared_cares_libpath:
550 o['libraries'] += ['-L%s' % options.shared_cares_libpath]
551 if options.shared_cares_libname:
552 o['libraries'] += ['-l%s' % options.shared_cares_libname]
553 elif options.shared_cares:
554 o['libraries'] += ['-lcares']
555 if options.shared_cares_includes:
556 o['include_dirs'] += [options.shared_cares_includes]
559 def configure_libuv(o):
560 o['variables']['node_shared_libuv'] = b(options.shared_libuv)
562 # assume shared libuv if one of these is set?
563 if options.shared_libuv_libpath:
564 o['libraries'] += ['-L%s' % options.shared_libuv_libpath]
566 o['variables']['uv_library'] = 'static_library'
568 if options.shared_libuv_libname:
569 o['libraries'] += ['-l%s' % options.shared_libuv_libname]
570 elif options.shared_libuv:
571 o['libraries'] += ['-luv']
572 if options.shared_libuv_includes:
573 o['include_dirs'] += [options.shared_libuv_includes]
577 o['variables']['node_shared_v8'] = b(options.shared_v8)
578 o['variables']['v8_enable_gdbjit'] = 1 if options.gdb else 0
579 o['variables']['v8_no_strict_aliasing'] = 1 # Work around compiler bugs.
580 o['variables']['v8_optimized_debug'] = 0 # Compile with -O0 in debug builds.
581 o['variables']['v8_random_seed'] = 0 # Use a random seed for hash tables.
582 o['variables']['v8_use_snapshot'] = b(not options.without_snapshot)
584 # assume shared_v8 if one of these is set?
585 if options.shared_v8_libpath:
586 o['libraries'] += ['-L%s' % options.shared_v8_libpath]
587 if options.shared_v8_libname:
588 o['libraries'] += ['-l%s' % options.shared_v8_libname]
589 elif options.shared_v8:
590 o['libraries'] += ['-lv8']
591 if options.shared_v8_includes:
592 o['include_dirs'] += [options.shared_v8_includes]
595 def configure_openssl(o):
596 o['variables']['node_use_openssl'] = b(not options.without_ssl)
597 o['variables']['node_shared_openssl'] = b(options.shared_openssl)
599 if options.without_ssl:
602 # OpenSSL uses `#ifndef OPENSSL_NO_SSL2` checks so only define the
603 # macro when we want to _disable_ SSL2.
604 if not options.with_sslv2:
605 o['defines'] += ['OPENSSL_NO_SSL2=1']
607 if options.shared_openssl:
608 (libs, cflags) = pkg_config('openssl') or ('-lssl -lcrypto', '')
610 if options.shared_openssl_libpath:
611 o['libraries'] += ['-L%s' % options.shared_openssl_libpath]
613 if options.shared_openssl_libname:
614 libnames = options.shared_openssl_libname.split(',')
615 o['libraries'] += ['-l%s' % s for s in libnames]
617 o['libraries'] += libs.split()
619 if options.shared_openssl_includes:
620 o['include_dirs'] += [options.shared_openssl_includes]
622 o['cflags'] += cflags.split()
625 def configure_winsdk(o):
629 winsdk_dir = os.environ.get('WindowsSdkDir')
631 if winsdk_dir and os.path.isfile(winsdk_dir + '\\bin\\ctrpp.exe'):
632 print('Found ctrpp in WinSDK--will build generated files '
633 'into tools/msvs/genfiles.')
634 o['variables']['node_has_winsdk'] = 'true'
637 print('ctrpp not found in WinSDK path--using pre-gen files '
638 'from tools/msvs/genfiles.')
641 def configure_icu(o):
642 have_icu_path = bool(options.with_icu_path)
643 o['variables']['v8_enable_i18n_support'] = int(have_icu_path)
645 o['variables']['icu_gyp_path'] = options.with_icu_path
648 # determine the "flavor" (operating system) we're building for,
649 # leveraging gyp's GetFlavor function
651 if (options.dest_os):
652 flavor_params['flavor'] = options.dest_os
653 flavor = GetFlavor(flavor_params)
656 'variables': { 'python': sys.executable },
663 configure_node(output)
664 configure_libz(output)
665 configure_http_parser(output)
666 configure_cares(output)
667 configure_libuv(output)
669 configure_openssl(output)
670 configure_winsdk(output)
671 configure_icu(output)
673 # variables should be a root level element,
674 # move everything else to target_defaults
675 variables = output['variables']
676 del output['variables']
678 'variables': variables,
679 'target_defaults': output
681 pprint.pprint(output, indent=2)
683 def write(filename, data):
684 filename = os.path.join(root_dir, filename)
685 print 'creating ', filename
686 f = open(filename, 'w+')
689 write('config.gypi', '# Do not edit. Generated by the configure script.\n' +
690 pprint.pformat(output, indent=2) + '\n')
693 'BUILDTYPE': 'Debug' if options.debug else 'Release',
694 'USE_NINJA': str(int(options.use_ninja or 0)),
695 'USE_XCODE': str(int(options.use_xcode or 0)),
696 'PYTHON': sys.executable,
700 config['PREFIX'] = options.prefix
702 config = '\n'.join(map('='.join, config.iteritems())) + '\n'
705 '# Do not edit. Generated by the configure script.\n' + config)
707 gyp_args = [sys.executable, 'tools/gyp_node.py', '--no-parallel']
709 if options.use_ninja:
710 gyp_args += ['-f', 'ninja-' + flavor]
711 elif options.use_xcode:
712 gyp_args += ['-f', 'xcode']
713 elif flavor == 'win':
714 gyp_args += ['-f', 'msvs', '-G', 'msvs_version=auto']
716 gyp_args += ['-f', 'make-' + flavor]
720 subprocess.call(gyp_args)