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')
57 parser.add_option('--no-ssl2',
60 help='disable OpenSSL v2')
63 parser.add_option('--openssl-includes',
65 dest='shared_openssl_includes',
66 help=optparse.SUPPRESS_HELP)
69 parser.add_option('--openssl-libpath',
71 dest='shared_openssl_libpath',
72 help=optparse.SUPPRESS_HELP)
75 parser.add_option('--openssl-use-sys',
77 dest='shared_openssl',
78 help=optparse.SUPPRESS_HELP)
80 parser.add_option('--shared-cares',
83 help='link to a shared cares DLL instead of static linking')
85 parser.add_option('--shared-cares-includes',
87 dest='shared_cares_includes',
88 help='directory containing cares header files')
90 parser.add_option('--shared-cares-libname',
92 dest='shared_cares_libname',
93 help='alternative lib name to link to (default: \'cares\')')
95 parser.add_option('--shared-cares-libpath',
97 dest='shared_cares_libpath',
98 help='a directory to search for the shared cares DLL')
100 parser.add_option('--shared-http-parser',
102 dest='shared_http_parser',
103 help='link to a shared http_parser DLL instead of static linking')
105 parser.add_option('--shared-http-parser-includes',
107 dest='shared_http_parser_includes',
108 help='directory containing http_parser header files')
110 parser.add_option('--shared-http-parser-libname',
112 dest='shared_http_parser_libname',
113 help='alternative lib name to link to (default: \'http_parser\')')
115 parser.add_option('--shared-http-parser-libpath',
117 dest='shared_http_parser_libpath',
118 help='a directory to search for the shared http_parser DLL')
120 parser.add_option('--shared-libuv',
123 help='link to a shared libuv DLL instead of static linking')
125 parser.add_option('--shared-libuv-includes',
127 dest='shared_libuv_includes',
128 help='directory containing libuv header files')
130 parser.add_option('--shared-libuv-libname',
132 dest='shared_libuv_libname',
133 help='alternative lib name to link to (default: \'uv\')')
135 parser.add_option('--shared-libuv-libpath',
137 dest='shared_libuv_libpath',
138 help='a directory to search for the shared libuv DLL')
140 parser.add_option('--shared-openssl',
142 dest='shared_openssl',
143 help='link to a shared OpenSSl DLL instead of static linking')
145 parser.add_option('--shared-openssl-includes',
147 dest='shared_openssl_includes',
148 help='directory containing OpenSSL header files')
150 parser.add_option('--shared-openssl-libname',
152 dest='shared_openssl_libname',
153 help='alternative lib name to link to (default: \'crypto,ssl\')')
155 parser.add_option('--shared-openssl-libpath',
157 dest='shared_openssl_libpath',
158 help='a directory to search for the shared OpenSSL DLLs')
160 parser.add_option('--shared-v8',
163 help='link to a shared V8 DLL instead of static linking')
165 parser.add_option('--shared-v8-includes',
167 dest='shared_v8_includes',
168 help='directory containing V8 header files')
170 parser.add_option('--shared-v8-libname',
172 dest='shared_v8_libname',
173 help='alternative lib name to link to (default: \'v8\')')
175 parser.add_option('--shared-v8-libpath',
177 dest='shared_v8_libpath',
178 help='a directory to search for the shared V8 DLL')
180 parser.add_option('--shared-zlib',
183 help='link to a shared zlib DLL instead of static linking')
185 parser.add_option('--shared-zlib-includes',
187 dest='shared_zlib_includes',
188 help='directory containing zlib header files')
190 parser.add_option('--shared-zlib-libname',
192 dest='shared_zlib_libname',
193 help='alternative lib name to link to (default: \'z\')')
195 parser.add_option('--shared-zlib-libpath',
197 dest='shared_zlib_libpath',
198 help='a directory to search for the shared zlib DLL')
200 # TODO document when we've decided on what the tracing API and its options will
202 parser.add_option('--systemtap-includes',
204 dest='systemtap_includes',
205 help=optparse.SUPPRESS_HELP)
207 parser.add_option('--tag',
210 help='custom build tag')
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-perfctr',
231 help='build with performance counters (default is true on Windows)')
233 parser.add_option('--without-dtrace',
235 dest='without_dtrace',
236 help='build without DTrace')
238 parser.add_option('--without-etw',
241 help='build without ETW')
243 parser.add_option('--without-npm',
246 help='don\'t install the bundled npm package manager')
248 parser.add_option('--without-perfctr',
250 dest='without_perfctr',
251 help='build without performance counters')
253 parser.add_option('--without-snapshot',
255 dest='without_snapshot',
256 help='build without snapshotting V8 libraries. You might want to set'
257 ' this for cross-compiling. [Default: False]')
259 parser.add_option('--without-ssl',
262 help='build without SSL')
264 parser.add_option('--xcode',
267 help='generate build files for use with xcode')
269 (options, args) = parser.parse_args()
273 """Returns the string 'true' if value is truthy, 'false' otherwise."""
281 cmd = os.popen('pkg-config --libs %s' % pkg, 'r')
282 libs = cmd.readline().strip()
284 if (ret): return None
286 cmd = os.popen('pkg-config --cflags %s' % pkg, 'r')
287 cflags = cmd.readline().strip()
289 if (ret): return None
291 return (libs, cflags)
295 """Checks predefined macros using the CC command."""
298 p = subprocess.Popen(shlex.split(CC) + ['-dM', '-E', '-'],
299 stdin=subprocess.PIPE,
300 stdout=subprocess.PIPE,
301 stderr=subprocess.PIPE)
303 print '''Node.js configure error: No acceptable C compiler found!
305 Please make sure you have a C compiler installed on your system and/or
306 consider adjusting the CC environment variable if you installed
307 it in a non-standard prefix.
312 out = p.communicate()[0]
314 out = str(out).split('\n')
318 lst = shlex.split(line)
327 """Check for ARMv7 instructions"""
328 cc_macros_cache = cc_macros()
329 return ('__ARM_ARCH_7__' in cc_macros_cache or
330 '__ARM_ARCH_7A__' in cc_macros_cache or
331 '__ARM_ARCH_7R__' in cc_macros_cache or
332 '__ARM_ARCH_7M__' in cc_macros_cache)
336 """Check for ARM NEON support"""
337 return '__ARM_NEON__' in cc_macros()
340 def is_arm_hard_float_abi():
341 """Check for hardfloat or softfloat eabi on ARM"""
342 # GCC versions 4.6 and above define __ARM_PCS or __ARM_PCS_VFP to specify
343 # the Floating Point ABI used (PCS stands for Procedure Call Standard).
344 # We use these as well as a couple of other defines to statically determine
346 # GCC versions 4.4 and below don't support hard-fp.
347 # GCC versions 4.5 may support hard-fp without defining __ARM_PCS or
350 if compiler_version() >= (4, 6, 0):
351 return '__ARM_PCS_VFP' in cc_macros()
352 elif compiler_version() < (4, 5, 0):
354 elif '__ARM_PCS_VFP' in cc_macros():
356 elif ('__ARM_PCS' in cc_macros() or
357 '__SOFTFP' in cc_macros() or
358 not '__VFP_FP__' in cc_macros()):
361 print '''Node.js configure error: Your version of GCC does not report
362 the Floating-Point ABI to compile for your hardware
364 Please manually specify which floating-point ABI to use with the
365 --with-arm-float-abi option.
371 """Host architecture check using the CC command."""
376 '__x86_64__' : 'x64',
382 rtn = 'ia32' # default
385 if i in k and k[i] != '0':
393 """Host architecture check using environ vars (better way to do this?)"""
395 arch = os.environ.get('PROCESSOR_ARCHITECTURE', 'x86')
404 return matchup.get(arch, 'ia32')
407 def compiler_version():
409 proc = subprocess.Popen(shlex.split(CC) + ['--version'], stdout=subprocess.PIPE)
413 is_clang = 'clang' in proc.communicate()[0].split('\n')[0]
415 proc = subprocess.Popen(shlex.split(CC) + ['-dumpversion'], stdout=subprocess.PIPE)
416 version = tuple(map(int, proc.communicate()[0].split('.')))
418 return (version, is_clang)
421 def configure_arm(o):
422 if options.arm_float_abi:
423 arm_float_abi = options.arm_float_abi
425 arm_float_abi = 'hard' if is_arm_hard_float_abi() else 'default'
426 o['variables']['armv7'] = int(is_arch_armv7())
427 o['variables']['arm_fpu'] = 'vfpv3' # V8 3.18 no longer supports VFP2.
428 o['variables']['arm_neon'] = int(is_arm_neon())
429 o['variables']['arm_thumb'] = 0 # -marm
430 o['variables']['arm_float_abi'] = arm_float_abi
433 def configure_node(o):
434 if options.dest_os == 'android':
435 o['variables']['OS'] = "android"
436 o['variables']['v8_enable_gdbjit'] = 1 if options.gdb else 0
437 o['variables']['v8_no_strict_aliasing'] = 1 # work around compiler bugs
438 o['variables']['node_prefix'] = os.path.expanduser(options.prefix or '')
439 o['variables']['node_install_npm'] = b(not options.without_npm)
440 o['default_configuration'] = 'Debug' if options.debug else 'Release'
442 host_arch = host_arch_win() if os.name == 'nt' else host_arch_cc()
443 target_arch = options.dest_cpu or host_arch
444 o['variables']['host_arch'] = host_arch
445 o['variables']['target_arch'] = target_arch
447 if target_arch == 'arm':
450 cc_version, is_clang = compiler_version()
451 o['variables']['clang'] = 1 if is_clang else 0
453 if not is_clang and cc_version != 0:
454 o['variables']['gcc_version'] = 10 * cc_version[0] + cc_version[1]
456 # clang has always supported -fvisibility=hidden, right?
457 if not is_clang and cc_version < (4,0,0):
458 o['variables']['visibility'] = ''
460 # By default, enable DTrace on SunOS systems. Don't allow it on other
461 # systems, since it won't work. (The MacOS build process is different than
462 # SunOS, and we haven't implemented it.)
463 if flavor in ('solaris', 'mac'):
464 o['variables']['node_use_dtrace'] = b(not options.without_dtrace)
465 o['variables']['uv_use_dtrace'] = o['variables']['node_use_dtrace']
466 o['variables']['uv_parent_path'] = '/deps/uv/'
467 elif flavor == 'linux':
468 o['variables']['node_use_dtrace'] = 'false'
469 o['variables']['node_use_systemtap'] = b(options.with_dtrace)
470 if options.systemtap_includes:
471 o['include_dirs'] += [options.systemtap_includes]
472 elif options.with_dtrace:
474 'DTrace is currently only supported on SunOS, MacOS or Linux systems.')
476 o['variables']['node_use_dtrace'] = 'false'
477 o['variables']['node_use_systemtap'] = 'false'
479 # if we're on illumos based systems wrap the helper library into the
481 if flavor == 'solaris':
482 o['variables']['node_use_mdb'] = 'true'
484 o['variables']['node_use_mdb'] = 'false'
486 if options.no_ifaddrs:
487 o['defines'] += ['SUNOS_NO_IFADDRS']
489 # By default, enable ETW on Windows.
491 o['variables']['node_use_etw'] = b(not options.without_etw);
492 elif options.with_etw:
493 raise Exception('ETW is only supported on Windows.')
495 o['variables']['node_use_etw'] = 'false'
497 # By default, enable Performance counters on Windows.
499 o['variables']['node_use_perfctr'] = b(not options.without_perfctr);
500 elif options.with_perfctr:
501 raise Exception('Performance counter is only supported on Windows.')
503 o['variables']['node_use_perfctr'] = 'false'
506 o['variables']['node_tag'] = '-' + options.tag
508 o['variables']['node_tag'] = ''
511 def configure_libz(o):
512 o['variables']['node_shared_zlib'] = b(options.shared_zlib)
514 # assume shared_zlib if one of these is set?
515 if options.shared_zlib_libpath:
516 o['libraries'] += ['-L%s' % options.shared_zlib_libpath]
517 if options.shared_zlib_libname:
518 o['libraries'] += ['-l%s' % options.shared_zlib_libname]
519 elif options.shared_zlib:
520 o['libraries'] += ['-lz']
521 if options.shared_zlib_includes:
522 o['include_dirs'] += [options.shared_zlib_includes]
525 def configure_http_parser(o):
526 o['variables']['node_shared_http_parser'] = b(options.shared_http_parser)
528 # assume shared http_parser if one of these is set?
529 if options.shared_http_parser_libpath:
530 o['libraries'] += ['-L%s' % options.shared_http_parser_libpath]
531 if options.shared_http_parser_libname:
532 o['libraries'] += ['-l%s' % options.shared_http_parser_libname]
533 elif options.shared_http_parser:
534 o['libraries'] += ['-lhttp_parser']
535 if options.shared_http_parser_includes:
536 o['include_dirs'] += [options.shared_http_parser_includes]
539 def configure_cares(o):
540 o['variables']['node_shared_cares'] = b(options.shared_cares)
542 # assume shared cares if one of these is set?
543 if options.shared_cares_libpath:
544 o['libraries'] += ['-L%s' % options.shared_cares_libpath]
545 if options.shared_cares_libname:
546 o['libraries'] += ['-l%s' % options.shared_cares_libname]
547 elif options.shared_cares:
548 o['libraries'] += ['-lcares']
549 if options.shared_cares_includes:
550 o['include_dirs'] += [options.shared_cares_includes]
553 def configure_libuv(o):
554 o['variables']['node_shared_libuv'] = b(options.shared_libuv)
556 # assume shared libuv if one of these is set?
557 if options.shared_libuv_libpath:
558 o['libraries'] += ['-L%s' % options.shared_libuv_libpath]
559 if options.shared_libuv_libname:
560 o['libraries'] += ['-l%s' % options.shared_libuv_libname]
561 elif options.shared_libuv:
562 o['libraries'] += ['-luv']
563 if options.shared_libuv_includes:
564 o['include_dirs'] += [options.shared_libuv_includes]
568 o['variables']['v8_use_snapshot'] = b(not options.without_snapshot)
569 o['variables']['node_shared_v8'] = b(options.shared_v8)
571 # assume shared_v8 if one of these is set?
572 if options.shared_v8_libpath:
573 o['libraries'] += ['-L%s' % options.shared_v8_libpath]
574 if options.shared_v8_libname:
575 o['libraries'] += ['-l%s' % options.shared_v8_libname]
576 elif options.shared_v8:
577 o['libraries'] += ['-lv8']
578 if options.shared_v8_includes:
579 o['include_dirs'] += [options.shared_v8_includes]
582 def configure_openssl(o):
583 o['variables']['node_use_openssl'] = b(not options.without_ssl)
584 o['variables']['node_shared_openssl'] = b(options.shared_openssl)
586 if options.without_ssl:
590 o['defines'] += ['OPENSSL_NO_SSL2=1']
592 if options.shared_openssl:
593 (libs, cflags) = pkg_config('openssl') or ('-lssl -lcrypto', '')
595 if options.shared_openssl_libpath:
596 o['libraries'] += ['-L%s' % options.shared_openssl_libpath]
598 if options.shared_openssl_libname:
599 libnames = options.shared_openssl_libname.split(',')
600 o['libraries'] += ['-l%s' % s for s in libnames]
602 o['libraries'] += libs.split()
604 if options.shared_openssl_includes:
605 o['include_dirs'] += [options.shared_openssl_includes]
607 o['cflags'] += cflags.split()
610 def configure_winsdk(o):
614 winsdk_dir = os.environ.get("WindowsSdkDir")
616 if winsdk_dir and os.path.isfile(winsdk_dir + '\\bin\\ctrpp.exe'):
617 print "Found ctrpp in WinSDK--will build generated files into tools/msvs/genfiles."
618 o['variables']['node_has_winsdk'] = 'true'
621 print "ctrpp not found in WinSDK path--using pre-gen files from tools/msvs/genfiles."
624 # determine the "flavor" (operating system) we're building for,
625 # leveraging gyp's GetFlavor function
627 if (options.dest_os):
628 flavor_params['flavor'] = options.dest_os;
629 flavor = GetFlavor(flavor_params);
632 'variables': { 'python': sys.executable },
639 configure_node(output)
640 configure_libz(output)
641 configure_http_parser(output)
642 configure_cares(output)
643 configure_libuv(output)
645 configure_openssl(output)
646 configure_winsdk(output)
649 # variables should be a root level element,
650 # move everything else to target_defaults
651 variables = output['variables']
652 del output['variables']
654 'variables': variables,
655 'target_defaults': output
657 pprint.pprint(output, indent=2)
659 def write(filename, data):
660 filename = os.path.join(root_dir, filename)
661 print "creating ", filename
662 f = open(filename, 'w+')
665 write('config.gypi', "# Do not edit. Generated by the configure script.\n" +
666 pprint.pformat(output, indent=2) + "\n")
669 'BUILDTYPE': 'Debug' if options.debug else 'Release',
670 'USE_NINJA': str(int(options.use_ninja or 0)),
671 'USE_XCODE': str(int(options.use_xcode or 0)),
672 'PYTHON': sys.executable,
676 config['PREFIX'] = options.prefix
678 config = '\n'.join(map('='.join, config.iteritems())) + '\n'
681 '# Do not edit. Generated by the configure script.\n' + config)
683 if options.use_ninja:
684 gyp_args = ['-f', 'ninja-' + flavor]
685 elif options.use_xcode:
686 gyp_args = ['-f', 'xcode']
687 elif flavor == 'win':
688 gyp_args = ['-f', 'msvs', '-G', 'msvs_version=auto']
690 gyp_args = ['-f', 'make-' + flavor]
692 subprocess.call([sys.executable, 'tools/gyp_node'] + gyp_args)