test: remove --use-http1 test runner flag
[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('--with-sslv2',
256     action='store_true',
257     dest='with_sslv2',
258     help='enable SSL v2')
259
260 parser.add_option('--without-dtrace',
261     action='store_true',
262     dest='without_dtrace',
263     help='build without DTrace')
264
265 parser.add_option('--without-etw',
266     action='store_true',
267     dest='without_etw',
268     help='build without ETW')
269
270 parser.add_option('--without-npm',
271     action='store_true',
272     dest='without_npm',
273     help='don\'t install the bundled npm package manager')
274
275 parser.add_option('--without-perfctr',
276     action='store_true',
277     dest='without_perfctr',
278     help='build without performance counters')
279
280 parser.add_option('--without-snapshot',
281     action='store_true',
282     dest='without_snapshot',
283     help='build without snapshotting V8 libraries. You might want to set'
284          ' this for cross-compiling. [Default: False]')
285
286 parser.add_option('--without-ssl',
287     action='store_true',
288     dest='without_ssl',
289     help='build without SSL')
290
291 parser.add_option('--xcode',
292     action='store_true',
293     dest='use_xcode',
294     help='generate build files for use with xcode')
295
296 (options, args) = parser.parse_args()
297
298 # set up auto-download list
299 auto_downloads = nodedownload.parse(options.download_list)
300
301 def b(value):
302   """Returns the string 'true' if value is truthy, 'false' otherwise."""
303   if value:
304     return 'true'
305   else:
306     return 'false'
307
308
309 def pkg_config(pkg):
310   cmd = os.popen('pkg-config --libs %s' % pkg, 'r')
311   libs = cmd.readline().strip()
312   ret = cmd.close()
313   if (ret): return None
314
315   cmd = os.popen('pkg-config --cflags %s' % pkg, 'r')
316   cflags = cmd.readline().strip()
317   ret = cmd.close()
318   if (ret): return None
319
320   return (libs, cflags)
321
322
323 def cc_macros():
324   """Checks predefined macros using the CC command."""
325
326   try:
327     p = subprocess.Popen(shlex.split(CC) + ['-dM', '-E', '-'],
328                          stdin=subprocess.PIPE,
329                          stdout=subprocess.PIPE,
330                          stderr=subprocess.PIPE)
331   except OSError:
332     print '''Node.js configure error: No acceptable C compiler found!
333
334         Please make sure you have a C compiler installed on your system and/or
335         consider adjusting the CC environment variable if you installed
336         it in a non-standard prefix.
337         '''
338     sys.exit()
339
340   p.stdin.write('\n')
341   out = p.communicate()[0]
342
343   out = str(out).split('\n')
344
345   k = {}
346   for line in out:
347     lst = shlex.split(line)
348     if len(lst) > 2:
349       key = lst[1]
350       val = lst[2]
351       k[key] = val
352   return k
353
354
355 def is_arch_armv7():
356   """Check for ARMv7 instructions"""
357   cc_macros_cache = cc_macros()
358   return ('__ARM_ARCH_7__' in cc_macros_cache or
359           '__ARM_ARCH_7A__' in cc_macros_cache or
360           '__ARM_ARCH_7R__' in cc_macros_cache or
361           '__ARM_ARCH_7M__' in cc_macros_cache)
362
363
364 def is_arch_armv6():
365   """Check for ARMv6 instructions"""
366   cc_macros_cache = cc_macros()
367   return ('__ARM_ARCH_6__' in cc_macros_cache or
368           '__ARM_ARCH_6M__' in cc_macros_cache)
369
370
371 def is_arm_neon():
372   """Check for ARM NEON support"""
373   return '__ARM_NEON__' in cc_macros()
374
375
376 def is_arm_hard_float_abi():
377   """Check for hardfloat or softfloat eabi on ARM"""
378   # GCC versions 4.6 and above define __ARM_PCS or __ARM_PCS_VFP to specify
379   # the Floating Point ABI used (PCS stands for Procedure Call Standard).
380   # We use these as well as a couple of other defines to statically determine
381   # what FP ABI used.
382
383   return '__ARM_PCS_VFP' in cc_macros()
384
385
386 def host_arch_cc():
387   """Host architecture check using the CC command."""
388
389   k = cc_macros()
390
391   matchup = {
392     '__x86_64__'  : 'x64',
393     '__i386__'    : 'ia32',
394     '__arm__'     : 'arm',
395     '__mips__'    : 'mips',
396   }
397
398   rtn = 'ia32' # default
399
400   for i in matchup:
401     if i in k and k[i] != '0':
402       rtn = matchup[i]
403       break
404
405   return rtn
406
407
408 def host_arch_win():
409   """Host architecture check using environ vars (better way to do this?)"""
410
411   observed_arch = os.environ.get('PROCESSOR_ARCHITECTURE', 'x86')
412   arch = os.environ.get('PROCESSOR_ARCHITEW6432', observed_arch)
413
414   matchup = {
415     'AMD64'  : 'x64',
416     'x86'    : 'ia32',
417     'arm'    : 'arm',
418     'mips'   : 'mips',
419   }
420
421   return matchup.get(arch, 'ia32')
422
423
424 def configure_arm(o):
425   if options.arm_float_abi:
426     arm_float_abi = options.arm_float_abi
427   elif is_arm_hard_float_abi():
428     arm_float_abi = 'hard'
429   else:
430     arm_float_abi = 'default'
431
432   if is_arch_armv7():
433     o['variables']['arm_version'] = '7'
434   elif is_arch_armv6():
435     o['variables']['arm_version'] = '6'
436   else:
437     o['variables']['arm_version'] = 'default'
438
439   o['variables']['arm_fpu'] = 'vfpv3'  # V8 3.18 no longer supports VFP2.
440   o['variables']['arm_neon'] = int(is_arm_neon())
441   o['variables']['arm_thumb'] = 0      # -marm
442   o['variables']['arm_float_abi'] = arm_float_abi
443
444
445 def configure_node(o):
446   if options.dest_os == 'android':
447     o['variables']['OS'] = 'android'
448   o['variables']['node_prefix'] = os.path.expanduser(options.prefix or '')
449   o['variables']['node_install_npm'] = b(not options.without_npm)
450   o['default_configuration'] = 'Debug' if options.debug else 'Release'
451
452   host_arch = host_arch_win() if os.name == 'nt' else host_arch_cc()
453   target_arch = options.dest_cpu or host_arch
454   o['variables']['host_arch'] = host_arch
455   o['variables']['target_arch'] = target_arch
456
457   if target_arch != host_arch and not options.without_snapshot:
458     o['variables']['want_separate_host_toolset'] = 1
459   else:
460     o['variables']['want_separate_host_toolset'] = 0
461
462   if target_arch == 'arm':
463     configure_arm(o)
464
465   if flavor in ('solaris', 'mac', 'linux', 'freebsd'):
466     use_dtrace = not options.without_dtrace
467     # Don't enable by default on linux and freebsd
468     if flavor in ('linux', 'freebsd'):
469       use_dtrace = options.with_dtrace
470
471     if flavor == 'linux':
472       if options.systemtap_includes:
473         o['include_dirs'] += [options.systemtap_includes]
474     o['variables']['node_use_dtrace'] = b(use_dtrace)
475     o['variables']['uv_use_dtrace'] = b(use_dtrace)
476     o['variables']['uv_parent_path'] = '/deps/uv/'
477   elif options.with_dtrace:
478     raise Exception(
479        'DTrace is currently only supported on SunOS, MacOS or Linux systems.')
480   else:
481     o['variables']['node_use_dtrace'] = 'false'
482
483   # if we're on illumos based systems wrap the helper library into the
484   # executable
485   if flavor == 'solaris':
486     o['variables']['node_use_mdb'] = 'true'
487   else:
488     o['variables']['node_use_mdb'] = 'false'
489
490   if options.no_ifaddrs:
491     o['defines'] += ['SUNOS_NO_IFADDRS']
492
493   # By default, enable ETW on Windows.
494   if flavor == 'win':
495     o['variables']['node_use_etw'] = b(not options.without_etw)
496   elif options.with_etw:
497     raise Exception('ETW is only supported on Windows.')
498   else:
499     o['variables']['node_use_etw'] = 'false'
500
501   # By default, enable Performance counters on Windows.
502   if flavor == 'win':
503     o['variables']['node_use_perfctr'] = b(not options.without_perfctr)
504   elif options.with_perfctr:
505     raise Exception('Performance counter is only supported on Windows.')
506   else:
507     o['variables']['node_use_perfctr'] = 'false'
508
509   if options.tag:
510     o['variables']['node_tag'] = '-' + options.tag
511   else:
512     o['variables']['node_tag'] = ''
513
514   if options.v8_options:
515     o['variables']['node_v8_options'] = options.v8_options.replace('"', '\\"')
516
517
518 def configure_libz(o):
519   o['variables']['node_shared_zlib'] = b(options.shared_zlib)
520
521   # assume shared_zlib if one of these is set?
522   if options.shared_zlib_libpath:
523     o['libraries'] += ['-L%s' % options.shared_zlib_libpath]
524   if options.shared_zlib_libname:
525     o['libraries'] += ['-l%s' % options.shared_zlib_libname]
526   elif options.shared_zlib:
527     o['libraries'] += ['-lz']
528   if options.shared_zlib_includes:
529     o['include_dirs'] += [options.shared_zlib_includes]
530
531
532 def configure_http_parser(o):
533     o['variables']['node_shared_http_parser'] = b(options.shared_http_parser)
534
535     # assume shared http_parser if one of these is set?
536     if options.shared_http_parser_libpath:
537         o['libraries'] += ['-L%s' % options.shared_http_parser_libpath]
538     if options.shared_http_parser_libname:
539         o['libraries'] += ['-l%s' % options.shared_http_parser_libname]
540     elif options.shared_http_parser:
541         o['libraries'] += ['-lhttp_parser']
542     if options.shared_http_parser_includes:
543         o['include_dirs'] += [options.shared_http_parser_includes]
544
545
546 def configure_libuv(o):
547   o['variables']['node_shared_libuv'] = b(options.shared_libuv)
548
549   # assume shared libuv if one of these is set?
550   if options.shared_libuv_libpath:
551     o['libraries'] += ['-L%s' % options.shared_libuv_libpath]
552   else:
553     o['variables']['uv_library'] = 'static_library'
554
555   if options.shared_libuv_libname:
556     o['libraries'] += ['-l%s' % options.shared_libuv_libname]
557   elif options.shared_libuv:
558     o['libraries'] += ['-luv']
559   if options.shared_libuv_includes:
560     o['include_dirs'] += [options.shared_libuv_includes]
561
562
563 def configure_v8(o):
564   o['variables']['node_shared_v8'] = b(options.shared_v8)
565   o['variables']['v8_enable_gdbjit'] = 1 if options.gdb else 0
566   o['variables']['v8_no_strict_aliasing'] = 1  # Work around compiler bugs.
567   o['variables']['v8_optimized_debug'] = 0  # Compile with -O0 in debug builds.
568   o['variables']['v8_random_seed'] = 0  # Use a random seed for hash tables.
569   o['variables']['v8_use_snapshot'] = b(not options.without_snapshot)
570
571   # assume shared_v8 if one of these is set?
572   if options.shared_v8_libpath:
573     o['libraries'] += ['-L%s' % options.shared_v8_libpath]
574   if options.shared_v8_libname:
575     o['libraries'] += ['-l%s' % options.shared_v8_libname]
576   elif options.shared_v8:
577     o['libraries'] += ['-lv8']
578   if options.shared_v8_includes:
579     o['include_dirs'] += [options.shared_v8_includes]
580
581
582 def configure_openssl(o):
583   o['variables']['node_use_openssl'] = b(not options.without_ssl)
584   o['variables']['node_shared_openssl'] = b(options.shared_openssl)
585   o['variables']['openssl_no_asm'] = (
586     1 if options.openssl_no_asm else 0)
587
588   if options.without_ssl:
589     return
590
591   # OpenSSL uses `#ifndef OPENSSL_NO_SSL2` checks so only define the
592   # macro when we want to _disable_ SSL2.
593   if not options.with_sslv2:
594     o['defines'] += ['OPENSSL_NO_SSL2=1']
595
596   if options.shared_openssl:
597     (libs, cflags) = pkg_config('openssl') or ('-lssl -lcrypto', '')
598
599     if options.shared_openssl_libpath:
600       o['libraries'] += ['-L%s' % options.shared_openssl_libpath]
601
602     if options.shared_openssl_libname:
603       libnames = options.shared_openssl_libname.split(',')
604       o['libraries'] += ['-l%s' % s for s in libnames]
605     else:
606       o['libraries'] += libs.split()
607
608     if options.shared_openssl_includes:
609       o['include_dirs'] += [options.shared_openssl_includes]
610     else:
611       o['cflags'] += cflags.split()
612
613
614 def configure_fullystatic(o):
615   if options.fully_static:
616     o['libraries'] += ['-static']
617     if flavor == 'mac':
618       print("Generation of static executable will not work on OSX "
619             "when using default compilation environment")
620
621
622 def configure_winsdk(o):
623   if flavor != 'win':
624     return
625
626   winsdk_dir = os.environ.get('WindowsSdkDir')
627
628   if winsdk_dir and os.path.isfile(winsdk_dir + '\\bin\\ctrpp.exe'):
629     print('Found ctrpp in WinSDK--will build generated files '
630           'into tools/msvs/genfiles.')
631     o['variables']['node_has_winsdk'] = 'true'
632     return
633
634   print('ctrpp not found in WinSDK path--using pre-gen files '
635         'from tools/msvs/genfiles.')
636
637 def write(filename, data):
638   filename = os.path.join(root_dir, filename)
639   print 'creating ', filename
640   f = open(filename, 'w+')
641   f.write(data)
642
643 do_not_edit = '# Do not edit. Generated by the configure script.\n'
644
645 def glob_to_var(dir_base, dir_sub):
646   list = []
647   dir_all = os.path.join(dir_base, dir_sub)
648   files = os.walk(dir_all)
649   for ent in files:
650     (path, dirs, files) = ent
651     for file in files:
652       if file.endswith('.cpp') or file.endswith('.c') or file.endswith('.h'):
653         list.append('%s/%s' % (dir_sub, file))
654     break
655   return list
656
657 def configure_intl(o):
658   icus = [
659     {
660       'url': 'http://download.icu-project.org/files/icu4c/54.1/icu4c-54_1-src.zip',
661       # from https://ssl.icu-project.org/files/icu4c/54.1/icu4c-src-54_1.md5:
662       'md5': '6b89d60e2f0e140898ae4d7f72323bca',
663     },
664   ]
665   def icu_download(path):
666     # download ICU, if needed
667     for icu in icus:
668       url = icu['url']
669       md5 = icu['md5']
670       local = url.split('/')[-1]
671       targetfile = os.path.join(root_dir, 'deps', local)
672       if not os.path.isfile(targetfile):
673         if nodedownload.candownload(auto_downloads, "icu"):
674           nodedownload.retrievefile(url, targetfile)
675       else:
676         print ' Re-using existing %s' % targetfile
677       if os.path.isfile(targetfile):
678         sys.stdout.write(' Checking file integrity with MD5:\r')
679         gotmd5 = nodedownload.md5sum(targetfile)
680         print ' MD5:      %s  %s' % (gotmd5, targetfile)
681         if (md5 == gotmd5):
682           return targetfile
683         else:
684           print ' Expected: %s      *MISMATCH*' % md5
685           print '\n ** Corrupted ZIP? Delete %s to retry download.\n' % targetfile
686     return None
687   icu_config = {
688     'variables': {}
689   }
690   icu_config_name = 'icu_config.gypi'
691   def write_config(data, name):
692     return
693
694   # write an empty file to start with
695   write(icu_config_name, do_not_edit +
696         pprint.pformat(icu_config, indent=2) + '\n')
697
698   # always set icu_small, node.gyp depends on it being defined.
699   o['variables']['icu_small'] = b(False)
700
701   with_intl = options.with_intl
702   with_icu_source = options.with_icu_source
703   have_icu_path = bool(options.with_icu_path)
704   if have_icu_path and with_intl:
705     print 'Error: Cannot specify both --with-icu-path and --with-intl'
706     sys.exit(1)
707   elif have_icu_path:
708     # Chromium .gyp mode: --with-icu-path
709     o['variables']['v8_enable_i18n_support'] = 1
710     # use the .gyp given
711     o['variables']['icu_gyp_path'] = options.with_icu_path
712     return
713   # --with-intl=<with_intl>
714   # set the default
715   if with_intl is None:
716     with_intl = 'none'  # The default mode of Intl
717   # sanity check localelist
718   if options.with_icu_locales and (with_intl != 'small-icu'):
719     print 'Error: --with-icu-locales only makes sense with --with-intl=small-icu'
720     sys.exit(1)
721   if with_intl == 'none' or with_intl is None:
722     o['variables']['v8_enable_i18n_support'] = 0
723     return  # no Intl
724   elif with_intl == 'small-icu':
725     # small ICU (English only)
726     o['variables']['v8_enable_i18n_support'] = 1
727     o['variables']['icu_small'] = b(True)
728     with_icu_locales = options.with_icu_locales
729     if not with_icu_locales:
730       with_icu_locales = 'root,en'
731     locs = set(with_icu_locales.split(','))
732     locs.add('root')  # must have root
733     o['variables']['icu_locales'] = string.join(locs,',')
734   elif with_intl == 'full-icu':
735     # full ICU
736     o['variables']['v8_enable_i18n_support'] = 1
737   elif with_intl == 'system-icu':
738     # ICU from pkg-config.
739     o['variables']['v8_enable_i18n_support'] = 1
740     pkgicu = pkg_config('icu-i18n')
741     if not pkgicu:
742       print 'Error: could not load pkg-config data for "icu-i18n".'
743       print 'See above errors or the README.md.'
744       sys.exit(1)
745     (libs, cflags) = pkgicu
746     o['libraries'] += libs.split()
747     o['cflags'] += cflags.split()
748     # use the "system" .gyp
749     o['variables']['icu_gyp_path'] = 'tools/icu/icu-system.gyp'
750     return
751   else:
752     print 'Error: unknown value --with-intl=%s' % with_intl
753     sys.exit(1)
754   # Note: non-ICU implementations could use other 'with_intl'
755   # values.
756
757   # this is just the 'deps' dir. Used for unpacking.
758   icu_parent_path = os.path.join(root_dir, 'deps')
759
760   # The full path to the ICU source directory.
761   icu_full_path = os.path.join(icu_parent_path, 'icu')
762
763   # icu-tmp is used to download and unpack the ICU tarball.
764   icu_tmp_path = os.path.join(icu_parent_path, 'icu-tmp')
765
766   # --with-icu-source processing
767   # first, check that they didn't pass --with-icu-source=deps/icu
768   if with_icu_source and os.path.abspath(icu_full_path) == os.path.abspath(with_icu_source):
769     print 'Ignoring redundant --with-icu-source=%s' % (with_icu_source)
770     with_icu_source = None
771   # if with_icu_source is still set, try to use it.
772   if with_icu_source:
773     if os.path.isdir(icu_full_path):
774       print 'Deleting old ICU source: %s' % (icu_full_path)
775       shutil.rmtree(icu_full_path)
776     # now, what path was given?
777     if os.path.isdir(with_icu_source):
778       # it's a path. Copy it.
779       print '%s -> %s' % (with_icu_source, icu_full_path)
780       shutil.copytree(with_icu_source, icu_full_path)
781     else:
782       # could be file or URL.
783       # Set up temporary area
784       if os.path.isdir(icu_tmp_path):
785         shutil.rmtree(icu_tmp_path)
786       os.mkdir(icu_tmp_path)
787       icu_tarball = None
788       if os.path.isfile(with_icu_source):
789         # it's a file. Try to unpack it.
790         icu_tarball = with_icu_source
791       else:
792         # Can we download it?
793         local = os.path.join(icu_tmp_path, with_icu_source.split('/')[-1])  # local part
794         icu_tarball = nodedownload.retrievefile(with_icu_source, local)
795       # continue with "icu_tarball"
796       nodedownload.unpack(icu_tarball, icu_tmp_path)
797       # Did it unpack correctly? Should contain 'icu'
798       tmp_icu = os.path.join(icu_tmp_path, 'icu')
799       if os.path.isdir(tmp_icu):
800         os.rename(tmp_icu, icu_full_path)
801         shutil.rmtree(icu_tmp_path)
802       else:
803         print ' Error: --with-icu-source=%s did not result in an "icu" dir.' % with_icu_source
804         shutil.rmtree(icu_tmp_path)
805         sys.exit(1)
806
807   # ICU mode. (icu-generic.gyp)
808   byteorder = sys.byteorder
809   o['variables']['icu_gyp_path'] = 'tools/icu/icu-generic.gyp'
810   # ICU source dir relative to root
811   o['variables']['icu_path'] = icu_full_path
812   if not os.path.isdir(icu_full_path):
813     print '* ECMA-402 (Intl) support didn\'t find ICU in %s..' % (icu_full_path)
814     # can we download (or find) a zipfile?
815     localzip = icu_download(icu_full_path)
816     if localzip:
817       nodedownload.unpack(localzip, icu_parent_path)
818   if not os.path.isdir(icu_full_path):
819     print ' Cannot build Intl without ICU in %s.' % (icu_full_path)
820     print ' (Fix, or disable with "--with-intl=none" )'
821     sys.exit(1)
822   else:
823     print '* Using ICU in %s' % (icu_full_path)
824   # Now, what version of ICU is it? We just need the "major", such as 54.
825   # uvernum.h contains it as a #define.
826   uvernum_h = os.path.join(icu_full_path, 'source/common/unicode/uvernum.h')
827   if not os.path.isfile(uvernum_h):
828     print ' Error: could not load %s - is ICU installed?' % uvernum_h
829     sys.exit(1)
830   icu_ver_major = None
831   matchVerExp = r'^\s*#define\s+U_ICU_VERSION_SHORT\s+"([^"]*)".*'
832   match_version = re.compile(matchVerExp)
833   for line in open(uvernum_h).readlines():
834     m = match_version.match(line)
835     if m:
836       icu_ver_major = m.group(1)
837   if not icu_ver_major:
838     print ' Could not read U_ICU_VERSION_SHORT version from %s' % uvernum_h
839     sys.exit(1)
840   icu_endianness = sys.byteorder[0];  # TODO(srl295): EBCDIC should be 'e'
841   o['variables']['icu_ver_major'] = icu_ver_major
842   o['variables']['icu_endianness'] = icu_endianness
843   icu_data_file_l = 'icudt%s%s.dat' % (icu_ver_major, 'l')
844   icu_data_file = 'icudt%s%s.dat' % (icu_ver_major, icu_endianness)
845   # relative to configure
846   icu_data_path = os.path.join(icu_full_path,
847                                'source/data/in',
848                                icu_data_file_l)
849   # relative to dep..
850   icu_data_in = os.path.join('../../deps/icu/source/data/in', icu_data_file_l)
851   if not os.path.isfile(icu_data_path) and icu_endianness != 'l':
852     # use host endianness
853     icu_data_path = os.path.join(icu_full_path,
854                                  'source/data/in',
855                                  icu_data_file)
856     # relative to dep..
857     icu_data_in = os.path.join('icu/source/data/in',
858                                icu_data_file)
859   # this is the input '.dat' file to use .. icudt*.dat
860   # may be little-endian if from a icu-project.org tarball
861   o['variables']['icu_data_in'] = icu_data_in
862   # this is the icudt*.dat file which node will be using (platform endianness)
863   o['variables']['icu_data_file'] = icu_data_file
864   if not os.path.isfile(icu_data_path):
865     print ' Error: ICU prebuilt data file %s does not exist.' % icu_data_path
866     print ' See the README.md.'
867     # .. and we're not about to build it from .gyp!
868     sys.exit(1)
869   # map from variable name to subdirs
870   icu_src = {
871     'stubdata': 'stubdata',
872     'common': 'common',
873     'i18n': 'i18n',
874     'io': 'io',
875     'tools': 'tools/toolutil',
876     'genccode': 'tools/genccode',
877     'genrb': 'tools/genrb',
878     'icupkg': 'tools/icupkg',
879   }
880   # this creates a variable icu_src_XXX for each of the subdirs
881   # with a list of the src files to use
882   for i in icu_src:
883     var  = 'icu_src_%s' % i
884     path = '../../deps/icu/source/%s' % icu_src[i]
885     icu_config['variables'][var] = glob_to_var('tools/icu', path)
886   # write updated icu_config.gypi with a bunch of paths
887   write(icu_config_name, do_not_edit +
888         pprint.pformat(icu_config, indent=2) + '\n')
889   return  # end of configure_intl
890
891 # determine the "flavor" (operating system) we're building for,
892 # leveraging gyp's GetFlavor function
893 flavor_params = {}
894 if (options.dest_os):
895   flavor_params['flavor'] = options.dest_os
896 flavor = GetFlavor(flavor_params)
897
898 output = {
899   'variables': { 'python': sys.executable },
900   'include_dirs': [],
901   'libraries': [],
902   'defines': [],
903   'cflags': [],
904 }
905
906 configure_node(output)
907 configure_libz(output)
908 configure_http_parser(output)
909 configure_libuv(output)
910 configure_v8(output)
911 configure_openssl(output)
912 configure_winsdk(output)
913 configure_intl(output)
914 configure_fullystatic(output)
915
916 # variables should be a root level element,
917 # move everything else to target_defaults
918 variables = output['variables']
919 del output['variables']
920 output = {
921   'variables': variables,
922   'target_defaults': output
923 }
924 pprint.pprint(output, indent=2)
925
926 write('config.gypi', do_not_edit +
927       pprint.pformat(output, indent=2) + '\n')
928
929 config = {
930   'BUILDTYPE': 'Debug' if options.debug else 'Release',
931   'USE_NINJA': str(int(options.use_ninja or 0)),
932   'USE_XCODE': str(int(options.use_xcode or 0)),
933   'PYTHON': sys.executable,
934 }
935
936 if options.prefix:
937   config['PREFIX'] = options.prefix
938
939 config = '\n'.join(map('='.join, config.iteritems())) + '\n'
940
941 write('config.mk',
942       '# Do not edit. Generated by the configure script.\n' + config)
943
944 gyp_args = [sys.executable, 'tools/gyp_node.py', '--no-parallel']
945
946 if options.use_ninja:
947   gyp_args += ['-f', 'ninja-' + flavor]
948 elif options.use_xcode:
949   gyp_args += ['-f', 'xcode']
950 elif flavor == 'win' and sys.platform != 'msys':
951   gyp_args += ['-f', 'msvs', '-G', 'msvs_version=auto']
952 else:
953   gyp_args += ['-f', 'make-' + flavor]
954
955 gyp_args += args
956
957 sys.exit(subprocess.call(gyp_args))