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)
438 """Check for ARMv6 instructions"""
439 cc_macros_cache = cc_macros()
440 return ('__ARM_ARCH_6__' in cc_macros_cache or
441 '__ARM_ARCH_6M__' in cc_macros_cache)
444 def is_arm_hard_float_abi():
445 """Check for hardfloat or softfloat eabi on ARM"""
446 # GCC versions 4.6 and above define __ARM_PCS or __ARM_PCS_VFP to specify
447 # the Floating Point ABI used (PCS stands for Procedure Call Standard).
448 # We use these as well as a couple of other defines to statically determine
451 return '__ARM_PCS_VFP' in cc_macros()
455 """Host architecture check using the CC command."""
460 '__aarch64__' : 'arm64',
464 '__x86_64__' : 'x64',
467 rtn = 'ia32' # default
470 if i in k and k[i] != '0':
478 """Host architecture check using environ vars (better way to do this?)"""
480 observed_arch = os.environ.get('PROCESSOR_ARCHITECTURE', 'x86')
481 arch = os.environ.get('PROCESSOR_ARCHITEW6432', observed_arch)
490 return matchup.get(arch, 'ia32')
493 def configure_arm(o):
494 if options.arm_float_abi:
495 arm_float_abi = options.arm_float_abi
496 elif is_arm_hard_float_abi():
497 arm_float_abi = 'hard'
499 arm_float_abi = 'default'
502 o['variables']['arm_fpu'] = 'vfpv3'
503 o['variables']['arm_version'] = '7'
505 o['variables']['arm_fpu'] = 'vfpv2'
506 o['variables']['arm_version'] = '6' if is_arch_armv6() else 'default'
508 o['variables']['arm_thumb'] = 0 # -marm
509 o['variables']['arm_float_abi'] = arm_float_abi
511 # Print warning when snapshot is enabled and building on armv6
512 if is_arch_armv6() and options.with_snapshot:
513 warn('when building on ARMv6, don\'t use --with-snapshot')
516 def configure_mips(o):
517 can_use_fpu_instructions = (options.mips_float_abi != 'soft')
518 o['variables']['v8_can_use_fpu_instructions'] = b(can_use_fpu_instructions)
519 o['variables']['v8_use_mips_abi_hardfloat'] = b(can_use_fpu_instructions)
520 o['variables']['mips_arch_variant'] = options.mips_arch_variant
521 o['variables']['mips_fpu_mode'] = options.mips_fpu_mode
524 def configure_node(o):
525 if options.dest_os == 'android':
526 o['variables']['OS'] = 'android'
527 o['variables']['node_prefix'] = os.path.expanduser(options.prefix or '')
528 o['variables']['node_install_npm'] = b(not options.without_npm)
529 o['default_configuration'] = 'Debug' if options.debug else 'Release'
531 host_arch = host_arch_win() if os.name == 'nt' else host_arch_cc()
532 target_arch = options.dest_cpu or host_arch
533 o['variables']['host_arch'] = host_arch
534 o['variables']['target_arch'] = target_arch
536 if target_arch != host_arch and options.with_snapshot:
537 o['variables']['want_separate_host_toolset'] = 1
539 o['variables']['want_separate_host_toolset'] = 0
541 if target_arch == 'arm':
543 elif (target_arch == 'arm64' and
544 not options.shared_openssl and
545 not options.without_ssl):
546 # FIXME(bnoordhuis) It's not possible to build the bundled openssl due to
547 # deps/openssl/asm/arm-elf-gas/modes/ghash-armv4.S, which is 32 bits only.
548 warn('not building openssl, arm64 not yet supported')
549 options.without_ssl = True
550 elif target_arch in ('mips', 'mipsel'):
553 if flavor in ('solaris', 'mac', 'linux', 'freebsd'):
554 use_dtrace = not options.without_dtrace
555 # Don't enable by default on linux and freebsd
556 if flavor in ('linux', 'freebsd'):
557 use_dtrace = options.with_dtrace
559 if flavor == 'linux':
560 if options.systemtap_includes:
561 o['include_dirs'] += [options.systemtap_includes]
562 o['variables']['node_use_dtrace'] = b(use_dtrace)
563 o['variables']['uv_use_dtrace'] = b(use_dtrace)
564 o['variables']['uv_parent_path'] = '/deps/uv/'
565 elif options.with_dtrace:
567 'DTrace is currently only supported on SunOS, MacOS or Linux systems.')
569 o['variables']['node_use_dtrace'] = 'false'
571 # Enable Lttng if --with-lttng was defined. Use logic similar to
572 # ETW for windows. Lttng is only available on the Linux platform.
573 if flavor == 'linux':
574 o['variables']['node_use_lttng'] = b(options.with_lttng)
575 elif options.with_lttng:
576 raise Exception('lttng is only supported on Linux.')
578 o['variables']['node_use_lttng'] = 'false'
580 if options.no_ifaddrs:
581 o['defines'] += ['SUNOS_NO_IFADDRS']
583 # By default, enable ETW on Windows.
585 o['variables']['node_use_etw'] = b(not options.without_etw)
586 elif options.with_etw:
587 raise Exception('ETW is only supported on Windows.')
589 o['variables']['node_use_etw'] = 'false'
591 # By default, enable Performance counters on Windows.
593 o['variables']['node_use_perfctr'] = b(not options.without_perfctr)
594 elif options.with_perfctr:
595 raise Exception('Performance counter is only supported on Windows.')
597 o['variables']['node_use_perfctr'] = 'false'
600 o['variables']['node_tag'] = '-' + options.tag
602 o['variables']['node_tag'] = ''
604 if options.v8_options:
605 o['variables']['node_v8_options'] = options.v8_options.replace('"', '\\"')
608 def configure_libz(o):
609 o['variables']['node_shared_zlib'] = b(options.shared_zlib)
611 # assume shared_zlib if one of these is set?
612 if options.shared_zlib_libpath:
613 o['libraries'] += ['-L%s' % options.shared_zlib_libpath]
614 if options.shared_zlib_libname:
615 o['libraries'] += ['-l%s' % options.shared_zlib_libname]
616 elif options.shared_zlib:
617 o['libraries'] += ['-lz']
618 if options.shared_zlib_includes:
619 o['include_dirs'] += [options.shared_zlib_includes]
622 def configure_http_parser(o):
623 o['variables']['node_shared_http_parser'] = b(options.shared_http_parser)
625 # assume shared http_parser if one of these is set?
626 if options.shared_http_parser_libpath:
627 o['libraries'] += ['-L%s' % options.shared_http_parser_libpath]
628 if options.shared_http_parser_libname:
629 o['libraries'] += ['-l%s' % options.shared_http_parser_libname]
630 elif options.shared_http_parser:
631 o['libraries'] += ['-lhttp_parser']
632 if options.shared_http_parser_includes:
633 o['include_dirs'] += [options.shared_http_parser_includes]
636 def configure_libuv(o):
637 o['variables']['node_shared_libuv'] = b(options.shared_libuv)
639 # assume shared libuv if one of these is set?
640 if options.shared_libuv_libpath:
641 o['libraries'] += ['-L%s' % options.shared_libuv_libpath]
643 o['variables']['uv_library'] = 'static_library'
645 if options.shared_libuv_libname:
646 o['libraries'] += ['-l%s' % options.shared_libuv_libname]
647 elif options.shared_libuv:
648 o['libraries'] += ['-luv']
649 if options.shared_libuv_includes:
650 o['include_dirs'] += [options.shared_libuv_includes]
654 o['variables']['node_shared_v8'] = b(options.shared_v8)
655 o['variables']['v8_enable_gdbjit'] = 1 if options.gdb else 0
656 o['variables']['v8_no_strict_aliasing'] = 1 # Work around compiler bugs.
657 o['variables']['v8_optimized_debug'] = 0 # Compile with -O0 in debug builds.
658 o['variables']['v8_random_seed'] = 0 # Use a random seed for hash tables.
659 o['variables']['v8_use_snapshot'] = b(options.with_snapshot)
661 # assume shared_v8 if one of these is set?
662 if options.shared_v8_libpath:
663 o['libraries'] += ['-L%s' % options.shared_v8_libpath]
664 if options.shared_v8_libname:
665 o['libraries'] += ['-l%s' % options.shared_v8_libname]
666 elif options.shared_v8:
667 o['libraries'] += ['-lv8']
668 if options.shared_v8_includes:
669 o['include_dirs'] += [options.shared_v8_includes]
672 def configure_openssl(o):
673 o['variables']['node_use_openssl'] = b(not options.without_ssl)
674 o['variables']['node_shared_openssl'] = b(options.shared_openssl)
675 o['variables']['openssl_no_asm'] = (
676 1 if options.openssl_no_asm else 0)
678 if options.without_ssl:
681 if options.shared_openssl:
682 (libs, cflags) = pkg_config('openssl') or ('-lssl -lcrypto', '')
684 if options.shared_openssl_libpath:
685 o['libraries'] += ['-L%s' % options.shared_openssl_libpath]
687 if options.shared_openssl_libname:
688 libnames = options.shared_openssl_libname.split(',')
689 o['libraries'] += ['-l%s' % s for s in libnames]
691 o['libraries'] += libs.split()
693 if options.shared_openssl_includes:
694 o['include_dirs'] += [options.shared_openssl_includes]
696 o['cflags'] += cflags.split()
699 def configure_fullystatic(o):
700 if options.fully_static:
701 o['libraries'] += ['-static']
703 print("Generation of static executable will not work on OSX "
704 "when using default compilation environment")
707 def configure_winsdk(o):
711 winsdk_dir = os.environ.get('WindowsSdkDir')
713 if winsdk_dir and os.path.isfile(winsdk_dir + '\\bin\\ctrpp.exe'):
714 print('Found ctrpp in WinSDK--will build generated files '
715 'into tools/msvs/genfiles.')
716 o['variables']['node_has_winsdk'] = 'true'
719 print('ctrpp not found in WinSDK path--using pre-gen files '
720 'from tools/msvs/genfiles.')
722 def write(filename, data):
723 filename = os.path.join(root_dir, filename)
724 print 'creating ', filename
725 f = open(filename, 'w+')
728 do_not_edit = '# Do not edit. Generated by the configure script.\n'
730 def glob_to_var(dir_base, dir_sub):
732 dir_all = os.path.join(dir_base, dir_sub)
733 files = os.walk(dir_all)
735 (path, dirs, files) = ent
737 if file.endswith('.cpp') or file.endswith('.c') or file.endswith('.h'):
738 list.append('%s/%s' % (dir_sub, file))
742 def configure_intl(o):
745 'url': 'http://download.icu-project.org/files/icu4c/54.1/icu4c-54_1-src.zip',
746 # from https://ssl.icu-project.org/files/icu4c/54.1/icu4c-src-54_1.md5:
747 'md5': '6b89d60e2f0e140898ae4d7f72323bca',
750 def icu_download(path):
751 # download ICU, if needed
755 local = url.split('/')[-1]
756 targetfile = os.path.join(root_dir, 'deps', local)
757 if not os.path.isfile(targetfile):
758 if nodedownload.candownload(auto_downloads, "icu"):
759 nodedownload.retrievefile(url, targetfile)
761 print ' Re-using existing %s' % targetfile
762 if os.path.isfile(targetfile):
763 sys.stdout.write(' Checking file integrity with MD5:\r')
764 gotmd5 = nodedownload.md5sum(targetfile)
765 print ' MD5: %s %s' % (gotmd5, targetfile)
769 print ' Expected: %s *MISMATCH*' % md5
770 print '\n ** Corrupted ZIP? Delete %s to retry download.\n' % targetfile
775 icu_config_name = 'icu_config.gypi'
776 def write_config(data, name):
779 # write an empty file to start with
780 write(icu_config_name, do_not_edit +
781 pprint.pformat(icu_config, indent=2) + '\n')
783 # always set icu_small, node.gyp depends on it being defined.
784 o['variables']['icu_small'] = b(False)
786 with_intl = options.with_intl
787 with_icu_source = options.with_icu_source
788 have_icu_path = bool(options.with_icu_path)
789 if have_icu_path and with_intl:
790 print 'Error: Cannot specify both --with-icu-path and --with-intl'
793 # Chromium .gyp mode: --with-icu-path
794 o['variables']['v8_enable_i18n_support'] = 1
796 o['variables']['icu_gyp_path'] = options.with_icu_path
798 # --with-intl=<with_intl>
800 if with_intl is None:
801 with_intl = 'none' # The default mode of Intl
802 # sanity check localelist
803 if options.with_icu_locales and (with_intl != 'small-icu'):
804 print 'Error: --with-icu-locales only makes sense with --with-intl=small-icu'
806 if with_intl == 'none' or with_intl is None:
807 o['variables']['v8_enable_i18n_support'] = 0
809 elif with_intl == 'small-icu':
810 # small ICU (English only)
811 o['variables']['v8_enable_i18n_support'] = 1
812 o['variables']['icu_small'] = b(True)
813 with_icu_locales = options.with_icu_locales
814 if not with_icu_locales:
815 with_icu_locales = 'root,en'
816 locs = set(with_icu_locales.split(','))
817 locs.add('root') # must have root
818 o['variables']['icu_locales'] = string.join(locs,',')
819 elif with_intl == 'full-icu':
821 o['variables']['v8_enable_i18n_support'] = 1
822 elif with_intl == 'system-icu':
823 # ICU from pkg-config.
824 o['variables']['v8_enable_i18n_support'] = 1
825 pkgicu = pkg_config('icu-i18n')
827 print 'Error: could not load pkg-config data for "icu-i18n".'
828 print 'See above errors or the README.md.'
830 (libs, cflags) = pkgicu
831 o['libraries'] += libs.split()
832 o['cflags'] += cflags.split()
833 # use the "system" .gyp
834 o['variables']['icu_gyp_path'] = 'tools/icu/icu-system.gyp'
837 print 'Error: unknown value --with-intl=%s' % with_intl
839 # Note: non-ICU implementations could use other 'with_intl'
842 # this is just the 'deps' dir. Used for unpacking.
843 icu_parent_path = os.path.join(root_dir, 'deps')
845 # The full path to the ICU source directory.
846 icu_full_path = os.path.join(icu_parent_path, 'icu')
848 # icu-tmp is used to download and unpack the ICU tarball.
849 icu_tmp_path = os.path.join(icu_parent_path, 'icu-tmp')
851 # --with-icu-source processing
852 # first, check that they didn't pass --with-icu-source=deps/icu
853 if with_icu_source and os.path.abspath(icu_full_path) == os.path.abspath(with_icu_source):
854 print 'Ignoring redundant --with-icu-source=%s' % (with_icu_source)
855 with_icu_source = None
856 # if with_icu_source is still set, try to use it.
858 if os.path.isdir(icu_full_path):
859 print 'Deleting old ICU source: %s' % (icu_full_path)
860 shutil.rmtree(icu_full_path)
861 # now, what path was given?
862 if os.path.isdir(with_icu_source):
863 # it's a path. Copy it.
864 print '%s -> %s' % (with_icu_source, icu_full_path)
865 shutil.copytree(with_icu_source, icu_full_path)
867 # could be file or URL.
868 # Set up temporary area
869 if os.path.isdir(icu_tmp_path):
870 shutil.rmtree(icu_tmp_path)
871 os.mkdir(icu_tmp_path)
873 if os.path.isfile(with_icu_source):
874 # it's a file. Try to unpack it.
875 icu_tarball = with_icu_source
877 # Can we download it?
878 local = os.path.join(icu_tmp_path, with_icu_source.split('/')[-1]) # local part
879 icu_tarball = nodedownload.retrievefile(with_icu_source, local)
880 # continue with "icu_tarball"
881 nodedownload.unpack(icu_tarball, icu_tmp_path)
882 # Did it unpack correctly? Should contain 'icu'
883 tmp_icu = os.path.join(icu_tmp_path, 'icu')
884 if os.path.isdir(tmp_icu):
885 os.rename(tmp_icu, icu_full_path)
886 shutil.rmtree(icu_tmp_path)
888 print ' Error: --with-icu-source=%s did not result in an "icu" dir.' % with_icu_source
889 shutil.rmtree(icu_tmp_path)
892 # ICU mode. (icu-generic.gyp)
893 o['variables']['icu_gyp_path'] = 'tools/icu/icu-generic.gyp'
894 # ICU source dir relative to root
895 o['variables']['icu_path'] = icu_full_path
896 if not os.path.isdir(icu_full_path):
897 print '* ECMA-402 (Intl) support didn\'t find ICU in %s..' % (icu_full_path)
898 # can we download (or find) a zipfile?
899 localzip = icu_download(icu_full_path)
901 nodedownload.unpack(localzip, icu_parent_path)
902 if not os.path.isdir(icu_full_path):
903 print ' Cannot build Intl without ICU in %s.' % (icu_full_path)
904 print ' (Fix, or disable with "--with-intl=none" )'
907 print '* Using ICU in %s' % (icu_full_path)
908 # Now, what version of ICU is it? We just need the "major", such as 54.
909 # uvernum.h contains it as a #define.
910 uvernum_h = os.path.join(icu_full_path, 'source/common/unicode/uvernum.h')
911 if not os.path.isfile(uvernum_h):
912 print ' Error: could not load %s - is ICU installed?' % uvernum_h
915 matchVerExp = r'^\s*#define\s+U_ICU_VERSION_SHORT\s+"([^"]*)".*'
916 match_version = re.compile(matchVerExp)
917 for line in open(uvernum_h).readlines():
918 m = match_version.match(line)
920 icu_ver_major = m.group(1)
921 if not icu_ver_major:
922 print ' Could not read U_ICU_VERSION_SHORT version from %s' % uvernum_h
924 icu_endianness = sys.byteorder[0]; # TODO(srl295): EBCDIC should be 'e'
925 o['variables']['icu_ver_major'] = icu_ver_major
926 o['variables']['icu_endianness'] = icu_endianness
927 icu_data_file_l = 'icudt%s%s.dat' % (icu_ver_major, 'l')
928 icu_data_file = 'icudt%s%s.dat' % (icu_ver_major, icu_endianness)
929 # relative to configure
930 icu_data_path = os.path.join(icu_full_path,
934 icu_data_in = os.path.join('../../deps/icu/source/data/in', icu_data_file_l)
935 if not os.path.isfile(icu_data_path) and icu_endianness != 'l':
936 # use host endianness
937 icu_data_path = os.path.join(icu_full_path,
941 icu_data_in = os.path.join('icu/source/data/in',
943 # this is the input '.dat' file to use .. icudt*.dat
944 # may be little-endian if from a icu-project.org tarball
945 o['variables']['icu_data_in'] = icu_data_in
946 # this is the icudt*.dat file which node will be using (platform endianness)
947 o['variables']['icu_data_file'] = icu_data_file
948 if not os.path.isfile(icu_data_path):
949 print ' Error: ICU prebuilt data file %s does not exist.' % icu_data_path
950 print ' See the README.md.'
951 # .. and we're not about to build it from .gyp!
953 # map from variable name to subdirs
955 'stubdata': 'stubdata',
959 'tools': 'tools/toolutil',
960 'genccode': 'tools/genccode',
961 'genrb': 'tools/genrb',
962 'icupkg': 'tools/icupkg',
964 # this creates a variable icu_src_XXX for each of the subdirs
965 # with a list of the src files to use
967 var = 'icu_src_%s' % i
968 path = '../../deps/icu/source/%s' % icu_src[i]
969 icu_config['variables'][var] = glob_to_var('tools/icu', path)
970 # write updated icu_config.gypi with a bunch of paths
971 write(icu_config_name, do_not_edit +
972 pprint.pformat(icu_config, indent=2) + '\n')
973 return # end of configure_intl
975 # Print a warning when the compiler is too old.
978 # determine the "flavor" (operating system) we're building for,
979 # leveraging gyp's GetFlavor function
981 if (options.dest_os):
982 flavor_params['flavor'] = options.dest_os
983 flavor = GetFlavor(flavor_params)
986 'variables': { 'python': sys.executable },
993 configure_node(output)
994 configure_libz(output)
995 configure_http_parser(output)
996 configure_libuv(output)
998 configure_openssl(output)
999 configure_winsdk(output)
1000 configure_intl(output)
1001 configure_fullystatic(output)
1003 # variables should be a root level element,
1004 # move everything else to target_defaults
1005 variables = output['variables']
1006 del output['variables']
1008 'variables': variables,
1009 'target_defaults': output
1011 pprint.pprint(output, indent=2)
1013 write('config.gypi', do_not_edit +
1014 pprint.pformat(output, indent=2) + '\n')
1017 'BUILDTYPE': 'Debug' if options.debug else 'Release',
1018 'USE_XCODE': str(int(options.use_xcode or 0)),
1019 'PYTHON': sys.executable,
1023 config['PREFIX'] = options.prefix
1025 config = '\n'.join(map('='.join, config.iteritems())) + '\n'
1028 '# Do not edit. Generated by the configure script.\n' + config)
1030 gyp_args = [sys.executable, 'tools/gyp_node.py', '--no-parallel']
1032 if options.use_xcode:
1033 gyp_args += ['-f', 'xcode']
1034 elif flavor == 'win' and sys.platform != 'msys':
1035 gyp_args += ['-f', 'msvs', '-G', 'msvs_version=auto']
1037 gyp_args += ['-f', 'make-' + flavor]
1042 warn('warnings were emitted in the configure phase')
1044 sys.exit(subprocess.call(gyp_args))