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 # Options should be in alphabetical order but keep --prefix at the top,
29 # that's arguably the one people will be looking for most.
30 parser.add_option('--prefix',
33 help='select the install prefix (defaults to /usr/local)')
35 parser.add_option('--debug',
38 help='also build debug build')
40 parser.add_option('--dest-cpu',
43 help='CPU architecture to build for. '
44 'Valid values are: arm, arm64, ia32, mips, mipsel, x32, x64')
46 parser.add_option('--dest-os',
49 help='operating system to build for. Valid values are: '
50 'win, mac, solaris, freebsd, openbsd, linux, android')
52 parser.add_option('--gdb',
55 help='add gdb support')
57 parser.add_option('--no-ifaddrs',
60 help='use on deprecated SunOS systems that do not support ifaddrs.h')
62 parser.add_option("--fully-static",
65 help="Generate an executable without external dynamic libraries. This "
66 "will not work on OSX when using default compilation environment")
68 parser.add_option("--openssl-no-asm",
70 dest="openssl_no_asm",
71 help="Do not build optimized assembly for OpenSSL")
74 parser.add_option('--openssl-includes',
76 dest='shared_openssl_includes',
77 help=optparse.SUPPRESS_HELP)
80 parser.add_option('--openssl-libpath',
82 dest='shared_openssl_libpath',
83 help=optparse.SUPPRESS_HELP)
86 parser.add_option('--openssl-use-sys',
88 dest='shared_openssl',
89 help=optparse.SUPPRESS_HELP)
91 parser.add_option('--shared-http-parser',
93 dest='shared_http_parser',
94 help='link to a shared http_parser DLL instead of static linking')
96 parser.add_option('--shared-http-parser-includes',
98 dest='shared_http_parser_includes',
99 help='directory containing http_parser header files')
101 parser.add_option('--shared-http-parser-libname',
103 dest='shared_http_parser_libname',
104 help='alternative lib name to link to (default: \'http_parser\')')
106 parser.add_option('--shared-http-parser-libpath',
108 dest='shared_http_parser_libpath',
109 help='a directory to search for the shared http_parser DLL')
111 parser.add_option('--shared-libuv',
114 help='link to a shared libuv DLL instead of static linking')
116 parser.add_option('--shared-libuv-includes',
118 dest='shared_libuv_includes',
119 help='directory containing libuv header files')
121 parser.add_option('--shared-libuv-libname',
123 dest='shared_libuv_libname',
124 help='alternative lib name to link to (default: \'uv\')')
126 parser.add_option('--shared-libuv-libpath',
128 dest='shared_libuv_libpath',
129 help='a directory to search for the shared libuv DLL')
131 parser.add_option('--shared-openssl',
133 dest='shared_openssl',
134 help='link to a shared OpenSSl DLL instead of static linking')
136 parser.add_option('--shared-openssl-includes',
138 dest='shared_openssl_includes',
139 help='directory containing OpenSSL header files')
141 parser.add_option('--shared-openssl-libname',
143 dest='shared_openssl_libname',
144 help='alternative lib name to link to (default: \'crypto,ssl\')')
146 parser.add_option('--shared-openssl-libpath',
148 dest='shared_openssl_libpath',
149 help='a directory to search for the shared OpenSSL DLLs')
151 parser.add_option('--shared-v8',
154 help='link to a shared V8 DLL instead of static linking')
156 parser.add_option('--shared-v8-includes',
158 dest='shared_v8_includes',
159 help='directory containing V8 header files')
161 parser.add_option('--shared-v8-libname',
163 dest='shared_v8_libname',
164 help='alternative lib name to link to (default: \'v8\')')
166 parser.add_option('--shared-v8-libpath',
168 dest='shared_v8_libpath',
169 help='a directory to search for the shared V8 DLL')
171 parser.add_option('--shared-zlib',
174 help='link to a shared zlib DLL instead of static linking')
176 parser.add_option('--shared-zlib-includes',
178 dest='shared_zlib_includes',
179 help='directory containing zlib header files')
181 parser.add_option('--shared-zlib-libname',
183 dest='shared_zlib_libname',
184 help='alternative lib name to link to (default: \'z\')')
186 parser.add_option('--shared-zlib-libpath',
188 dest='shared_zlib_libpath',
189 help='a directory to search for the shared zlib DLL')
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('--v8-options',
206 help='v8 options to pass, see `node --v8-options` for examples.')
208 parser.add_option('--with-arm-float-abi',
210 dest='arm_float_abi',
211 help='specifies which floating-point ABI to use. Valid values are: '
212 'soft, softfp, hard')
214 parser.add_option('--with-mips-arch-variant',
216 dest='mips_arch_variant',
218 help='MIPS arch variant: loongson, r1, r2, r6, rx')
220 parser.add_option('--with-mips-fpu-mode',
222 dest='mips_fpu_mode',
224 help='MIPS FPU mode: fp32, fp64, fpxx')
226 parser.add_option('--with-mips-float-abi',
228 dest='mips_float_abi',
230 help='MIPS floating-point ABI: soft, hard')
232 parser.add_option('--with-dtrace',
235 help='build with DTrace (default is true on sunos)')
237 parser.add_option('--with-lttng',
240 help='build with Lttng (Only available to Linux)')
242 parser.add_option('--with-etw',
245 help='build with ETW (default is true on Windows)')
247 parser.add_option('--download',
249 dest='download_list',
250 help=nodedownload.help())
252 parser.add_option('--with-icu-path',
254 dest='with_icu_path',
255 help='Path to icu.gyp (ICU i18n, Chromium version only.)')
257 parser.add_option('--with-icu-locales',
259 dest='with_icu_locales',
260 help='Comma-separated list of locales for "small-icu". Default: "root,en". "root" is assumed.')
262 parser.add_option('--with-intl',
265 help='Intl mode: none, full-icu, small-icu (default is none)')
267 parser.add_option('--with-icu-source',
269 dest='with_icu_source',
270 help='Intl mode: optional local path to icu/ dir, or path/URL of icu source archive.')
272 parser.add_option('--with-perfctr',
275 help='build with performance counters (default is true on Windows)')
277 parser.add_option('--without-dtrace',
279 dest='without_dtrace',
280 help='build without DTrace')
282 parser.add_option('--without-etw',
285 help='build without ETW')
287 parser.add_option('--without-npm',
290 help='don\'t install the bundled npm package manager')
292 parser.add_option('--without-perfctr',
294 dest='without_perfctr',
295 help='build without performance counters')
297 parser.add_option('--with-snapshot',
299 dest='with_snapshot',
300 help=optparse.SUPPRESS_HELP)
302 # Dummy option for backwards compatibility.
303 parser.add_option('--without-snapshot',
305 dest='unused_without_snapshot',
306 help=optparse.SUPPRESS_HELP)
308 parser.add_option('--without-ssl',
311 help='build without SSL')
313 parser.add_option('--xcode',
316 help='generate build files for use with xcode')
318 (options, args) = parser.parse_args()
320 # set up auto-download list
321 auto_downloads = nodedownload.parse(options.download_list)
326 prefix = '\033[1m\033[93mWARNING\033[0m' if os.isatty(1) else 'WARNING'
327 print('%s: %s' % (prefix, msg))
329 # track if warnings occured
333 """Returns the string 'true' if value is truthy, 'false' otherwise."""
341 cmd = os.popen('pkg-config --libs %s' % pkg, 'r')
342 libs = cmd.readline().strip()
344 if (ret): return None
346 cmd = os.popen('pkg-config --cflags %s' % pkg, 'r')
347 cflags = cmd.readline().strip()
349 if (ret): return None
351 return (libs, cflags)
354 def try_check_compiler(cc, lang):
356 proc = subprocess.Popen(shlex.split(cc) + ['-E', '-P', '-x', lang, '-'],
357 stdin=subprocess.PIPE, stdout=subprocess.PIPE)
359 return (False, False, '', '')
361 proc.stdin.write('__clang__ __GNUC__ __GNUC_MINOR__ __GNUC_PATCHLEVEL__ '
362 '__clang_major__ __clang_minor__ __clang_patchlevel__')
364 values = (proc.communicate()[0].split() + ['0'] * 7)[0:7]
365 is_clang = values[0] == '1'
366 gcc_version = '%s.%s.%s' % tuple(values[1:1+3])
367 clang_version = '%s.%s.%s' % tuple(values[4:4+3])
369 return (True, is_clang, clang_version, gcc_version)
372 # Note: Apple clang self-reports as clang 4.2.0 and gcc 4.2.1. It passes
373 # the version check more by accident than anything else but a more rigorous
374 # check involves checking the build number against a whitelist. I'm not
375 # quite prepared to go that far yet.
376 def check_compiler():
377 if sys.platform == 'win32':
380 ok, is_clang, clang_version, gcc_version = try_check_compiler(CXX, 'c++')
382 warn('failed to autodetect C++ compiler version (CXX=%s)' % CXX)
383 elif clang_version < '3.4.0' if is_clang else gcc_version < '4.8.0':
384 warn('C++ compiler too old, need g++ 4.8 or clang++ 3.4 (CXX=%s)' % CXX)
386 ok, is_clang, clang_version, gcc_version = try_check_compiler(CC, 'c')
388 warn('failed to autodetect C compiler version (CC=%s)' % CC)
389 elif not is_clang and gcc_version < '4.2.0':
390 # clang 3.2 is a little white lie because any clang version will probably
391 # do for the C bits. However, we might as well encourage people to upgrade
392 # to a version that is not completely ancient.
393 warn('C compiler too old, need gcc 4.2 or clang 3.2 (CC=%s)' % CC)
397 """Checks predefined macros using the CC command."""
400 p = subprocess.Popen(shlex.split(CC) + ['-dM', '-E', '-'],
401 stdin=subprocess.PIPE,
402 stdout=subprocess.PIPE,
403 stderr=subprocess.PIPE)
405 print '''Node.js configure error: No acceptable C compiler found!
407 Please make sure you have a C compiler installed on your system and/or
408 consider adjusting the CC environment variable if you installed
409 it in a non-standard prefix.
414 out = p.communicate()[0]
416 out = str(out).split('\n')
420 lst = shlex.split(line)
429 """Check for ARMv7 instructions"""
430 cc_macros_cache = cc_macros()
431 return ('__ARM_ARCH_7__' in cc_macros_cache or
432 '__ARM_ARCH_7A__' in cc_macros_cache or
433 '__ARM_ARCH_7R__' in cc_macros_cache or
434 '__ARM_ARCH_7M__' in cc_macros_cache or
435 '__ARM_ARCH_7S__' in cc_macros_cache)
439 """Check for ARMv6 instructions"""
440 cc_macros_cache = cc_macros()
441 return ('__ARM_ARCH_6__' in cc_macros_cache or
442 '__ARM_ARCH_6M__' in cc_macros_cache)
445 def is_arm_hard_float_abi():
446 """Check for hardfloat or softfloat eabi on ARM"""
447 # GCC versions 4.6 and above define __ARM_PCS or __ARM_PCS_VFP to specify
448 # the Floating Point ABI used (PCS stands for Procedure Call Standard).
449 # We use these as well as a couple of other defines to statically determine
452 return '__ARM_PCS_VFP' in cc_macros()
456 """Host architecture check using the CC command."""
461 '__aarch64__' : 'arm64',
465 '__x86_64__' : 'x64',
468 rtn = 'ia32' # default
471 if i in k and k[i] != '0':
479 """Host architecture check using environ vars (better way to do this?)"""
481 observed_arch = os.environ.get('PROCESSOR_ARCHITECTURE', 'x86')
482 arch = os.environ.get('PROCESSOR_ARCHITEW6432', observed_arch)
491 return matchup.get(arch, 'ia32')
494 def configure_arm(o):
495 if options.arm_float_abi:
496 arm_float_abi = options.arm_float_abi
497 elif is_arm_hard_float_abi():
498 arm_float_abi = 'hard'
500 arm_float_abi = 'default'
503 o['variables']['arm_fpu'] = 'vfpv3'
504 o['variables']['arm_version'] = '7'
506 o['variables']['arm_fpu'] = 'vfpv2'
507 o['variables']['arm_version'] = '6' if is_arch_armv6() else 'default'
509 o['variables']['arm_thumb'] = 0 # -marm
510 o['variables']['arm_float_abi'] = arm_float_abi
512 if options.dest_os == 'android':
513 o['variables']['arm_fpu'] = 'vfpv3'
514 o['variables']['arm_version'] = '7'
516 # Print warning when snapshot is enabled and building on armv6
517 if is_arch_armv6() and options.with_snapshot:
518 warn('when building on ARMv6, don\'t use --with-snapshot')
521 def configure_mips(o):
522 can_use_fpu_instructions = (options.mips_float_abi != 'soft')
523 o['variables']['v8_can_use_fpu_instructions'] = b(can_use_fpu_instructions)
524 o['variables']['v8_use_mips_abi_hardfloat'] = b(can_use_fpu_instructions)
525 o['variables']['mips_arch_variant'] = options.mips_arch_variant
526 o['variables']['mips_fpu_mode'] = options.mips_fpu_mode
529 def configure_node(o):
530 if options.dest_os == 'android':
531 o['variables']['OS'] = 'android'
532 o['variables']['node_prefix'] = os.path.expanduser(options.prefix or '')
533 o['variables']['node_install_npm'] = b(not options.without_npm)
534 o['default_configuration'] = 'Debug' if options.debug else 'Release'
536 host_arch = host_arch_win() if os.name == 'nt' else host_arch_cc()
537 target_arch = options.dest_cpu or host_arch
538 o['variables']['host_arch'] = host_arch
539 o['variables']['target_arch'] = target_arch
541 if target_arch != host_arch and options.with_snapshot:
542 o['variables']['want_separate_host_toolset'] = 1
544 o['variables']['want_separate_host_toolset'] = 0
546 if target_arch == 'arm':
548 elif (target_arch == 'arm64' and
549 not options.shared_openssl and
550 not options.without_ssl):
551 # FIXME(bnoordhuis) It's not possible to build the bundled openssl due to
552 # deps/openssl/asm/arm-elf-gas/modes/ghash-armv4.S, which is 32 bits only.
553 warn('not building openssl, arm64 not yet supported')
554 options.without_ssl = True
555 elif target_arch in ('mips', 'mipsel'):
558 if flavor in ('solaris', 'mac', 'linux', 'freebsd'):
559 use_dtrace = not options.without_dtrace
560 # Don't enable by default on linux and freebsd
561 if flavor in ('linux', 'freebsd'):
562 use_dtrace = options.with_dtrace
564 if flavor == 'linux':
565 if options.systemtap_includes:
566 o['include_dirs'] += [options.systemtap_includes]
567 o['variables']['node_use_dtrace'] = b(use_dtrace)
568 o['variables']['uv_use_dtrace'] = b(use_dtrace)
569 o['variables']['uv_parent_path'] = '/deps/uv/'
570 elif options.with_dtrace:
572 'DTrace is currently only supported on SunOS, MacOS or Linux systems.')
574 o['variables']['node_use_dtrace'] = 'false'
576 # Enable Lttng if --with-lttng was defined. Use logic similar to
577 # ETW for windows. Lttng is only available on the Linux platform.
578 if flavor == 'linux':
579 o['variables']['node_use_lttng'] = b(options.with_lttng)
580 elif options.with_lttng:
581 raise Exception('lttng is only supported on Linux.')
583 o['variables']['node_use_lttng'] = 'false'
585 if options.no_ifaddrs:
586 o['defines'] += ['SUNOS_NO_IFADDRS']
588 # By default, enable ETW on Windows.
590 o['variables']['node_use_etw'] = b(not options.without_etw)
591 elif options.with_etw:
592 raise Exception('ETW is only supported on Windows.')
594 o['variables']['node_use_etw'] = 'false'
596 # By default, enable Performance counters on Windows.
598 o['variables']['node_use_perfctr'] = b(not options.without_perfctr)
599 elif options.with_perfctr:
600 raise Exception('Performance counter is only supported on Windows.')
602 o['variables']['node_use_perfctr'] = 'false'
605 o['variables']['node_tag'] = '-' + options.tag
607 o['variables']['node_tag'] = ''
609 if options.v8_options:
610 o['variables']['node_v8_options'] = options.v8_options.replace('"', '\\"')
613 def configure_libz(o):
614 o['variables']['node_shared_zlib'] = b(options.shared_zlib)
616 # assume shared_zlib if one of these is set?
617 if options.shared_zlib_libpath:
618 o['libraries'] += ['-L%s' % options.shared_zlib_libpath]
619 if options.shared_zlib_libname:
620 o['libraries'] += ['-l%s' % options.shared_zlib_libname]
621 elif options.shared_zlib:
622 o['libraries'] += ['-lz']
623 if options.shared_zlib_includes:
624 o['include_dirs'] += [options.shared_zlib_includes]
627 def configure_http_parser(o):
628 o['variables']['node_shared_http_parser'] = b(options.shared_http_parser)
630 # assume shared http_parser if one of these is set?
631 if options.shared_http_parser_libpath:
632 o['libraries'] += ['-L%s' % options.shared_http_parser_libpath]
633 if options.shared_http_parser_libname:
634 o['libraries'] += ['-l%s' % options.shared_http_parser_libname]
635 elif options.shared_http_parser:
636 o['libraries'] += ['-lhttp_parser']
637 if options.shared_http_parser_includes:
638 o['include_dirs'] += [options.shared_http_parser_includes]
641 def configure_libuv(o):
642 o['variables']['node_shared_libuv'] = b(options.shared_libuv)
644 # assume shared libuv if one of these is set?
645 if options.shared_libuv_libpath:
646 o['libraries'] += ['-L%s' % options.shared_libuv_libpath]
648 o['variables']['uv_library'] = 'static_library'
650 if options.shared_libuv_libname:
651 o['libraries'] += ['-l%s' % options.shared_libuv_libname]
652 elif options.shared_libuv:
653 o['libraries'] += ['-luv']
654 if options.shared_libuv_includes:
655 o['include_dirs'] += [options.shared_libuv_includes]
659 o['variables']['node_shared_v8'] = b(options.shared_v8)
660 o['variables']['v8_enable_gdbjit'] = 1 if options.gdb else 0
661 o['variables']['v8_no_strict_aliasing'] = 1 # Work around compiler bugs.
662 o['variables']['v8_optimized_debug'] = 0 # Compile with -O0 in debug builds.
663 o['variables']['v8_random_seed'] = 0 # Use a random seed for hash tables.
664 o['variables']['v8_use_snapshot'] = b(options.with_snapshot)
666 # assume shared_v8 if one of these is set?
667 if options.shared_v8_libpath:
668 o['libraries'] += ['-L%s' % options.shared_v8_libpath]
669 if options.shared_v8_libname:
670 o['libraries'] += ['-l%s' % options.shared_v8_libname]
671 elif options.shared_v8:
672 o['libraries'] += ['-lv8', '-lv8_platform']
673 if options.shared_v8_includes:
674 o['include_dirs'] += [options.shared_v8_includes]
677 def configure_openssl(o):
678 o['variables']['node_use_openssl'] = b(not options.without_ssl)
679 o['variables']['node_shared_openssl'] = b(options.shared_openssl)
680 o['variables']['openssl_no_asm'] = (
681 1 if options.openssl_no_asm else 0)
683 if options.without_ssl:
686 if options.shared_openssl:
687 (libs, cflags) = pkg_config('openssl') or ('-lssl -lcrypto', '')
689 if options.shared_openssl_libpath:
690 o['libraries'] += ['-L%s' % options.shared_openssl_libpath]
692 if options.shared_openssl_libname:
693 libnames = options.shared_openssl_libname.split(',')
694 o['libraries'] += ['-l%s' % s for s in libnames]
696 o['libraries'] += libs.split()
698 if options.shared_openssl_includes:
699 o['include_dirs'] += [options.shared_openssl_includes]
701 o['cflags'] += cflags.split()
704 def configure_fullystatic(o):
705 if options.fully_static:
706 o['libraries'] += ['-static']
708 print("Generation of static executable will not work on OSX "
709 "when using default compilation environment")
712 def configure_winsdk(o):
716 winsdk_dir = os.environ.get('WindowsSdkDir')
718 if winsdk_dir and os.path.isfile(winsdk_dir + '\\bin\\ctrpp.exe'):
719 print('Found ctrpp in WinSDK--will build generated files '
720 'into tools/msvs/genfiles.')
721 o['variables']['node_has_winsdk'] = 'true'
724 print('ctrpp not found in WinSDK path--using pre-gen files '
725 'from tools/msvs/genfiles.')
727 def write(filename, data):
728 filename = os.path.join(root_dir, filename)
729 print 'creating ', filename
730 f = open(filename, 'w+')
733 do_not_edit = '# Do not edit. Generated by the configure script.\n'
735 def glob_to_var(dir_base, dir_sub):
737 dir_all = os.path.join(dir_base, dir_sub)
738 files = os.walk(dir_all)
740 (path, dirs, files) = ent
742 if file.endswith('.cpp') or file.endswith('.c') or file.endswith('.h'):
743 list.append('%s/%s' % (dir_sub, file))
747 def configure_intl(o):
750 'url': 'http://download.icu-project.org/files/icu4c/54.1/icu4c-54_1-src.zip',
751 # from https://ssl.icu-project.org/files/icu4c/54.1/icu4c-src-54_1.md5:
752 'md5': '6b89d60e2f0e140898ae4d7f72323bca',
755 def icu_download(path):
756 # download ICU, if needed
760 local = url.split('/')[-1]
761 targetfile = os.path.join(root_dir, 'deps', local)
762 if not os.path.isfile(targetfile):
763 if nodedownload.candownload(auto_downloads, "icu"):
764 nodedownload.retrievefile(url, targetfile)
766 print ' Re-using existing %s' % targetfile
767 if os.path.isfile(targetfile):
768 sys.stdout.write(' Checking file integrity with MD5:\r')
769 gotmd5 = nodedownload.md5sum(targetfile)
770 print ' MD5: %s %s' % (gotmd5, targetfile)
774 print ' Expected: %s *MISMATCH*' % md5
775 print '\n ** Corrupted ZIP? Delete %s to retry download.\n' % targetfile
780 icu_config_name = 'icu_config.gypi'
781 def write_config(data, name):
784 # write an empty file to start with
785 write(icu_config_name, do_not_edit +
786 pprint.pformat(icu_config, indent=2) + '\n')
788 # always set icu_small, node.gyp depends on it being defined.
789 o['variables']['icu_small'] = b(False)
791 with_intl = options.with_intl
792 with_icu_source = options.with_icu_source
793 have_icu_path = bool(options.with_icu_path)
794 if have_icu_path and with_intl:
795 print 'Error: Cannot specify both --with-icu-path and --with-intl'
798 # Chromium .gyp mode: --with-icu-path
799 o['variables']['v8_enable_i18n_support'] = 1
801 o['variables']['icu_gyp_path'] = options.with_icu_path
803 # --with-intl=<with_intl>
805 if with_intl is None:
806 with_intl = 'none' # The default mode of Intl
807 # sanity check localelist
808 if options.with_icu_locales and (with_intl != 'small-icu'):
809 print 'Error: --with-icu-locales only makes sense with --with-intl=small-icu'
811 if with_intl == 'none' or with_intl is None:
812 o['variables']['v8_enable_i18n_support'] = 0
814 elif with_intl == 'small-icu':
815 # small ICU (English only)
816 o['variables']['v8_enable_i18n_support'] = 1
817 o['variables']['icu_small'] = b(True)
818 with_icu_locales = options.with_icu_locales
819 if not with_icu_locales:
820 with_icu_locales = 'root,en'
821 locs = set(with_icu_locales.split(','))
822 locs.add('root') # must have root
823 o['variables']['icu_locales'] = string.join(locs,',')
824 elif with_intl == 'full-icu':
826 o['variables']['v8_enable_i18n_support'] = 1
827 elif with_intl == 'system-icu':
828 # ICU from pkg-config.
829 o['variables']['v8_enable_i18n_support'] = 1
830 pkgicu = pkg_config('icu-i18n')
832 print 'Error: could not load pkg-config data for "icu-i18n".'
833 print 'See above errors or the README.md.'
835 (libs, cflags) = pkgicu
836 o['libraries'] += libs.split()
837 o['cflags'] += cflags.split()
838 # use the "system" .gyp
839 o['variables']['icu_gyp_path'] = 'tools/icu/icu-system.gyp'
842 print 'Error: unknown value --with-intl=%s' % with_intl
844 # Note: non-ICU implementations could use other 'with_intl'
847 # this is just the 'deps' dir. Used for unpacking.
848 icu_parent_path = os.path.join(root_dir, 'deps')
850 # The full path to the ICU source directory.
851 icu_full_path = os.path.join(icu_parent_path, 'icu')
853 # icu-tmp is used to download and unpack the ICU tarball.
854 icu_tmp_path = os.path.join(icu_parent_path, 'icu-tmp')
856 # --with-icu-source processing
857 # first, check that they didn't pass --with-icu-source=deps/icu
858 if with_icu_source and os.path.abspath(icu_full_path) == os.path.abspath(with_icu_source):
859 print 'Ignoring redundant --with-icu-source=%s' % (with_icu_source)
860 with_icu_source = None
861 # if with_icu_source is still set, try to use it.
863 if os.path.isdir(icu_full_path):
864 print 'Deleting old ICU source: %s' % (icu_full_path)
865 shutil.rmtree(icu_full_path)
866 # now, what path was given?
867 if os.path.isdir(with_icu_source):
868 # it's a path. Copy it.
869 print '%s -> %s' % (with_icu_source, icu_full_path)
870 shutil.copytree(with_icu_source, icu_full_path)
872 # could be file or URL.
873 # Set up temporary area
874 if os.path.isdir(icu_tmp_path):
875 shutil.rmtree(icu_tmp_path)
876 os.mkdir(icu_tmp_path)
878 if os.path.isfile(with_icu_source):
879 # it's a file. Try to unpack it.
880 icu_tarball = with_icu_source
882 # Can we download it?
883 local = os.path.join(icu_tmp_path, with_icu_source.split('/')[-1]) # local part
884 icu_tarball = nodedownload.retrievefile(with_icu_source, local)
885 # continue with "icu_tarball"
886 nodedownload.unpack(icu_tarball, icu_tmp_path)
887 # Did it unpack correctly? Should contain 'icu'
888 tmp_icu = os.path.join(icu_tmp_path, 'icu')
889 if os.path.isdir(tmp_icu):
890 os.rename(tmp_icu, icu_full_path)
891 shutil.rmtree(icu_tmp_path)
893 print ' Error: --with-icu-source=%s did not result in an "icu" dir.' % with_icu_source
894 shutil.rmtree(icu_tmp_path)
897 # ICU mode. (icu-generic.gyp)
898 o['variables']['icu_gyp_path'] = 'tools/icu/icu-generic.gyp'
899 # ICU source dir relative to root
900 o['variables']['icu_path'] = icu_full_path
901 if not os.path.isdir(icu_full_path):
902 print '* ECMA-402 (Intl) support didn\'t find ICU in %s..' % (icu_full_path)
903 # can we download (or find) a zipfile?
904 localzip = icu_download(icu_full_path)
906 nodedownload.unpack(localzip, icu_parent_path)
907 if not os.path.isdir(icu_full_path):
908 print ' Cannot build Intl without ICU in %s.' % (icu_full_path)
909 print ' (Fix, or disable with "--with-intl=none" )'
912 print '* Using ICU in %s' % (icu_full_path)
913 # Now, what version of ICU is it? We just need the "major", such as 54.
914 # uvernum.h contains it as a #define.
915 uvernum_h = os.path.join(icu_full_path, 'source/common/unicode/uvernum.h')
916 if not os.path.isfile(uvernum_h):
917 print ' Error: could not load %s - is ICU installed?' % uvernum_h
920 matchVerExp = r'^\s*#define\s+U_ICU_VERSION_SHORT\s+"([^"]*)".*'
921 match_version = re.compile(matchVerExp)
922 for line in open(uvernum_h).readlines():
923 m = match_version.match(line)
925 icu_ver_major = m.group(1)
926 if not icu_ver_major:
927 print ' Could not read U_ICU_VERSION_SHORT version from %s' % uvernum_h
929 icu_endianness = sys.byteorder[0]; # TODO(srl295): EBCDIC should be 'e'
930 o['variables']['icu_ver_major'] = icu_ver_major
931 o['variables']['icu_endianness'] = icu_endianness
932 icu_data_file_l = 'icudt%s%s.dat' % (icu_ver_major, 'l')
933 icu_data_file = 'icudt%s%s.dat' % (icu_ver_major, icu_endianness)
934 # relative to configure
935 icu_data_path = os.path.join(icu_full_path,
939 icu_data_in = os.path.join('../../deps/icu/source/data/in', icu_data_file_l)
940 if not os.path.isfile(icu_data_path) and icu_endianness != 'l':
941 # use host endianness
942 icu_data_path = os.path.join(icu_full_path,
946 icu_data_in = os.path.join('icu/source/data/in',
948 # this is the input '.dat' file to use .. icudt*.dat
949 # may be little-endian if from a icu-project.org tarball
950 o['variables']['icu_data_in'] = icu_data_in
951 # this is the icudt*.dat file which node will be using (platform endianness)
952 o['variables']['icu_data_file'] = icu_data_file
953 if not os.path.isfile(icu_data_path):
954 print ' Error: ICU prebuilt data file %s does not exist.' % icu_data_path
955 print ' See the README.md.'
956 # .. and we're not about to build it from .gyp!
958 # map from variable name to subdirs
960 'stubdata': 'stubdata',
964 'tools': 'tools/toolutil',
965 'genccode': 'tools/genccode',
966 'genrb': 'tools/genrb',
967 'icupkg': 'tools/icupkg',
969 # this creates a variable icu_src_XXX for each of the subdirs
970 # with a list of the src files to use
972 var = 'icu_src_%s' % i
973 path = '../../deps/icu/source/%s' % icu_src[i]
974 icu_config['variables'][var] = glob_to_var('tools/icu', path)
975 # write updated icu_config.gypi with a bunch of paths
976 write(icu_config_name, do_not_edit +
977 pprint.pformat(icu_config, indent=2) + '\n')
978 return # end of configure_intl
980 # Print a warning when the compiler is too old.
983 # determine the "flavor" (operating system) we're building for,
984 # leveraging gyp's GetFlavor function
986 if (options.dest_os):
987 flavor_params['flavor'] = options.dest_os
988 flavor = GetFlavor(flavor_params)
991 'variables': { 'python': sys.executable },
998 configure_node(output)
999 configure_libz(output)
1000 configure_http_parser(output)
1001 configure_libuv(output)
1002 configure_v8(output)
1003 configure_openssl(output)
1004 configure_winsdk(output)
1005 configure_intl(output)
1006 configure_fullystatic(output)
1008 # variables should be a root level element,
1009 # move everything else to target_defaults
1010 variables = output['variables']
1011 del output['variables']
1013 'variables': variables,
1014 'target_defaults': output
1016 pprint.pprint(output, indent=2)
1018 write('config.gypi', do_not_edit +
1019 pprint.pformat(output, indent=2) + '\n')
1022 'BUILDTYPE': 'Debug' if options.debug else 'Release',
1023 'USE_XCODE': str(int(options.use_xcode or 0)),
1024 'PYTHON': sys.executable,
1028 config['PREFIX'] = options.prefix
1030 config = '\n'.join(map('='.join, config.iteritems())) + '\n'
1033 '# Do not edit. Generated by the configure script.\n' + config)
1035 gyp_args = [sys.executable, 'tools/gyp_node.py', '--no-parallel']
1037 if options.use_xcode:
1038 gyp_args += ['-f', 'xcode']
1039 elif flavor == 'win' and sys.platform != 'msys':
1040 gyp_args += ['-f', 'msvs', '-G', 'msvs_version=auto']
1042 gyp_args += ['-f', 'make-' + flavor]
1047 warn('warnings were emitted in the configure phase')
1049 sys.exit(subprocess.call(gyp_args))