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