12 # gcc and g++ as defaults matches what GYP's Makefile generator does,
14 CC = os.environ.get('CC', 'cc' if sys.platform == 'darwin' else 'gcc')
15 CXX = os.environ.get('CXX', 'c++' if sys.platform == 'darwin' else 'g++')
17 root_dir = os.path.dirname(__file__)
18 sys.path.insert(0, os.path.join(root_dir, 'tools', 'gyp', 'pylib'))
19 from gyp.common import GetFlavor
21 # imports in tools/configure.d
22 sys.path.insert(0, os.path.join(root_dir, 'tools', 'configure.d'))
26 parser = optparse.OptionParser()
28 valid_os = ('win', 'mac', 'solaris', 'freebsd', 'openbsd', 'linux',
30 valid_arch = ('arm', 'arm64', 'ia32', 'mips', 'mipsel', 'ppc', 'ppc64', 'x32',
32 valid_arm_float_abi = ('soft', 'softfp', 'hard')
33 valid_arm_fpu = ('vfp', 'vfpv3', 'vfpv3-d16', 'neon')
34 valid_mips_arch = ('loongson', 'r1', 'r2', 'r6', 'rx')
35 valid_mips_fpu = ('fp32', 'fp64', 'fpxx')
36 valid_mips_float_abi = ('soft', 'hard')
37 valid_intl_modes = ('none', 'small-icu', 'full-icu', 'system-icu')
39 # create option groups
40 shared_optgroup = optparse.OptionGroup(parser, "Shared libraries",
41 "Flags that allows you to control whether you want to build against "
42 "built-in dependencies or its shared representations. If necessary, "
43 "provide multiple libraries with comma.")
44 intl_optgroup = optparse.OptionGroup(parser, "Internationalization",
45 "Flags that lets you enable i18n features in Node.js as well as which "
46 "library you want to build against.")
48 # Options should be in alphabetical order but keep --prefix at the top,
49 # that's arguably the one people will be looking for most.
50 parser.add_option('--prefix',
54 help='select the install prefix [default: %default]')
56 parser.add_option('--debug',
59 help='also build debug build')
61 parser.add_option('--dest-cpu',
65 help='CPU architecture to build for ({0})'.format(', '.join(valid_arch)))
67 parser.add_option('--dest-os',
71 help='operating system to build for ({0})'.format(', '.join(valid_os)))
73 parser.add_option('--gdb',
76 help='add gdb support')
78 parser.add_option('--no-ifaddrs',
81 help='use on deprecated SunOS systems that do not support ifaddrs.h')
83 parser.add_option("--fully-static",
86 help="Generate an executable without external dynamic libraries. This "
87 "will not work on OSX when using the default compilation environment")
89 parser.add_option("--partly-static",
92 help="Generate an executable with libgcc and libstdc++ libraries. This "
93 "will not work on OSX when using the default compilation environment")
95 parser.add_option("--link-module",
98 help="Path to a JS file to be bundled in the binary as a builtin."
99 "This module will be referenced by path without extension."
100 "e.g. /root/x/y.js will be referenced via require('root/x/y')."
101 "Can be used multiple times")
103 parser.add_option("--openssl-no-asm",
105 dest="openssl_no_asm",
106 help="Do not build optimized assembly for OpenSSL")
108 parser.add_option('--openssl-fips',
111 help='Build OpenSSL using FIPS canister .o file in supplied folder')
113 shared_optgroup.add_option('--shared-http-parser',
115 dest='shared_http_parser',
116 help='link to a shared http_parser DLL instead of static linking')
118 shared_optgroup.add_option('--shared-http-parser-includes',
120 dest='shared_http_parser_includes',
121 help='directory containing http_parser header files')
123 shared_optgroup.add_option('--shared-http-parser-libname',
125 dest='shared_http_parser_libname',
126 default='http_parser',
127 help='alternative lib name to link to [default: %default]')
129 shared_optgroup.add_option('--shared-http-parser-libpath',
131 dest='shared_http_parser_libpath',
132 help='a directory to search for the shared http_parser DLL')
134 shared_optgroup.add_option('--shared-libuv',
137 help='link to a shared libuv DLL instead of static linking')
139 shared_optgroup.add_option('--shared-libuv-includes',
141 dest='shared_libuv_includes',
142 help='directory containing libuv header files')
144 shared_optgroup.add_option('--shared-libuv-libname',
146 dest='shared_libuv_libname',
148 help='alternative lib name to link to [default: %default]')
150 shared_optgroup.add_option('--shared-libuv-libpath',
152 dest='shared_libuv_libpath',
153 help='a directory to search for the shared libuv DLL')
155 shared_optgroup.add_option('--shared-openssl',
157 dest='shared_openssl',
158 help='link to a shared OpenSSl DLL instead of static linking')
160 shared_optgroup.add_option('--shared-openssl-includes',
162 dest='shared_openssl_includes',
163 help='directory containing OpenSSL header files')
165 shared_optgroup.add_option('--shared-openssl-libname',
167 dest='shared_openssl_libname',
168 default='crypto,ssl',
169 help='alternative lib name to link to [default: %default]')
171 shared_optgroup.add_option('--shared-openssl-libpath',
173 dest='shared_openssl_libpath',
174 help='a directory to search for the shared OpenSSL DLLs')
176 shared_optgroup.add_option('--shared-zlib',
179 help='link to a shared zlib DLL instead of static linking')
181 shared_optgroup.add_option('--shared-zlib-includes',
183 dest='shared_zlib_includes',
184 help='directory containing zlib header files')
186 shared_optgroup.add_option('--shared-zlib-libname',
188 dest='shared_zlib_libname',
190 help='alternative lib name to link to [default: %default]')
192 shared_optgroup.add_option('--shared-zlib-libpath',
194 dest='shared_zlib_libpath',
195 help='a directory to search for the shared zlib DLL')
197 parser.add_option_group(shared_optgroup)
199 # TODO document when we've decided on what the tracing API and its options will
201 parser.add_option('--systemtap-includes',
203 dest='systemtap_includes',
204 help=optparse.SUPPRESS_HELP)
206 parser.add_option('--tag',
209 help='custom build tag')
211 parser.add_option('--release-urlbase',
213 dest='release_urlbase',
214 help='Provide a custom URL prefix for the `process.release` properties '
215 '`sourceUrl` and `headersUrl`. When compiling a release build, this '
216 'will default to https://nodejs.org/download/release/')
218 parser.add_option('--v8-options',
221 help='v8 options to pass, see `node --v8-options` for examples.')
223 parser.add_option('--with-arm-float-abi',
225 dest='arm_float_abi',
226 choices=valid_arm_float_abi,
227 help='specifies which floating-point ABI to use ({0}).'.format(
228 ', '.join(valid_arm_float_abi)))
230 parser.add_option('--with-arm-fpu',
233 choices=valid_arm_fpu,
234 help='ARM FPU mode ({0}) [default: %default]'.format(
235 ', '.join(valid_arm_fpu)))
237 parser.add_option('--with-mips-arch-variant',
239 dest='mips_arch_variant',
241 choices=valid_mips_arch,
242 help='MIPS arch variant ({0}) [default: %default]'.format(
243 ', '.join(valid_mips_arch)))
245 parser.add_option('--with-mips-fpu-mode',
247 dest='mips_fpu_mode',
249 choices=valid_mips_fpu,
250 help='MIPS FPU mode ({0}) [default: %default]'.format(
251 ', '.join(valid_mips_fpu)))
253 parser.add_option('--with-mips-float-abi',
255 dest='mips_float_abi',
257 choices=valid_mips_float_abi,
258 help='MIPS floating-point ABI ({0}) [default: %default]'.format(
259 ', '.join(valid_mips_float_abi)))
261 parser.add_option('--with-dtrace',
264 help='build with DTrace (default is true on sunos and darwin)')
266 parser.add_option('--with-lttng',
269 help='build with Lttng (Only available to Linux)')
271 parser.add_option('--with-etw',
274 help='build with ETW (default is true on Windows)')
276 intl_optgroup.add_option('--with-intl',
280 choices=valid_intl_modes,
281 help='Intl mode (valid choices: {0}) [default: %default]'.format(
282 ', '.join(valid_intl_modes)))
284 intl_optgroup.add_option('--with-icu-path',
286 dest='with_icu_path',
287 help='Path to icu.gyp (ICU i18n, Chromium version only.)')
289 intl_optgroup.add_option('--with-icu-locales',
291 dest='with_icu_locales',
293 help='Comma-separated list of locales for "small-icu". "root" is assumed. '
294 '[default: %default]')
296 intl_optgroup.add_option('--with-icu-source',
298 dest='with_icu_source',
299 help='Intl mode: optional local path to icu/ dir, or path/URL of icu source archive.')
301 intl_optgroup.add_option('--download',
303 dest='download_list',
304 help=nodedownload.help())
306 intl_optgroup.add_option('--download-path',
308 dest='download_path',
309 default=os.path.join(root_dir, 'deps'),
310 help='Download directory [default: %default]')
312 parser.add_option_group(intl_optgroup)
314 parser.add_option('--with-perfctr',
317 help='build with performance counters (default is true on Windows)')
319 parser.add_option('--without-dtrace',
321 dest='without_dtrace',
322 help='build without DTrace')
324 parser.add_option('--without-etw',
327 help='build without ETW')
329 parser.add_option('--without-npm',
332 help='don\'t install the bundled npm package manager')
334 parser.add_option('--without-perfctr',
336 dest='without_perfctr',
337 help='build without performance counters')
339 # Dummy option for backwards compatibility
340 parser.add_option('--with-snapshot',
342 dest='unused_with_snapshot',
343 help=optparse.SUPPRESS_HELP)
345 parser.add_option('--without-snapshot',
347 dest='without_snapshot',
348 help=optparse.SUPPRESS_HELP)
350 parser.add_option('--without-ssl',
353 help='build without SSL')
355 parser.add_option('--xcode',
358 help='generate build files for use with xcode')
360 parser.add_option('--enable-asan',
363 help='build with asan')
365 parser.add_option('--enable-static',
367 dest='enable_static',
368 help='build as static library')
370 (options, args) = parser.parse_args()
372 # Expand ~ in the install prefix now, it gets written to multiple files.
373 options.prefix = os.path.expanduser(options.prefix or '')
375 # set up auto-download list
376 auto_downloads = nodedownload.parse(options.download_list)
381 prefix = '\033[1m\033[93mWARNING\033[0m' if os.isatty(1) else 'WARNING'
382 print('%s: %s' % (prefix, msg))
384 # track if warnings occured
388 """Returns the string 'true' if value is truthy, 'false' otherwise."""
396 pkg_config = os.environ.get('PKG_CONFIG', 'pkg-config')
397 args = '--silence-errors'
399 for flag in ['--libs-only-l', '--cflags-only-I', '--libs-only-L']:
401 val = subprocess.check_output([pkg_config, args, flag, pkg])
402 # check_output returns bytes
403 val = val.encode().strip().rstrip('\n')
404 except subprocess.CalledProcessError:
405 # most likely missing a .pc-file
408 # no pkg-config/pkgconf installed
409 return (None, None, None)
414 def try_check_compiler(cc, lang):
416 proc = subprocess.Popen(shlex.split(cc) + ['-E', '-P', '-x', lang, '-'],
417 stdin=subprocess.PIPE, stdout=subprocess.PIPE)
419 return (False, False, '', '')
421 proc.stdin.write('__clang__ __GNUC__ __GNUC_MINOR__ __GNUC_PATCHLEVEL__ '
422 '__clang_major__ __clang_minor__ __clang_patchlevel__')
424 values = (proc.communicate()[0].split() + ['0'] * 7)[0:7]
425 is_clang = values[0] == '1'
426 gcc_version = '%s.%s.%s' % tuple(values[1:1+3])
427 clang_version = '%s.%s.%s' % tuple(values[4:4+3])
429 return (True, is_clang, clang_version, gcc_version)
433 # The version of asm compiler is needed for building openssl asm files.
434 # See deps/openssl/openssl.gypi for detail.
435 # Commands and regular expressions to obtain its version number are taken from
436 # https://github.com/openssl/openssl/blob/OpenSSL_1_0_2-stable/crypto/sha/asm/sha512-x86_64.pl#L112-L129
438 def get_llvm_version(cc):
440 proc = subprocess.Popen(shlex.split(cc) + ['-v'], stdin=subprocess.PIPE,
441 stderr=subprocess.PIPE, stdout=subprocess.PIPE)
443 print '''Node.js configure error: No acceptable C compiler found!
445 Please make sure you have a C compiler installed on your system and/or
446 consider adjusting the CC environment variable if you installed
447 it in a non-standard prefix.
451 match = re.search(r"(^clang version|based on LLVM) ([3-9]\.[0-9]+)",
452 proc.communicate()[1])
455 return match.group(2)
460 def get_gas_version(cc):
462 proc = subprocess.Popen(shlex.split(cc) + ['-Wa,-v', '-c', '-o',
464 'assembler', '/dev/null'],
465 stdin=subprocess.PIPE, stderr=subprocess.PIPE,
466 stdout=subprocess.PIPE)
468 print '''Node.js configure error: No acceptable C compiler found!
470 Please make sure you have a C compiler installed on your system and/or
471 consider adjusting the CC environment variable if you installed
472 it in a non-standard prefix.
476 match = re.match(r"GNU assembler version ([2-9]\.[0-9]+)",
477 proc.communicate()[1])
480 return match.group(1)
484 # Note: Apple clang self-reports as clang 4.2.0 and gcc 4.2.1. It passes
485 # the version check more by accident than anything else but a more rigorous
486 # check involves checking the build number against a whitelist. I'm not
487 # quite prepared to go that far yet.
488 def check_compiler(o):
489 if sys.platform == 'win32':
492 ok, is_clang, clang_version, gcc_version = try_check_compiler(CXX, 'c++')
494 warn('failed to autodetect C++ compiler version (CXX=%s)' % CXX)
495 elif clang_version < '3.4.0' if is_clang else gcc_version < '4.8.0':
496 warn('C++ compiler too old, need g++ 4.8 or clang++ 3.4 (CXX=%s)' % CXX)
498 ok, is_clang, clang_version, gcc_version = try_check_compiler(CC, 'c')
500 warn('failed to autodetect C compiler version (CC=%s)' % CC)
501 elif not is_clang and gcc_version < '4.2.0':
502 # clang 3.2 is a little white lie because any clang version will probably
503 # do for the C bits. However, we might as well encourage people to upgrade
504 # to a version that is not completely ancient.
505 warn('C compiler too old, need gcc 4.2 or clang 3.2 (CC=%s)' % CC)
507 # Need llvm_version or gas_version when openssl asm files are compiled
508 if options.without_ssl or options.openssl_no_asm or options.shared_openssl:
512 o['variables']['llvm_version'] = get_llvm_version(CC)
514 o['variables']['gas_version'] = get_gas_version(CC)
517 def cc_macros(cc=None):
518 """Checks predefined macros using the C compiler command."""
521 p = subprocess.Popen(shlex.split(cc or CC) + ['-dM', '-E', '-'],
522 stdin=subprocess.PIPE,
523 stdout=subprocess.PIPE,
524 stderr=subprocess.PIPE)
526 print '''Node.js configure error: No acceptable C compiler found!
528 Please make sure you have a C compiler installed on your system and/or
529 consider adjusting the CC environment variable if you installed
530 it in a non-standard prefix.
535 out = p.communicate()[0]
537 out = str(out).split('\n')
541 lst = shlex.split(line)
550 """Check for ARMv7 instructions"""
551 cc_macros_cache = cc_macros()
552 return cc_macros_cache.get('__ARM_ARCH') == '7'
556 """Check for ARMv6 instructions"""
557 cc_macros_cache = cc_macros()
558 return cc_macros_cache.get('__ARM_ARCH') == '6'
561 def is_arm_hard_float_abi():
562 """Check for hardfloat or softfloat eabi on ARM"""
563 # GCC versions 4.6 and above define __ARM_PCS or __ARM_PCS_VFP to specify
564 # the Floating Point ABI used (PCS stands for Procedure Call Standard).
565 # We use these as well as a couple of other defines to statically determine
568 return '__ARM_PCS_VFP' in cc_macros()
572 """Host architecture check using the CC command."""
574 if sys.platform.startswith('aix'):
575 # we only support gcc at this point and the default on AIX
576 # would be xlc so hard code gcc
579 k = cc_macros(os.environ.get('CC_host'))
582 '__aarch64__' : 'arm64',
585 '__MIPSEL__' : 'mipsel',
587 '__PPC64__' : 'ppc64',
589 '__x86_64__' : 'x64',
592 rtn = 'ia32' # default
595 if i in k and k[i] != '0':
603 """Host architecture check using environ vars (better way to do this?)"""
605 observed_arch = os.environ.get('PROCESSOR_ARCHITECTURE', 'x86')
606 arch = os.environ.get('PROCESSOR_ARCHITEW6432', observed_arch)
615 return matchup.get(arch, 'ia32')
618 def configure_arm(o):
619 if options.arm_float_abi:
620 arm_float_abi = options.arm_float_abi
621 elif is_arm_hard_float_abi():
622 arm_float_abi = 'hard'
624 arm_float_abi = 'default'
630 o['variables']['arm_version'] = '7'
632 o['variables']['arm_version'] = '6' if is_arch_armv6() else 'default'
634 o['variables']['arm_thumb'] = 0 # -marm
635 o['variables']['arm_float_abi'] = arm_float_abi
637 if options.dest_os == 'android':
639 o['variables']['arm_version'] = '7'
641 o['variables']['arm_fpu'] = options.arm_fpu or arm_fpu
644 def configure_mips(o):
645 can_use_fpu_instructions = (options.mips_float_abi != 'soft')
646 o['variables']['v8_can_use_fpu_instructions'] = b(can_use_fpu_instructions)
647 o['variables']['v8_use_mips_abi_hardfloat'] = b(can_use_fpu_instructions)
648 o['variables']['mips_arch_variant'] = options.mips_arch_variant
649 o['variables']['mips_fpu_mode'] = options.mips_fpu_mode
652 def configure_node(o):
653 if options.dest_os == 'android':
654 o['variables']['OS'] = 'android'
655 o['variables']['node_prefix'] = options.prefix
656 o['variables']['node_install_npm'] = b(not options.without_npm)
657 o['default_configuration'] = 'Debug' if options.debug else 'Release'
659 host_arch = host_arch_win() if os.name == 'nt' else host_arch_cc()
660 target_arch = options.dest_cpu or host_arch
661 # ia32 is preferred by the build tools (GYP) over x86 even if we prefer the latter
662 # the Makefile resets this to x86 afterward
663 if target_arch == 'x86':
665 o['variables']['host_arch'] = host_arch
666 o['variables']['target_arch'] = target_arch
667 o['variables']['node_byteorder'] = sys.byteorder
669 cross_compiling = target_arch != host_arch
670 want_snapshots = not options.without_snapshot
671 o['variables']['want_separate_host_toolset'] = int(
672 cross_compiling and want_snapshots)
674 if target_arch == 'arm':
676 elif target_arch in ('mips', 'mipsel'):
680 o['variables']['node_core_target_name'] = 'node_base'
681 o['variables']['node_target_type'] = 'static_library'
683 if flavor in ('solaris', 'mac', 'linux', 'freebsd'):
684 use_dtrace = not options.without_dtrace
685 # Don't enable by default on linux and freebsd
686 if flavor in ('linux', 'freebsd'):
687 use_dtrace = options.with_dtrace
689 if flavor == 'linux':
690 if options.systemtap_includes:
691 o['include_dirs'] += [options.systemtap_includes]
692 o['variables']['node_use_dtrace'] = b(use_dtrace)
693 o['variables']['uv_use_dtrace'] = b(use_dtrace)
694 o['variables']['uv_parent_path'] = '/deps/uv/'
695 elif options.with_dtrace:
697 'DTrace is currently only supported on SunOS, MacOS or Linux systems.')
699 o['variables']['node_use_dtrace'] = 'false'
701 # Enable Lttng if --with-lttng was defined. Use logic similar to
702 # ETW for windows. Lttng is only available on the Linux platform.
703 if flavor == 'linux':
704 o['variables']['node_use_lttng'] = b(options.with_lttng)
705 elif options.with_lttng:
706 raise Exception('lttng is only supported on Linux.')
708 o['variables']['node_use_lttng'] = 'false'
710 if options.no_ifaddrs:
711 o['defines'] += ['SUNOS_NO_IFADDRS']
713 # By default, enable ETW on Windows.
715 o['variables']['node_use_etw'] = b(not options.without_etw)
716 elif options.with_etw:
717 raise Exception('ETW is only supported on Windows.')
719 o['variables']['node_use_etw'] = 'false'
721 # By default, enable Performance counters on Windows.
723 o['variables']['node_use_perfctr'] = b(not options.without_perfctr)
724 elif options.with_perfctr:
725 raise Exception('Performance counter is only supported on Windows.')
727 o['variables']['node_use_perfctr'] = 'false'
730 o['variables']['node_tag'] = '-' + options.tag
732 o['variables']['node_tag'] = ''
734 o['variables']['node_release_urlbase'] = options.release_urlbase or ''
736 if options.v8_options:
737 o['variables']['node_v8_options'] = options.v8_options.replace('"', '\\"')
739 if options.enable_static:
740 o['variables']['node_target_type'] = 'static_library'
742 if options.linked_module:
743 o['variables']['library_files'] = options.linked_module
745 o['variables']['asan'] = int(options.enable_asan or 0)
747 def configure_library(lib, output):
748 shared_lib = 'shared_' + lib
749 output['variables']['node_' + shared_lib] = b(getattr(options, shared_lib))
751 if getattr(options, shared_lib):
752 (pkg_libs, pkg_cflags, pkg_libpath) = pkg_config(lib)
755 output['include_dirs'] += (
756 filter(None, map(str.strip, pkg_cflags.split('-I'))))
757 elif options.__dict__[shared_lib + '_includes']:
758 output['include_dirs'] += [options.__dict__[shared_lib + '_includes']]
760 # libpath needs to be provided ahead libraries
762 output['libraries'] += [pkg_libpath]
763 elif options.__dict__[shared_lib + '_libpath']:
764 output['libraries'] += [
765 '-L%s' % options.__dict__[shared_lib + '_libpath']]
767 default_libs = getattr(options, shared_lib + '_libname')
768 default_libs = map('-l{0}'.format, default_libs.split(','))
771 output['libraries'] += pkg_libs.split()
773 output['libraries'] += default_libs
777 o['variables']['v8_enable_gdbjit'] = 1 if options.gdb else 0
778 o['variables']['v8_no_strict_aliasing'] = 1 # Work around compiler bugs.
779 o['variables']['v8_optimized_debug'] = 0 # Compile with -O0 in debug builds.
780 o['variables']['v8_random_seed'] = 0 # Use a random seed for hash tables.
781 o['variables']['v8_use_snapshot'] = 'false' if options.without_snapshot else 'true'
783 def configure_openssl(o):
784 o['variables']['node_use_openssl'] = b(not options.without_ssl)
785 o['variables']['node_shared_openssl'] = b(options.shared_openssl)
786 o['variables']['openssl_no_asm'] = 1 if options.openssl_no_asm else 0
787 if options.openssl_fips:
788 o['variables']['openssl_fips'] = options.openssl_fips
789 fips_dir = os.path.join(root_dir, 'deps', 'openssl', 'fips')
790 fips_ld = os.path.abspath(os.path.join(fips_dir, 'fipsld'))
791 o['make_fips_settings'] = [
792 ['LINK', fips_ld + ' <(openssl_fips)/bin/fipsld'],
795 o['variables']['openssl_fips'] = ''
798 if options.without_ssl:
800 configure_library('openssl', o)
803 def configure_static(o):
804 if options.fully_static or options.partly_static:
806 print("Generation of static executable will not work on OSX "
807 "when using the default compilation environment")
810 if options.fully_static:
811 o['libraries'] += ['-static']
812 elif options.partly_static:
813 o['libraries'] += ['-static-libgcc', '-static-libstdc++']
814 if options.enable_asan:
815 o['libraries'] += ['-static-libasan']
818 def configure_winsdk(o):
822 winsdk_dir = os.environ.get('WindowsSdkDir')
824 if winsdk_dir and os.path.isfile(winsdk_dir + '\\bin\\ctrpp.exe'):
825 print('Found ctrpp in WinSDK--will build generated files '
826 'into tools/msvs/genfiles.')
827 o['variables']['node_has_winsdk'] = 'true'
830 print('ctrpp not found in WinSDK path--using pre-gen files '
831 'from tools/msvs/genfiles.')
833 def write(filename, data):
834 filename = os.path.join(root_dir, filename)
835 print 'creating ', filename
836 f = open(filename, 'w+')
839 do_not_edit = '# Do not edit. Generated by the configure script.\n'
841 def glob_to_var(dir_base, dir_sub, patch_dir):
843 dir_all = os.path.join(dir_base, dir_sub)
844 files = os.walk(dir_all)
846 (path, dirs, files) = ent
848 if file.endswith('.cpp') or file.endswith('.c') or file.endswith('.h'):
849 # srcfile uses "slash" as dir separator as its output is consumed by gyp
850 srcfile = '%s/%s' % (dir_sub, file)
852 patchfile = '%s/%s/%s' % (dir_base, patch_dir, file)
853 if os.path.isfile(patchfile):
854 srcfile = '%s/%s' % (patch_dir, file)
855 print 'Using version-specific floating patch %s' % patchfile
860 def configure_intl(o):
863 'url': 'https://ssl.icu-project.org/files/icu4c/56.1/icu4c-56_1-src.zip',
864 'md5': '61d71888f14bf00cc3e8a6f2c087d367',
867 def icu_download(path):
868 # download ICU, if needed
869 if not os.access(options.download_path, os.W_OK):
870 print 'Error: cannot write to desired download path. ' \
871 'Either create it or verify permissions.'
876 local = url.split('/')[-1]
877 targetfile = os.path.join(options.download_path, local)
878 if not os.path.isfile(targetfile):
879 if nodedownload.candownload(auto_downloads, "icu"):
880 nodedownload.retrievefile(url, targetfile)
882 print ' Re-using existing %s' % targetfile
883 if os.path.isfile(targetfile):
884 sys.stdout.write(' Checking file integrity with MD5:\r')
885 gotmd5 = nodedownload.md5sum(targetfile)
886 print ' MD5: %s %s' % (gotmd5, targetfile)
890 print ' Expected: %s *MISMATCH*' % md5
891 print '\n ** Corrupted ZIP? Delete %s to retry download.\n' % targetfile
896 icu_config_name = 'icu_config.gypi'
897 def write_config(data, name):
900 # write an empty file to start with
901 write(icu_config_name, do_not_edit +
902 pprint.pformat(icu_config, indent=2) + '\n')
904 # always set icu_small, node.gyp depends on it being defined.
905 o['variables']['icu_small'] = b(False)
907 with_intl = options.with_intl
908 with_icu_source = options.with_icu_source
909 have_icu_path = bool(options.with_icu_path)
910 if have_icu_path and with_intl != 'none':
911 print 'Error: Cannot specify both --with-icu-path and --with-intl'
914 # Chromium .gyp mode: --with-icu-path
915 o['variables']['v8_enable_i18n_support'] = 1
917 o['variables']['icu_gyp_path'] = options.with_icu_path
919 # --with-intl=<with_intl>
921 if with_intl in (None, 'none'):
922 o['variables']['v8_enable_i18n_support'] = 0
924 elif with_intl == 'small-icu':
925 # small ICU (English only)
926 o['variables']['v8_enable_i18n_support'] = 1
927 o['variables']['icu_small'] = b(True)
928 locs = set(options.with_icu_locales.split(','))
929 locs.add('root') # must have root
930 o['variables']['icu_locales'] = string.join(locs,',')
931 elif with_intl == 'full-icu':
933 o['variables']['v8_enable_i18n_support'] = 1
934 elif with_intl == 'system-icu':
935 # ICU from pkg-config.
936 o['variables']['v8_enable_i18n_support'] = 1
937 pkgicu = pkg_config('icu-i18n')
938 if pkgicu[0] is None:
939 print 'Error: could not load pkg-config data for "icu-i18n".'
940 print 'See above errors or the README.md.'
942 (libs, cflags, libpath) = pkgicu
943 # libpath provides linker path which may contain spaces
945 o['libraries'] += [libpath]
946 # safe to split, cannot contain spaces
947 o['libraries'] += libs.split()
949 o['include_dirs'] += filter(None, map(str.strip, cflags.split('-I')))
950 # use the "system" .gyp
951 o['variables']['icu_gyp_path'] = 'tools/icu/icu-system.gyp'
954 # this is just the 'deps' dir. Used for unpacking.
955 icu_parent_path = os.path.join(root_dir, 'deps')
957 # The full path to the ICU source directory.
958 icu_full_path = os.path.join(icu_parent_path, 'icu')
960 # icu-tmp is used to download and unpack the ICU tarball.
961 icu_tmp_path = os.path.join(icu_parent_path, 'icu-tmp')
963 # --with-icu-source processing
964 # first, check that they didn't pass --with-icu-source=deps/icu
965 if with_icu_source and os.path.abspath(icu_full_path) == os.path.abspath(with_icu_source):
966 print 'Ignoring redundant --with-icu-source=%s' % (with_icu_source)
967 with_icu_source = None
968 # if with_icu_source is still set, try to use it.
970 if os.path.isdir(icu_full_path):
971 print 'Deleting old ICU source: %s' % (icu_full_path)
972 shutil.rmtree(icu_full_path)
973 # now, what path was given?
974 if os.path.isdir(with_icu_source):
975 # it's a path. Copy it.
976 print '%s -> %s' % (with_icu_source, icu_full_path)
977 shutil.copytree(with_icu_source, icu_full_path)
979 # could be file or URL.
980 # Set up temporary area
981 if os.path.isdir(icu_tmp_path):
982 shutil.rmtree(icu_tmp_path)
983 os.mkdir(icu_tmp_path)
985 if os.path.isfile(with_icu_source):
986 # it's a file. Try to unpack it.
987 icu_tarball = with_icu_source
989 # Can we download it?
990 local = os.path.join(icu_tmp_path, with_icu_source.split('/')[-1]) # local part
991 icu_tarball = nodedownload.retrievefile(with_icu_source, local)
992 # continue with "icu_tarball"
993 nodedownload.unpack(icu_tarball, icu_tmp_path)
994 # Did it unpack correctly? Should contain 'icu'
995 tmp_icu = os.path.join(icu_tmp_path, 'icu')
996 if os.path.isdir(tmp_icu):
997 os.rename(tmp_icu, icu_full_path)
998 shutil.rmtree(icu_tmp_path)
1000 print ' Error: --with-icu-source=%s did not result in an "icu" dir.' % with_icu_source
1001 shutil.rmtree(icu_tmp_path)
1004 # ICU mode. (icu-generic.gyp)
1005 o['variables']['icu_gyp_path'] = 'tools/icu/icu-generic.gyp'
1006 # ICU source dir relative to root
1007 o['variables']['icu_path'] = icu_full_path
1008 if not os.path.isdir(icu_full_path):
1009 print '* ECMA-402 (Intl) support didn\'t find ICU in %s..' % (icu_full_path)
1010 # can we download (or find) a zipfile?
1011 localzip = icu_download(icu_full_path)
1013 nodedownload.unpack(localzip, icu_parent_path)
1014 if not os.path.isdir(icu_full_path):
1015 print ' Cannot build Intl without ICU in %s.' % (icu_full_path)
1016 print ' (Fix, or disable with "--with-intl=none" )'
1019 print '* Using ICU in %s' % (icu_full_path)
1020 # Now, what version of ICU is it? We just need the "major", such as 54.
1021 # uvernum.h contains it as a #define.
1022 uvernum_h = os.path.join(icu_full_path, 'source/common/unicode/uvernum.h')
1023 if not os.path.isfile(uvernum_h):
1024 print ' Error: could not load %s - is ICU installed?' % uvernum_h
1026 icu_ver_major = None
1027 matchVerExp = r'^\s*#define\s+U_ICU_VERSION_SHORT\s+"([^"]*)".*'
1028 match_version = re.compile(matchVerExp)
1029 for line in open(uvernum_h).readlines():
1030 m = match_version.match(line)
1032 icu_ver_major = m.group(1)
1033 if not icu_ver_major:
1034 print ' Could not read U_ICU_VERSION_SHORT version from %s' % uvernum_h
1036 icu_endianness = sys.byteorder[0]; # TODO(srl295): EBCDIC should be 'e'
1037 o['variables']['icu_ver_major'] = icu_ver_major
1038 o['variables']['icu_endianness'] = icu_endianness
1039 icu_data_file_l = 'icudt%s%s.dat' % (icu_ver_major, 'l')
1040 icu_data_file = 'icudt%s%s.dat' % (icu_ver_major, icu_endianness)
1041 # relative to configure
1042 icu_data_path = os.path.join(icu_full_path,
1046 icu_data_in = os.path.join('../../deps/icu/source/data/in', icu_data_file_l)
1047 if not os.path.isfile(icu_data_path) and icu_endianness != 'l':
1048 # use host endianness
1049 icu_data_path = os.path.join(icu_full_path,
1053 icu_data_in = os.path.join('icu/source/data/in',
1055 # this is the input '.dat' file to use .. icudt*.dat
1056 # may be little-endian if from a icu-project.org tarball
1057 o['variables']['icu_data_in'] = icu_data_in
1058 # this is the icudt*.dat file which node will be using (platform endianness)
1059 o['variables']['icu_data_file'] = icu_data_file
1060 if not os.path.isfile(icu_data_path):
1061 print ' Error: ICU prebuilt data file %s does not exist.' % icu_data_path
1062 print ' See the README.md.'
1063 # .. and we're not about to build it from .gyp!
1065 # map from variable name to subdirs
1067 'stubdata': 'stubdata',
1071 'tools': 'tools/toolutil',
1072 'genccode': 'tools/genccode',
1073 'genrb': 'tools/genrb',
1074 'icupkg': 'tools/icupkg',
1076 # this creates a variable icu_src_XXX for each of the subdirs
1077 # with a list of the src files to use
1079 var = 'icu_src_%s' % i
1080 path = '../../deps/icu/source/%s' % icu_src[i]
1081 icu_config['variables'][var] = glob_to_var('tools/icu', path, 'patches/%s/source/%s' % (icu_ver_major, icu_src[i]) )
1082 # write updated icu_config.gypi with a bunch of paths
1083 write(icu_config_name, do_not_edit +
1084 pprint.pformat(icu_config, indent=2) + '\n')
1085 return # end of configure_intl
1088 'variables': { 'python': sys.executable },
1095 # Print a warning when the compiler is too old.
1096 check_compiler(output)
1098 # determine the "flavor" (operating system) we're building for,
1099 # leveraging gyp's GetFlavor function
1101 if (options.dest_os):
1102 flavor_params['flavor'] = options.dest_os
1103 flavor = GetFlavor(flavor_params)
1105 configure_node(output)
1106 configure_library('zlib', output)
1107 configure_library('http_parser', output)
1108 configure_library('libuv', output)
1109 configure_v8(output)
1110 configure_openssl(output)
1111 configure_winsdk(output)
1112 configure_intl(output)
1113 configure_static(output)
1115 # variables should be a root level element,
1116 # move everything else to target_defaults
1117 variables = output['variables']
1118 del output['variables']
1120 # make_global_settings for special FIPS linking
1121 # should not be used to compile modules in node-gyp
1122 config_fips = { 'make_global_settings' : [] }
1123 if 'make_fips_settings' in output:
1124 config_fips['make_global_settings'] = output['make_fips_settings']
1125 del output['make_fips_settings']
1126 write('config_fips.gypi', do_not_edit +
1127 pprint.pformat(config_fips, indent=2) + '\n')
1129 # make_global_settings should be a root level element too
1130 if 'make_global_settings' in output:
1131 make_global_settings = output['make_global_settings']
1132 del output['make_global_settings']
1134 make_global_settings = False
1137 'variables': variables,
1138 'target_defaults': output,
1140 if make_global_settings:
1141 output['make_global_settings'] = make_global_settings
1143 pprint.pprint(output, indent=2)
1145 write('config.gypi', do_not_edit +
1146 pprint.pformat(output, indent=2) + '\n')
1149 'BUILDTYPE': 'Debug' if options.debug else 'Release',
1150 'USE_XCODE': str(int(options.use_xcode or 0)),
1151 'PYTHON': sys.executable,
1155 config['PREFIX'] = options.prefix
1157 config = '\n'.join(map('='.join, config.iteritems())) + '\n'
1160 '# Do not edit. Generated by the configure script.\n' + config)
1162 gyp_args = [sys.executable, 'tools/gyp_node.py', '--no-parallel']
1164 if options.use_xcode:
1165 gyp_args += ['-f', 'xcode']
1166 elif flavor == 'win' and sys.platform != 'msys':
1167 gyp_args += ['-f', 'msvs', '-G', 'msvs_version=auto']
1169 gyp_args += ['-f', 'make-' + flavor]
1174 warn('warnings were emitted in the configure phase')
1176 sys.exit(subprocess.call(gyp_args))