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('--v8-options',
210 help='v8 options to pass, see `node --v8-options` for examples.')
212 parser.add_option('--with-arm-float-abi',
214 dest='arm_float_abi',
215 help='specifies which floating-point ABI to use. Valid values are: '
216 'soft, softfp, hard')
218 parser.add_option('--with-dtrace',
221 help='build with DTrace (default is true on sunos)')
223 parser.add_option('--with-etw',
226 help='build with ETW (default is true on Windows)')
228 parser.add_option('--with-icu-path',
230 dest='with_icu_path',
231 help='Path to icu.gyp (ICU i18n, Chromium version only.)')
233 parser.add_option('--with-perfctr',
236 help='build with performance counters (default is true on Windows)')
238 parser.add_option('--with-sslv2',
241 help='enable SSL v2')
243 parser.add_option('--without-dtrace',
245 dest='without_dtrace',
246 help='build without DTrace')
248 parser.add_option('--without-etw',
251 help='build without ETW')
253 parser.add_option('--without-npm',
256 help='don\'t install the bundled npm package manager')
258 parser.add_option('--without-perfctr',
260 dest='without_perfctr',
261 help='build without performance counters')
263 parser.add_option('--without-snapshot',
265 dest='without_snapshot',
266 help='build without snapshotting V8 libraries. You might want to set'
267 ' this for cross-compiling. [Default: False]')
269 parser.add_option('--without-ssl',
272 help='build without SSL')
274 parser.add_option('--xcode',
277 help='generate build files for use with xcode')
279 (options, args) = parser.parse_args()
283 """Returns the string 'true' if value is truthy, 'false' otherwise."""
291 cmd = os.popen('pkg-config --libs %s' % pkg, 'r')
292 libs = cmd.readline().strip()
294 if (ret): return None
296 cmd = os.popen('pkg-config --cflags %s' % pkg, 'r')
297 cflags = cmd.readline().strip()
299 if (ret): return None
301 return (libs, cflags)
305 """Checks predefined macros using the CC command."""
308 p = subprocess.Popen(shlex.split(CC) + ['-dM', '-E', '-'],
309 stdin=subprocess.PIPE,
310 stdout=subprocess.PIPE,
311 stderr=subprocess.PIPE)
313 print '''Node.js configure error: No acceptable C compiler found!
315 Please make sure you have a C compiler installed on your system and/or
316 consider adjusting the CC environment variable if you installed
317 it in a non-standard prefix.
322 out = p.communicate()[0]
324 out = str(out).split('\n')
328 lst = shlex.split(line)
337 """Check for ARMv7 instructions"""
338 cc_macros_cache = cc_macros()
339 return ('__ARM_ARCH_7__' in cc_macros_cache or
340 '__ARM_ARCH_7A__' in cc_macros_cache or
341 '__ARM_ARCH_7R__' in cc_macros_cache or
342 '__ARM_ARCH_7M__' in cc_macros_cache)
346 """Check for ARM NEON support"""
347 return '__ARM_NEON__' in cc_macros()
350 def is_arm_hard_float_abi():
351 """Check for hardfloat or softfloat eabi on ARM"""
352 # GCC versions 4.6 and above define __ARM_PCS or __ARM_PCS_VFP to specify
353 # the Floating Point ABI used (PCS stands for Procedure Call Standard).
354 # We use these as well as a couple of other defines to statically determine
356 # GCC versions 4.4 and below don't support hard-fp.
357 # GCC versions 4.5 may support hard-fp without defining __ARM_PCS or
360 if compiler_version() >= (4, 6, 0):
361 return '__ARM_PCS_VFP' in cc_macros()
362 elif compiler_version() < (4, 5, 0):
364 elif '__ARM_PCS_VFP' in cc_macros():
366 elif ('__ARM_PCS' in cc_macros() or
367 '__SOFTFP' in cc_macros() or
368 not '__VFP_FP__' in cc_macros()):
371 print '''Node.js configure error: Your version of GCC does not report
372 the Floating-Point ABI to compile for your hardware
374 Please manually specify which floating-point ABI to use with the
375 --with-arm-float-abi option.
381 """Host architecture check using the CC command."""
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'],
420 stdout=subprocess.PIPE)
424 is_clang = 'clang' in proc.communicate()[0].split('\n')[0]
426 proc = subprocess.Popen(shlex.split(CC) + ['-dumpversion'],
427 stdout=subprocess.PIPE)
428 version = tuple(map(int, proc.communicate()[0].split('.')))
430 return (version, is_clang)
433 def configure_arm(o):
434 if options.arm_float_abi:
435 arm_float_abi = options.arm_float_abi
436 elif is_arm_hard_float_abi():
437 arm_float_abi = 'hard'
439 arm_float_abi = 'default'
440 o['variables']['armv7'] = int(is_arch_armv7())
441 o['variables']['arm_fpu'] = 'vfpv3' # V8 3.18 no longer supports VFP2.
442 o['variables']['arm_neon'] = int(is_arm_neon())
443 o['variables']['arm_thumb'] = 0 # -marm
444 o['variables']['arm_float_abi'] = arm_float_abi
447 def configure_node(o):
448 if options.dest_os == 'android':
449 o['variables']['OS'] = 'android'
450 o['variables']['node_prefix'] = os.path.expanduser(options.prefix or '')
451 o['variables']['node_install_npm'] = b(not options.without_npm)
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 if flavor in ('solaris', 'mac', 'linux', 'freebsd'):
473 use_dtrace = not options.without_dtrace
474 # Don't enable by default on linux and freebsd
475 if flavor in ('linux', 'freebsd'):
476 use_dtrace = options.with_dtrace
478 if flavor == 'linux':
479 if options.systemtap_includes:
480 o['include_dirs'] += [options.systemtap_includes]
481 o['variables']['node_use_dtrace'] = b(use_dtrace)
482 o['variables']['uv_use_dtrace'] = b(use_dtrace)
483 o['variables']['uv_parent_path'] = '/deps/uv/'
484 elif options.with_dtrace:
486 'DTrace is currently only supported on SunOS, MacOS or Linux systems.')
488 o['variables']['node_use_dtrace'] = 'false'
490 # if we're on illumos based systems wrap the helper library into the
492 if flavor == 'solaris':
493 o['variables']['node_use_mdb'] = 'true'
495 o['variables']['node_use_mdb'] = 'false'
497 if options.no_ifaddrs:
498 o['defines'] += ['SUNOS_NO_IFADDRS']
500 # By default, enable ETW on Windows.
502 o['variables']['node_use_etw'] = b(not options.without_etw)
503 elif options.with_etw:
504 raise Exception('ETW is only supported on Windows.')
506 o['variables']['node_use_etw'] = 'false'
508 # By default, enable Performance counters on Windows.
510 o['variables']['node_use_perfctr'] = b(not options.without_perfctr)
511 elif options.with_perfctr:
512 raise Exception('Performance counter is only supported on Windows.')
514 o['variables']['node_use_perfctr'] = 'false'
517 o['variables']['node_tag'] = '-' + options.tag
519 o['variables']['node_tag'] = ''
521 if options.v8_options:
522 o['variables']['node_v8_options'] = options.v8_options.replace('"', '\\"')
525 def configure_libz(o):
526 o['variables']['node_shared_zlib'] = b(options.shared_zlib)
528 # assume shared_zlib if one of these is set?
529 if options.shared_zlib_libpath:
530 o['libraries'] += ['-L%s' % options.shared_zlib_libpath]
531 if options.shared_zlib_libname:
532 o['libraries'] += ['-l%s' % options.shared_zlib_libname]
533 elif options.shared_zlib:
534 o['libraries'] += ['-lz']
535 if options.shared_zlib_includes:
536 o['include_dirs'] += [options.shared_zlib_includes]
539 def configure_http_parser(o):
540 o['variables']['node_shared_http_parser'] = b(options.shared_http_parser)
542 # assume shared http_parser if one of these is set?
543 if options.shared_http_parser_libpath:
544 o['libraries'] += ['-L%s' % options.shared_http_parser_libpath]
545 if options.shared_http_parser_libname:
546 o['libraries'] += ['-l%s' % options.shared_http_parser_libname]
547 elif options.shared_http_parser:
548 o['libraries'] += ['-lhttp_parser']
549 if options.shared_http_parser_includes:
550 o['include_dirs'] += [options.shared_http_parser_includes]
553 def configure_cares(o):
554 o['variables']['node_shared_cares'] = b(options.shared_cares)
556 # assume shared cares if one of these is set?
557 if options.shared_cares_libpath:
558 o['libraries'] += ['-L%s' % options.shared_cares_libpath]
559 if options.shared_cares_libname:
560 o['libraries'] += ['-l%s' % options.shared_cares_libname]
561 elif options.shared_cares:
562 o['libraries'] += ['-lcares']
563 if options.shared_cares_includes:
564 o['include_dirs'] += [options.shared_cares_includes]
567 def configure_libuv(o):
568 o['variables']['node_shared_libuv'] = b(options.shared_libuv)
570 # assume shared libuv if one of these is set?
571 if options.shared_libuv_libpath:
572 o['libraries'] += ['-L%s' % options.shared_libuv_libpath]
574 o['variables']['uv_library'] = 'static_library'
576 if options.shared_libuv_libname:
577 o['libraries'] += ['-l%s' % options.shared_libuv_libname]
578 elif options.shared_libuv:
579 o['libraries'] += ['-luv']
580 if options.shared_libuv_includes:
581 o['include_dirs'] += [options.shared_libuv_includes]
585 o['variables']['node_shared_v8'] = b(options.shared_v8)
586 o['variables']['v8_enable_gdbjit'] = 1 if options.gdb else 0
587 o['variables']['v8_no_strict_aliasing'] = 1 # Work around compiler bugs.
588 o['variables']['v8_optimized_debug'] = 0 # Compile with -O0 in debug builds.
589 o['variables']['v8_random_seed'] = 0 # Use a random seed for hash tables.
590 o['variables']['v8_use_snapshot'] = b(not options.without_snapshot)
592 # assume shared_v8 if one of these is set?
593 if options.shared_v8_libpath:
594 o['libraries'] += ['-L%s' % options.shared_v8_libpath]
595 if options.shared_v8_libname:
596 o['libraries'] += ['-l%s' % options.shared_v8_libname]
597 elif options.shared_v8:
598 o['libraries'] += ['-lv8']
599 if options.shared_v8_includes:
600 o['include_dirs'] += [options.shared_v8_includes]
603 def configure_openssl(o):
604 o['variables']['node_use_openssl'] = b(not options.without_ssl)
605 o['variables']['node_shared_openssl'] = b(options.shared_openssl)
607 if options.without_ssl:
610 # OpenSSL uses `#ifndef OPENSSL_NO_SSL2` checks so only define the
611 # macro when we want to _disable_ SSL2.
612 if not options.with_sslv2:
613 o['defines'] += ['OPENSSL_NO_SSL2=1']
615 if options.shared_openssl:
616 (libs, cflags) = pkg_config('openssl') or ('-lssl -lcrypto', '')
618 if options.shared_openssl_libpath:
619 o['libraries'] += ['-L%s' % options.shared_openssl_libpath]
621 if options.shared_openssl_libname:
622 libnames = options.shared_openssl_libname.split(',')
623 o['libraries'] += ['-l%s' % s for s in libnames]
625 o['libraries'] += libs.split()
627 if options.shared_openssl_includes:
628 o['include_dirs'] += [options.shared_openssl_includes]
630 o['cflags'] += cflags.split()
633 def configure_winsdk(o):
637 winsdk_dir = os.environ.get('WindowsSdkDir')
639 if winsdk_dir and os.path.isfile(winsdk_dir + '\\bin\\ctrpp.exe'):
640 print('Found ctrpp in WinSDK--will build generated files '
641 'into tools/msvs/genfiles.')
642 o['variables']['node_has_winsdk'] = 'true'
645 print('ctrpp not found in WinSDK path--using pre-gen files '
646 'from tools/msvs/genfiles.')
649 def configure_icu(o):
650 have_icu_path = bool(options.with_icu_path)
651 o['variables']['v8_enable_i18n_support'] = int(have_icu_path)
653 o['variables']['icu_gyp_path'] = options.with_icu_path
656 # determine the "flavor" (operating system) we're building for,
657 # leveraging gyp's GetFlavor function
659 if (options.dest_os):
660 flavor_params['flavor'] = options.dest_os
661 flavor = GetFlavor(flavor_params)
664 'variables': { 'python': sys.executable },
671 configure_node(output)
672 configure_libz(output)
673 configure_http_parser(output)
674 configure_cares(output)
675 configure_libuv(output)
677 configure_openssl(output)
678 configure_winsdk(output)
679 configure_icu(output)
681 # variables should be a root level element,
682 # move everything else to target_defaults
683 variables = output['variables']
684 del output['variables']
686 'variables': variables,
687 'target_defaults': output
689 pprint.pprint(output, indent=2)
691 def write(filename, data):
692 filename = os.path.join(root_dir, filename)
693 print 'creating ', filename
694 f = open(filename, 'w+')
697 write('config.gypi', '# Do not edit. Generated by the configure script.\n' +
698 pprint.pformat(output, indent=2) + '\n')
701 'BUILDTYPE': 'Debug' if options.debug else 'Release',
702 'USE_NINJA': str(int(options.use_ninja or 0)),
703 'USE_XCODE': str(int(options.use_xcode or 0)),
704 'PYTHON': sys.executable,
708 config['PREFIX'] = options.prefix
710 config = '\n'.join(map('='.join, config.iteritems())) + '\n'
713 '# Do not edit. Generated by the configure script.\n' + config)
715 gyp_args = [sys.executable, 'tools/gyp_node.py', '--no-parallel']
717 if options.use_ninja:
718 gyp_args += ['-f', 'ninja-' + flavor]
719 elif options.use_xcode:
720 gyp_args += ['-f', 'xcode']
721 elif flavor == 'win':
722 gyp_args += ['-f', 'msvs', '-G', 'msvs_version=auto']
724 gyp_args += ['-f', 'make-' + flavor]
728 subprocess.call(gyp_args)