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-zlib',
154 help='link to a shared zlib DLL instead of static linking')
156 parser.add_option('--shared-zlib-includes',
158 dest='shared_zlib_includes',
159 help='directory containing zlib header files')
161 parser.add_option('--shared-zlib-libname',
163 dest='shared_zlib_libname',
164 help='alternative lib name to link to (default: \'z\')')
166 parser.add_option('--shared-zlib-libpath',
168 dest='shared_zlib_libpath',
169 help='a directory to search for the shared zlib DLL')
171 # TODO document when we've decided on what the tracing API and its options will
173 parser.add_option('--systemtap-includes',
175 dest='systemtap_includes',
176 help=optparse.SUPPRESS_HELP)
178 parser.add_option('--tag',
181 help='custom build tag')
183 parser.add_option('--v8-options',
186 help='v8 options to pass, see `node --v8-options` for examples.')
188 parser.add_option('--with-arm-float-abi',
190 dest='arm_float_abi',
191 help='specifies which floating-point ABI to use. Valid values are: '
192 'soft, softfp, hard')
194 parser.add_option('--with-mips-arch-variant',
196 dest='mips_arch_variant',
198 help='MIPS arch variant: loongson, r1, r2, r6, rx')
200 parser.add_option('--with-mips-fpu-mode',
202 dest='mips_fpu_mode',
204 help='MIPS FPU mode: fp32, fp64, fpxx')
206 parser.add_option('--with-mips-float-abi',
208 dest='mips_float_abi',
210 help='MIPS floating-point ABI: soft, hard')
212 parser.add_option('--with-dtrace',
215 help='build with DTrace (default is true on sunos)')
217 parser.add_option('--with-lttng',
220 help='build with Lttng (Only available to Linux)')
222 parser.add_option('--with-etw',
225 help='build with ETW (default is true on Windows)')
227 parser.add_option('--download',
229 dest='download_list',
230 help=nodedownload.help())
232 parser.add_option('--with-icu-path',
234 dest='with_icu_path',
235 help='Path to icu.gyp (ICU i18n, Chromium version only.)')
237 parser.add_option('--with-icu-locales',
239 dest='with_icu_locales',
240 help='Comma-separated list of locales for "small-icu". Default: "root,en". "root" is assumed.')
242 parser.add_option('--with-intl',
245 help='Intl mode: none, full-icu, small-icu (default is none)')
247 parser.add_option('--with-icu-source',
249 dest='with_icu_source',
250 help='Intl mode: optional local path to icu/ dir, or path/URL of icu source archive.')
252 parser.add_option('--with-perfctr',
255 help='build with performance counters (default is true on Windows)')
257 parser.add_option('--without-dtrace',
259 dest='without_dtrace',
260 help='build without DTrace')
262 parser.add_option('--without-etw',
265 help='build without ETW')
267 parser.add_option('--without-npm',
270 help='don\'t install the bundled npm package manager')
272 parser.add_option('--without-perfctr',
274 dest='without_perfctr',
275 help='build without performance counters')
277 parser.add_option('--with-snapshot',
279 dest='with_snapshot',
280 help=optparse.SUPPRESS_HELP)
282 # Dummy option for backwards compatibility.
283 parser.add_option('--without-snapshot',
285 dest='unused_without_snapshot',
286 help=optparse.SUPPRESS_HELP)
288 parser.add_option('--without-ssl',
291 help='build without SSL')
293 parser.add_option('--xcode',
296 help='generate build files for use with xcode')
298 (options, args) = parser.parse_args()
300 # set up auto-download list
301 auto_downloads = nodedownload.parse(options.download_list)
306 prefix = '\033[1m\033[93mWARNING\033[0m' if os.isatty(1) else 'WARNING'
307 print('%s: %s' % (prefix, msg))
309 # track if warnings occured
313 """Returns the string 'true' if value is truthy, 'false' otherwise."""
321 cmd = os.popen('pkg-config --libs %s' % pkg, 'r')
322 libs = cmd.readline().strip()
324 if (ret): return None
326 cmd = os.popen('pkg-config --cflags %s' % pkg, 'r')
327 cflags = cmd.readline().strip()
329 if (ret): return None
331 return (libs, cflags)
334 def try_check_compiler(cc, lang):
336 proc = subprocess.Popen(shlex.split(cc) + ['-E', '-P', '-x', lang, '-'],
337 stdin=subprocess.PIPE, stdout=subprocess.PIPE)
339 return (False, False, '', '')
341 proc.stdin.write('__clang__ __GNUC__ __GNUC_MINOR__ __GNUC_PATCHLEVEL__ '
342 '__clang_major__ __clang_minor__ __clang_patchlevel__')
344 values = (proc.communicate()[0].split() + ['0'] * 7)[0:7]
345 is_clang = values[0] == '1'
346 gcc_version = '%s.%s.%s' % tuple(values[1:1+3])
347 clang_version = '%s.%s.%s' % tuple(values[4:4+3])
349 return (True, is_clang, clang_version, gcc_version)
352 # Note: Apple clang self-reports as clang 4.2.0 and gcc 4.2.1. It passes
353 # the version check more by accident than anything else but a more rigorous
354 # check involves checking the build number against a whitelist. I'm not
355 # quite prepared to go that far yet.
356 def check_compiler():
357 if sys.platform == 'win32':
360 ok, is_clang, clang_version, gcc_version = try_check_compiler(CXX, 'c++')
362 warn('failed to autodetect C++ compiler version (CXX=%s)' % CXX)
363 elif clang_version < '3.4.0' if is_clang else gcc_version < '4.8.0':
364 warn('C++ compiler too old, need g++ 4.8 or clang++ 3.4 (CXX=%s)' % CXX)
366 ok, is_clang, clang_version, gcc_version = try_check_compiler(CC, 'c')
368 warn('failed to autodetect C compiler version (CC=%s)' % CC)
369 elif not is_clang and gcc_version < '4.2.0':
370 # clang 3.2 is a little white lie because any clang version will probably
371 # do for the C bits. However, we might as well encourage people to upgrade
372 # to a version that is not completely ancient.
373 warn('C compiler too old, need gcc 4.2 or clang 3.2 (CC=%s)' % CC)
377 """Checks predefined macros using the CC command."""
380 p = subprocess.Popen(shlex.split(CC) + ['-dM', '-E', '-'],
381 stdin=subprocess.PIPE,
382 stdout=subprocess.PIPE,
383 stderr=subprocess.PIPE)
385 print '''Node.js configure error: No acceptable C compiler found!
387 Please make sure you have a C compiler installed on your system and/or
388 consider adjusting the CC environment variable if you installed
389 it in a non-standard prefix.
394 out = p.communicate()[0]
396 out = str(out).split('\n')
400 lst = shlex.split(line)
409 """Check for ARMv7 instructions"""
410 cc_macros_cache = cc_macros()
411 return ('__ARM_ARCH_7__' in cc_macros_cache or
412 '__ARM_ARCH_7A__' in cc_macros_cache or
413 '__ARM_ARCH_7R__' in cc_macros_cache or
414 '__ARM_ARCH_7M__' in cc_macros_cache or
415 '__ARM_ARCH_7S__' in cc_macros_cache)
419 """Check for ARMv6 instructions"""
420 cc_macros_cache = cc_macros()
421 return ('__ARM_ARCH_6__' in cc_macros_cache or
422 '__ARM_ARCH_6M__' in cc_macros_cache)
425 def is_arm_hard_float_abi():
426 """Check for hardfloat or softfloat eabi on ARM"""
427 # GCC versions 4.6 and above define __ARM_PCS or __ARM_PCS_VFP to specify
428 # the Floating Point ABI used (PCS stands for Procedure Call Standard).
429 # We use these as well as a couple of other defines to statically determine
432 return '__ARM_PCS_VFP' in cc_macros()
436 """Host architecture check using the CC command."""
441 '__aarch64__' : 'arm64',
445 '__x86_64__' : 'x64',
448 rtn = 'ia32' # default
451 if i in k and k[i] != '0':
459 """Host architecture check using environ vars (better way to do this?)"""
461 observed_arch = os.environ.get('PROCESSOR_ARCHITECTURE', 'x86')
462 arch = os.environ.get('PROCESSOR_ARCHITEW6432', observed_arch)
471 return matchup.get(arch, 'ia32')
474 def configure_arm(o):
475 if options.arm_float_abi:
476 arm_float_abi = options.arm_float_abi
477 elif is_arm_hard_float_abi():
478 arm_float_abi = 'hard'
480 arm_float_abi = 'default'
483 o['variables']['arm_fpu'] = 'vfpv3'
484 o['variables']['arm_version'] = '7'
486 o['variables']['arm_fpu'] = 'vfpv2'
487 o['variables']['arm_version'] = '6' if is_arch_armv6() else 'default'
489 o['variables']['arm_thumb'] = 0 # -marm
490 o['variables']['arm_float_abi'] = arm_float_abi
492 if options.dest_os == 'android':
493 o['variables']['arm_fpu'] = 'vfpv3'
494 o['variables']['arm_version'] = '7'
496 # Print warning when snapshot is enabled and building on armv6
497 if is_arch_armv6() and options.with_snapshot:
498 warn('when building on ARMv6, don\'t use --with-snapshot')
501 def configure_mips(o):
502 can_use_fpu_instructions = (options.mips_float_abi != 'soft')
503 o['variables']['v8_can_use_fpu_instructions'] = b(can_use_fpu_instructions)
504 o['variables']['v8_use_mips_abi_hardfloat'] = b(can_use_fpu_instructions)
505 o['variables']['mips_arch_variant'] = options.mips_arch_variant
506 o['variables']['mips_fpu_mode'] = options.mips_fpu_mode
509 def configure_node(o):
510 if options.dest_os == 'android':
511 o['variables']['OS'] = 'android'
512 o['variables']['node_prefix'] = os.path.expanduser(options.prefix or '')
513 o['variables']['node_install_npm'] = b(not options.without_npm)
514 o['default_configuration'] = 'Debug' if options.debug else 'Release'
516 host_arch = host_arch_win() if os.name == 'nt' else host_arch_cc()
517 target_arch = options.dest_cpu or host_arch
518 o['variables']['host_arch'] = host_arch
519 o['variables']['target_arch'] = target_arch
521 if target_arch != host_arch and options.with_snapshot:
522 o['variables']['want_separate_host_toolset'] = 1
524 o['variables']['want_separate_host_toolset'] = 0
526 if target_arch == 'arm':
528 elif (target_arch == 'arm64' and
529 not options.shared_openssl and
530 not options.without_ssl):
531 # FIXME(bnoordhuis) It's not possible to build the bundled openssl due to
532 # deps/openssl/asm/arm-elf-gas/modes/ghash-armv4.S, which is 32 bits only.
533 warn('not building openssl, arm64 not yet supported')
534 options.without_ssl = True
535 elif target_arch in ('mips', 'mipsel'):
538 if flavor in ('solaris', 'mac', 'linux', 'freebsd'):
539 use_dtrace = not options.without_dtrace
540 # Don't enable by default on linux and freebsd
541 if flavor in ('linux', 'freebsd'):
542 use_dtrace = options.with_dtrace
544 if flavor == 'linux':
545 if options.systemtap_includes:
546 o['include_dirs'] += [options.systemtap_includes]
547 o['variables']['node_use_dtrace'] = b(use_dtrace)
548 o['variables']['uv_use_dtrace'] = b(use_dtrace)
549 o['variables']['uv_parent_path'] = '/deps/uv/'
550 elif options.with_dtrace:
552 'DTrace is currently only supported on SunOS, MacOS or Linux systems.')
554 o['variables']['node_use_dtrace'] = 'false'
556 # Enable Lttng if --with-lttng was defined. Use logic similar to
557 # ETW for windows. Lttng is only available on the Linux platform.
558 if flavor == 'linux':
559 o['variables']['node_use_lttng'] = b(options.with_lttng)
560 elif options.with_lttng:
561 raise Exception('lttng is only supported on Linux.')
563 o['variables']['node_use_lttng'] = 'false'
565 if options.no_ifaddrs:
566 o['defines'] += ['SUNOS_NO_IFADDRS']
568 # By default, enable ETW on Windows.
570 o['variables']['node_use_etw'] = b(not options.without_etw)
571 elif options.with_etw:
572 raise Exception('ETW is only supported on Windows.')
574 o['variables']['node_use_etw'] = 'false'
576 # By default, enable Performance counters on Windows.
578 o['variables']['node_use_perfctr'] = b(not options.without_perfctr)
579 elif options.with_perfctr:
580 raise Exception('Performance counter is only supported on Windows.')
582 o['variables']['node_use_perfctr'] = 'false'
585 o['variables']['node_tag'] = '-' + options.tag
587 o['variables']['node_tag'] = ''
589 if options.v8_options:
590 o['variables']['node_v8_options'] = options.v8_options.replace('"', '\\"')
593 def configure_libz(o):
594 o['variables']['node_shared_zlib'] = b(options.shared_zlib)
596 # assume shared_zlib if one of these is set?
597 if options.shared_zlib_libpath:
598 o['libraries'] += ['-L%s' % options.shared_zlib_libpath]
599 if options.shared_zlib_libname:
600 o['libraries'] += ['-l%s' % options.shared_zlib_libname]
601 elif options.shared_zlib:
602 o['libraries'] += ['-lz']
603 if options.shared_zlib_includes:
604 o['include_dirs'] += [options.shared_zlib_includes]
607 def configure_http_parser(o):
608 o['variables']['node_shared_http_parser'] = b(options.shared_http_parser)
610 # assume shared http_parser if one of these is set?
611 if options.shared_http_parser_libpath:
612 o['libraries'] += ['-L%s' % options.shared_http_parser_libpath]
613 if options.shared_http_parser_libname:
614 o['libraries'] += ['-l%s' % options.shared_http_parser_libname]
615 elif options.shared_http_parser:
616 o['libraries'] += ['-lhttp_parser']
617 if options.shared_http_parser_includes:
618 o['include_dirs'] += [options.shared_http_parser_includes]
621 def configure_libuv(o):
622 o['variables']['node_shared_libuv'] = b(options.shared_libuv)
624 # assume shared libuv if one of these is set?
625 if options.shared_libuv_libpath:
626 o['libraries'] += ['-L%s' % options.shared_libuv_libpath]
628 o['variables']['uv_library'] = 'static_library'
630 if options.shared_libuv_libname:
631 o['libraries'] += ['-l%s' % options.shared_libuv_libname]
632 elif options.shared_libuv:
633 o['libraries'] += ['-luv']
634 if options.shared_libuv_includes:
635 o['include_dirs'] += [options.shared_libuv_includes]
639 o['variables']['v8_enable_gdbjit'] = 1 if options.gdb else 0
640 o['variables']['v8_no_strict_aliasing'] = 1 # Work around compiler bugs.
641 o['variables']['v8_optimized_debug'] = 0 # Compile with -O0 in debug builds.
642 o['variables']['v8_random_seed'] = 0 # Use a random seed for hash tables.
643 o['variables']['v8_use_snapshot'] = b(options.with_snapshot)
645 def configure_openssl(o):
646 o['variables']['node_use_openssl'] = b(not options.without_ssl)
647 o['variables']['node_shared_openssl'] = b(options.shared_openssl)
648 o['variables']['openssl_no_asm'] = (
649 1 if options.openssl_no_asm else 0)
651 if options.without_ssl:
654 if options.shared_openssl:
655 (libs, cflags) = pkg_config('openssl') or ('-lssl -lcrypto', '')
657 if options.shared_openssl_libpath:
658 o['libraries'] += ['-L%s' % options.shared_openssl_libpath]
660 if options.shared_openssl_libname:
661 libnames = options.shared_openssl_libname.split(',')
662 o['libraries'] += ['-l%s' % s for s in libnames]
664 o['libraries'] += libs.split()
666 if options.shared_openssl_includes:
667 o['include_dirs'] += [options.shared_openssl_includes]
669 o['cflags'] += cflags.split()
672 def configure_fullystatic(o):
673 if options.fully_static:
674 o['libraries'] += ['-static']
676 print("Generation of static executable will not work on OSX "
677 "when using default compilation environment")
680 def configure_winsdk(o):
684 winsdk_dir = os.environ.get('WindowsSdkDir')
686 if winsdk_dir and os.path.isfile(winsdk_dir + '\\bin\\ctrpp.exe'):
687 print('Found ctrpp in WinSDK--will build generated files '
688 'into tools/msvs/genfiles.')
689 o['variables']['node_has_winsdk'] = 'true'
692 print('ctrpp not found in WinSDK path--using pre-gen files '
693 'from tools/msvs/genfiles.')
695 def write(filename, data):
696 filename = os.path.join(root_dir, filename)
697 print 'creating ', filename
698 f = open(filename, 'w+')
701 do_not_edit = '# Do not edit. Generated by the configure script.\n'
703 def glob_to_var(dir_base, dir_sub):
705 dir_all = os.path.join(dir_base, dir_sub)
706 files = os.walk(dir_all)
708 (path, dirs, files) = ent
710 if file.endswith('.cpp') or file.endswith('.c') or file.endswith('.h'):
711 list.append('%s/%s' % (dir_sub, file))
715 def configure_intl(o):
718 'url': 'http://download.icu-project.org/files/icu4c/54.1/icu4c-54_1-src.zip',
719 # from https://ssl.icu-project.org/files/icu4c/54.1/icu4c-src-54_1.md5:
720 'md5': '6b89d60e2f0e140898ae4d7f72323bca',
723 def icu_download(path):
724 # download ICU, if needed
728 local = url.split('/')[-1]
729 targetfile = os.path.join(root_dir, 'deps', local)
730 if not os.path.isfile(targetfile):
731 if nodedownload.candownload(auto_downloads, "icu"):
732 nodedownload.retrievefile(url, targetfile)
734 print ' Re-using existing %s' % targetfile
735 if os.path.isfile(targetfile):
736 sys.stdout.write(' Checking file integrity with MD5:\r')
737 gotmd5 = nodedownload.md5sum(targetfile)
738 print ' MD5: %s %s' % (gotmd5, targetfile)
742 print ' Expected: %s *MISMATCH*' % md5
743 print '\n ** Corrupted ZIP? Delete %s to retry download.\n' % targetfile
748 icu_config_name = 'icu_config.gypi'
749 def write_config(data, name):
752 # write an empty file to start with
753 write(icu_config_name, do_not_edit +
754 pprint.pformat(icu_config, indent=2) + '\n')
756 # always set icu_small, node.gyp depends on it being defined.
757 o['variables']['icu_small'] = b(False)
759 with_intl = options.with_intl
760 with_icu_source = options.with_icu_source
761 have_icu_path = bool(options.with_icu_path)
762 if have_icu_path and with_intl:
763 print 'Error: Cannot specify both --with-icu-path and --with-intl'
766 # Chromium .gyp mode: --with-icu-path
767 o['variables']['v8_enable_i18n_support'] = 1
769 o['variables']['icu_gyp_path'] = options.with_icu_path
771 # --with-intl=<with_intl>
773 if with_intl is None:
774 with_intl = 'none' # The default mode of Intl
775 # sanity check localelist
776 if options.with_icu_locales and (with_intl != 'small-icu'):
777 print 'Error: --with-icu-locales only makes sense with --with-intl=small-icu'
779 if with_intl == 'none' or with_intl is None:
780 o['variables']['v8_enable_i18n_support'] = 0
782 elif with_intl == 'small-icu':
783 # small ICU (English only)
784 o['variables']['v8_enable_i18n_support'] = 1
785 o['variables']['icu_small'] = b(True)
786 with_icu_locales = options.with_icu_locales
787 if not with_icu_locales:
788 with_icu_locales = 'root,en'
789 locs = set(with_icu_locales.split(','))
790 locs.add('root') # must have root
791 o['variables']['icu_locales'] = string.join(locs,',')
792 elif with_intl == 'full-icu':
794 o['variables']['v8_enable_i18n_support'] = 1
795 elif with_intl == 'system-icu':
796 # ICU from pkg-config.
797 o['variables']['v8_enable_i18n_support'] = 1
798 pkgicu = pkg_config('icu-i18n')
800 print 'Error: could not load pkg-config data for "icu-i18n".'
801 print 'See above errors or the README.md.'
803 (libs, cflags) = pkgicu
804 o['libraries'] += libs.split()
805 o['cflags'] += cflags.split()
806 # use the "system" .gyp
807 o['variables']['icu_gyp_path'] = 'tools/icu/icu-system.gyp'
810 print 'Error: unknown value --with-intl=%s' % with_intl
812 # Note: non-ICU implementations could use other 'with_intl'
815 # this is just the 'deps' dir. Used for unpacking.
816 icu_parent_path = os.path.join(root_dir, 'deps')
818 # The full path to the ICU source directory.
819 icu_full_path = os.path.join(icu_parent_path, 'icu')
821 # icu-tmp is used to download and unpack the ICU tarball.
822 icu_tmp_path = os.path.join(icu_parent_path, 'icu-tmp')
824 # --with-icu-source processing
825 # first, check that they didn't pass --with-icu-source=deps/icu
826 if with_icu_source and os.path.abspath(icu_full_path) == os.path.abspath(with_icu_source):
827 print 'Ignoring redundant --with-icu-source=%s' % (with_icu_source)
828 with_icu_source = None
829 # if with_icu_source is still set, try to use it.
831 if os.path.isdir(icu_full_path):
832 print 'Deleting old ICU source: %s' % (icu_full_path)
833 shutil.rmtree(icu_full_path)
834 # now, what path was given?
835 if os.path.isdir(with_icu_source):
836 # it's a path. Copy it.
837 print '%s -> %s' % (with_icu_source, icu_full_path)
838 shutil.copytree(with_icu_source, icu_full_path)
840 # could be file or URL.
841 # Set up temporary area
842 if os.path.isdir(icu_tmp_path):
843 shutil.rmtree(icu_tmp_path)
844 os.mkdir(icu_tmp_path)
846 if os.path.isfile(with_icu_source):
847 # it's a file. Try to unpack it.
848 icu_tarball = with_icu_source
850 # Can we download it?
851 local = os.path.join(icu_tmp_path, with_icu_source.split('/')[-1]) # local part
852 icu_tarball = nodedownload.retrievefile(with_icu_source, local)
853 # continue with "icu_tarball"
854 nodedownload.unpack(icu_tarball, icu_tmp_path)
855 # Did it unpack correctly? Should contain 'icu'
856 tmp_icu = os.path.join(icu_tmp_path, 'icu')
857 if os.path.isdir(tmp_icu):
858 os.rename(tmp_icu, icu_full_path)
859 shutil.rmtree(icu_tmp_path)
861 print ' Error: --with-icu-source=%s did not result in an "icu" dir.' % with_icu_source
862 shutil.rmtree(icu_tmp_path)
865 # ICU mode. (icu-generic.gyp)
866 o['variables']['icu_gyp_path'] = 'tools/icu/icu-generic.gyp'
867 # ICU source dir relative to root
868 o['variables']['icu_path'] = icu_full_path
869 if not os.path.isdir(icu_full_path):
870 print '* ECMA-402 (Intl) support didn\'t find ICU in %s..' % (icu_full_path)
871 # can we download (or find) a zipfile?
872 localzip = icu_download(icu_full_path)
874 nodedownload.unpack(localzip, icu_parent_path)
875 if not os.path.isdir(icu_full_path):
876 print ' Cannot build Intl without ICU in %s.' % (icu_full_path)
877 print ' (Fix, or disable with "--with-intl=none" )'
880 print '* Using ICU in %s' % (icu_full_path)
881 # Now, what version of ICU is it? We just need the "major", such as 54.
882 # uvernum.h contains it as a #define.
883 uvernum_h = os.path.join(icu_full_path, 'source/common/unicode/uvernum.h')
884 if not os.path.isfile(uvernum_h):
885 print ' Error: could not load %s - is ICU installed?' % uvernum_h
888 matchVerExp = r'^\s*#define\s+U_ICU_VERSION_SHORT\s+"([^"]*)".*'
889 match_version = re.compile(matchVerExp)
890 for line in open(uvernum_h).readlines():
891 m = match_version.match(line)
893 icu_ver_major = m.group(1)
894 if not icu_ver_major:
895 print ' Could not read U_ICU_VERSION_SHORT version from %s' % uvernum_h
897 icu_endianness = sys.byteorder[0]; # TODO(srl295): EBCDIC should be 'e'
898 o['variables']['icu_ver_major'] = icu_ver_major
899 o['variables']['icu_endianness'] = icu_endianness
900 icu_data_file_l = 'icudt%s%s.dat' % (icu_ver_major, 'l')
901 icu_data_file = 'icudt%s%s.dat' % (icu_ver_major, icu_endianness)
902 # relative to configure
903 icu_data_path = os.path.join(icu_full_path,
907 icu_data_in = os.path.join('../../deps/icu/source/data/in', icu_data_file_l)
908 if not os.path.isfile(icu_data_path) and icu_endianness != 'l':
909 # use host endianness
910 icu_data_path = os.path.join(icu_full_path,
914 icu_data_in = os.path.join('icu/source/data/in',
916 # this is the input '.dat' file to use .. icudt*.dat
917 # may be little-endian if from a icu-project.org tarball
918 o['variables']['icu_data_in'] = icu_data_in
919 # this is the icudt*.dat file which node will be using (platform endianness)
920 o['variables']['icu_data_file'] = icu_data_file
921 if not os.path.isfile(icu_data_path):
922 print ' Error: ICU prebuilt data file %s does not exist.' % icu_data_path
923 print ' See the README.md.'
924 # .. and we're not about to build it from .gyp!
926 # map from variable name to subdirs
928 'stubdata': 'stubdata',
932 'tools': 'tools/toolutil',
933 'genccode': 'tools/genccode',
934 'genrb': 'tools/genrb',
935 'icupkg': 'tools/icupkg',
937 # this creates a variable icu_src_XXX for each of the subdirs
938 # with a list of the src files to use
940 var = 'icu_src_%s' % i
941 path = '../../deps/icu/source/%s' % icu_src[i]
942 icu_config['variables'][var] = glob_to_var('tools/icu', path)
943 # write updated icu_config.gypi with a bunch of paths
944 write(icu_config_name, do_not_edit +
945 pprint.pformat(icu_config, indent=2) + '\n')
946 return # end of configure_intl
948 # Print a warning when the compiler is too old.
951 # determine the "flavor" (operating system) we're building for,
952 # leveraging gyp's GetFlavor function
954 if (options.dest_os):
955 flavor_params['flavor'] = options.dest_os
956 flavor = GetFlavor(flavor_params)
959 'variables': { 'python': sys.executable },
966 configure_node(output)
967 configure_libz(output)
968 configure_http_parser(output)
969 configure_libuv(output)
971 configure_openssl(output)
972 configure_winsdk(output)
973 configure_intl(output)
974 configure_fullystatic(output)
976 # variables should be a root level element,
977 # move everything else to target_defaults
978 variables = output['variables']
979 del output['variables']
981 'variables': variables,
982 'target_defaults': output
984 pprint.pprint(output, indent=2)
986 write('config.gypi', do_not_edit +
987 pprint.pformat(output, indent=2) + '\n')
990 'BUILDTYPE': 'Debug' if options.debug else 'Release',
991 'USE_XCODE': str(int(options.use_xcode or 0)),
992 'PYTHON': sys.executable,
996 config['PREFIX'] = options.prefix
998 config = '\n'.join(map('='.join, config.iteritems())) + '\n'
1001 '# Do not edit. Generated by the configure script.\n' + config)
1003 gyp_args = [sys.executable, 'tools/gyp_node.py', '--no-parallel']
1005 if options.use_xcode:
1006 gyp_args += ['-f', 'xcode']
1007 elif flavor == 'win' and sys.platform != 'msys':
1008 gyp_args += ['-f', 'msvs', '-G', 'msvs_version=auto']
1010 gyp_args += ['-f', 'make-' + flavor]
1015 warn('warnings were emitted in the configure phase')
1017 sys.exit(subprocess.call(gyp_args))