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', 'vfpv2', '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 default compilation environment")
89 parser.add_option("--link-module",
92 help="Path to a JS file to be bundled in the binary as a builtin."
93 "This module will be referenced by path without extension."
94 "e.g. /root/x/y.js will be referenced via require('root/x/y')."
95 "Can be used multiple times")
97 parser.add_option("--openssl-no-asm",
99 dest="openssl_no_asm",
100 help="Do not build optimized assembly for OpenSSL")
102 parser.add_option('--openssl-fips',
105 help='Build OpenSSL using FIPS canister .o file in supplied folder')
107 shared_optgroup.add_option('--shared-http-parser',
109 dest='shared_http_parser',
110 help='link to a shared http_parser DLL instead of static linking')
112 shared_optgroup.add_option('--shared-http-parser-includes',
114 dest='shared_http_parser_includes',
115 help='directory containing http_parser header files')
117 shared_optgroup.add_option('--shared-http-parser-libname',
119 dest='shared_http_parser_libname',
120 default='http_parser',
121 help='alternative lib name to link to [default: %default]')
123 shared_optgroup.add_option('--shared-http-parser-libpath',
125 dest='shared_http_parser_libpath',
126 help='a directory to search for the shared http_parser DLL')
128 shared_optgroup.add_option('--shared-libuv',
131 help='link to a shared libuv DLL instead of static linking')
133 shared_optgroup.add_option('--shared-libuv-includes',
135 dest='shared_libuv_includes',
136 help='directory containing libuv header files')
138 shared_optgroup.add_option('--shared-libuv-libname',
140 dest='shared_libuv_libname',
142 help='alternative lib name to link to [default: %default]')
144 shared_optgroup.add_option('--shared-libuv-libpath',
146 dest='shared_libuv_libpath',
147 help='a directory to search for the shared libuv DLL')
149 shared_optgroup.add_option('--shared-openssl',
151 dest='shared_openssl',
152 help='link to a shared OpenSSl DLL instead of static linking')
154 shared_optgroup.add_option('--shared-openssl-includes',
156 dest='shared_openssl_includes',
157 help='directory containing OpenSSL header files')
159 shared_optgroup.add_option('--shared-openssl-libname',
161 dest='shared_openssl_libname',
162 default='crypto,ssl',
163 help='alternative lib name to link to [default: %default]')
165 shared_optgroup.add_option('--shared-openssl-libpath',
167 dest='shared_openssl_libpath',
168 help='a directory to search for the shared OpenSSL DLLs')
170 shared_optgroup.add_option('--shared-zlib',
173 help='link to a shared zlib DLL instead of static linking')
175 shared_optgroup.add_option('--shared-zlib-includes',
177 dest='shared_zlib_includes',
178 help='directory containing zlib header files')
180 shared_optgroup.add_option('--shared-zlib-libname',
182 dest='shared_zlib_libname',
184 help='alternative lib name to link to [default: %default]')
186 shared_optgroup.add_option('--shared-zlib-libpath',
188 dest='shared_zlib_libpath',
189 help='a directory to search for the shared zlib DLL')
191 parser.add_option_group(shared_optgroup)
193 # TODO document when we've decided on what the tracing API and its options will
195 parser.add_option('--systemtap-includes',
197 dest='systemtap_includes',
198 help=optparse.SUPPRESS_HELP)
200 parser.add_option('--tag',
203 help='custom build tag')
205 parser.add_option('--release-urlbase',
207 dest='release_urlbase',
208 help='Provide a custom URL prefix for the `process.release` properties '
209 '`sourceUrl` and `headersUrl`. When compiling a release build, this '
210 'will default to https://nodejs.org/download/release/')
212 parser.add_option('--v8-options',
215 help='v8 options to pass, see `node --v8-options` for examples.')
217 parser.add_option('--with-arm-float-abi',
219 dest='arm_float_abi',
220 choices=valid_arm_float_abi,
221 help='specifies which floating-point ABI to use ({0}).'.format(
222 ', '.join(valid_arm_float_abi)))
224 parser.add_option('--with-arm-fpu',
227 choices=valid_arm_fpu,
228 help='ARM FPU mode ({0}) [default: %default]'.format(
229 ', '.join(valid_arm_fpu)))
231 parser.add_option('--with-mips-arch-variant',
233 dest='mips_arch_variant',
235 choices=valid_mips_arch,
236 help='MIPS arch variant ({0}) [default: %default]'.format(
237 ', '.join(valid_mips_arch)))
239 parser.add_option('--with-mips-fpu-mode',
241 dest='mips_fpu_mode',
243 choices=valid_mips_fpu,
244 help='MIPS FPU mode ({0}) [default: %default]'.format(
245 ', '.join(valid_mips_fpu)))
247 parser.add_option('--with-mips-float-abi',
249 dest='mips_float_abi',
251 choices=valid_mips_float_abi,
252 help='MIPS floating-point ABI ({0}) [default: %default]'.format(
253 ', '.join(valid_mips_float_abi)))
255 parser.add_option('--with-dtrace',
258 help='build with DTrace (default is true on sunos and darwin)')
260 parser.add_option('--with-lttng',
263 help='build with Lttng (Only available to Linux)')
265 parser.add_option('--with-etw',
268 help='build with ETW (default is true on Windows)')
270 intl_optgroup.add_option('--with-intl',
274 choices=valid_intl_modes,
275 help='Intl mode (valid choices: {0}) [default: %default]'.format(
276 ', '.join(valid_intl_modes)))
278 intl_optgroup.add_option('--with-icu-path',
280 dest='with_icu_path',
281 help='Path to icu.gyp (ICU i18n, Chromium version only.)')
283 intl_optgroup.add_option('--with-icu-locales',
285 dest='with_icu_locales',
287 help='Comma-separated list of locales for "small-icu". "root" is assumed. '
288 '[default: %default]')
290 intl_optgroup.add_option('--with-icu-source',
292 dest='with_icu_source',
293 help='Intl mode: optional local path to icu/ dir, or path/URL of icu source archive.')
295 intl_optgroup.add_option('--download',
297 dest='download_list',
298 help=nodedownload.help())
300 intl_optgroup.add_option('--download-path',
302 dest='download_path',
303 default=os.path.join(root_dir, 'deps'),
304 help='Download directory [default: %default]')
306 parser.add_option_group(intl_optgroup)
308 parser.add_option('--with-perfctr',
311 help='build with performance counters (default is true on Windows)')
313 parser.add_option('--without-dtrace',
315 dest='without_dtrace',
316 help='build without DTrace')
318 parser.add_option('--without-etw',
321 help='build without ETW')
323 parser.add_option('--without-npm',
326 help='don\'t install the bundled npm package manager')
328 parser.add_option('--without-perfctr',
330 dest='without_perfctr',
331 help='build without performance counters')
333 # Dummy option for backwards compatibility
334 parser.add_option('--with-snapshot',
336 dest='unused_with_snapshot',
337 help=optparse.SUPPRESS_HELP)
339 parser.add_option('--without-snapshot',
341 dest='without_snapshot',
342 help=optparse.SUPPRESS_HELP)
344 parser.add_option('--without-ssl',
347 help='build without SSL')
349 parser.add_option('--xcode',
352 help='generate build files for use with xcode')
354 parser.add_option('--enable-asan',
357 help='build with asan')
359 parser.add_option('--enable-static',
361 dest='enable_static',
362 help='build as static library')
364 (options, args) = parser.parse_args()
366 # Expand ~ in the install prefix now, it gets written to multiple files.
367 options.prefix = os.path.expanduser(options.prefix or '')
369 # set up auto-download list
370 auto_downloads = nodedownload.parse(options.download_list)
375 prefix = '\033[1m\033[93mWARNING\033[0m' if os.isatty(1) else 'WARNING'
376 print('%s: %s' % (prefix, msg))
378 # track if warnings occured
382 """Returns the string 'true' if value is truthy, 'false' otherwise."""
390 pkg_config = os.environ.get('PKG_CONFIG', 'pkg-config')
391 args = '--silence-errors'
393 for flag in ['--libs-only-l', '--cflags-only-I', '--libs-only-L']:
395 val = subprocess.check_output([pkg_config, args, flag, pkg])
396 # check_output returns bytes
397 val = val.encode().strip().rstrip('\n')
398 except subprocess.CalledProcessError:
399 # most likely missing a .pc-file
402 # no pkg-config/pkgconf installed
403 return (None, None, None)
408 def try_check_compiler(cc, lang):
410 proc = subprocess.Popen(shlex.split(cc) + ['-E', '-P', '-x', lang, '-'],
411 stdin=subprocess.PIPE, stdout=subprocess.PIPE)
413 return (False, False, '', '')
415 proc.stdin.write('__clang__ __GNUC__ __GNUC_MINOR__ __GNUC_PATCHLEVEL__ '
416 '__clang_major__ __clang_minor__ __clang_patchlevel__')
418 values = (proc.communicate()[0].split() + ['0'] * 7)[0:7]
419 is_clang = values[0] == '1'
420 gcc_version = '%s.%s.%s' % tuple(values[1:1+3])
421 clang_version = '%s.%s.%s' % tuple(values[4:4+3])
423 return (True, is_clang, clang_version, gcc_version)
427 # The version of asm compiler is needed for building openssl asm files.
428 # See deps/openssl/openssl.gypi for detail.
429 # Commands and regular expressions to obtain its version number are taken from
430 # https://github.com/openssl/openssl/blob/OpenSSL_1_0_2-stable/crypto/sha/asm/sha512-x86_64.pl#L112-L129
432 def get_llvm_version(cc):
434 proc = subprocess.Popen(shlex.split(cc) + ['-v'], stdin=subprocess.PIPE,
435 stderr=subprocess.PIPE, stdout=subprocess.PIPE)
437 print '''Node.js configure error: No acceptable C compiler found!
439 Please make sure you have a C compiler installed on your system and/or
440 consider adjusting the CC environment variable if you installed
441 it in a non-standard prefix.
445 match = re.search(r"(^clang version|based on LLVM) ([3-9]\.[0-9]+)",
446 proc.communicate()[1])
449 return match.group(2)
454 def get_gas_version(cc):
456 proc = subprocess.Popen(shlex.split(cc) + ['-Wa,-v', '-c', '-o',
458 'assembler', '/dev/null'],
459 stdin=subprocess.PIPE, stderr=subprocess.PIPE,
460 stdout=subprocess.PIPE)
462 print '''Node.js configure error: No acceptable C compiler found!
464 Please make sure you have a C compiler installed on your system and/or
465 consider adjusting the CC environment variable if you installed
466 it in a non-standard prefix.
470 match = re.match(r"GNU assembler version ([2-9]\.[0-9]+)",
471 proc.communicate()[1])
474 return match.group(1)
478 # Note: Apple clang self-reports as clang 4.2.0 and gcc 4.2.1. It passes
479 # the version check more by accident than anything else but a more rigorous
480 # check involves checking the build number against a whitelist. I'm not
481 # quite prepared to go that far yet.
482 def check_compiler(o):
483 if sys.platform == 'win32':
486 ok, is_clang, clang_version, gcc_version = try_check_compiler(CXX, 'c++')
488 warn('failed to autodetect C++ compiler version (CXX=%s)' % CXX)
489 elif clang_version < '3.4.0' if is_clang else gcc_version < '4.8.0':
490 warn('C++ compiler too old, need g++ 4.8 or clang++ 3.4 (CXX=%s)' % CXX)
492 ok, is_clang, clang_version, gcc_version = try_check_compiler(CC, 'c')
494 warn('failed to autodetect C compiler version (CC=%s)' % CC)
495 elif not is_clang and gcc_version < '4.2.0':
496 # clang 3.2 is a little white lie because any clang version will probably
497 # do for the C bits. However, we might as well encourage people to upgrade
498 # to a version that is not completely ancient.
499 warn('C compiler too old, need gcc 4.2 or clang 3.2 (CC=%s)' % CC)
501 # Need llvm_version or gas_version when openssl asm files are compiled
502 if options.without_ssl or options.openssl_no_asm or options.shared_openssl:
506 o['variables']['llvm_version'] = get_llvm_version(CC)
508 o['variables']['gas_version'] = get_gas_version(CC)
511 def cc_macros(cc=None):
512 """Checks predefined macros using the C compiler command."""
515 p = subprocess.Popen(shlex.split(cc or CC) + ['-dM', '-E', '-'],
516 stdin=subprocess.PIPE,
517 stdout=subprocess.PIPE,
518 stderr=subprocess.PIPE)
520 print '''Node.js configure error: No acceptable C compiler found!
522 Please make sure you have a C compiler installed on your system and/or
523 consider adjusting the CC environment variable if you installed
524 it in a non-standard prefix.
529 out = p.communicate()[0]
531 out = str(out).split('\n')
535 lst = shlex.split(line)
544 """Check for ARMv7 instructions"""
545 cc_macros_cache = cc_macros()
546 return ('__ARM_ARCH_7__' in cc_macros_cache or
547 '__ARM_ARCH_7A__' in cc_macros_cache or
548 '__ARM_ARCH_7R__' in cc_macros_cache or
549 '__ARM_ARCH_7M__' in cc_macros_cache or
550 '__ARM_ARCH_7S__' in cc_macros_cache)
554 """Check for ARMv6 instructions"""
555 cc_macros_cache = cc_macros()
556 return ('__ARM_ARCH_6__' in cc_macros_cache or
557 '__ARM_ARCH_6M__' in cc_macros_cache)
560 def is_arm_hard_float_abi():
561 """Check for hardfloat or softfloat eabi on ARM"""
562 # GCC versions 4.6 and above define __ARM_PCS or __ARM_PCS_VFP to specify
563 # the Floating Point ABI used (PCS stands for Procedure Call Standard).
564 # We use these as well as a couple of other defines to statically determine
567 return '__ARM_PCS_VFP' in cc_macros()
571 """Host architecture check using the CC command."""
573 if sys.platform.startswith('aix'):
574 # we only support gcc at this point and the default on AIX
575 # would be xlc so hard code gcc
581 '__aarch64__' : 'arm64',
584 '__MIPSEL__' : 'mipsel',
586 '__PPC64__' : 'ppc64',
588 '__x86_64__' : 'x64',
591 rtn = 'ia32' # default
594 if i in k and k[i] != '0':
602 """Host architecture check using environ vars (better way to do this?)"""
604 observed_arch = os.environ.get('PROCESSOR_ARCHITECTURE', 'x86')
605 arch = os.environ.get('PROCESSOR_ARCHITEW6432', observed_arch)
614 return matchup.get(arch, 'ia32')
617 def configure_arm(o):
618 if options.arm_float_abi:
619 arm_float_abi = options.arm_float_abi
620 elif is_arm_hard_float_abi():
621 arm_float_abi = 'hard'
623 arm_float_abi = 'default'
629 o['variables']['arm_version'] = '7'
631 o['variables']['arm_version'] = '6' if is_arch_armv6() else 'default'
633 o['variables']['arm_thumb'] = 0 # -marm
634 o['variables']['arm_float_abi'] = arm_float_abi
636 if options.dest_os == 'android':
638 o['variables']['arm_version'] = '7'
640 o['variables']['arm_fpu'] = options.arm_fpu or arm_fpu
643 def configure_mips(o):
644 can_use_fpu_instructions = (options.mips_float_abi != 'soft')
645 o['variables']['v8_can_use_fpu_instructions'] = b(can_use_fpu_instructions)
646 o['variables']['v8_use_mips_abi_hardfloat'] = b(can_use_fpu_instructions)
647 o['variables']['mips_arch_variant'] = options.mips_arch_variant
648 o['variables']['mips_fpu_mode'] = options.mips_fpu_mode
651 def configure_node(o):
652 if options.dest_os == 'android':
653 o['variables']['OS'] = 'android'
654 o['variables']['node_prefix'] = options.prefix
655 o['variables']['node_install_npm'] = b(not options.without_npm)
656 o['default_configuration'] = 'Debug' if options.debug else 'Release'
658 host_arch = host_arch_win() if os.name == 'nt' else host_arch_cc()
659 target_arch = options.dest_cpu or host_arch
660 # ia32 is preferred by the build tools (GYP) over x86 even if we prefer the latter
661 # the Makefile resets this to x86 afterward
662 if target_arch == 'x86':
664 o['variables']['host_arch'] = host_arch
665 o['variables']['target_arch'] = target_arch
666 o['variables']['node_byteorder'] = sys.byteorder
668 cross_compiling = target_arch != host_arch
669 want_snapshots = not options.without_snapshot
670 o['variables']['want_separate_host_toolset'] = int(
671 cross_compiling and want_snapshots)
673 if target_arch == 'arm':
675 elif target_arch in ('mips', 'mipsel'):
678 if flavor in ('solaris', 'mac', 'linux', 'freebsd'):
679 use_dtrace = not options.without_dtrace
680 # Don't enable by default on linux and freebsd
681 if flavor in ('linux', 'freebsd'):
682 use_dtrace = options.with_dtrace
684 if flavor == 'linux':
685 if options.systemtap_includes:
686 o['include_dirs'] += [options.systemtap_includes]
687 o['variables']['node_use_dtrace'] = b(use_dtrace)
688 o['variables']['uv_use_dtrace'] = b(use_dtrace)
689 o['variables']['uv_parent_path'] = '/deps/uv/'
690 elif options.with_dtrace:
692 'DTrace is currently only supported on SunOS, MacOS or Linux systems.')
694 o['variables']['node_use_dtrace'] = 'false'
696 # Enable Lttng if --with-lttng was defined. Use logic similar to
697 # ETW for windows. Lttng is only available on the Linux platform.
698 if flavor == 'linux':
699 o['variables']['node_use_lttng'] = b(options.with_lttng)
700 elif options.with_lttng:
701 raise Exception('lttng is only supported on Linux.')
703 o['variables']['node_use_lttng'] = 'false'
705 if options.no_ifaddrs:
706 o['defines'] += ['SUNOS_NO_IFADDRS']
708 # By default, enable ETW on Windows.
710 o['variables']['node_use_etw'] = b(not options.without_etw)
711 elif options.with_etw:
712 raise Exception('ETW is only supported on Windows.')
714 o['variables']['node_use_etw'] = 'false'
716 # By default, enable Performance counters on Windows.
718 o['variables']['node_use_perfctr'] = b(not options.without_perfctr)
719 elif options.with_perfctr:
720 raise Exception('Performance counter is only supported on Windows.')
722 o['variables']['node_use_perfctr'] = 'false'
725 o['variables']['node_tag'] = '-' + options.tag
727 o['variables']['node_tag'] = ''
729 o['variables']['node_release_urlbase'] = options.release_urlbase or ''
731 if options.v8_options:
732 o['variables']['node_v8_options'] = options.v8_options.replace('"', '\\"')
734 if options.enable_static:
735 o['variables']['node_target_type'] = 'static_library'
737 if options.linked_module:
738 o['variables']['library_files'] = options.linked_module
740 o['variables']['asan'] = int(options.enable_asan or 0)
742 def configure_library(lib, output):
743 shared_lib = 'shared_' + lib
744 output['variables']['node_' + shared_lib] = b(getattr(options, shared_lib))
746 if getattr(options, shared_lib):
747 (pkg_libs, pkg_cflags, pkg_libpath) = pkg_config(lib)
750 output['include_dirs'] += (
751 filter(None, map(str.strip, pkg_cflags.split('-I'))))
752 elif options.__dict__[shared_lib + '_includes']:
753 output['include_dirs'] += [options.__dict__[shared_lib + '_includes']]
755 # libpath needs to be provided ahead libraries
757 output['libraries'] += [pkg_libpath]
758 elif options.__dict__[shared_lib + '_libpath']:
759 output['libraries'] += [
760 '-L%s' % options.__dict__[shared_lib + '_libpath']]
762 default_libs = getattr(options, shared_lib + '_libname')
763 default_libs = map('-l{0}'.format, default_libs.split(','))
766 output['libraries'] += pkg_libs.split()
768 output['libraries'] += default_libs
772 o['variables']['v8_enable_gdbjit'] = 1 if options.gdb else 0
773 o['variables']['v8_no_strict_aliasing'] = 1 # Work around compiler bugs.
774 o['variables']['v8_optimized_debug'] = 0 # Compile with -O0 in debug builds.
775 o['variables']['v8_random_seed'] = 0 # Use a random seed for hash tables.
776 o['variables']['v8_use_snapshot'] = 0 if options.without_snapshot else 1
778 def configure_openssl(o):
779 o['variables']['node_use_openssl'] = b(not options.without_ssl)
780 o['variables']['node_shared_openssl'] = b(options.shared_openssl)
781 o['variables']['openssl_no_asm'] = 1 if options.openssl_no_asm else 0
782 if options.openssl_fips:
783 o['variables']['openssl_fips'] = options.openssl_fips
784 fips_dir = os.path.join(root_dir, 'deps', 'openssl', 'fips')
785 fips_ld = os.path.abspath(os.path.join(fips_dir, 'fipsld'))
786 o['make_global_settings'] = [
787 ['LINK', fips_ld + ' <(openssl_fips)/bin/fipsld'],
790 o['variables']['openssl_fips'] = ''
793 if options.without_ssl:
795 configure_library('openssl', o)
798 def configure_fullystatic(o):
799 if options.fully_static:
800 o['libraries'] += ['-static']
802 print("Generation of static executable will not work on OSX "
803 "when using default compilation environment")
806 def configure_winsdk(o):
810 winsdk_dir = os.environ.get('WindowsSdkDir')
812 if winsdk_dir and os.path.isfile(winsdk_dir + '\\bin\\ctrpp.exe'):
813 print('Found ctrpp in WinSDK--will build generated files '
814 'into tools/msvs/genfiles.')
815 o['variables']['node_has_winsdk'] = 'true'
818 print('ctrpp not found in WinSDK path--using pre-gen files '
819 'from tools/msvs/genfiles.')
821 def write(filename, data):
822 filename = os.path.join(root_dir, filename)
823 print 'creating ', filename
824 f = open(filename, 'w+')
827 do_not_edit = '# Do not edit. Generated by the configure script.\n'
829 def glob_to_var(dir_base, dir_sub, patch_dir):
831 dir_all = os.path.join(dir_base, dir_sub)
832 files = os.walk(dir_all)
834 (path, dirs, files) = ent
836 if file.endswith('.cpp') or file.endswith('.c') or file.endswith('.h'):
837 # srcfile uses "slash" as dir separator as its output is consumed by gyp
838 srcfile = '%s/%s' % (dir_sub, file)
840 patchfile = '%s/%s/%s' % (dir_base, patch_dir, file)
841 if os.path.isfile(patchfile):
842 srcfile = '%s/%s' % (patch_dir, file)
843 print 'Using version-specific floating patch %s' % patchfile
848 def configure_intl(o):
851 'url': 'https://ssl.icu-project.org/files/icu4c/56.1/icu4c-56_1-src.zip',
852 'md5': '61d71888f14bf00cc3e8a6f2c087d367',
855 def icu_download(path):
856 # download ICU, if needed
857 if not os.access(options.download_path, os.W_OK):
858 print 'Error: cannot write to desired download path. ' \
859 'Either create it or verify permissions.'
864 local = url.split('/')[-1]
865 targetfile = os.path.join(options.download_path, local)
866 if not os.path.isfile(targetfile):
867 if nodedownload.candownload(auto_downloads, "icu"):
868 nodedownload.retrievefile(url, targetfile)
870 print ' Re-using existing %s' % targetfile
871 if os.path.isfile(targetfile):
872 sys.stdout.write(' Checking file integrity with MD5:\r')
873 gotmd5 = nodedownload.md5sum(targetfile)
874 print ' MD5: %s %s' % (gotmd5, targetfile)
878 print ' Expected: %s *MISMATCH*' % md5
879 print '\n ** Corrupted ZIP? Delete %s to retry download.\n' % targetfile
884 icu_config_name = 'icu_config.gypi'
885 def write_config(data, name):
888 # write an empty file to start with
889 write(icu_config_name, do_not_edit +
890 pprint.pformat(icu_config, indent=2) + '\n')
892 # always set icu_small, node.gyp depends on it being defined.
893 o['variables']['icu_small'] = b(False)
895 with_intl = options.with_intl
896 with_icu_source = options.with_icu_source
897 have_icu_path = bool(options.with_icu_path)
898 if have_icu_path and with_intl != 'none':
899 print 'Error: Cannot specify both --with-icu-path and --with-intl'
902 # Chromium .gyp mode: --with-icu-path
903 o['variables']['v8_enable_i18n_support'] = 1
905 o['variables']['icu_gyp_path'] = options.with_icu_path
907 # --with-intl=<with_intl>
909 if with_intl in (None, 'none'):
910 o['variables']['v8_enable_i18n_support'] = 0
912 elif with_intl == 'small-icu':
913 # small ICU (English only)
914 o['variables']['v8_enable_i18n_support'] = 1
915 o['variables']['icu_small'] = b(True)
916 locs = set(options.with_icu_locales.split(','))
917 locs.add('root') # must have root
918 o['variables']['icu_locales'] = string.join(locs,',')
919 elif with_intl == 'full-icu':
921 o['variables']['v8_enable_i18n_support'] = 1
922 elif with_intl == 'system-icu':
923 # ICU from pkg-config.
924 o['variables']['v8_enable_i18n_support'] = 1
925 pkgicu = pkg_config('icu-i18n')
926 if pkgicu[0] is None:
927 print 'Error: could not load pkg-config data for "icu-i18n".'
928 print 'See above errors or the README.md.'
930 (libs, cflags, libpath) = pkgicu
931 # libpath provides linker path which may contain spaces
933 o['libraries'] += [libpath]
934 # safe to split, cannot contain spaces
935 o['libraries'] += libs.split()
937 o['include_dirs'] += filter(None, map(str.strip, cflags.split('-I')))
938 # use the "system" .gyp
939 o['variables']['icu_gyp_path'] = 'tools/icu/icu-system.gyp'
942 # this is just the 'deps' dir. Used for unpacking.
943 icu_parent_path = os.path.join(root_dir, 'deps')
945 # The full path to the ICU source directory.
946 icu_full_path = os.path.join(icu_parent_path, 'icu')
948 # icu-tmp is used to download and unpack the ICU tarball.
949 icu_tmp_path = os.path.join(icu_parent_path, 'icu-tmp')
951 # --with-icu-source processing
952 # first, check that they didn't pass --with-icu-source=deps/icu
953 if with_icu_source and os.path.abspath(icu_full_path) == os.path.abspath(with_icu_source):
954 print 'Ignoring redundant --with-icu-source=%s' % (with_icu_source)
955 with_icu_source = None
956 # if with_icu_source is still set, try to use it.
958 if os.path.isdir(icu_full_path):
959 print 'Deleting old ICU source: %s' % (icu_full_path)
960 shutil.rmtree(icu_full_path)
961 # now, what path was given?
962 if os.path.isdir(with_icu_source):
963 # it's a path. Copy it.
964 print '%s -> %s' % (with_icu_source, icu_full_path)
965 shutil.copytree(with_icu_source, icu_full_path)
967 # could be file or URL.
968 # Set up temporary area
969 if os.path.isdir(icu_tmp_path):
970 shutil.rmtree(icu_tmp_path)
971 os.mkdir(icu_tmp_path)
973 if os.path.isfile(with_icu_source):
974 # it's a file. Try to unpack it.
975 icu_tarball = with_icu_source
977 # Can we download it?
978 local = os.path.join(icu_tmp_path, with_icu_source.split('/')[-1]) # local part
979 icu_tarball = nodedownload.retrievefile(with_icu_source, local)
980 # continue with "icu_tarball"
981 nodedownload.unpack(icu_tarball, icu_tmp_path)
982 # Did it unpack correctly? Should contain 'icu'
983 tmp_icu = os.path.join(icu_tmp_path, 'icu')
984 if os.path.isdir(tmp_icu):
985 os.rename(tmp_icu, icu_full_path)
986 shutil.rmtree(icu_tmp_path)
988 print ' Error: --with-icu-source=%s did not result in an "icu" dir.' % with_icu_source
989 shutil.rmtree(icu_tmp_path)
992 # ICU mode. (icu-generic.gyp)
993 o['variables']['icu_gyp_path'] = 'tools/icu/icu-generic.gyp'
994 # ICU source dir relative to root
995 o['variables']['icu_path'] = icu_full_path
996 if not os.path.isdir(icu_full_path):
997 print '* ECMA-402 (Intl) support didn\'t find ICU in %s..' % (icu_full_path)
998 # can we download (or find) a zipfile?
999 localzip = icu_download(icu_full_path)
1001 nodedownload.unpack(localzip, icu_parent_path)
1002 if not os.path.isdir(icu_full_path):
1003 print ' Cannot build Intl without ICU in %s.' % (icu_full_path)
1004 print ' (Fix, or disable with "--with-intl=none" )'
1007 print '* Using ICU in %s' % (icu_full_path)
1008 # Now, what version of ICU is it? We just need the "major", such as 54.
1009 # uvernum.h contains it as a #define.
1010 uvernum_h = os.path.join(icu_full_path, 'source/common/unicode/uvernum.h')
1011 if not os.path.isfile(uvernum_h):
1012 print ' Error: could not load %s - is ICU installed?' % uvernum_h
1014 icu_ver_major = None
1015 matchVerExp = r'^\s*#define\s+U_ICU_VERSION_SHORT\s+"([^"]*)".*'
1016 match_version = re.compile(matchVerExp)
1017 for line in open(uvernum_h).readlines():
1018 m = match_version.match(line)
1020 icu_ver_major = m.group(1)
1021 if not icu_ver_major:
1022 print ' Could not read U_ICU_VERSION_SHORT version from %s' % uvernum_h
1024 icu_endianness = sys.byteorder[0]; # TODO(srl295): EBCDIC should be 'e'
1025 o['variables']['icu_ver_major'] = icu_ver_major
1026 o['variables']['icu_endianness'] = icu_endianness
1027 icu_data_file_l = 'icudt%s%s.dat' % (icu_ver_major, 'l')
1028 icu_data_file = 'icudt%s%s.dat' % (icu_ver_major, icu_endianness)
1029 # relative to configure
1030 icu_data_path = os.path.join(icu_full_path,
1034 icu_data_in = os.path.join('../../deps/icu/source/data/in', icu_data_file_l)
1035 if not os.path.isfile(icu_data_path) and icu_endianness != 'l':
1036 # use host endianness
1037 icu_data_path = os.path.join(icu_full_path,
1041 icu_data_in = os.path.join('icu/source/data/in',
1043 # this is the input '.dat' file to use .. icudt*.dat
1044 # may be little-endian if from a icu-project.org tarball
1045 o['variables']['icu_data_in'] = icu_data_in
1046 # this is the icudt*.dat file which node will be using (platform endianness)
1047 o['variables']['icu_data_file'] = icu_data_file
1048 if not os.path.isfile(icu_data_path):
1049 print ' Error: ICU prebuilt data file %s does not exist.' % icu_data_path
1050 print ' See the README.md.'
1051 # .. and we're not about to build it from .gyp!
1053 # map from variable name to subdirs
1055 'stubdata': 'stubdata',
1059 'tools': 'tools/toolutil',
1060 'genccode': 'tools/genccode',
1061 'genrb': 'tools/genrb',
1062 'icupkg': 'tools/icupkg',
1064 # this creates a variable icu_src_XXX for each of the subdirs
1065 # with a list of the src files to use
1067 var = 'icu_src_%s' % i
1068 path = '../../deps/icu/source/%s' % icu_src[i]
1069 icu_config['variables'][var] = glob_to_var('tools/icu', path, 'patches/%s/source/%s' % (icu_ver_major, icu_src[i]) )
1070 # write updated icu_config.gypi with a bunch of paths
1071 write(icu_config_name, do_not_edit +
1072 pprint.pformat(icu_config, indent=2) + '\n')
1073 return # end of configure_intl
1076 'variables': { 'python': sys.executable },
1083 # Print a warning when the compiler is too old.
1084 check_compiler(output)
1086 # determine the "flavor" (operating system) we're building for,
1087 # leveraging gyp's GetFlavor function
1089 if (options.dest_os):
1090 flavor_params['flavor'] = options.dest_os
1091 flavor = GetFlavor(flavor_params)
1093 configure_node(output)
1094 configure_library('zlib', output)
1095 configure_library('http_parser', output)
1096 configure_library('libuv', output)
1097 configure_v8(output)
1098 configure_openssl(output)
1099 configure_winsdk(output)
1100 configure_intl(output)
1101 configure_fullystatic(output)
1103 # variables should be a root level element,
1104 # move everything else to target_defaults
1105 variables = output['variables']
1106 del output['variables']
1108 # make_global_settings should be a root level element too
1109 if 'make_global_settings' in output:
1110 make_global_settings = output['make_global_settings']
1111 del output['make_global_settings']
1113 make_global_settings = False
1116 'variables': variables,
1117 'target_defaults': output,
1119 if make_global_settings:
1120 output['make_global_settings'] = make_global_settings
1122 pprint.pprint(output, indent=2)
1124 write('config.gypi', do_not_edit +
1125 pprint.pformat(output, indent=2) + '\n')
1128 'BUILDTYPE': 'Debug' if options.debug else 'Release',
1129 'USE_XCODE': str(int(options.use_xcode or 0)),
1130 'PYTHON': sys.executable,
1134 config['PREFIX'] = options.prefix
1136 config = '\n'.join(map('='.join, config.iteritems())) + '\n'
1139 '# Do not edit. Generated by the configure script.\n' + config)
1141 gyp_args = [sys.executable, 'tools/gyp_node.py', '--no-parallel']
1143 if options.use_xcode:
1144 gyp_args += ['-f', 'xcode']
1145 elif flavor == 'win' and sys.platform != 'msys':
1146 gyp_args += ['-f', 'msvs', '-G', 'msvs_version=auto']
1148 gyp_args += ['-f', 'make-' + flavor]
1153 warn('warnings were emitted in the configure phase')
1155 sys.exit(subprocess.call(gyp_args))