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',
570 '__PPC64__' : 'ppc64',
572 '__x86_64__' : 'x64',
575 rtn = 'ia32' # default
578 if i in k and k[i] != '0':
586 """Host architecture check using environ vars (better way to do this?)"""
588 observed_arch = os.environ.get('PROCESSOR_ARCHITECTURE', 'x86')
589 arch = os.environ.get('PROCESSOR_ARCHITEW6432', observed_arch)
598 return matchup.get(arch, 'ia32')
601 def configure_arm(o):
602 if options.arm_float_abi:
603 arm_float_abi = options.arm_float_abi
604 elif is_arm_hard_float_abi():
605 arm_float_abi = 'hard'
607 arm_float_abi = 'default'
610 o['variables']['arm_fpu'] = 'vfpv3'
611 o['variables']['arm_version'] = '7'
613 o['variables']['arm_fpu'] = 'vfpv2'
614 o['variables']['arm_version'] = '6' if is_arch_armv6() else 'default'
616 o['variables']['arm_thumb'] = 0 # -marm
617 o['variables']['arm_float_abi'] = arm_float_abi
619 if options.dest_os == 'android':
620 o['variables']['arm_fpu'] = 'vfpv3'
621 o['variables']['arm_version'] = '7'
624 def configure_mips(o):
625 can_use_fpu_instructions = (options.mips_float_abi != 'soft')
626 o['variables']['v8_can_use_fpu_instructions'] = b(can_use_fpu_instructions)
627 o['variables']['v8_use_mips_abi_hardfloat'] = b(can_use_fpu_instructions)
628 o['variables']['mips_arch_variant'] = options.mips_arch_variant
629 o['variables']['mips_fpu_mode'] = options.mips_fpu_mode
632 def configure_node(o):
633 if options.dest_os == 'android':
634 o['variables']['OS'] = 'android'
635 o['variables']['node_prefix'] = options.prefix
636 o['variables']['node_install_npm'] = b(not options.without_npm)
637 o['default_configuration'] = 'Debug' if options.debug else 'Release'
639 host_arch = host_arch_win() if os.name == 'nt' else host_arch_cc()
640 target_arch = options.dest_cpu or host_arch
641 # ia32 is preferred by the build tools (GYP) over x86 even if we prefer the latter
642 # the Makefile resets this to x86 afterward
643 if target_arch == 'x86':
645 o['variables']['host_arch'] = host_arch
646 o['variables']['target_arch'] = target_arch
647 o['variables']['node_byteorder'] = sys.byteorder
649 cross_compiling = target_arch != host_arch
650 want_snapshots = not options.without_snapshot
651 o['variables']['want_separate_host_toolset'] = int(
652 cross_compiling and want_snapshots)
654 if target_arch == 'arm':
656 elif target_arch in ('mips', 'mipsel'):
659 if flavor in ('solaris', 'mac', 'linux', 'freebsd'):
660 use_dtrace = not options.without_dtrace
661 # Don't enable by default on linux and freebsd
662 if flavor in ('linux', 'freebsd'):
663 use_dtrace = options.with_dtrace
665 if flavor == 'linux':
666 if options.systemtap_includes:
667 o['include_dirs'] += [options.systemtap_includes]
668 o['variables']['node_use_dtrace'] = b(use_dtrace)
669 o['variables']['uv_use_dtrace'] = b(use_dtrace)
670 o['variables']['uv_parent_path'] = '/deps/uv/'
671 elif options.with_dtrace:
673 'DTrace is currently only supported on SunOS, MacOS or Linux systems.')
675 o['variables']['node_use_dtrace'] = 'false'
677 # Enable Lttng if --with-lttng was defined. Use logic similar to
678 # ETW for windows. Lttng is only available on the Linux platform.
679 if flavor == 'linux':
680 o['variables']['node_use_lttng'] = b(options.with_lttng)
681 elif options.with_lttng:
682 raise Exception('lttng is only supported on Linux.')
684 o['variables']['node_use_lttng'] = 'false'
686 if options.no_ifaddrs:
687 o['defines'] += ['SUNOS_NO_IFADDRS']
689 # By default, enable ETW on Windows.
691 o['variables']['node_use_etw'] = b(not options.without_etw)
692 elif options.with_etw:
693 raise Exception('ETW is only supported on Windows.')
695 o['variables']['node_use_etw'] = 'false'
697 # By default, enable Performance counters on Windows.
699 o['variables']['node_use_perfctr'] = b(not options.without_perfctr)
700 elif options.with_perfctr:
701 raise Exception('Performance counter is only supported on Windows.')
703 o['variables']['node_use_perfctr'] = 'false'
706 o['variables']['node_tag'] = '-' + options.tag
708 o['variables']['node_tag'] = ''
710 o['variables']['node_release_urlbase'] = options.release_urlbase or ''
712 if options.v8_options:
713 o['variables']['node_v8_options'] = options.v8_options.replace('"', '\\"')
715 if options.enable_static:
716 o['variables']['node_target_type'] = 'static_library'
718 if options.linked_module:
719 o['variables']['library_files'] = options.linked_module
721 o['variables']['asan'] = int(options.enable_asan or 0)
723 def configure_library(lib, output):
724 shared_lib = 'shared_' + lib
725 output['variables']['node_' + shared_lib] = b(getattr(options, shared_lib))
727 if getattr(options, shared_lib):
728 (pkg_libs, pkg_cflags, pkg_libpath) = pkg_config(lib)
731 output['include_dirs'] += (
732 filter(None, map(str.strip, pkg_cflags.split('-I'))))
734 # libpath needs to be provided ahead libraries
736 output['libraries'] += (
737 filter(None, map(str.strip, pkg_cflags.split('-L'))))
739 default_libs = getattr(options, shared_lib + '_libname')
740 default_libs = map('-l{0}'.format, default_libs.split(','))
743 output['libraries'] += pkg_libs.split()
745 output['libraries'] += default_libs
749 o['variables']['v8_enable_gdbjit'] = 1 if options.gdb else 0
750 o['variables']['v8_no_strict_aliasing'] = 1 # Work around compiler bugs.
751 o['variables']['v8_optimized_debug'] = 0 # Compile with -O0 in debug builds.
752 o['variables']['v8_random_seed'] = 0 # Use a random seed for hash tables.
753 o['variables']['v8_use_snapshot'] = 0 if options.without_snapshot else 1
755 def configure_openssl(o):
756 o['variables']['node_use_openssl'] = b(not options.without_ssl)
757 o['variables']['node_shared_openssl'] = b(options.shared_openssl)
758 o['variables']['openssl_no_asm'] = 1 if options.openssl_no_asm else 0
759 if options.openssl_fips:
760 o['variables']['openssl_fips'] = options.openssl_fips
761 fips_dir = os.path.join(root_dir, 'deps', 'openssl', 'fips')
762 fips_ld = os.path.abspath(os.path.join(fips_dir, 'fipsld'))
763 o['make_global_settings'] = [
764 ['LINK', fips_ld + ' <(openssl_fips)/bin/fipsld'],
767 o['variables']['openssl_fips'] = ''
770 if options.without_ssl:
772 configure_library('openssl', o)
775 def configure_fullystatic(o):
776 if options.fully_static:
777 o['libraries'] += ['-static']
779 print("Generation of static executable will not work on OSX "
780 "when using default compilation environment")
783 def configure_winsdk(o):
787 winsdk_dir = os.environ.get('WindowsSdkDir')
789 if winsdk_dir and os.path.isfile(winsdk_dir + '\\bin\\ctrpp.exe'):
790 print('Found ctrpp in WinSDK--will build generated files '
791 'into tools/msvs/genfiles.')
792 o['variables']['node_has_winsdk'] = 'true'
795 print('ctrpp not found in WinSDK path--using pre-gen files '
796 'from tools/msvs/genfiles.')
798 def write(filename, data):
799 filename = os.path.join(root_dir, filename)
800 print 'creating ', filename
801 f = open(filename, 'w+')
804 do_not_edit = '# Do not edit. Generated by the configure script.\n'
806 def glob_to_var(dir_base, dir_sub, patch_dir):
808 dir_all = os.path.join(dir_base, dir_sub)
809 files = os.walk(dir_all)
811 (path, dirs, files) = ent
813 if file.endswith('.cpp') or file.endswith('.c') or file.endswith('.h'):
814 # srcfile uses "slash" as dir separator as its output is consumed by gyp
815 srcfile = '%s/%s' % (dir_sub, file)
817 patchfile = '%s/%s/%s' % (dir_base, patch_dir, file)
818 if os.path.isfile(patchfile):
819 srcfile = '%s/%s' % (patch_dir, file)
820 print 'Using version-specific floating patch %s' % patchfile
825 def configure_intl(o):
828 'url': 'http://download.icu-project.org/files/icu4c/55.1/icu4c-55_1-src.zip',
829 # from https://ssl.icu-project.org/files/icu4c/55.1/icu4c-src-55_1.md5:
830 'md5': '4cddf1e1d47622fdd9de2cd7bb5001fd',
833 def icu_download(path):
834 # download ICU, if needed
838 local = url.split('/')[-1]
839 targetfile = os.path.join(root_dir, 'deps', local)
840 if not os.path.isfile(targetfile):
841 if nodedownload.candownload(auto_downloads, "icu"):
842 nodedownload.retrievefile(url, targetfile)
844 print ' Re-using existing %s' % targetfile
845 if os.path.isfile(targetfile):
846 sys.stdout.write(' Checking file integrity with MD5:\r')
847 gotmd5 = nodedownload.md5sum(targetfile)
848 print ' MD5: %s %s' % (gotmd5, targetfile)
852 print ' Expected: %s *MISMATCH*' % md5
853 print '\n ** Corrupted ZIP? Delete %s to retry download.\n' % targetfile
858 icu_config_name = 'icu_config.gypi'
859 def write_config(data, name):
862 # write an empty file to start with
863 write(icu_config_name, do_not_edit +
864 pprint.pformat(icu_config, indent=2) + '\n')
866 # always set icu_small, node.gyp depends on it being defined.
867 o['variables']['icu_small'] = b(False)
869 with_intl = options.with_intl
870 with_icu_source = options.with_icu_source
871 have_icu_path = bool(options.with_icu_path)
872 if have_icu_path and with_intl != 'none':
873 print 'Error: Cannot specify both --with-icu-path and --with-intl'
876 # Chromium .gyp mode: --with-icu-path
877 o['variables']['v8_enable_i18n_support'] = 1
879 o['variables']['icu_gyp_path'] = options.with_icu_path
881 # --with-intl=<with_intl>
883 if with_intl in (None, 'none'):
884 o['variables']['v8_enable_i18n_support'] = 0
886 elif with_intl == 'small-icu':
887 # small ICU (English only)
888 o['variables']['v8_enable_i18n_support'] = 1
889 o['variables']['icu_small'] = b(True)
890 locs = set(options.with_icu_locales.split(','))
891 locs.add('root') # must have root
892 o['variables']['icu_locales'] = string.join(locs,',')
893 elif with_intl == 'full-icu':
895 o['variables']['v8_enable_i18n_support'] = 1
896 elif with_intl == 'system-icu':
897 # ICU from pkg-config.
898 o['variables']['v8_enable_i18n_support'] = 1
899 pkgicu = pkg_config('icu-i18n')
900 if pkgicu[0] is None:
901 print 'Error: could not load pkg-config data for "icu-i18n".'
902 print 'See above errors or the README.md.'
904 (libs, cflags, libpath) = pkgicu
905 # libpath provides linker path which may contain spaces
907 o['libraries'] += [libpath]
908 # safe to split, cannot contain spaces
909 o['libraries'] += libs.split()
911 o['include_dirs'] += filter(None, map(str.strip, cflags.split('-I')))
912 # use the "system" .gyp
913 o['variables']['icu_gyp_path'] = 'tools/icu/icu-system.gyp'
916 # this is just the 'deps' dir. Used for unpacking.
917 icu_parent_path = os.path.join(root_dir, 'deps')
919 # The full path to the ICU source directory.
920 icu_full_path = os.path.join(icu_parent_path, 'icu')
922 # icu-tmp is used to download and unpack the ICU tarball.
923 icu_tmp_path = os.path.join(icu_parent_path, 'icu-tmp')
925 # --with-icu-source processing
926 # first, check that they didn't pass --with-icu-source=deps/icu
927 if with_icu_source and os.path.abspath(icu_full_path) == os.path.abspath(with_icu_source):
928 print 'Ignoring redundant --with-icu-source=%s' % (with_icu_source)
929 with_icu_source = None
930 # if with_icu_source is still set, try to use it.
932 if os.path.isdir(icu_full_path):
933 print 'Deleting old ICU source: %s' % (icu_full_path)
934 shutil.rmtree(icu_full_path)
935 # now, what path was given?
936 if os.path.isdir(with_icu_source):
937 # it's a path. Copy it.
938 print '%s -> %s' % (with_icu_source, icu_full_path)
939 shutil.copytree(with_icu_source, icu_full_path)
941 # could be file or URL.
942 # Set up temporary area
943 if os.path.isdir(icu_tmp_path):
944 shutil.rmtree(icu_tmp_path)
945 os.mkdir(icu_tmp_path)
947 if os.path.isfile(with_icu_source):
948 # it's a file. Try to unpack it.
949 icu_tarball = with_icu_source
951 # Can we download it?
952 local = os.path.join(icu_tmp_path, with_icu_source.split('/')[-1]) # local part
953 icu_tarball = nodedownload.retrievefile(with_icu_source, local)
954 # continue with "icu_tarball"
955 nodedownload.unpack(icu_tarball, icu_tmp_path)
956 # Did it unpack correctly? Should contain 'icu'
957 tmp_icu = os.path.join(icu_tmp_path, 'icu')
958 if os.path.isdir(tmp_icu):
959 os.rename(tmp_icu, icu_full_path)
960 shutil.rmtree(icu_tmp_path)
962 print ' Error: --with-icu-source=%s did not result in an "icu" dir.' % with_icu_source
963 shutil.rmtree(icu_tmp_path)
966 # ICU mode. (icu-generic.gyp)
967 o['variables']['icu_gyp_path'] = 'tools/icu/icu-generic.gyp'
968 # ICU source dir relative to root
969 o['variables']['icu_path'] = icu_full_path
970 if not os.path.isdir(icu_full_path):
971 print '* ECMA-402 (Intl) support didn\'t find ICU in %s..' % (icu_full_path)
972 # can we download (or find) a zipfile?
973 localzip = icu_download(icu_full_path)
975 nodedownload.unpack(localzip, icu_parent_path)
976 if not os.path.isdir(icu_full_path):
977 print ' Cannot build Intl without ICU in %s.' % (icu_full_path)
978 print ' (Fix, or disable with "--with-intl=none" )'
981 print '* Using ICU in %s' % (icu_full_path)
982 # Now, what version of ICU is it? We just need the "major", such as 54.
983 # uvernum.h contains it as a #define.
984 uvernum_h = os.path.join(icu_full_path, 'source/common/unicode/uvernum.h')
985 if not os.path.isfile(uvernum_h):
986 print ' Error: could not load %s - is ICU installed?' % uvernum_h
989 matchVerExp = r'^\s*#define\s+U_ICU_VERSION_SHORT\s+"([^"]*)".*'
990 match_version = re.compile(matchVerExp)
991 for line in open(uvernum_h).readlines():
992 m = match_version.match(line)
994 icu_ver_major = m.group(1)
995 if not icu_ver_major:
996 print ' Could not read U_ICU_VERSION_SHORT version from %s' % uvernum_h
998 icu_endianness = sys.byteorder[0]; # TODO(srl295): EBCDIC should be 'e'
999 o['variables']['icu_ver_major'] = icu_ver_major
1000 o['variables']['icu_endianness'] = icu_endianness
1001 icu_data_file_l = 'icudt%s%s.dat' % (icu_ver_major, 'l')
1002 icu_data_file = 'icudt%s%s.dat' % (icu_ver_major, icu_endianness)
1003 # relative to configure
1004 icu_data_path = os.path.join(icu_full_path,
1008 icu_data_in = os.path.join('../../deps/icu/source/data/in', icu_data_file_l)
1009 if not os.path.isfile(icu_data_path) and icu_endianness != 'l':
1010 # use host endianness
1011 icu_data_path = os.path.join(icu_full_path,
1015 icu_data_in = os.path.join('icu/source/data/in',
1017 # this is the input '.dat' file to use .. icudt*.dat
1018 # may be little-endian if from a icu-project.org tarball
1019 o['variables']['icu_data_in'] = icu_data_in
1020 # this is the icudt*.dat file which node will be using (platform endianness)
1021 o['variables']['icu_data_file'] = icu_data_file
1022 if not os.path.isfile(icu_data_path):
1023 print ' Error: ICU prebuilt data file %s does not exist.' % icu_data_path
1024 print ' See the README.md.'
1025 # .. and we're not about to build it from .gyp!
1027 # map from variable name to subdirs
1029 'stubdata': 'stubdata',
1033 'tools': 'tools/toolutil',
1034 'genccode': 'tools/genccode',
1035 'genrb': 'tools/genrb',
1036 'icupkg': 'tools/icupkg',
1038 # this creates a variable icu_src_XXX for each of the subdirs
1039 # with a list of the src files to use
1041 var = 'icu_src_%s' % i
1042 path = '../../deps/icu/source/%s' % icu_src[i]
1043 icu_config['variables'][var] = glob_to_var('tools/icu', path, 'patches/%s/source/%s' % (icu_ver_major, icu_src[i]) )
1044 # write updated icu_config.gypi with a bunch of paths
1045 write(icu_config_name, do_not_edit +
1046 pprint.pformat(icu_config, indent=2) + '\n')
1047 return # end of configure_intl
1050 'variables': { 'python': sys.executable },
1057 # Print a warning when the compiler is too old.
1058 check_compiler(output)
1060 # determine the "flavor" (operating system) we're building for,
1061 # leveraging gyp's GetFlavor function
1063 if (options.dest_os):
1064 flavor_params['flavor'] = options.dest_os
1065 flavor = GetFlavor(flavor_params)
1067 configure_node(output)
1068 configure_library('zlib', output)
1069 configure_library('http_parser', output)
1070 configure_library('libuv', output)
1071 configure_v8(output)
1072 configure_openssl(output)
1073 configure_winsdk(output)
1074 configure_intl(output)
1075 configure_fullystatic(output)
1077 # variables should be a root level element,
1078 # move everything else to target_defaults
1079 variables = output['variables']
1080 del output['variables']
1082 # make_global_settings should be a root level element too
1083 if 'make_global_settings' in output:
1084 make_global_settings = output['make_global_settings']
1085 del output['make_global_settings']
1087 make_global_settings = False
1090 'variables': variables,
1091 'target_defaults': output,
1093 if make_global_settings:
1094 output['make_global_settings'] = make_global_settings
1096 pprint.pprint(output, indent=2)
1098 write('config.gypi', do_not_edit +
1099 pprint.pformat(output, indent=2) + '\n')
1102 'BUILDTYPE': 'Debug' if options.debug else 'Release',
1103 'USE_XCODE': str(int(options.use_xcode or 0)),
1104 'PYTHON': sys.executable,
1108 config['PREFIX'] = options.prefix
1110 config = '\n'.join(map('='.join, config.iteritems())) + '\n'
1113 '# Do not edit. Generated by the configure script.\n' + config)
1115 gyp_args = [sys.executable, 'tools/gyp_node.py', '--no-parallel']
1117 if options.use_xcode:
1118 gyp_args += ['-f', 'xcode']
1119 elif flavor == 'win' and sys.platform != 'msys':
1120 gyp_args += ['-f', 'msvs', '-G', 'msvs_version=auto']
1122 gyp_args += ['-f', 'make-' + flavor]
1127 warn('warnings were emitted in the configure phase')
1129 sys.exit(subprocess.call(gyp_args))