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_mips_arch = ('loongson', 'r1', 'r2', 'r6', 'rx')
34 valid_mips_fpu = ('fp32', 'fp64', 'fpxx')
35 valid_mips_float_abi = ('soft', 'hard')
36 valid_intl_modes = ('none', 'small-icu', 'full-icu', 'system-icu')
38 # create option groups
39 shared_optgroup = optparse.OptionGroup(parser, "Shared libraries",
40 "Flags that allows you to control whether you want to build against "
41 "built-in dependencies or its shared representations. If necessary, "
42 "provide multiple libraries with comma.")
43 intl_optgroup = optparse.OptionGroup(parser, "Internationalization",
44 "Flags that lets you enable i18n features in Node.js as well as which "
45 "library you want to build against.")
47 # Options should be in alphabetical order but keep --prefix at the top,
48 # that's arguably the one people will be looking for most.
49 parser.add_option('--prefix',
53 help='select the install prefix [default: %default]')
55 parser.add_option('--debug',
58 help='also build debug build')
60 parser.add_option('--dest-cpu',
64 help='CPU architecture to build for ({0})'.format(', '.join(valid_arch)))
66 parser.add_option('--dest-os',
70 help='operating system to build for ({0})'.format(', '.join(valid_os)))
72 parser.add_option('--gdb',
75 help='add gdb support')
77 parser.add_option('--no-ifaddrs',
80 help='use on deprecated SunOS systems that do not support ifaddrs.h')
82 parser.add_option("--fully-static",
85 help="Generate an executable without external dynamic libraries. This "
86 "will not work on OSX when using default compilation environment")
88 parser.add_option("--link-module",
91 help="Path to a JS file to be bundled in the binary as a builtin."
92 "This module will be referenced by basename without extension."
93 "Can be used multiple times")
95 parser.add_option("--openssl-no-asm",
97 dest="openssl_no_asm",
98 help="Do not build optimized assembly for OpenSSL")
100 parser.add_option('--openssl-fips',
103 help='Build OpenSSL using FIPS canister .o file in supplied folder')
105 shared_optgroup.add_option('--shared-http-parser',
107 dest='shared_http_parser',
108 help='link to a shared http_parser DLL instead of static linking')
110 shared_optgroup.add_option('--shared-http-parser-includes',
112 dest='shared_http_parser_includes',
113 help='directory containing http_parser header files')
115 shared_optgroup.add_option('--shared-http-parser-libname',
117 dest='shared_http_parser_libname',
118 default='http_parser',
119 help='alternative lib name to link to [default: %default]')
121 shared_optgroup.add_option('--shared-http-parser-libpath',
123 dest='shared_http_parser_libpath',
124 help='a directory to search for the shared http_parser DLL')
126 shared_optgroup.add_option('--shared-libuv',
129 help='link to a shared libuv DLL instead of static linking')
131 shared_optgroup.add_option('--shared-libuv-includes',
133 dest='shared_libuv_includes',
134 help='directory containing libuv header files')
136 shared_optgroup.add_option('--shared-libuv-libname',
138 dest='shared_libuv_libname',
140 help='alternative lib name to link to [default: %default]')
142 shared_optgroup.add_option('--shared-libuv-libpath',
144 dest='shared_libuv_libpath',
145 help='a directory to search for the shared libuv DLL')
147 shared_optgroup.add_option('--shared-openssl',
149 dest='shared_openssl',
150 help='link to a shared OpenSSl DLL instead of static linking')
152 shared_optgroup.add_option('--shared-openssl-includes',
154 dest='shared_openssl_includes',
155 help='directory containing OpenSSL header files')
157 shared_optgroup.add_option('--shared-openssl-libname',
159 dest='shared_openssl_libname',
160 default='crypto,ssl',
161 help='alternative lib name to link to [default: %default]')
163 shared_optgroup.add_option('--shared-openssl-libpath',
165 dest='shared_openssl_libpath',
166 help='a directory to search for the shared OpenSSL DLLs')
168 shared_optgroup.add_option('--shared-zlib',
171 help='link to a shared zlib DLL instead of static linking')
173 shared_optgroup.add_option('--shared-zlib-includes',
175 dest='shared_zlib_includes',
176 help='directory containing zlib header files')
178 shared_optgroup.add_option('--shared-zlib-libname',
180 dest='shared_zlib_libname',
182 help='alternative lib name to link to [default: %default]')
184 shared_optgroup.add_option('--shared-zlib-libpath',
186 dest='shared_zlib_libpath',
187 help='a directory to search for the shared zlib DLL')
189 parser.add_option_group(shared_optgroup)
191 # TODO document when we've decided on what the tracing API and its options will
193 parser.add_option('--systemtap-includes',
195 dest='systemtap_includes',
196 help=optparse.SUPPRESS_HELP)
198 parser.add_option('--tag',
201 help='custom build tag')
203 parser.add_option('--release-urlbase',
205 dest='release_urlbase',
206 help='Provide a custom URL prefix for the `process.release` properties '
207 '`sourceUrl` and `headersUrl`. When compiling a release build, this '
208 'will default to https://iojs.org/download/release/')
210 parser.add_option('--v8-options',
213 help='v8 options to pass, see `node --v8-options` for examples.')
215 parser.add_option('--with-arm-float-abi',
217 dest='arm_float_abi',
218 choices=valid_arm_float_abi,
219 help='specifies which floating-point ABI to use ({0}).'.format(
220 ', '.join(valid_arm_float_abi)))
222 parser.add_option('--with-mips-arch-variant',
224 dest='mips_arch_variant',
226 choices=valid_mips_arch,
227 help='MIPS arch variant ({0}) [default: %default]'.format(
228 ', '.join(valid_mips_arch)))
230 parser.add_option('--with-mips-fpu-mode',
232 dest='mips_fpu_mode',
234 choices=valid_mips_fpu,
235 help='MIPS FPU mode ({0}) [default: %default]'.format(
236 ', '.join(valid_mips_fpu)))
238 parser.add_option('--with-mips-float-abi',
240 dest='mips_float_abi',
242 choices=valid_mips_float_abi,
243 help='MIPS floating-point ABI ({0}) [default: %default]'.format(
244 ', '.join(valid_mips_float_abi)))
246 parser.add_option('--with-dtrace',
249 help='build with DTrace (default is true on sunos and darwin)')
251 parser.add_option('--with-lttng',
254 help='build with Lttng (Only available to Linux)')
256 parser.add_option('--with-etw',
259 help='build with ETW (default is true on Windows)')
261 intl_optgroup.add_option('--with-intl',
265 choices=valid_intl_modes,
266 help='Intl mode (valid choices: {0}) [default: %default]'.format(
267 ', '.join(valid_intl_modes)))
269 intl_optgroup.add_option('--with-icu-path',
271 dest='with_icu_path',
272 help='Path to icu.gyp (ICU i18n, Chromium version only.)')
274 intl_optgroup.add_option('--with-icu-locales',
276 dest='with_icu_locales',
278 help='Comma-separated list of locales for "small-icu". "root" is assumed. '
279 '[default: %default]')
281 intl_optgroup.add_option('--with-icu-source',
283 dest='with_icu_source',
284 help='Intl mode: optional local path to icu/ dir, or path/URL of icu source archive.')
286 intl_optgroup.add_option('--download',
288 dest='download_list',
289 help=nodedownload.help())
291 parser.add_option_group(intl_optgroup)
293 parser.add_option('--with-perfctr',
296 help='build with performance counters (default is true on Windows)')
298 parser.add_option('--without-dtrace',
300 dest='without_dtrace',
301 help='build without DTrace')
303 parser.add_option('--without-etw',
306 help='build without ETW')
308 parser.add_option('--without-npm',
311 help='don\'t install the bundled npm package manager')
313 parser.add_option('--without-perfctr',
315 dest='without_perfctr',
316 help='build without performance counters')
318 # Dummy option for backwards compatibility
319 parser.add_option('--with-snapshot',
321 dest='unused_with_snapshot',
322 help=optparse.SUPPRESS_HELP)
324 parser.add_option('--without-snapshot',
326 dest='without_snapshot',
327 help=optparse.SUPPRESS_HELP)
329 parser.add_option('--without-ssl',
332 help='build without SSL')
334 parser.add_option('--xcode',
337 help='generate build files for use with xcode')
339 parser.add_option('--enable-asan',
342 help='build with asan')
344 parser.add_option('--enable-static',
346 dest='enable_static',
347 help='build as static library')
349 (options, args) = parser.parse_args()
351 # Expand ~ in the install prefix now, it gets written to multiple files.
352 options.prefix = os.path.expanduser(options.prefix or '')
354 # set up auto-download list
355 auto_downloads = nodedownload.parse(options.download_list)
360 prefix = '\033[1m\033[93mWARNING\033[0m' if os.isatty(1) else 'WARNING'
361 print('%s: %s' % (prefix, msg))
363 # track if warnings occured
367 """Returns the string 'true' if value is truthy, 'false' otherwise."""
375 pkg_config = os.environ.get('PKG_CONFIG', 'pkg-config')
376 args = '--silence-errors'
378 for flag in ['--libs-only-l', '--cflags-only-I', '--libs-only-L']:
380 val = subprocess.check_output([pkg_config, args, flag, pkg])
381 # check_output returns bytes
382 val = val.encode().strip().rstrip('\n')
383 except subprocess.CalledProcessError:
384 # most likely missing a .pc-file
387 # no pkg-config/pkgconf installed
388 return (None, None, None)
393 def try_check_compiler(cc, lang):
395 proc = subprocess.Popen(shlex.split(cc) + ['-E', '-P', '-x', lang, '-'],
396 stdin=subprocess.PIPE, stdout=subprocess.PIPE)
398 return (False, False, '', '')
400 proc.stdin.write('__clang__ __GNUC__ __GNUC_MINOR__ __GNUC_PATCHLEVEL__ '
401 '__clang_major__ __clang_minor__ __clang_patchlevel__')
403 values = (proc.communicate()[0].split() + ['0'] * 7)[0:7]
404 is_clang = values[0] == '1'
405 gcc_version = '%s.%s.%s' % tuple(values[1:1+3])
406 clang_version = '%s.%s.%s' % tuple(values[4:4+3])
408 return (True, is_clang, clang_version, gcc_version)
412 # The version of asm compiler is needed for building openssl asm files.
413 # See deps/openssl/openssl.gypi for detail.
414 # Commands and reglar expressions to obtain its version number is taken from
415 # https://github.com/openssl/openssl/blob/OpenSSL_1_0_2-stable/crypto/sha/asm/sha512-x86_64.pl#L112-L129
417 def get_llvm_version(cc):
419 proc = subprocess.Popen(shlex.split(cc) + ['-v'], stdin=subprocess.PIPE,
420 stderr=subprocess.PIPE, stdout=subprocess.PIPE)
422 print '''Node.js configure error: No acceptable C compiler found!
424 Please make sure you have a C compiler installed on your system and/or
425 consider adjusting the CC environment variable if you installed
426 it in a non-standard prefix.
430 match = re.search(r"(^clang version|based on LLVM) ([3-9]\.[0-9]+)",
431 proc.communicate()[1])
434 return match.group(2)
439 def get_gas_version(cc):
441 proc = subprocess.Popen(shlex.split(cc) + ['-Wa,-v', '-c', '-o',
443 'assembler', '/dev/null'],
444 stdin=subprocess.PIPE, stderr=subprocess.PIPE,
445 stdout=subprocess.PIPE)
447 print '''Node.js configure error: No acceptable C compiler found!
449 Please make sure you have a C compiler installed on your system and/or
450 consider adjusting the CC environment variable if you installed
451 it in a non-standard prefix.
455 match = re.match(r"GNU assembler version ([2-9]\.[0-9]+)",
456 proc.communicate()[1])
459 return match.group(1)
463 # Note: Apple clang self-reports as clang 4.2.0 and gcc 4.2.1. It passes
464 # the version check more by accident than anything else but a more rigorous
465 # check involves checking the build number against a whitelist. I'm not
466 # quite prepared to go that far yet.
467 def check_compiler(o):
468 if sys.platform == 'win32':
471 ok, is_clang, clang_version, gcc_version = try_check_compiler(CXX, 'c++')
473 warn('failed to autodetect C++ compiler version (CXX=%s)' % CXX)
474 elif clang_version < '3.4.0' if is_clang else gcc_version < '4.8.0':
475 warn('C++ compiler too old, need g++ 4.8 or clang++ 3.4 (CXX=%s)' % CXX)
477 ok, is_clang, clang_version, gcc_version = try_check_compiler(CC, 'c')
479 warn('failed to autodetect C compiler version (CC=%s)' % CC)
480 elif not is_clang and gcc_version < '4.2.0':
481 # clang 3.2 is a little white lie because any clang version will probably
482 # do for the C bits. However, we might as well encourage people to upgrade
483 # to a version that is not completely ancient.
484 warn('C compiler too old, need gcc 4.2 or clang 3.2 (CC=%s)' % CC)
486 # Need llvm_version or gas_version when openssl asm files are compiled
487 if options.without_ssl or options.openssl_no_asm or options.shared_openssl:
491 o['variables']['llvm_version'] = get_llvm_version(CC)
493 o['variables']['gas_version'] = get_gas_version(CC)
496 def cc_macros(cc=None):
497 """Checks predefined macros using the C compiler command."""
500 p = subprocess.Popen(shlex.split(cc or CC) + ['-dM', '-E', '-'],
501 stdin=subprocess.PIPE,
502 stdout=subprocess.PIPE,
503 stderr=subprocess.PIPE)
505 print '''Node.js configure error: No acceptable C compiler found!
507 Please make sure you have a C compiler installed on your system and/or
508 consider adjusting the CC environment variable if you installed
509 it in a non-standard prefix.
514 out = p.communicate()[0]
516 out = str(out).split('\n')
520 lst = shlex.split(line)
529 """Check for ARMv7 instructions"""
530 cc_macros_cache = cc_macros()
531 return ('__ARM_ARCH_7__' in cc_macros_cache or
532 '__ARM_ARCH_7A__' in cc_macros_cache or
533 '__ARM_ARCH_7R__' in cc_macros_cache or
534 '__ARM_ARCH_7M__' in cc_macros_cache or
535 '__ARM_ARCH_7S__' in cc_macros_cache)
539 """Check for ARMv6 instructions"""
540 cc_macros_cache = cc_macros()
541 return ('__ARM_ARCH_6__' in cc_macros_cache or
542 '__ARM_ARCH_6M__' in cc_macros_cache)
545 def is_arm_hard_float_abi():
546 """Check for hardfloat or softfloat eabi on ARM"""
547 # GCC versions 4.6 and above define __ARM_PCS or __ARM_PCS_VFP to specify
548 # the Floating Point ABI used (PCS stands for Procedure Call Standard).
549 # We use these as well as a couple of other defines to statically determine
552 return '__ARM_PCS_VFP' in cc_macros()
556 """Host architecture check using the CC command."""
558 if sys.platform.startswith('aix'):
559 # we only support gcc at this point and the default on AIX
560 # would be xlc so hard code gcc
566 '__aarch64__' : 'arm64',
569 '__MIPSEL__' : 'mipsel',
571 '__PPC64__' : 'ppc64',
573 '__x86_64__' : 'x64',
576 rtn = 'ia32' # default
579 if i in k and k[i] != '0':
587 """Host architecture check using environ vars (better way to do this?)"""
589 observed_arch = os.environ.get('PROCESSOR_ARCHITECTURE', 'x86')
590 arch = os.environ.get('PROCESSOR_ARCHITEW6432', observed_arch)
599 return matchup.get(arch, 'ia32')
602 def configure_arm(o):
603 if options.arm_float_abi:
604 arm_float_abi = options.arm_float_abi
605 elif is_arm_hard_float_abi():
606 arm_float_abi = 'hard'
608 arm_float_abi = 'default'
611 o['variables']['arm_fpu'] = 'vfpv3'
612 o['variables']['arm_version'] = '7'
614 o['variables']['arm_fpu'] = 'vfpv2'
615 o['variables']['arm_version'] = '6' if is_arch_armv6() else 'default'
617 o['variables']['arm_thumb'] = 0 # -marm
618 o['variables']['arm_float_abi'] = arm_float_abi
620 if options.dest_os == 'android':
621 o['variables']['arm_fpu'] = 'vfpv3'
622 o['variables']['arm_version'] = '7'
625 def configure_mips(o):
626 can_use_fpu_instructions = (options.mips_float_abi != 'soft')
627 o['variables']['v8_can_use_fpu_instructions'] = b(can_use_fpu_instructions)
628 o['variables']['v8_use_mips_abi_hardfloat'] = b(can_use_fpu_instructions)
629 o['variables']['mips_arch_variant'] = options.mips_arch_variant
630 o['variables']['mips_fpu_mode'] = options.mips_fpu_mode
633 def configure_node(o):
634 if options.dest_os == 'android':
635 o['variables']['OS'] = 'android'
636 o['variables']['node_prefix'] = options.prefix
637 o['variables']['node_install_npm'] = b(not options.without_npm)
638 o['default_configuration'] = 'Debug' if options.debug else 'Release'
640 host_arch = host_arch_win() if os.name == 'nt' else host_arch_cc()
641 target_arch = options.dest_cpu or host_arch
642 # ia32 is preferred by the build tools (GYP) over x86 even if we prefer the latter
643 # the Makefile resets this to x86 afterward
644 if target_arch == 'x86':
646 o['variables']['host_arch'] = host_arch
647 o['variables']['target_arch'] = target_arch
648 o['variables']['node_byteorder'] = sys.byteorder
650 cross_compiling = target_arch != host_arch
651 want_snapshots = not options.without_snapshot
652 o['variables']['want_separate_host_toolset'] = int(
653 cross_compiling and want_snapshots)
655 if target_arch == 'arm':
657 elif target_arch in ('mips', 'mipsel'):
660 if flavor in ('solaris', 'mac', 'linux', 'freebsd'):
661 use_dtrace = not options.without_dtrace
662 # Don't enable by default on linux and freebsd
663 if flavor in ('linux', 'freebsd'):
664 use_dtrace = options.with_dtrace
666 if flavor == 'linux':
667 if options.systemtap_includes:
668 o['include_dirs'] += [options.systemtap_includes]
669 o['variables']['node_use_dtrace'] = b(use_dtrace)
670 o['variables']['uv_use_dtrace'] = b(use_dtrace)
671 o['variables']['uv_parent_path'] = '/deps/uv/'
672 elif options.with_dtrace:
674 'DTrace is currently only supported on SunOS, MacOS or Linux systems.')
676 o['variables']['node_use_dtrace'] = 'false'
678 # Enable Lttng if --with-lttng was defined. Use logic similar to
679 # ETW for windows. Lttng is only available on the Linux platform.
680 if flavor == 'linux':
681 o['variables']['node_use_lttng'] = b(options.with_lttng)
682 elif options.with_lttng:
683 raise Exception('lttng is only supported on Linux.')
685 o['variables']['node_use_lttng'] = 'false'
687 if options.no_ifaddrs:
688 o['defines'] += ['SUNOS_NO_IFADDRS']
690 # By default, enable ETW on Windows.
692 o['variables']['node_use_etw'] = b(not options.without_etw)
693 elif options.with_etw:
694 raise Exception('ETW is only supported on Windows.')
696 o['variables']['node_use_etw'] = 'false'
698 # By default, enable Performance counters on Windows.
700 o['variables']['node_use_perfctr'] = b(not options.without_perfctr)
701 elif options.with_perfctr:
702 raise Exception('Performance counter is only supported on Windows.')
704 o['variables']['node_use_perfctr'] = 'false'
707 o['variables']['node_tag'] = '-' + options.tag
709 o['variables']['node_tag'] = ''
711 o['variables']['node_release_urlbase'] = options.release_urlbase or ''
713 if options.v8_options:
714 o['variables']['node_v8_options'] = options.v8_options.replace('"', '\\"')
716 if options.enable_static:
717 o['variables']['node_target_type'] = 'static_library'
719 if options.linked_module:
720 o['variables']['library_files'] = options.linked_module
722 o['variables']['asan'] = int(options.enable_asan or 0)
724 def configure_library(lib, output):
725 shared_lib = 'shared_' + lib
726 output['variables']['node_' + shared_lib] = b(getattr(options, shared_lib))
728 if getattr(options, shared_lib):
729 (pkg_libs, pkg_cflags, pkg_libpath) = pkg_config(lib)
732 output['include_dirs'] += (
733 filter(None, map(str.strip, pkg_cflags.split('-I'))))
735 # libpath needs to be provided ahead libraries
737 output['libraries'] += (
738 filter(None, map(str.strip, pkg_cflags.split('-L'))))
740 default_libs = getattr(options, shared_lib + '_libname')
741 default_libs = map('-l{0}'.format, default_libs.split(','))
744 output['libraries'] += pkg_libs.split()
746 output['libraries'] += default_libs
750 o['variables']['v8_enable_gdbjit'] = 1 if options.gdb else 0
751 o['variables']['v8_no_strict_aliasing'] = 1 # Work around compiler bugs.
752 o['variables']['v8_optimized_debug'] = 0 # Compile with -O0 in debug builds.
753 o['variables']['v8_random_seed'] = 0 # Use a random seed for hash tables.
754 o['variables']['v8_use_snapshot'] = 0 if options.without_snapshot else 1
756 def configure_openssl(o):
757 o['variables']['node_use_openssl'] = b(not options.without_ssl)
758 o['variables']['node_shared_openssl'] = b(options.shared_openssl)
759 o['variables']['openssl_no_asm'] = 1 if options.openssl_no_asm else 0
760 if options.openssl_fips:
761 o['variables']['openssl_fips'] = options.openssl_fips
762 fips_dir = os.path.join(root_dir, 'deps', 'openssl', 'fips')
763 fips_ld = os.path.abspath(os.path.join(fips_dir, 'fipsld'))
764 o['make_global_settings'] = [
765 ['LINK', fips_ld + ' <(openssl_fips)/bin/fipsld'],
768 o['variables']['openssl_fips'] = ''
771 if options.without_ssl:
773 configure_library('openssl', o)
776 def configure_fullystatic(o):
777 if options.fully_static:
778 o['libraries'] += ['-static']
780 print("Generation of static executable will not work on OSX "
781 "when using default compilation environment")
784 def configure_winsdk(o):
788 winsdk_dir = os.environ.get('WindowsSdkDir')
790 if winsdk_dir and os.path.isfile(winsdk_dir + '\\bin\\ctrpp.exe'):
791 print('Found ctrpp in WinSDK--will build generated files '
792 'into tools/msvs/genfiles.')
793 o['variables']['node_has_winsdk'] = 'true'
796 print('ctrpp not found in WinSDK path--using pre-gen files '
797 'from tools/msvs/genfiles.')
799 def write(filename, data):
800 filename = os.path.join(root_dir, filename)
801 print 'creating ', filename
802 f = open(filename, 'w+')
805 do_not_edit = '# Do not edit. Generated by the configure script.\n'
807 def glob_to_var(dir_base, dir_sub, patch_dir):
809 dir_all = os.path.join(dir_base, dir_sub)
810 files = os.walk(dir_all)
812 (path, dirs, files) = ent
814 if file.endswith('.cpp') or file.endswith('.c') or file.endswith('.h'):
815 # srcfile uses "slash" as dir separator as its output is consumed by gyp
816 srcfile = '%s/%s' % (dir_sub, file)
818 patchfile = '%s/%s/%s' % (dir_base, patch_dir, file)
819 if os.path.isfile(patchfile):
820 srcfile = '%s/%s' % (patch_dir, file)
821 print 'Using version-specific floating patch %s' % patchfile
826 def configure_intl(o):
829 'url': 'http://download.icu-project.org/files/icu4c/55.1/icu4c-55_1-src.zip',
830 # from https://ssl.icu-project.org/files/icu4c/55.1/icu4c-src-55_1.md5:
831 'md5': '4cddf1e1d47622fdd9de2cd7bb5001fd',
834 def icu_download(path):
835 # download ICU, if needed
839 local = url.split('/')[-1]
840 targetfile = os.path.join(root_dir, 'deps', local)
841 if not os.path.isfile(targetfile):
842 if nodedownload.candownload(auto_downloads, "icu"):
843 nodedownload.retrievefile(url, targetfile)
845 print ' Re-using existing %s' % targetfile
846 if os.path.isfile(targetfile):
847 sys.stdout.write(' Checking file integrity with MD5:\r')
848 gotmd5 = nodedownload.md5sum(targetfile)
849 print ' MD5: %s %s' % (gotmd5, targetfile)
853 print ' Expected: %s *MISMATCH*' % md5
854 print '\n ** Corrupted ZIP? Delete %s to retry download.\n' % targetfile
859 icu_config_name = 'icu_config.gypi'
860 def write_config(data, name):
863 # write an empty file to start with
864 write(icu_config_name, do_not_edit +
865 pprint.pformat(icu_config, indent=2) + '\n')
867 # always set icu_small, node.gyp depends on it being defined.
868 o['variables']['icu_small'] = b(False)
870 with_intl = options.with_intl
871 with_icu_source = options.with_icu_source
872 have_icu_path = bool(options.with_icu_path)
873 if have_icu_path and with_intl != 'none':
874 print 'Error: Cannot specify both --with-icu-path and --with-intl'
877 # Chromium .gyp mode: --with-icu-path
878 o['variables']['v8_enable_i18n_support'] = 1
880 o['variables']['icu_gyp_path'] = options.with_icu_path
882 # --with-intl=<with_intl>
884 if with_intl in (None, 'none'):
885 o['variables']['v8_enable_i18n_support'] = 0
887 elif with_intl == 'small-icu':
888 # small ICU (English only)
889 o['variables']['v8_enable_i18n_support'] = 1
890 o['variables']['icu_small'] = b(True)
891 locs = set(options.with_icu_locales.split(','))
892 locs.add('root') # must have root
893 o['variables']['icu_locales'] = string.join(locs,',')
894 elif with_intl == 'full-icu':
896 o['variables']['v8_enable_i18n_support'] = 1
897 elif with_intl == 'system-icu':
898 # ICU from pkg-config.
899 o['variables']['v8_enable_i18n_support'] = 1
900 pkgicu = pkg_config('icu-i18n')
901 if pkgicu[0] is None:
902 print 'Error: could not load pkg-config data for "icu-i18n".'
903 print 'See above errors or the README.md.'
905 (libs, cflags, libpath) = pkgicu
906 # libpath provides linker path which may contain spaces
908 o['libraries'] += [libpath]
909 # safe to split, cannot contain spaces
910 o['libraries'] += libs.split()
912 o['include_dirs'] += filter(None, map(str.strip, cflags.split('-I')))
913 # use the "system" .gyp
914 o['variables']['icu_gyp_path'] = 'tools/icu/icu-system.gyp'
917 # this is just the 'deps' dir. Used for unpacking.
918 icu_parent_path = os.path.join(root_dir, 'deps')
920 # The full path to the ICU source directory.
921 icu_full_path = os.path.join(icu_parent_path, 'icu')
923 # icu-tmp is used to download and unpack the ICU tarball.
924 icu_tmp_path = os.path.join(icu_parent_path, 'icu-tmp')
926 # --with-icu-source processing
927 # first, check that they didn't pass --with-icu-source=deps/icu
928 if with_icu_source and os.path.abspath(icu_full_path) == os.path.abspath(with_icu_source):
929 print 'Ignoring redundant --with-icu-source=%s' % (with_icu_source)
930 with_icu_source = None
931 # if with_icu_source is still set, try to use it.
933 if os.path.isdir(icu_full_path):
934 print 'Deleting old ICU source: %s' % (icu_full_path)
935 shutil.rmtree(icu_full_path)
936 # now, what path was given?
937 if os.path.isdir(with_icu_source):
938 # it's a path. Copy it.
939 print '%s -> %s' % (with_icu_source, icu_full_path)
940 shutil.copytree(with_icu_source, icu_full_path)
942 # could be file or URL.
943 # Set up temporary area
944 if os.path.isdir(icu_tmp_path):
945 shutil.rmtree(icu_tmp_path)
946 os.mkdir(icu_tmp_path)
948 if os.path.isfile(with_icu_source):
949 # it's a file. Try to unpack it.
950 icu_tarball = with_icu_source
952 # Can we download it?
953 local = os.path.join(icu_tmp_path, with_icu_source.split('/')[-1]) # local part
954 icu_tarball = nodedownload.retrievefile(with_icu_source, local)
955 # continue with "icu_tarball"
956 nodedownload.unpack(icu_tarball, icu_tmp_path)
957 # Did it unpack correctly? Should contain 'icu'
958 tmp_icu = os.path.join(icu_tmp_path, 'icu')
959 if os.path.isdir(tmp_icu):
960 os.rename(tmp_icu, icu_full_path)
961 shutil.rmtree(icu_tmp_path)
963 print ' Error: --with-icu-source=%s did not result in an "icu" dir.' % with_icu_source
964 shutil.rmtree(icu_tmp_path)
967 # ICU mode. (icu-generic.gyp)
968 o['variables']['icu_gyp_path'] = 'tools/icu/icu-generic.gyp'
969 # ICU source dir relative to root
970 o['variables']['icu_path'] = icu_full_path
971 if not os.path.isdir(icu_full_path):
972 print '* ECMA-402 (Intl) support didn\'t find ICU in %s..' % (icu_full_path)
973 # can we download (or find) a zipfile?
974 localzip = icu_download(icu_full_path)
976 nodedownload.unpack(localzip, icu_parent_path)
977 if not os.path.isdir(icu_full_path):
978 print ' Cannot build Intl without ICU in %s.' % (icu_full_path)
979 print ' (Fix, or disable with "--with-intl=none" )'
982 print '* Using ICU in %s' % (icu_full_path)
983 # Now, what version of ICU is it? We just need the "major", such as 54.
984 # uvernum.h contains it as a #define.
985 uvernum_h = os.path.join(icu_full_path, 'source/common/unicode/uvernum.h')
986 if not os.path.isfile(uvernum_h):
987 print ' Error: could not load %s - is ICU installed?' % uvernum_h
990 matchVerExp = r'^\s*#define\s+U_ICU_VERSION_SHORT\s+"([^"]*)".*'
991 match_version = re.compile(matchVerExp)
992 for line in open(uvernum_h).readlines():
993 m = match_version.match(line)
995 icu_ver_major = m.group(1)
996 if not icu_ver_major:
997 print ' Could not read U_ICU_VERSION_SHORT version from %s' % uvernum_h
999 icu_endianness = sys.byteorder[0]; # TODO(srl295): EBCDIC should be 'e'
1000 o['variables']['icu_ver_major'] = icu_ver_major
1001 o['variables']['icu_endianness'] = icu_endianness
1002 icu_data_file_l = 'icudt%s%s.dat' % (icu_ver_major, 'l')
1003 icu_data_file = 'icudt%s%s.dat' % (icu_ver_major, icu_endianness)
1004 # relative to configure
1005 icu_data_path = os.path.join(icu_full_path,
1009 icu_data_in = os.path.join('../../deps/icu/source/data/in', icu_data_file_l)
1010 if not os.path.isfile(icu_data_path) and icu_endianness != 'l':
1011 # use host endianness
1012 icu_data_path = os.path.join(icu_full_path,
1016 icu_data_in = os.path.join('icu/source/data/in',
1018 # this is the input '.dat' file to use .. icudt*.dat
1019 # may be little-endian if from a icu-project.org tarball
1020 o['variables']['icu_data_in'] = icu_data_in
1021 # this is the icudt*.dat file which node will be using (platform endianness)
1022 o['variables']['icu_data_file'] = icu_data_file
1023 if not os.path.isfile(icu_data_path):
1024 print ' Error: ICU prebuilt data file %s does not exist.' % icu_data_path
1025 print ' See the README.md.'
1026 # .. and we're not about to build it from .gyp!
1028 # map from variable name to subdirs
1030 'stubdata': 'stubdata',
1034 'tools': 'tools/toolutil',
1035 'genccode': 'tools/genccode',
1036 'genrb': 'tools/genrb',
1037 'icupkg': 'tools/icupkg',
1039 # this creates a variable icu_src_XXX for each of the subdirs
1040 # with a list of the src files to use
1042 var = 'icu_src_%s' % i
1043 path = '../../deps/icu/source/%s' % icu_src[i]
1044 icu_config['variables'][var] = glob_to_var('tools/icu', path, 'patches/%s/source/%s' % (icu_ver_major, icu_src[i]) )
1045 # write updated icu_config.gypi with a bunch of paths
1046 write(icu_config_name, do_not_edit +
1047 pprint.pformat(icu_config, indent=2) + '\n')
1048 return # end of configure_intl
1051 'variables': { 'python': sys.executable },
1058 # Print a warning when the compiler is too old.
1059 check_compiler(output)
1061 # determine the "flavor" (operating system) we're building for,
1062 # leveraging gyp's GetFlavor function
1064 if (options.dest_os):
1065 flavor_params['flavor'] = options.dest_os
1066 flavor = GetFlavor(flavor_params)
1068 configure_node(output)
1069 configure_library('zlib', output)
1070 configure_library('http_parser', output)
1071 configure_library('libuv', output)
1072 configure_v8(output)
1073 configure_openssl(output)
1074 configure_winsdk(output)
1075 configure_intl(output)
1076 configure_fullystatic(output)
1078 # variables should be a root level element,
1079 # move everything else to target_defaults
1080 variables = output['variables']
1081 del output['variables']
1083 # make_global_settings should be a root level element too
1084 if 'make_global_settings' in output:
1085 make_global_settings = output['make_global_settings']
1086 del output['make_global_settings']
1088 make_global_settings = False
1091 'variables': variables,
1092 'target_defaults': output,
1094 if make_global_settings:
1095 output['make_global_settings'] = make_global_settings
1097 pprint.pprint(output, indent=2)
1099 write('config.gypi', do_not_edit +
1100 pprint.pformat(output, indent=2) + '\n')
1103 'BUILDTYPE': 'Debug' if options.debug else 'Release',
1104 'USE_XCODE': str(int(options.use_xcode or 0)),
1105 'PYTHON': sys.executable,
1109 config['PREFIX'] = options.prefix
1111 config = '\n'.join(map('='.join, config.iteritems())) + '\n'
1114 '# Do not edit. Generated by the configure script.\n' + config)
1116 gyp_args = [sys.executable, 'tools/gyp_node.py', '--no-parallel']
1118 if options.use_xcode:
1119 gyp_args += ['-f', 'xcode']
1120 elif flavor == 'win' and sys.platform != 'msys':
1121 gyp_args += ['-f', 'msvs', '-G', 'msvs_version=auto']
1123 gyp_args += ['-f', 'make-' + flavor]
1128 warn('warnings were emitted in the configure phase')
1130 sys.exit(subprocess.call(gyp_args))