build: Warn when using snapshot on Armv6
[platform/upstream/nodejs.git] / configure
1 #!/usr/bin/env python
2 import optparse
3 import os
4 import pprint
5 import re
6 import shlex
7 import subprocess
8 import sys
9 import shutil
10 import string
11
12 CC = os.environ.get('CC', 'cc')
13
14 root_dir = os.path.dirname(__file__)
15 sys.path.insert(0, os.path.join(root_dir, 'tools', 'gyp', 'pylib'))
16 from gyp.common import GetFlavor
17
18 # imports in tools/configure.d
19 sys.path.insert(0, os.path.join(root_dir, 'tools', 'configure.d'))
20 import nodedownload
21
22 # parse our options
23 parser = optparse.OptionParser()
24
25 # Options should be in alphabetical order but keep --prefix at the top,
26 # that's arguably the one people will be looking for most.
27 parser.add_option('--prefix',
28     action='store',
29     dest='prefix',
30     help='select the install prefix (defaults to /usr/local)')
31
32 parser.add_option('--debug',
33     action='store_true',
34     dest='debug',
35     help='also build debug build')
36
37 parser.add_option('--dest-cpu',
38     action='store',
39     dest='dest_cpu',
40     help='CPU architecture to build for. Valid values are: arm, ia32, x32, x64')
41
42 parser.add_option('--dest-os',
43     action='store',
44     dest='dest_os',
45     help='operating system to build for. Valid values are: '
46          'win, mac, solaris, freebsd, openbsd, linux, android')
47
48 parser.add_option('--gdb',
49     action='store_true',
50     dest='gdb',
51     help='add gdb support')
52
53 parser.add_option('--ninja',
54     action='store_true',
55     dest='use_ninja',
56     help='generate files for the ninja build system')
57
58 parser.add_option('--no-ifaddrs',
59     action='store_true',
60     dest='no_ifaddrs',
61     help='use on deprecated SunOS systems that do not support ifaddrs.h')
62
63 parser.add_option("--fully-static",
64     action="store_true",
65     dest="fully_static",
66     help="Generate an executable without external dynamic libraries. This "
67          "will not work on OSX when using default compilation environment")
68
69 parser.add_option("--openssl-no-asm",
70     action="store_true",
71     dest="openssl_no_asm",
72     help="Do not build optimized assembly for OpenSSL")
73
74 # deprecated
75 parser.add_option('--openssl-includes',
76     action='store',
77     dest='shared_openssl_includes',
78     help=optparse.SUPPRESS_HELP)
79
80 # deprecated
81 parser.add_option('--openssl-libpath',
82     action='store',
83     dest='shared_openssl_libpath',
84     help=optparse.SUPPRESS_HELP)
85
86 # deprecated
87 parser.add_option('--openssl-use-sys',
88     action='store_true',
89     dest='shared_openssl',
90     help=optparse.SUPPRESS_HELP)
91
92 parser.add_option('--shared-http-parser',
93     action='store_true',
94     dest='shared_http_parser',
95     help='link to a shared http_parser DLL instead of static linking')
96
97 parser.add_option('--shared-http-parser-includes',
98     action='store',
99     dest='shared_http_parser_includes',
100     help='directory containing http_parser header files')
101
102 parser.add_option('--shared-http-parser-libname',
103     action='store',
104     dest='shared_http_parser_libname',
105     help='alternative lib name to link to (default: \'http_parser\')')
106
107 parser.add_option('--shared-http-parser-libpath',
108     action='store',
109     dest='shared_http_parser_libpath',
110     help='a directory to search for the shared http_parser DLL')
111
112 parser.add_option('--shared-libuv',
113     action='store_true',
114     dest='shared_libuv',
115     help='link to a shared libuv DLL instead of static linking')
116
117 parser.add_option('--shared-libuv-includes',
118     action='store',
119     dest='shared_libuv_includes',
120     help='directory containing libuv header files')
121
122 parser.add_option('--shared-libuv-libname',
123     action='store',
124     dest='shared_libuv_libname',
125     help='alternative lib name to link to (default: \'uv\')')
126
127 parser.add_option('--shared-libuv-libpath',
128     action='store',
129     dest='shared_libuv_libpath',
130     help='a directory to search for the shared libuv DLL')
131
132 parser.add_option('--shared-openssl',
133     action='store_true',
134     dest='shared_openssl',
135     help='link to a shared OpenSSl DLL instead of static linking')
136
137 parser.add_option('--shared-openssl-includes',
138     action='store',
139     dest='shared_openssl_includes',
140     help='directory containing OpenSSL header files')
141
142 parser.add_option('--shared-openssl-libname',
143     action='store',
144     dest='shared_openssl_libname',
145     help='alternative lib name to link to (default: \'crypto,ssl\')')
146
147 parser.add_option('--shared-openssl-libpath',
148     action='store',
149     dest='shared_openssl_libpath',
150     help='a directory to search for the shared OpenSSL DLLs')
151
152 parser.add_option('--shared-v8',
153     action='store_true',
154     dest='shared_v8',
155     help='link to a shared V8 DLL instead of static linking')
156
157 parser.add_option('--shared-v8-includes',
158     action='store',
159     dest='shared_v8_includes',
160     help='directory containing V8 header files')
161
162 parser.add_option('--shared-v8-libname',
163     action='store',
164     dest='shared_v8_libname',
165     help='alternative lib name to link to (default: \'v8\')')
166
167 parser.add_option('--shared-v8-libpath',
168     action='store',
169     dest='shared_v8_libpath',
170     help='a directory to search for the shared V8 DLL')
171
172 parser.add_option('--shared-zlib',
173     action='store_true',
174     dest='shared_zlib',
175     help='link to a shared zlib DLL instead of static linking')
176
177 parser.add_option('--shared-zlib-includes',
178     action='store',
179     dest='shared_zlib_includes',
180     help='directory containing zlib header files')
181
182 parser.add_option('--shared-zlib-libname',
183     action='store',
184     dest='shared_zlib_libname',
185     help='alternative lib name to link to (default: \'z\')')
186
187 parser.add_option('--shared-zlib-libpath',
188     action='store',
189     dest='shared_zlib_libpath',
190     help='a directory to search for the shared zlib DLL')
191
192 # TODO document when we've decided on what the tracing API and its options will
193 # look like
194 parser.add_option('--systemtap-includes',
195     action='store',
196     dest='systemtap_includes',
197     help=optparse.SUPPRESS_HELP)
198
199 parser.add_option('--tag',
200     action='store',
201     dest='tag',
202     help='custom build tag')
203
204 parser.add_option('--v8-options',
205     action='store',
206     dest='v8_options',
207     help='v8 options to pass, see `node --v8-options` for examples.')
208
209 parser.add_option('--with-arm-float-abi',
210     action='store',
211     dest='arm_float_abi',
212     help='specifies which floating-point ABI to use. Valid values are: '
213          'soft, softfp, hard')
214
215 parser.add_option('--with-dtrace',
216     action='store_true',
217     dest='with_dtrace',
218     help='build with DTrace (default is true on sunos)')
219
220 parser.add_option('--with-etw',
221     action='store_true',
222     dest='with_etw',
223     help='build with ETW (default is true on Windows)')
224
225 parser.add_option('--download',
226     action='store',
227     dest='download_list',
228     help=nodedownload.help())
229
230 parser.add_option('--with-icu-path',
231     action='store',
232     dest='with_icu_path',
233     help='Path to icu.gyp (ICU i18n, Chromium version only.)')
234
235 parser.add_option('--with-icu-locales',
236     action='store',
237     dest='with_icu_locales',
238     help='Comma-separated list of locales for "small-icu". Default: "root,en". "root" is assumed.')
239
240 parser.add_option('--with-intl',
241     action='store',
242     dest='with_intl',
243     help='Intl mode: none, full-icu, small-icu (default is none)')
244
245 parser.add_option('--with-icu-source',
246     action='store',
247     dest='with_icu_source',
248     help='Intl mode: optional local path to icu/ dir, or path/URL of icu source archive.')
249
250 parser.add_option('--with-perfctr',
251     action='store_true',
252     dest='with_perfctr',
253     help='build with performance counters (default is true on Windows)')
254
255 parser.add_option('--without-dtrace',
256     action='store_true',
257     dest='without_dtrace',
258     help='build without DTrace')
259
260 parser.add_option('--without-etw',
261     action='store_true',
262     dest='without_etw',
263     help='build without ETW')
264
265 parser.add_option('--without-npm',
266     action='store_true',
267     dest='without_npm',
268     help='don\'t install the bundled npm package manager')
269
270 parser.add_option('--without-perfctr',
271     action='store_true',
272     dest='without_perfctr',
273     help='build without performance counters')
274
275 parser.add_option('--without-snapshot',
276     action='store_true',
277     dest='without_snapshot',
278     help='build without snapshotting V8 libraries. You might want to set'
279          ' this for cross-compiling. [Default: False]')
280
281 parser.add_option('--without-ssl',
282     action='store_true',
283     dest='without_ssl',
284     help='build without SSL')
285
286 parser.add_option('--xcode',
287     action='store_true',
288     dest='use_xcode',
289     help='generate build files for use with xcode')
290
291 (options, args) = parser.parse_args()
292
293 # set up auto-download list
294 auto_downloads = nodedownload.parse(options.download_list)
295
296 def b(value):
297   """Returns the string 'true' if value is truthy, 'false' otherwise."""
298   if value:
299     return 'true'
300   else:
301     return 'false'
302
303
304 def pkg_config(pkg):
305   cmd = os.popen('pkg-config --libs %s' % pkg, 'r')
306   libs = cmd.readline().strip()
307   ret = cmd.close()
308   if (ret): return None
309
310   cmd = os.popen('pkg-config --cflags %s' % pkg, 'r')
311   cflags = cmd.readline().strip()
312   ret = cmd.close()
313   if (ret): return None
314
315   return (libs, cflags)
316
317
318 def cc_macros():
319   """Checks predefined macros using the CC command."""
320
321   try:
322     p = subprocess.Popen(shlex.split(CC) + ['-dM', '-E', '-'],
323                          stdin=subprocess.PIPE,
324                          stdout=subprocess.PIPE,
325                          stderr=subprocess.PIPE)
326   except OSError:
327     print '''Node.js configure error: No acceptable C compiler found!
328
329         Please make sure you have a C compiler installed on your system and/or
330         consider adjusting the CC environment variable if you installed
331         it in a non-standard prefix.
332         '''
333     sys.exit()
334
335   p.stdin.write('\n')
336   out = p.communicate()[0]
337
338   out = str(out).split('\n')
339
340   k = {}
341   for line in out:
342     lst = shlex.split(line)
343     if len(lst) > 2:
344       key = lst[1]
345       val = lst[2]
346       k[key] = val
347   return k
348
349
350 def is_arch_armv7():
351   """Check for ARMv7 instructions"""
352   cc_macros_cache = cc_macros()
353   return ('__ARM_ARCH_7__' in cc_macros_cache or
354           '__ARM_ARCH_7A__' in cc_macros_cache or
355           '__ARM_ARCH_7R__' in cc_macros_cache or
356           '__ARM_ARCH_7M__' in cc_macros_cache)
357
358
359 def is_arch_armv6():
360   """Check for ARMv6 instructions"""
361   cc_macros_cache = cc_macros()
362   return ('__ARM_ARCH_6__' in cc_macros_cache or
363           '__ARM_ARCH_6M__' in cc_macros_cache)
364
365
366 def is_arm_neon():
367   """Check for ARM NEON support"""
368   return '__ARM_NEON__' in cc_macros()
369
370
371 def is_arm_hard_float_abi():
372   """Check for hardfloat or softfloat eabi on ARM"""
373   # GCC versions 4.6 and above define __ARM_PCS or __ARM_PCS_VFP to specify
374   # the Floating Point ABI used (PCS stands for Procedure Call Standard).
375   # We use these as well as a couple of other defines to statically determine
376   # what FP ABI used.
377
378   return '__ARM_PCS_VFP' in cc_macros()
379
380
381 def host_arch_cc():
382   """Host architecture check using the CC command."""
383
384   k = cc_macros()
385
386   matchup = {
387     '__x86_64__'  : 'x64',
388     '__i386__'    : 'ia32',
389     '__arm__'     : 'arm',
390     '__mips__'    : 'mips',
391   }
392
393   rtn = 'ia32' # default
394
395   for i in matchup:
396     if i in k and k[i] != '0':
397       rtn = matchup[i]
398       break
399
400   return rtn
401
402
403 def host_arch_win():
404   """Host architecture check using environ vars (better way to do this?)"""
405
406   observed_arch = os.environ.get('PROCESSOR_ARCHITECTURE', 'x86')
407   arch = os.environ.get('PROCESSOR_ARCHITEW6432', observed_arch)
408
409   matchup = {
410     'AMD64'  : 'x64',
411     'x86'    : 'ia32',
412     'arm'    : 'arm',
413     'mips'   : 'mips',
414   }
415
416   return matchup.get(arch, 'ia32')
417
418
419 def configure_arm(o):
420   if options.arm_float_abi:
421     arm_float_abi = options.arm_float_abi
422   elif is_arm_hard_float_abi():
423     arm_float_abi = 'hard'
424   else:
425     arm_float_abi = 'default'
426
427   if is_arch_armv7():
428     o['variables']['arm_version'] = '7'
429   elif is_arch_armv6():
430     o['variables']['arm_version'] = '6'
431   else:
432     o['variables']['arm_version'] = 'default'
433
434   o['variables']['arm_fpu'] = 'vfpv3'  # V8 3.18 no longer supports VFP2.
435   o['variables']['arm_neon'] = int(is_arm_neon())
436   o['variables']['arm_thumb'] = 0      # -marm
437   o['variables']['arm_float_abi'] = arm_float_abi
438
439
440 def configure_node(o):
441   if options.dest_os == 'android':
442     o['variables']['OS'] = 'android'
443   o['variables']['node_prefix'] = os.path.expanduser(options.prefix or '')
444   o['variables']['node_install_npm'] = b(not options.without_npm)
445   o['default_configuration'] = 'Debug' if options.debug else 'Release'
446
447   host_arch = host_arch_win() if os.name == 'nt' else host_arch_cc()
448   target_arch = options.dest_cpu or host_arch
449   o['variables']['host_arch'] = host_arch
450   o['variables']['target_arch'] = target_arch
451
452   if target_arch != host_arch and not options.without_snapshot:
453     o['variables']['want_separate_host_toolset'] = 1
454   else:
455     o['variables']['want_separate_host_toolset'] = 0
456
457   if target_arch == 'arm':
458     configure_arm(o)
459
460   if flavor in ('solaris', 'mac', 'linux', 'freebsd'):
461     use_dtrace = not options.without_dtrace
462     # Don't enable by default on linux and freebsd
463     if flavor in ('linux', 'freebsd'):
464       use_dtrace = options.with_dtrace
465
466     if flavor == 'linux':
467       if options.systemtap_includes:
468         o['include_dirs'] += [options.systemtap_includes]
469     o['variables']['node_use_dtrace'] = b(use_dtrace)
470     o['variables']['uv_use_dtrace'] = b(use_dtrace)
471     o['variables']['uv_parent_path'] = '/deps/uv/'
472   elif options.with_dtrace:
473     raise Exception(
474        'DTrace is currently only supported on SunOS, MacOS or Linux systems.')
475   else:
476     o['variables']['node_use_dtrace'] = 'false'
477
478   # if we're on illumos based systems wrap the helper library into the
479   # executable
480   if flavor == 'solaris':
481     o['variables']['node_use_mdb'] = 'true'
482   else:
483     o['variables']['node_use_mdb'] = 'false'
484
485   if options.no_ifaddrs:
486     o['defines'] += ['SUNOS_NO_IFADDRS']
487
488   # By default, enable ETW on Windows.
489   if flavor == 'win':
490     o['variables']['node_use_etw'] = b(not options.without_etw)
491   elif options.with_etw:
492     raise Exception('ETW is only supported on Windows.')
493   else:
494     o['variables']['node_use_etw'] = 'false'
495
496   # By default, enable Performance counters on Windows.
497   if flavor == 'win':
498     o['variables']['node_use_perfctr'] = b(not options.without_perfctr)
499   elif options.with_perfctr:
500     raise Exception('Performance counter is only supported on Windows.')
501   else:
502     o['variables']['node_use_perfctr'] = 'false'
503
504   if options.tag:
505     o['variables']['node_tag'] = '-' + options.tag
506   else:
507     o['variables']['node_tag'] = ''
508
509   if options.v8_options:
510     o['variables']['node_v8_options'] = options.v8_options.replace('"', '\\"')
511
512
513 def configure_libz(o):
514   o['variables']['node_shared_zlib'] = b(options.shared_zlib)
515
516   # assume shared_zlib if one of these is set?
517   if options.shared_zlib_libpath:
518     o['libraries'] += ['-L%s' % options.shared_zlib_libpath]
519   if options.shared_zlib_libname:
520     o['libraries'] += ['-l%s' % options.shared_zlib_libname]
521   elif options.shared_zlib:
522     o['libraries'] += ['-lz']
523   if options.shared_zlib_includes:
524     o['include_dirs'] += [options.shared_zlib_includes]
525
526
527 def configure_http_parser(o):
528     o['variables']['node_shared_http_parser'] = b(options.shared_http_parser)
529
530     # assume shared http_parser if one of these is set?
531     if options.shared_http_parser_libpath:
532         o['libraries'] += ['-L%s' % options.shared_http_parser_libpath]
533     if options.shared_http_parser_libname:
534         o['libraries'] += ['-l%s' % options.shared_http_parser_libname]
535     elif options.shared_http_parser:
536         o['libraries'] += ['-lhttp_parser']
537     if options.shared_http_parser_includes:
538         o['include_dirs'] += [options.shared_http_parser_includes]
539
540
541 def configure_libuv(o):
542   o['variables']['node_shared_libuv'] = b(options.shared_libuv)
543
544   # assume shared libuv if one of these is set?
545   if options.shared_libuv_libpath:
546     o['libraries'] += ['-L%s' % options.shared_libuv_libpath]
547   else:
548     o['variables']['uv_library'] = 'static_library'
549
550   if options.shared_libuv_libname:
551     o['libraries'] += ['-l%s' % options.shared_libuv_libname]
552   elif options.shared_libuv:
553     o['libraries'] += ['-luv']
554   if options.shared_libuv_includes:
555     o['include_dirs'] += [options.shared_libuv_includes]
556
557
558 def configure_v8(o):
559   o['variables']['node_shared_v8'] = b(options.shared_v8)
560   o['variables']['v8_enable_gdbjit'] = 1 if options.gdb else 0
561   o['variables']['v8_no_strict_aliasing'] = 1  # Work around compiler bugs.
562   o['variables']['v8_optimized_debug'] = 0  # Compile with -O0 in debug builds.
563   o['variables']['v8_random_seed'] = 0  # Use a random seed for hash tables.
564   o['variables']['v8_use_snapshot'] = b(not options.without_snapshot)
565
566   # assume shared_v8 if one of these is set?
567   if options.shared_v8_libpath:
568     o['libraries'] += ['-L%s' % options.shared_v8_libpath]
569   if options.shared_v8_libname:
570     o['libraries'] += ['-l%s' % options.shared_v8_libname]
571   elif options.shared_v8:
572     o['libraries'] += ['-lv8']
573   if options.shared_v8_includes:
574     o['include_dirs'] += [options.shared_v8_includes]
575
576
577 def configure_openssl(o):
578   o['variables']['node_use_openssl'] = b(not options.without_ssl)
579   o['variables']['node_shared_openssl'] = b(options.shared_openssl)
580   o['variables']['openssl_no_asm'] = (
581     1 if options.openssl_no_asm else 0)
582
583   if options.without_ssl:
584     return
585
586   if options.shared_openssl:
587     (libs, cflags) = pkg_config('openssl') or ('-lssl -lcrypto', '')
588
589     if options.shared_openssl_libpath:
590       o['libraries'] += ['-L%s' % options.shared_openssl_libpath]
591
592     if options.shared_openssl_libname:
593       libnames = options.shared_openssl_libname.split(',')
594       o['libraries'] += ['-l%s' % s for s in libnames]
595     else:
596       o['libraries'] += libs.split()
597
598     if options.shared_openssl_includes:
599       o['include_dirs'] += [options.shared_openssl_includes]
600     else:
601       o['cflags'] += cflags.split()
602
603
604 def configure_fullystatic(o):
605   if options.fully_static:
606     o['libraries'] += ['-static']
607     if flavor == 'mac':
608       print("Generation of static executable will not work on OSX "
609             "when using default compilation environment")
610
611
612 def configure_winsdk(o):
613   if flavor != 'win':
614     return
615
616   winsdk_dir = os.environ.get('WindowsSdkDir')
617
618   if winsdk_dir and os.path.isfile(winsdk_dir + '\\bin\\ctrpp.exe'):
619     print('Found ctrpp in WinSDK--will build generated files '
620           'into tools/msvs/genfiles.')
621     o['variables']['node_has_winsdk'] = 'true'
622     return
623
624   print('ctrpp not found in WinSDK path--using pre-gen files '
625         'from tools/msvs/genfiles.')
626
627 def write(filename, data):
628   filename = os.path.join(root_dir, filename)
629   print 'creating ', filename
630   f = open(filename, 'w+')
631   f.write(data)
632
633 do_not_edit = '# Do not edit. Generated by the configure script.\n'
634
635 def glob_to_var(dir_base, dir_sub):
636   list = []
637   dir_all = os.path.join(dir_base, dir_sub)
638   files = os.walk(dir_all)
639   for ent in files:
640     (path, dirs, files) = ent
641     for file in files:
642       if file.endswith('.cpp') or file.endswith('.c') or file.endswith('.h'):
643         list.append('%s/%s' % (dir_sub, file))
644     break
645   return list
646
647 def configure_intl(o):
648   icus = [
649     {
650       'url': 'http://download.icu-project.org/files/icu4c/54.1/icu4c-54_1-src.zip',
651       # from https://ssl.icu-project.org/files/icu4c/54.1/icu4c-src-54_1.md5:
652       'md5': '6b89d60e2f0e140898ae4d7f72323bca',
653     },
654   ]
655   def icu_download(path):
656     # download ICU, if needed
657     for icu in icus:
658       url = icu['url']
659       md5 = icu['md5']
660       local = url.split('/')[-1]
661       targetfile = os.path.join(root_dir, 'deps', local)
662       if not os.path.isfile(targetfile):
663         if nodedownload.candownload(auto_downloads, "icu"):
664           nodedownload.retrievefile(url, targetfile)
665       else:
666         print ' Re-using existing %s' % targetfile
667       if os.path.isfile(targetfile):
668         sys.stdout.write(' Checking file integrity with MD5:\r')
669         gotmd5 = nodedownload.md5sum(targetfile)
670         print ' MD5:      %s  %s' % (gotmd5, targetfile)
671         if (md5 == gotmd5):
672           return targetfile
673         else:
674           print ' Expected: %s      *MISMATCH*' % md5
675           print '\n ** Corrupted ZIP? Delete %s to retry download.\n' % targetfile
676     return None
677   icu_config = {
678     'variables': {}
679   }
680   icu_config_name = 'icu_config.gypi'
681   def write_config(data, name):
682     return
683
684   # write an empty file to start with
685   write(icu_config_name, do_not_edit +
686         pprint.pformat(icu_config, indent=2) + '\n')
687
688   # always set icu_small, node.gyp depends on it being defined.
689   o['variables']['icu_small'] = b(False)
690
691   with_intl = options.with_intl
692   with_icu_source = options.with_icu_source
693   have_icu_path = bool(options.with_icu_path)
694   if have_icu_path and with_intl:
695     print 'Error: Cannot specify both --with-icu-path and --with-intl'
696     sys.exit(1)
697   elif have_icu_path:
698     # Chromium .gyp mode: --with-icu-path
699     o['variables']['v8_enable_i18n_support'] = 1
700     # use the .gyp given
701     o['variables']['icu_gyp_path'] = options.with_icu_path
702     return
703   # --with-intl=<with_intl>
704   # set the default
705   if with_intl is None:
706     with_intl = 'none'  # The default mode of Intl
707   # sanity check localelist
708   if options.with_icu_locales and (with_intl != 'small-icu'):
709     print 'Error: --with-icu-locales only makes sense with --with-intl=small-icu'
710     sys.exit(1)
711   if with_intl == 'none' or with_intl is None:
712     o['variables']['v8_enable_i18n_support'] = 0
713     return  # no Intl
714   elif with_intl == 'small-icu':
715     # small ICU (English only)
716     o['variables']['v8_enable_i18n_support'] = 1
717     o['variables']['icu_small'] = b(True)
718     with_icu_locales = options.with_icu_locales
719     if not with_icu_locales:
720       with_icu_locales = 'root,en'
721     locs = set(with_icu_locales.split(','))
722     locs.add('root')  # must have root
723     o['variables']['icu_locales'] = string.join(locs,',')
724   elif with_intl == 'full-icu':
725     # full ICU
726     o['variables']['v8_enable_i18n_support'] = 1
727   elif with_intl == 'system-icu':
728     # ICU from pkg-config.
729     o['variables']['v8_enable_i18n_support'] = 1
730     pkgicu = pkg_config('icu-i18n')
731     if not pkgicu:
732       print 'Error: could not load pkg-config data for "icu-i18n".'
733       print 'See above errors or the README.md.'
734       sys.exit(1)
735     (libs, cflags) = pkgicu
736     o['libraries'] += libs.split()
737     o['cflags'] += cflags.split()
738     # use the "system" .gyp
739     o['variables']['icu_gyp_path'] = 'tools/icu/icu-system.gyp'
740     return
741   else:
742     print 'Error: unknown value --with-intl=%s' % with_intl
743     sys.exit(1)
744   # Note: non-ICU implementations could use other 'with_intl'
745   # values.
746
747   # this is just the 'deps' dir. Used for unpacking.
748   icu_parent_path = os.path.join(root_dir, 'deps')
749
750   # The full path to the ICU source directory.
751   icu_full_path = os.path.join(icu_parent_path, 'icu')
752
753   # icu-tmp is used to download and unpack the ICU tarball.
754   icu_tmp_path = os.path.join(icu_parent_path, 'icu-tmp')
755
756   # --with-icu-source processing
757   # first, check that they didn't pass --with-icu-source=deps/icu
758   if with_icu_source and os.path.abspath(icu_full_path) == os.path.abspath(with_icu_source):
759     print 'Ignoring redundant --with-icu-source=%s' % (with_icu_source)
760     with_icu_source = None
761   # if with_icu_source is still set, try to use it.
762   if with_icu_source:
763     if os.path.isdir(icu_full_path):
764       print 'Deleting old ICU source: %s' % (icu_full_path)
765       shutil.rmtree(icu_full_path)
766     # now, what path was given?
767     if os.path.isdir(with_icu_source):
768       # it's a path. Copy it.
769       print '%s -> %s' % (with_icu_source, icu_full_path)
770       shutil.copytree(with_icu_source, icu_full_path)
771     else:
772       # could be file or URL.
773       # Set up temporary area
774       if os.path.isdir(icu_tmp_path):
775         shutil.rmtree(icu_tmp_path)
776       os.mkdir(icu_tmp_path)
777       icu_tarball = None
778       if os.path.isfile(with_icu_source):
779         # it's a file. Try to unpack it.
780         icu_tarball = with_icu_source
781       else:
782         # Can we download it?
783         local = os.path.join(icu_tmp_path, with_icu_source.split('/')[-1])  # local part
784         icu_tarball = nodedownload.retrievefile(with_icu_source, local)
785       # continue with "icu_tarball"
786       nodedownload.unpack(icu_tarball, icu_tmp_path)
787       # Did it unpack correctly? Should contain 'icu'
788       tmp_icu = os.path.join(icu_tmp_path, 'icu')
789       if os.path.isdir(tmp_icu):
790         os.rename(tmp_icu, icu_full_path)
791         shutil.rmtree(icu_tmp_path)
792       else:
793         print ' Error: --with-icu-source=%s did not result in an "icu" dir.' % with_icu_source
794         shutil.rmtree(icu_tmp_path)
795         sys.exit(1)
796
797   # ICU mode. (icu-generic.gyp)
798   byteorder = sys.byteorder
799   o['variables']['icu_gyp_path'] = 'tools/icu/icu-generic.gyp'
800   # ICU source dir relative to root
801   o['variables']['icu_path'] = icu_full_path
802   if not os.path.isdir(icu_full_path):
803     print '* ECMA-402 (Intl) support didn\'t find ICU in %s..' % (icu_full_path)
804     # can we download (or find) a zipfile?
805     localzip = icu_download(icu_full_path)
806     if localzip:
807       nodedownload.unpack(localzip, icu_parent_path)
808   if not os.path.isdir(icu_full_path):
809     print ' Cannot build Intl without ICU in %s.' % (icu_full_path)
810     print ' (Fix, or disable with "--with-intl=none" )'
811     sys.exit(1)
812   else:
813     print '* Using ICU in %s' % (icu_full_path)
814   # Now, what version of ICU is it? We just need the "major", such as 54.
815   # uvernum.h contains it as a #define.
816   uvernum_h = os.path.join(icu_full_path, 'source/common/unicode/uvernum.h')
817   if not os.path.isfile(uvernum_h):
818     print ' Error: could not load %s - is ICU installed?' % uvernum_h
819     sys.exit(1)
820   icu_ver_major = None
821   matchVerExp = r'^\s*#define\s+U_ICU_VERSION_SHORT\s+"([^"]*)".*'
822   match_version = re.compile(matchVerExp)
823   for line in open(uvernum_h).readlines():
824     m = match_version.match(line)
825     if m:
826       icu_ver_major = m.group(1)
827   if not icu_ver_major:
828     print ' Could not read U_ICU_VERSION_SHORT version from %s' % uvernum_h
829     sys.exit(1)
830   icu_endianness = sys.byteorder[0];  # TODO(srl295): EBCDIC should be 'e'
831   o['variables']['icu_ver_major'] = icu_ver_major
832   o['variables']['icu_endianness'] = icu_endianness
833   icu_data_file_l = 'icudt%s%s.dat' % (icu_ver_major, 'l')
834   icu_data_file = 'icudt%s%s.dat' % (icu_ver_major, icu_endianness)
835   # relative to configure
836   icu_data_path = os.path.join(icu_full_path,
837                                'source/data/in',
838                                icu_data_file_l)
839   # relative to dep..
840   icu_data_in = os.path.join('../../deps/icu/source/data/in', icu_data_file_l)
841   if not os.path.isfile(icu_data_path) and icu_endianness != 'l':
842     # use host endianness
843     icu_data_path = os.path.join(icu_full_path,
844                                  'source/data/in',
845                                  icu_data_file)
846     # relative to dep..
847     icu_data_in = os.path.join('icu/source/data/in',
848                                icu_data_file)
849   # this is the input '.dat' file to use .. icudt*.dat
850   # may be little-endian if from a icu-project.org tarball
851   o['variables']['icu_data_in'] = icu_data_in
852   # this is the icudt*.dat file which node will be using (platform endianness)
853   o['variables']['icu_data_file'] = icu_data_file
854   if not os.path.isfile(icu_data_path):
855     print ' Error: ICU prebuilt data file %s does not exist.' % icu_data_path
856     print ' See the README.md.'
857     # .. and we're not about to build it from .gyp!
858     sys.exit(1)
859   # map from variable name to subdirs
860   icu_src = {
861     'stubdata': 'stubdata',
862     'common': 'common',
863     'i18n': 'i18n',
864     'io': 'io',
865     'tools': 'tools/toolutil',
866     'genccode': 'tools/genccode',
867     'genrb': 'tools/genrb',
868     'icupkg': 'tools/icupkg',
869   }
870   # this creates a variable icu_src_XXX for each of the subdirs
871   # with a list of the src files to use
872   for i in icu_src:
873     var  = 'icu_src_%s' % i
874     path = '../../deps/icu/source/%s' % icu_src[i]
875     icu_config['variables'][var] = glob_to_var('tools/icu', path)
876   # write updated icu_config.gypi with a bunch of paths
877   write(icu_config_name, do_not_edit +
878         pprint.pformat(icu_config, indent=2) + '\n')
879   return  # end of configure_intl
880
881 # determine the "flavor" (operating system) we're building for,
882 # leveraging gyp's GetFlavor function
883 flavor_params = {}
884 if (options.dest_os):
885   flavor_params['flavor'] = options.dest_os
886 flavor = GetFlavor(flavor_params)
887
888 output = {
889   'variables': { 'python': sys.executable },
890   'include_dirs': [],
891   'libraries': [],
892   'defines': [],
893   'cflags': [],
894 }
895
896 configure_node(output)
897 configure_libz(output)
898 configure_http_parser(output)
899 configure_libuv(output)
900 configure_v8(output)
901 configure_openssl(output)
902 configure_winsdk(output)
903 configure_intl(output)
904 configure_fullystatic(output)
905
906 # variables should be a root level element,
907 # move everything else to target_defaults
908 variables = output['variables']
909 del output['variables']
910 output = {
911   'variables': variables,
912   'target_defaults': output
913 }
914 pprint.pprint(output, indent=2)
915
916 write('config.gypi', do_not_edit +
917       pprint.pformat(output, indent=2) + '\n')
918
919 config = {
920   'BUILDTYPE': 'Debug' if options.debug else 'Release',
921   'USE_NINJA': str(int(options.use_ninja or 0)),
922   'USE_XCODE': str(int(options.use_xcode or 0)),
923   'PYTHON': sys.executable,
924 }
925
926 if options.prefix:
927   config['PREFIX'] = options.prefix
928
929 config = '\n'.join(map('='.join, config.iteritems())) + '\n'
930
931 write('config.mk',
932       '# Do not edit. Generated by the configure script.\n' + config)
933
934 gyp_args = [sys.executable, 'tools/gyp_node.py', '--no-parallel']
935
936 if options.use_ninja:
937   gyp_args += ['-f', 'ninja-' + flavor]
938 elif options.use_xcode:
939   gyp_args += ['-f', 'xcode']
940 elif flavor == 'win' and sys.platform != 'msys':
941   gyp_args += ['-f', 'msvs', '-G', 'msvs_version=auto']
942 else:
943   gyp_args += ['-f', 'make-' + flavor]
944
945 gyp_args += args
946
947 #print warning when snapshot is enabled and building on armv6
948 if (is_arch_armv6()) and (not options.without_snapshot):
949   print '\033[1;33mWarning!! When building on ARMv6 use --without-snapshot\033[1;m'
950
951 sys.exit(subprocess.call(gyp_args))