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', 'android')
29 valid_arch = ('arm', 'arm64', 'ia32', 'mips', 'mipsel', 'ppc', 'ppc64', 'x32',
31 valid_arm_float_abi = ('soft', 'softfp', 'hard')
32 valid_mips_arch = ('loongson', 'r1', 'r2', 'r6', 'rx')
33 valid_mips_fpu = ('fp32', 'fp64', 'fpxx')
34 valid_mips_float_abi = ('soft', 'hard')
35 valid_intl_modes = ('none', 'small-icu', 'full-icu', 'system-icu')
37 # create option groups
38 shared_optgroup = optparse.OptionGroup(parser, "Shared libraries",
39 "Flags that allows you to control whether you want to build against "
40 "built-in dependencies or its shared representations. If necessary, "
41 "provide multiple libraries with comma.")
42 intl_optgroup = optparse.OptionGroup(parser, "Internationalization",
43 "Flags that lets you enable i18n features in Node.js as well as which "
44 "library you want to build against.")
46 # Options should be in alphabetical order but keep --prefix at the top,
47 # that's arguably the one people will be looking for most.
48 parser.add_option('--prefix',
52 help='select the install prefix [default: %default]')
54 parser.add_option('--debug',
57 help='also build debug build')
59 parser.add_option('--dest-cpu',
63 help='CPU architecture to build for ({0})'.format(', '.join(valid_arch)))
65 parser.add_option('--dest-os',
69 help='operating system to build for ({0})'.format(', '.join(valid_os)))
71 parser.add_option('--gdb',
74 help='add gdb support')
76 parser.add_option('--no-ifaddrs',
79 help='use on deprecated SunOS systems that do not support ifaddrs.h')
81 parser.add_option("--fully-static",
84 help="Generate an executable without external dynamic libraries. This "
85 "will not work on OSX when using default compilation environment")
87 parser.add_option("--link-module",
90 help="Path to a JS file to be bundled in the binary as a builtin."
91 "This module will be referenced by basename without extension."
92 "Can be used multiple times")
94 parser.add_option("--openssl-no-asm",
96 dest="openssl_no_asm",
97 help="Do not build optimized assembly for OpenSSL")
99 parser.add_option('--openssl-fips',
102 help='Build OpenSSL using FIPS canister .o file in supplied folder')
104 shared_optgroup.add_option('--shared-http-parser',
106 dest='shared_http_parser',
107 help='link to a shared http_parser DLL instead of static linking')
109 shared_optgroup.add_option('--shared-http-parser-includes',
111 dest='shared_http_parser_includes',
112 help='directory containing http_parser header files')
114 shared_optgroup.add_option('--shared-http-parser-libname',
116 dest='shared_http_parser_libname',
117 default='http_parser',
118 help='alternative lib name to link to [default: %default]')
120 shared_optgroup.add_option('--shared-http-parser-libpath',
122 dest='shared_http_parser_libpath',
123 help='a directory to search for the shared http_parser DLL')
125 shared_optgroup.add_option('--shared-libuv',
128 help='link to a shared libuv DLL instead of static linking')
130 shared_optgroup.add_option('--shared-libuv-includes',
132 dest='shared_libuv_includes',
133 help='directory containing libuv header files')
135 shared_optgroup.add_option('--shared-libuv-libname',
137 dest='shared_libuv_libname',
139 help='alternative lib name to link to [default: %default]')
141 shared_optgroup.add_option('--shared-libuv-libpath',
143 dest='shared_libuv_libpath',
144 help='a directory to search for the shared libuv DLL')
146 shared_optgroup.add_option('--shared-openssl',
148 dest='shared_openssl',
149 help='link to a shared OpenSSl DLL instead of static linking')
151 shared_optgroup.add_option('--shared-openssl-includes',
153 dest='shared_openssl_includes',
154 help='directory containing OpenSSL header files')
156 shared_optgroup.add_option('--shared-openssl-libname',
158 dest='shared_openssl_libname',
159 default='crypto,ssl',
160 help='alternative lib name to link to [default: %default]')
162 shared_optgroup.add_option('--shared-openssl-libpath',
164 dest='shared_openssl_libpath',
165 help='a directory to search for the shared OpenSSL DLLs')
167 shared_optgroup.add_option('--shared-zlib',
170 help='link to a shared zlib DLL instead of static linking')
172 shared_optgroup.add_option('--shared-zlib-includes',
174 dest='shared_zlib_includes',
175 help='directory containing zlib header files')
177 shared_optgroup.add_option('--shared-zlib-libname',
179 dest='shared_zlib_libname',
181 help='alternative lib name to link to [default: %default]')
183 shared_optgroup.add_option('--shared-zlib-libpath',
185 dest='shared_zlib_libpath',
186 help='a directory to search for the shared zlib DLL')
188 parser.add_option_group(shared_optgroup)
190 # TODO document when we've decided on what the tracing API and its options will
192 parser.add_option('--systemtap-includes',
194 dest='systemtap_includes',
195 help=optparse.SUPPRESS_HELP)
197 parser.add_option('--tag',
200 help='custom build tag')
202 parser.add_option('--release-urlbase',
204 dest='release_urlbase',
205 help='Provide a custom URL prefix for the `process.release` properties '
206 '`sourceUrl` and `headersUrl`. When compiling a release build, this '
207 'will default to https://iojs.org/download/release/')
209 parser.add_option('--v8-options',
212 help='v8 options to pass, see `node --v8-options` for examples.')
214 parser.add_option('--with-arm-float-abi',
216 dest='arm_float_abi',
217 choices=valid_arm_float_abi,
218 help='specifies which floating-point ABI to use ({0}).'.format(
219 ', '.join(valid_arm_float_abi)))
221 parser.add_option('--with-mips-arch-variant',
223 dest='mips_arch_variant',
225 choices=valid_mips_arch,
226 help='MIPS arch variant ({0}) [default: %default]'.format(
227 ', '.join(valid_mips_arch)))
229 parser.add_option('--with-mips-fpu-mode',
231 dest='mips_fpu_mode',
233 choices=valid_mips_fpu,
234 help='MIPS FPU mode ({0}) [default: %default]'.format(
235 ', '.join(valid_mips_fpu)))
237 parser.add_option('--with-mips-float-abi',
239 dest='mips_float_abi',
241 choices=valid_mips_float_abi,
242 help='MIPS floating-point ABI ({0}) [default: %default]'.format(
243 ', '.join(valid_mips_float_abi)))
245 parser.add_option('--with-dtrace',
248 help='build with DTrace (default is true on sunos and darwin)')
250 parser.add_option('--with-lttng',
253 help='build with Lttng (Only available to Linux)')
255 parser.add_option('--with-etw',
258 help='build with ETW (default is true on Windows)')
260 intl_optgroup.add_option('--with-intl',
264 choices=valid_intl_modes,
265 help='Intl mode (valid choices: {0}) [default: %default]'.format(
266 ', '.join(valid_intl_modes)))
268 intl_optgroup.add_option('--with-icu-path',
270 dest='with_icu_path',
271 help='Path to icu.gyp (ICU i18n, Chromium version only.)')
273 intl_optgroup.add_option('--with-icu-locales',
275 dest='with_icu_locales',
277 help='Comma-separated list of locales for "small-icu". "root" is assumed. '
278 '[default: %default]')
280 intl_optgroup.add_option('--with-icu-source',
282 dest='with_icu_source',
283 help='Intl mode: optional local path to icu/ dir, or path/URL of icu source archive.')
285 intl_optgroup.add_option('--download',
287 dest='download_list',
288 help=nodedownload.help())
290 parser.add_option_group(intl_optgroup)
292 parser.add_option('--with-perfctr',
295 help='build with performance counters (default is true on Windows)')
297 parser.add_option('--without-dtrace',
299 dest='without_dtrace',
300 help='build without DTrace')
302 parser.add_option('--without-etw',
305 help='build without ETW')
307 parser.add_option('--without-npm',
310 help='don\'t install the bundled npm package manager')
312 parser.add_option('--without-perfctr',
314 dest='without_perfctr',
315 help='build without performance counters')
317 # Dummy option for backwards compatibility
318 parser.add_option('--with-snapshot',
320 dest='unused_with_snapshot',
321 help=optparse.SUPPRESS_HELP)
323 parser.add_option('--without-snapshot',
325 dest='without_snapshot',
326 help=optparse.SUPPRESS_HELP)
328 parser.add_option('--without-ssl',
331 help='build without SSL')
333 parser.add_option('--xcode',
336 help='generate build files for use with xcode')
338 parser.add_option('--enable-static',
340 dest='enable_static',
341 help='build as static library')
343 (options, args) = parser.parse_args()
345 # Expand ~ in the install prefix now, it gets written to multiple files.
346 options.prefix = os.path.expanduser(options.prefix or '')
348 # set up auto-download list
349 auto_downloads = nodedownload.parse(options.download_list)
354 prefix = '\033[1m\033[93mWARNING\033[0m' if os.isatty(1) else 'WARNING'
355 print('%s: %s' % (prefix, msg))
357 # track if warnings occured
361 """Returns the string 'true' if value is truthy, 'false' otherwise."""
369 pkg_config = os.environ.get('PKG_CONFIG', 'pkg-config')
370 args = '--silence-errors'
372 for flag in ['--libs-only-l', '--cflags-only-I', '--libs-only-L']:
374 val = subprocess.check_output([pkg_config, args, flag, pkg])
375 # check_output returns bytes
376 val = val.encode().strip().rstrip('\n')
377 except subprocess.CalledProcessError:
378 # most likely missing a .pc-file
381 # no pkg-config/pkgconf installed
382 return (None, None, None)
387 def try_check_compiler(cc, lang):
389 proc = subprocess.Popen(shlex.split(cc) + ['-E', '-P', '-x', lang, '-'],
390 stdin=subprocess.PIPE, stdout=subprocess.PIPE)
392 return (False, False, '', '')
394 proc.stdin.write('__clang__ __GNUC__ __GNUC_MINOR__ __GNUC_PATCHLEVEL__ '
395 '__clang_major__ __clang_minor__ __clang_patchlevel__')
397 values = (proc.communicate()[0].split() + ['0'] * 7)[0:7]
398 is_clang = values[0] == '1'
399 gcc_version = '%s.%s.%s' % tuple(values[1:1+3])
400 clang_version = '%s.%s.%s' % tuple(values[4:4+3])
402 return (True, is_clang, clang_version, gcc_version)
406 # The version of asm compiler is needed for building openssl asm files.
407 # See deps/openssl/openssl.gypi for detail.
408 # Commands and reglar expressions to obtain its version number is taken from
409 # https://github.com/openssl/openssl/blob/OpenSSL_1_0_2-stable/crypto/sha/asm/sha512-x86_64.pl#L112-L129
411 def get_llvm_version(cc):
413 proc = subprocess.Popen(shlex.split(cc) + ['-v'], stdin=subprocess.PIPE,
414 stderr=subprocess.PIPE, stdout=subprocess.PIPE)
416 print '''Node.js configure error: No acceptable C compiler found!
418 Please make sure you have a C compiler installed on your system and/or
419 consider adjusting the CC environment variable if you installed
420 it in a non-standard prefix.
424 match = re.search(r"(^clang version|based on LLVM) ([3-9]\.[0-9]+)",
425 proc.communicate()[1])
428 return match.group(2)
433 def get_gas_version(cc):
435 proc = subprocess.Popen(shlex.split(cc) + ['-Wa,-v', '-c', '-o',
437 'assembler', '/dev/null'],
438 stdin=subprocess.PIPE, stderr=subprocess.PIPE,
439 stdout=subprocess.PIPE)
441 print '''Node.js configure error: No acceptable C compiler found!
443 Please make sure you have a C compiler installed on your system and/or
444 consider adjusting the CC environment variable if you installed
445 it in a non-standard prefix.
449 match = re.match(r"GNU assembler version ([2-9]\.[0-9]+)",
450 proc.communicate()[1])
453 return match.group(1)
457 # Note: Apple clang self-reports as clang 4.2.0 and gcc 4.2.1. It passes
458 # the version check more by accident than anything else but a more rigorous
459 # check involves checking the build number against a whitelist. I'm not
460 # quite prepared to go that far yet.
461 def check_compiler(o):
462 if sys.platform == 'win32':
465 ok, is_clang, clang_version, gcc_version = try_check_compiler(CXX, 'c++')
467 warn('failed to autodetect C++ compiler version (CXX=%s)' % CXX)
468 elif clang_version < '3.4.0' if is_clang else gcc_version < '4.8.0':
469 warn('C++ compiler too old, need g++ 4.8 or clang++ 3.4 (CXX=%s)' % CXX)
471 ok, is_clang, clang_version, gcc_version = try_check_compiler(CC, 'c')
473 warn('failed to autodetect C compiler version (CC=%s)' % CC)
474 elif not is_clang and gcc_version < '4.2.0':
475 # clang 3.2 is a little white lie because any clang version will probably
476 # do for the C bits. However, we might as well encourage people to upgrade
477 # to a version that is not completely ancient.
478 warn('C compiler too old, need gcc 4.2 or clang 3.2 (CC=%s)' % CC)
480 # Need llvm_version or gas_version when openssl asm files are compiled
481 if options.without_ssl or options.openssl_no_asm or options.shared_openssl:
485 o['variables']['llvm_version'] = get_llvm_version(CC)
487 o['variables']['gas_version'] = get_gas_version(CC)
491 """Checks predefined macros using the CC command."""
494 p = subprocess.Popen(shlex.split(CC) + ['-dM', '-E', '-'],
495 stdin=subprocess.PIPE,
496 stdout=subprocess.PIPE,
497 stderr=subprocess.PIPE)
499 print '''Node.js configure error: No acceptable C compiler found!
501 Please make sure you have a C compiler installed on your system and/or
502 consider adjusting the CC environment variable if you installed
503 it in a non-standard prefix.
508 out = p.communicate()[0]
510 out = str(out).split('\n')
514 lst = shlex.split(line)
523 """Check for ARMv7 instructions"""
524 cc_macros_cache = cc_macros()
525 return ('__ARM_ARCH_7__' in cc_macros_cache or
526 '__ARM_ARCH_7A__' in cc_macros_cache or
527 '__ARM_ARCH_7R__' in cc_macros_cache or
528 '__ARM_ARCH_7M__' in cc_macros_cache or
529 '__ARM_ARCH_7S__' in cc_macros_cache)
533 """Check for ARMv6 instructions"""
534 cc_macros_cache = cc_macros()
535 return ('__ARM_ARCH_6__' in cc_macros_cache or
536 '__ARM_ARCH_6M__' in cc_macros_cache)
539 def is_arm_hard_float_abi():
540 """Check for hardfloat or softfloat eabi on ARM"""
541 # GCC versions 4.6 and above define __ARM_PCS or __ARM_PCS_VFP to specify
542 # the Floating Point ABI used (PCS stands for Procedure Call Standard).
543 # We use these as well as a couple of other defines to statically determine
546 return '__ARM_PCS_VFP' in cc_macros()
550 """Host architecture check using the CC command."""
555 '__aarch64__' : 'arm64',
559 '__PPC64__' : 'ppc64',
561 '__x86_64__' : 'x64',
564 rtn = 'ia32' # default
567 if i in k and k[i] != '0':
575 """Host architecture check using environ vars (better way to do this?)"""
577 observed_arch = os.environ.get('PROCESSOR_ARCHITECTURE', 'x86')
578 arch = os.environ.get('PROCESSOR_ARCHITEW6432', observed_arch)
587 return matchup.get(arch, 'ia32')
590 def configure_arm(o):
591 if options.arm_float_abi:
592 arm_float_abi = options.arm_float_abi
593 elif is_arm_hard_float_abi():
594 arm_float_abi = 'hard'
596 arm_float_abi = 'default'
599 o['variables']['arm_fpu'] = 'vfpv3'
600 o['variables']['arm_version'] = '7'
602 o['variables']['arm_fpu'] = 'vfpv2'
603 o['variables']['arm_version'] = '6' if is_arch_armv6() else 'default'
605 o['variables']['arm_thumb'] = 0 # -marm
606 o['variables']['arm_float_abi'] = arm_float_abi
608 if options.dest_os == 'android':
609 o['variables']['arm_fpu'] = 'vfpv3'
610 o['variables']['arm_version'] = '7'
613 def configure_mips(o):
614 can_use_fpu_instructions = (options.mips_float_abi != 'soft')
615 o['variables']['v8_can_use_fpu_instructions'] = b(can_use_fpu_instructions)
616 o['variables']['v8_use_mips_abi_hardfloat'] = b(can_use_fpu_instructions)
617 o['variables']['mips_arch_variant'] = options.mips_arch_variant
618 o['variables']['mips_fpu_mode'] = options.mips_fpu_mode
621 def configure_node(o):
622 if options.dest_os == 'android':
623 o['variables']['OS'] = 'android'
624 o['variables']['node_prefix'] = options.prefix
625 o['variables']['node_install_npm'] = b(not options.without_npm)
626 o['default_configuration'] = 'Debug' if options.debug else 'Release'
628 host_arch = host_arch_win() if os.name == 'nt' else host_arch_cc()
629 target_arch = options.dest_cpu or host_arch
630 # ia32 is preferred by the build tools (GYP) over x86 even if we prefer the latter
631 # the Makefile resets this to x86 afterward
632 if target_arch == 'x86':
634 o['variables']['host_arch'] = host_arch
635 o['variables']['target_arch'] = target_arch
636 o['variables']['node_byteorder'] = sys.byteorder
638 cross_compiling = target_arch != host_arch
639 want_snapshots = not options.without_snapshot
640 o['variables']['want_separate_host_toolset'] = int(
641 cross_compiling and want_snapshots)
643 if target_arch == 'arm':
645 elif target_arch in ('mips', 'mipsel'):
648 if flavor in ('solaris', 'mac', 'linux', 'freebsd'):
649 use_dtrace = not options.without_dtrace
650 # Don't enable by default on linux and freebsd
651 if flavor in ('linux', 'freebsd'):
652 use_dtrace = options.with_dtrace
654 if flavor == 'linux':
655 if options.systemtap_includes:
656 o['include_dirs'] += [options.systemtap_includes]
657 o['variables']['node_use_dtrace'] = b(use_dtrace)
658 o['variables']['uv_use_dtrace'] = b(use_dtrace)
659 o['variables']['uv_parent_path'] = '/deps/uv/'
660 elif options.with_dtrace:
662 'DTrace is currently only supported on SunOS, MacOS or Linux systems.')
664 o['variables']['node_use_dtrace'] = 'false'
666 # Enable Lttng if --with-lttng was defined. Use logic similar to
667 # ETW for windows. Lttng is only available on the Linux platform.
668 if flavor == 'linux':
669 o['variables']['node_use_lttng'] = b(options.with_lttng)
670 elif options.with_lttng:
671 raise Exception('lttng is only supported on Linux.')
673 o['variables']['node_use_lttng'] = 'false'
675 if options.no_ifaddrs:
676 o['defines'] += ['SUNOS_NO_IFADDRS']
678 # By default, enable ETW on Windows.
680 o['variables']['node_use_etw'] = b(not options.without_etw)
681 elif options.with_etw:
682 raise Exception('ETW is only supported on Windows.')
684 o['variables']['node_use_etw'] = 'false'
686 # By default, enable Performance counters on Windows.
688 o['variables']['node_use_perfctr'] = b(not options.without_perfctr)
689 elif options.with_perfctr:
690 raise Exception('Performance counter is only supported on Windows.')
692 o['variables']['node_use_perfctr'] = 'false'
695 o['variables']['node_tag'] = '-' + options.tag
697 o['variables']['node_tag'] = ''
699 o['variables']['node_release_urlbase'] = options.release_urlbase or ''
701 if options.v8_options:
702 o['variables']['node_v8_options'] = options.v8_options.replace('"', '\\"')
704 if options.enable_static:
705 o['variables']['node_target_type'] = 'static_library'
707 if options.linked_module:
708 o['variables']['library_files'] = options.linked_module
711 def configure_library(lib, output):
712 shared_lib = 'shared_' + lib
713 output['variables']['node_' + shared_lib] = b(getattr(options, shared_lib))
715 if getattr(options, shared_lib):
716 (pkg_libs, pkg_cflags, pkg_libpath) = pkg_config(lib)
719 output['include_dirs'] += (
720 filter(None, map(str.strip, pkg_cflags.split('-I'))))
722 # libpath needs to be provided ahead libraries
724 output['libraries'] += (
725 filter(None, map(str.strip, pkg_cflags.split('-L'))))
727 default_libs = getattr(options, shared_lib + '_libname')
728 default_libs = map('-l{0}'.format, default_libs.split(','))
731 output['libraries'] += pkg_libs.split()
733 output['libraries'] += default_libs
737 o['variables']['v8_enable_gdbjit'] = 1 if options.gdb else 0
738 o['variables']['v8_no_strict_aliasing'] = 1 # Work around compiler bugs.
739 o['variables']['v8_optimized_debug'] = 0 # Compile with -O0 in debug builds.
740 o['variables']['v8_random_seed'] = 0 # Use a random seed for hash tables.
741 o['variables']['v8_use_snapshot'] = 0 if options.without_snapshot else 1
743 def configure_openssl(o):
744 o['variables']['node_use_openssl'] = b(not options.without_ssl)
745 o['variables']['node_shared_openssl'] = b(options.shared_openssl)
746 o['variables']['openssl_no_asm'] = 1 if options.openssl_no_asm else 0
747 if options.openssl_fips:
748 o['variables']['openssl_fips'] = options.openssl_fips
749 fips_dir = os.path.join(root_dir, 'deps', 'openssl', 'fips')
750 fips_ld = os.path.abspath(os.path.join(fips_dir, 'fipsld'))
751 o['make_global_settings'] = [
752 ['LINK', fips_ld + ' <(openssl_fips)/bin/fipsld'],
755 o['variables']['openssl_fips'] = ''
758 if options.without_ssl:
760 configure_library('openssl', o)
763 def configure_fullystatic(o):
764 if options.fully_static:
765 o['libraries'] += ['-static']
767 print("Generation of static executable will not work on OSX "
768 "when using default compilation environment")
771 def configure_winsdk(o):
775 winsdk_dir = os.environ.get('WindowsSdkDir')
777 if winsdk_dir and os.path.isfile(winsdk_dir + '\\bin\\ctrpp.exe'):
778 print('Found ctrpp in WinSDK--will build generated files '
779 'into tools/msvs/genfiles.')
780 o['variables']['node_has_winsdk'] = 'true'
783 print('ctrpp not found in WinSDK path--using pre-gen files '
784 'from tools/msvs/genfiles.')
786 def write(filename, data):
787 filename = os.path.join(root_dir, filename)
788 print 'creating ', filename
789 f = open(filename, 'w+')
792 do_not_edit = '# Do not edit. Generated by the configure script.\n'
794 def glob_to_var(dir_base, dir_sub, patch_dir):
796 dir_all = os.path.join(dir_base, dir_sub)
797 files = os.walk(dir_all)
799 (path, dirs, files) = ent
801 if file.endswith('.cpp') or file.endswith('.c') or file.endswith('.h'):
802 # srcfile uses "slash" as dir separator as its output is consumed by gyp
803 srcfile = '%s/%s' % (dir_sub, file)
805 patchfile = '%s/%s/%s' % (dir_base, patch_dir, file)
806 if os.path.isfile(patchfile):
807 srcfile = '%s/%s' % (patch_dir, file)
808 print 'Using version-specific floating patch %s' % patchfile
813 def configure_intl(o):
816 'url': 'http://download.icu-project.org/files/icu4c/55.1/icu4c-55_1-src.zip',
817 # from https://ssl.icu-project.org/files/icu4c/55.1/icu4c-src-55_1.md5:
818 'md5': '4cddf1e1d47622fdd9de2cd7bb5001fd',
821 def icu_download(path):
822 # download ICU, if needed
826 local = url.split('/')[-1]
827 targetfile = os.path.join(root_dir, 'deps', local)
828 if not os.path.isfile(targetfile):
829 if nodedownload.candownload(auto_downloads, "icu"):
830 nodedownload.retrievefile(url, targetfile)
832 print ' Re-using existing %s' % targetfile
833 if os.path.isfile(targetfile):
834 sys.stdout.write(' Checking file integrity with MD5:\r')
835 gotmd5 = nodedownload.md5sum(targetfile)
836 print ' MD5: %s %s' % (gotmd5, targetfile)
840 print ' Expected: %s *MISMATCH*' % md5
841 print '\n ** Corrupted ZIP? Delete %s to retry download.\n' % targetfile
846 icu_config_name = 'icu_config.gypi'
847 def write_config(data, name):
850 # write an empty file to start with
851 write(icu_config_name, do_not_edit +
852 pprint.pformat(icu_config, indent=2) + '\n')
854 # always set icu_small, node.gyp depends on it being defined.
855 o['variables']['icu_small'] = b(False)
857 with_intl = options.with_intl
858 with_icu_source = options.with_icu_source
859 have_icu_path = bool(options.with_icu_path)
860 if have_icu_path and with_intl != 'none':
861 print 'Error: Cannot specify both --with-icu-path and --with-intl'
864 # Chromium .gyp mode: --with-icu-path
865 o['variables']['v8_enable_i18n_support'] = 1
867 o['variables']['icu_gyp_path'] = options.with_icu_path
869 # --with-intl=<with_intl>
871 if with_intl in (None, 'none'):
872 o['variables']['v8_enable_i18n_support'] = 0
874 elif with_intl == 'small-icu':
875 # small ICU (English only)
876 o['variables']['v8_enable_i18n_support'] = 1
877 o['variables']['icu_small'] = b(True)
878 locs = set(options.with_icu_locales.split(','))
879 locs.add('root') # must have root
880 o['variables']['icu_locales'] = string.join(locs,',')
881 elif with_intl == 'full-icu':
883 o['variables']['v8_enable_i18n_support'] = 1
884 elif with_intl == 'system-icu':
885 # ICU from pkg-config.
886 o['variables']['v8_enable_i18n_support'] = 1
887 pkgicu = pkg_config('icu-i18n')
888 if pkgicu[0] is None:
889 print 'Error: could not load pkg-config data for "icu-i18n".'
890 print 'See above errors or the README.md.'
892 (libs, cflags, libpath) = pkgicu
893 # libpath provides linker path which may contain spaces
895 o['libraries'] += [libpath]
896 # safe to split, cannot contain spaces
897 o['libraries'] += libs.split()
899 o['include_dirs'] += filter(None, map(str.strip, cflags.split('-I')))
900 # use the "system" .gyp
901 o['variables']['icu_gyp_path'] = 'tools/icu/icu-system.gyp'
904 # this is just the 'deps' dir. Used for unpacking.
905 icu_parent_path = os.path.join(root_dir, 'deps')
907 # The full path to the ICU source directory.
908 icu_full_path = os.path.join(icu_parent_path, 'icu')
910 # icu-tmp is used to download and unpack the ICU tarball.
911 icu_tmp_path = os.path.join(icu_parent_path, 'icu-tmp')
913 # --with-icu-source processing
914 # first, check that they didn't pass --with-icu-source=deps/icu
915 if with_icu_source and os.path.abspath(icu_full_path) == os.path.abspath(with_icu_source):
916 print 'Ignoring redundant --with-icu-source=%s' % (with_icu_source)
917 with_icu_source = None
918 # if with_icu_source is still set, try to use it.
920 if os.path.isdir(icu_full_path):
921 print 'Deleting old ICU source: %s' % (icu_full_path)
922 shutil.rmtree(icu_full_path)
923 # now, what path was given?
924 if os.path.isdir(with_icu_source):
925 # it's a path. Copy it.
926 print '%s -> %s' % (with_icu_source, icu_full_path)
927 shutil.copytree(with_icu_source, icu_full_path)
929 # could be file or URL.
930 # Set up temporary area
931 if os.path.isdir(icu_tmp_path):
932 shutil.rmtree(icu_tmp_path)
933 os.mkdir(icu_tmp_path)
935 if os.path.isfile(with_icu_source):
936 # it's a file. Try to unpack it.
937 icu_tarball = with_icu_source
939 # Can we download it?
940 local = os.path.join(icu_tmp_path, with_icu_source.split('/')[-1]) # local part
941 icu_tarball = nodedownload.retrievefile(with_icu_source, local)
942 # continue with "icu_tarball"
943 nodedownload.unpack(icu_tarball, icu_tmp_path)
944 # Did it unpack correctly? Should contain 'icu'
945 tmp_icu = os.path.join(icu_tmp_path, 'icu')
946 if os.path.isdir(tmp_icu):
947 os.rename(tmp_icu, icu_full_path)
948 shutil.rmtree(icu_tmp_path)
950 print ' Error: --with-icu-source=%s did not result in an "icu" dir.' % with_icu_source
951 shutil.rmtree(icu_tmp_path)
954 # ICU mode. (icu-generic.gyp)
955 o['variables']['icu_gyp_path'] = 'tools/icu/icu-generic.gyp'
956 # ICU source dir relative to root
957 o['variables']['icu_path'] = icu_full_path
958 if not os.path.isdir(icu_full_path):
959 print '* ECMA-402 (Intl) support didn\'t find ICU in %s..' % (icu_full_path)
960 # can we download (or find) a zipfile?
961 localzip = icu_download(icu_full_path)
963 nodedownload.unpack(localzip, icu_parent_path)
964 if not os.path.isdir(icu_full_path):
965 print ' Cannot build Intl without ICU in %s.' % (icu_full_path)
966 print ' (Fix, or disable with "--with-intl=none" )'
969 print '* Using ICU in %s' % (icu_full_path)
970 # Now, what version of ICU is it? We just need the "major", such as 54.
971 # uvernum.h contains it as a #define.
972 uvernum_h = os.path.join(icu_full_path, 'source/common/unicode/uvernum.h')
973 if not os.path.isfile(uvernum_h):
974 print ' Error: could not load %s - is ICU installed?' % uvernum_h
977 matchVerExp = r'^\s*#define\s+U_ICU_VERSION_SHORT\s+"([^"]*)".*'
978 match_version = re.compile(matchVerExp)
979 for line in open(uvernum_h).readlines():
980 m = match_version.match(line)
982 icu_ver_major = m.group(1)
983 if not icu_ver_major:
984 print ' Could not read U_ICU_VERSION_SHORT version from %s' % uvernum_h
986 icu_endianness = sys.byteorder[0]; # TODO(srl295): EBCDIC should be 'e'
987 o['variables']['icu_ver_major'] = icu_ver_major
988 o['variables']['icu_endianness'] = icu_endianness
989 icu_data_file_l = 'icudt%s%s.dat' % (icu_ver_major, 'l')
990 icu_data_file = 'icudt%s%s.dat' % (icu_ver_major, icu_endianness)
991 # relative to configure
992 icu_data_path = os.path.join(icu_full_path,
996 icu_data_in = os.path.join('../../deps/icu/source/data/in', icu_data_file_l)
997 if not os.path.isfile(icu_data_path) and icu_endianness != 'l':
998 # use host endianness
999 icu_data_path = os.path.join(icu_full_path,
1003 icu_data_in = os.path.join('icu/source/data/in',
1005 # this is the input '.dat' file to use .. icudt*.dat
1006 # may be little-endian if from a icu-project.org tarball
1007 o['variables']['icu_data_in'] = icu_data_in
1008 # this is the icudt*.dat file which node will be using (platform endianness)
1009 o['variables']['icu_data_file'] = icu_data_file
1010 if not os.path.isfile(icu_data_path):
1011 print ' Error: ICU prebuilt data file %s does not exist.' % icu_data_path
1012 print ' See the README.md.'
1013 # .. and we're not about to build it from .gyp!
1015 # map from variable name to subdirs
1017 'stubdata': 'stubdata',
1021 'tools': 'tools/toolutil',
1022 'genccode': 'tools/genccode',
1023 'genrb': 'tools/genrb',
1024 'icupkg': 'tools/icupkg',
1026 # this creates a variable icu_src_XXX for each of the subdirs
1027 # with a list of the src files to use
1029 var = 'icu_src_%s' % i
1030 path = '../../deps/icu/source/%s' % icu_src[i]
1031 icu_config['variables'][var] = glob_to_var('tools/icu', path, 'patches/%s/source/%s' % (icu_ver_major, icu_src[i]) )
1032 # write updated icu_config.gypi with a bunch of paths
1033 write(icu_config_name, do_not_edit +
1034 pprint.pformat(icu_config, indent=2) + '\n')
1035 return # end of configure_intl
1038 'variables': { 'python': sys.executable },
1045 # Print a warning when the compiler is too old.
1046 check_compiler(output)
1048 # determine the "flavor" (operating system) we're building for,
1049 # leveraging gyp's GetFlavor function
1051 if (options.dest_os):
1052 flavor_params['flavor'] = options.dest_os
1053 flavor = GetFlavor(flavor_params)
1055 configure_node(output)
1056 configure_library('zlib', output)
1057 configure_library('http_parser', output)
1058 configure_library('libuv', output)
1059 configure_v8(output)
1060 configure_openssl(output)
1061 configure_winsdk(output)
1062 configure_intl(output)
1063 configure_fullystatic(output)
1065 # variables should be a root level element,
1066 # move everything else to target_defaults
1067 variables = output['variables']
1068 del output['variables']
1070 # make_global_settings should be a root level element too
1071 if 'make_global_settings' in output:
1072 make_global_settings = output['make_global_settings']
1073 del output['make_global_settings']
1075 make_global_settings = False
1078 'variables': variables,
1079 'target_defaults': output,
1081 if make_global_settings:
1082 output['make_global_settings'] = make_global_settings
1084 pprint.pprint(output, indent=2)
1086 write('config.gypi', do_not_edit +
1087 pprint.pformat(output, indent=2) + '\n')
1090 'BUILDTYPE': 'Debug' if options.debug else 'Release',
1091 'USE_XCODE': str(int(options.use_xcode or 0)),
1092 'PYTHON': sys.executable,
1096 config['PREFIX'] = options.prefix
1098 config = '\n'.join(map('='.join, config.iteritems())) + '\n'
1101 '# Do not edit. Generated by the configure script.\n' + config)
1103 gyp_args = [sys.executable, 'tools/gyp_node.py', '--no-parallel']
1105 if options.use_xcode:
1106 gyp_args += ['-f', 'xcode']
1107 elif flavor == 'win' and sys.platform != 'msys':
1108 gyp_args += ['-f', 'msvs', '-G', 'msvs_version=auto']
1110 gyp_args += ['-f', 'make-' + flavor]
1115 warn('warnings were emitted in the configure phase')
1117 sys.exit(subprocess.call(gyp_args))