The data contained in this repository can be downloaded to your computer using one of several clients.
Please see the documentation of your version control software client for more information.

Please select the desired protocol below to get the URL.

This URL has Read-Only access.

Statistics
| Branch: | Revision:

main_repo / configure @ de32b389

History | View | Annotate | Download (12.8 KB)

1
#!/usr/bin/env python
2
import optparse
3
import os
4
import pprint
5
import re
6
import subprocess
7
import sys
8

    
9
CC = os.environ.get('CC', 'cc')
10

    
11
root_dir = os.path.dirname(__file__)
12
sys.path.insert(0, os.path.join(root_dir, 'deps', 'v8', 'tools'))
13

    
14
# parse our options
15
parser = optparse.OptionParser()
16

    
17
parser.add_option("--debug",
18
    action="store_true",
19
    dest="debug",
20
    help="Also build debug build")
21

    
22
parser.add_option("--prefix",
23
    action="store",
24
    dest="prefix",
25
    help="Select the install prefix (defaults to /usr/local)")
26

    
27
parser.add_option("--without-npm",
28
    action="store_true",
29
    dest="without_npm",
30
    help="Don\'t install the bundled npm package manager")
31

    
32
parser.add_option("--without-ssl",
33
    action="store_true",
34
    dest="without_ssl",
35
    help="Build without SSL")
36

    
37
parser.add_option("--without-snapshot",
38
    action="store_true",
39
    dest="without_snapshot",
40
    help="Build without snapshotting V8 libraries. You might want to set"
41
         " this for cross-compiling. [Default: False]")
42

    
43
parser.add_option("--shared-v8",
44
    action="store_true",
45
    dest="shared_v8",
46
    help="Link to a shared V8 DLL instead of static linking")
47

    
48
parser.add_option("--shared-v8-includes",
49
    action="store",
50
    dest="shared_v8_includes",
51
    help="Directory containing V8 header files")
52

    
53
parser.add_option("--shared-v8-libpath",
54
    action="store",
55
    dest="shared_v8_libpath",
56
    help="A directory to search for the shared V8 DLL")
57

    
58
parser.add_option("--shared-v8-libname",
59
    action="store",
60
    dest="shared_v8_libname",
61
    help="Alternative lib name to link to (default: 'v8')")
62

    
63
parser.add_option("--shared-openssl",
64
    action="store_true",
65
    dest="shared_openssl",
66
    help="Link to a shared OpenSSl DLL instead of static linking")
67

    
68
parser.add_option("--shared-openssl-includes",
69
    action="store",
70
    dest="shared_openssl_includes",
71
    help="Directory containing OpenSSL header files")
72

    
73
parser.add_option("--shared-openssl-libpath",
74
    action="store",
75
    dest="shared_openssl_libpath",
76
    help="A directory to search for the shared OpenSSL DLLs")
77

    
78
parser.add_option("--shared-openssl-libname",
79
    action="store",
80
    dest="shared_openssl_libname",
81
    help="Alternative lib name to link to (default: 'crypto,ssl')")
82

    
83
# deprecated
84
parser.add_option("--openssl-use-sys",
85
    action="store_true",
86
    dest="shared_openssl",
87
    help=optparse.SUPPRESS_HELP)
88

    
89
# deprecated
90
parser.add_option("--openssl-includes",
91
    action="store",
92
    dest="shared_openssl_includes",
93
    help=optparse.SUPPRESS_HELP)
94

    
95
# deprecated
96
parser.add_option("--openssl-libpath",
97
    action="store",
98
    dest="shared_openssl_libpath",
99
    help=optparse.SUPPRESS_HELP)
100

    
101
parser.add_option("--no-ssl2",
102
    action="store_true",
103
    dest="no_ssl2",
104
    help="Disable OpenSSL v2")
105

    
106
parser.add_option("--shared-zlib",
107
    action="store_true",
108
    dest="shared_zlib",
109
    help="Link to a shared zlib DLL instead of static linking")
110

    
111
parser.add_option("--shared-zlib-includes",
112
    action="store",
113
    dest="shared_zlib_includes",
114
    help="Directory containing zlib header files")
115

    
116
parser.add_option("--shared-zlib-libpath",
117
    action="store",
118
    dest="shared_zlib_libpath",
119
    help="A directory to search for the shared zlib DLL")
120

    
121
parser.add_option("--shared-zlib-libname",
122
    action="store",
123
    dest="shared_zlib_libname",
124
    help="Alternative lib name to link to (default: 'z')")
125

    
126
parser.add_option("--with-dtrace",
127
    action="store_true",
128
    dest="with_dtrace",
129
    help="Build with DTrace (default is true on supported systems)")
130

    
131
parser.add_option("--without-dtrace",
132
    action="store_true",
133
    dest="without_dtrace",
134
    help="Build without DTrace")
135

    
136
parser.add_option("--with-etw",
137
    action="store_true",
138
    dest="with_etw",
139
    help="Build with ETW (default is true on Windows)")
140

    
141
parser.add_option("--without-etw",
142
    action="store_true",
143
    dest="without_etw",
144
    help="Build without ETW")
145

    
146
# CHECKME does this still work with recent releases of V8?
147
parser.add_option("--gdb",
148
    action="store_true",
149
    dest="gdb",
150
    help="add gdb support")
151

    
152
parser.add_option("--dest-cpu",
153
    action="store",
154
    dest="dest_cpu",
155
    help="CPU architecture to build for. Valid values are: arm, ia32, x64")
156

    
157
parser.add_option("--no-ifaddrs",
158
    action="store_true",
159
    dest="no_ifaddrs",
160
    help="Use on deprecated SunOS systems that do not support ifaddrs.h")
161

    
162
parser.add_option("--with-arm-float-abi",
163
    action="store",
164
    dest="arm_float_abi",
165
    help="Specifies which floating-point ABI to use. Valid values are: "
166
         "soft, softfp, hard")
167

    
168
(options, args) = parser.parse_args()
169

    
170

    
171
def b(value):
172
  """Returns the string 'true' if value is truthy, 'false' otherwise."""
173
  if value:
174
    return 'true'
175
  else:
176
    return 'false'
177

    
178

    
179
def pkg_config(pkg):
180
  cmd = os.popen('pkg-config --libs %s' % pkg, 'r')
181
  libs = cmd.readline().strip()
182
  ret = cmd.close()
183
  if (ret): return None
184

    
185
  cmd = os.popen('pkg-config --cflags %s' % pkg, 'r')
186
  cflags = cmd.readline().strip()
187
  ret = cmd.close()
188
  if (ret): return None
189

    
190
  return (libs, cflags)
191

    
192

    
193
def cc_macros():
194
  """Checks predefined macros using the CC command."""
195

    
196
  try:
197
    p = subprocess.Popen(CC.split() + ['-dM', '-E', '-'],
198
                         stdin=subprocess.PIPE,
199
                         stdout=subprocess.PIPE,
200
                         stderr=subprocess.PIPE)
201
  except OSError:
202
    print '''Node.js configure error: No acceptable C compiler found!
203

    
204
        Please make sure you have a C compiler installed on your system and/or
205
        consider adjusting the CC environment variable if you installed
206
        it in a non-standard prefix.
207
        '''
208
    sys.exit()
209

    
210
  p.stdin.write('\n')
211
  out = p.communicate()[0]
212

    
213
  out = str(out).split('\n')
214

    
215
  k = {}
216
  for line in out:
217
    import shlex
218
    lst = shlex.split(line)
219
    if len(lst) > 2:
220
      key = lst[1]
221
      val = lst[2]
222
      k[key] = val
223
  return k
224

    
225

    
226
def is_arch_armv7():
227
  """Check for ARMv7 instructions"""
228
  cc_macros_cache = cc_macros()
229
  return ('__ARM_ARCH_7__' in cc_macros_cache or
230
          '__ARM_ARCH_7A__' in cc_macros_cache or
231
          '__ARM_ARCH_7R__' in cc_macros_cache or
232
          '__ARM_ARCH_7M__' in cc_macros_cache)
233

    
234

    
235
def arm_hard_float_abi():
236
  """Check for hardfloat or softfloat eabi on ARM"""
237
  # GCC versions 4.6 and above define __ARM_PCS or __ARM_PCS_VFP to specify
238
  # the Floating Point ABI used (PCS stands for Procedure Call Standard).
239
  # We use these as well as a couple of other defines to statically determine
240
  # what FP ABI used.
241
  # GCC versions 4.4 and below don't support hard-fp.
242
  # GCC versions 4.5 may support hard-fp without defining __ARM_PCS or
243
  # __ARM_PCS_VFP.
244

    
245
  if compiler_version() >= (4, 6, 0):
246
    return '__ARM_PCS_VFP' in cc_macros()
247
  elif compiler_version() < (4, 5, 0):
248
    return False
249
  elif '__ARM_PCS_VFP' in cc_macros():
250
    return True
251
  elif ('__ARM_PCS' in cc_macros() or
252
        '__SOFTFP' in cc_macros() or
253
        not '__VFP_FP__' in cc_macros()):
254
    return False
255
  else:
256
    print '''Node.js configure error: Your version of GCC does not report
257
      the Floating-Point ABI to compile for your hardware
258

    
259
      Please manually specify which floating-point ABI to use with the
260
      --with-arm-float-abi option.
261
      '''
262
    sys.exit()
263

    
264

    
265
def host_arch_cc():
266
  """Host architecture check using the CC command."""
267

    
268
  k = cc_macros()
269

    
270
  matchup = {
271
    '__x86_64__'  : 'x64',
272
    '__i386__'    : 'ia32',
273
    '__arm__'     : 'arm',
274
  }
275

    
276
  rtn = 'ia32' # default
277

    
278
  for i in matchup:
279
    if i in k and k[i] != '0':
280
      rtn = matchup[i]
281
      break
282

    
283
  return rtn
284

    
285

    
286
def host_arch_win():
287
  """Host architecture check using environ vars (better way to do this?)"""
288

    
289
  arch = os.environ.get('PROCESSOR_ARCHITECTURE', 'x86')
290

    
291
  matchup = {
292
    'AMD64'  : 'x64',
293
    'x86'    : 'ia32',
294
    'arm'    : 'arm',
295
  }
296

    
297
  return matchup.get(arch, 'ia32')
298

    
299

    
300
def compiler_version():
301
  try:
302
    proc = subprocess.Popen(CC.split() + ['--version'], stdout=subprocess.PIPE)
303
  except WindowsError:
304
    return (0, False)
305

    
306
  is_clang = 'clang' in proc.communicate()[0].split('\n')[0]
307

    
308
  proc = subprocess.Popen(CC.split() + ['-dumpversion'], stdout=subprocess.PIPE)
309
  version = tuple(map(int, proc.communicate()[0].split('.')))
310

    
311
  return (version, is_clang)
312

    
313

    
314
def configure_node(o):
315
  # TODO add gdb
316
  o['variables']['v8_no_strict_aliasing'] = 1 # work around compiler bugs
317
  o['variables']['node_prefix'] = os.path.expanduser(options.prefix or '')
318
  o['variables']['node_install_npm'] = b(not options.without_npm)
319
  o['default_configuration'] = 'Debug' if options.debug else 'Release'
320

    
321
  host_arch = host_arch_win() if os.name == 'nt' else host_arch_cc()
322
  target_arch = options.dest_cpu or host_arch
323
  o['variables']['host_arch'] = host_arch
324
  o['variables']['target_arch'] = target_arch
325

    
326
  # V8 on ARM requires that armv7 is set. CPU Model detected by
327
  # the presence of __ARM_ARCH_7__ and the like defines in compiler
328
  if target_arch == 'arm':
329
    if options.arm_float_abi:
330
      hard_float = options.arm_float_abi == 'hard'
331
    else:
332
      hard_float = arm_hard_float_abi()
333
    o['variables']['v8_use_arm_eabi_hardfloat'] = b(hard_float)
334
    o['variables']['armv7'] = 1 if is_arch_armv7() else 0
335

    
336
  # clang has always supported -fvisibility=hidden, right?
337
  cc_version, is_clang = compiler_version()
338
  if not is_clang and cc_version < (4,0,0):
339
    o['variables']['visibility'] = ''
340

    
341
  # By default, enable DTrace on SunOS systems. Don't allow it on other
342
  # systems, since it won't work.  (The MacOS build process is different than
343
  # SunOS, and we haven't implemented it.)
344
  if sys.platform.startswith('sunos'):
345
    o['variables']['node_use_dtrace'] = b(not options.without_dtrace)
346
  elif b(options.with_dtrace) == 'true':
347
    raise Exception('DTrace is currently only supported on SunOS systems.')
348
  else:
349
    o['variables']['node_use_dtrace'] = 'false'
350

    
351
  if options.no_ifaddrs:
352
    o['defines'] += ['SUNOS_NO_IFADDRS']
353

    
354
  # By default, enable ETW on Windows.
355
  if sys.platform.startswith('win32'):
356
    o['variables']['node_use_etw'] = b(not options.without_etw);
357
  elif b(options.with_etw) == 'true':
358
    raise Exception('ETW is only supported on Windows.')
359
  else:
360
    o['variables']['node_use_etw'] = 'false'
361

    
362

    
363
def configure_libz(o):
364
  o['variables']['node_shared_zlib'] = b(options.shared_zlib)
365

    
366
  # assume shared_zlib if one of these is set?
367
  if options.shared_zlib_libpath:
368
    o['libraries'] += ['-L%s' % options.shared_zlib_libpath]
369
  if options.shared_zlib_libname:
370
    o['libraries'] += ['-l%s' % options.shared_zlib_libname]
371
  elif options.shared_zlib:
372
    o['libraries'] += ['-lz']
373
  if options.shared_zlib_includes:
374
    o['include_dirs'] += [options.shared_zlib_includes]
375

    
376

    
377
def configure_v8(o):
378
  o['variables']['v8_use_snapshot'] = b(not options.without_snapshot)
379
  o['variables']['node_shared_v8'] = b(options.shared_v8)
380

    
381
  # assume shared_v8 if one of these is set?
382
  if options.shared_v8_libpath:
383
    o['libraries'] += ['-L%s' % options.shared_v8_libpath]
384
  if options.shared_v8_libname:
385
    o['libraries'] += ['-l%s' % options.shared_v8_libname]
386
  elif options.shared_v8:
387
    o['libraries'] += ['-lv8']
388
  if options.shared_v8_includes:
389
    o['include_dirs'] += [options.shared_v8_includes]
390

    
391

    
392
def configure_openssl(o):
393
  o['variables']['node_use_openssl'] = b(not options.without_ssl)
394
  o['variables']['node_shared_openssl'] = b(options.shared_openssl)
395

    
396
  if options.without_ssl:
397
    return
398

    
399
  if options.no_ssl2:
400
    o['defines'] += ['OPENSSL_NO_SSL2=1']
401

    
402
  if options.shared_openssl:
403
    (libs, cflags) = pkg_config('openssl') or ('-lssl -lcrypto', '')
404

    
405
    if options.shared_openssl_libpath:
406
      o['libraries'] += ['-L%s' % options.shared_openssl_libpath]
407

    
408
    if options.shared_openssl_libname:
409
      libnames = options.shared_openssl_libname.split(',')
410
      o['libraries'] += ['-l%s' % s for s in libnames]
411
    else:
412
      o['libraries'] += libs.split()
413

    
414
    if options.shared_openssl_includes:
415
      o['include_dirs'] += [options.shared_openssl_includes]
416
    else:
417
      o['cflags'] += cflags.split()
418

    
419

    
420
output = {
421
  'variables': {},
422
  'include_dirs': [],
423
  'libraries': [],
424
  'defines': [],
425
  'cflags': [],
426
}
427

    
428
configure_node(output)
429
configure_libz(output)
430
configure_v8(output)
431
configure_openssl(output)
432

    
433
# variables should be a root level element,
434
# move everything else to target_defaults
435
variables = output['variables']
436
del output['variables']
437
output = {
438
  'variables': variables,
439
  'target_defaults': output
440
}
441
pprint.pprint(output, indent=2)
442

    
443
def write(filename, data):
444
  filename = os.path.join(root_dir, filename)
445
  print "creating ", filename
446
  f = open(filename, 'w+')
447
  f.write(data)
448

    
449
write('config.gypi', "# Do not edit. Generated by the configure script.\n" +
450
  pprint.pformat(output, indent=2) + "\n")
451

    
452
write('config.mk', "# Do not edit. Generated by the configure script.\n" +
453
  ("BUILDTYPE=%s\n" % ('Debug' if options.debug else 'Release')))
454

    
455
if os.name == 'nt':
456
  gyp_args = ['-f', 'msvs', '-G', 'msvs_version=2010']
457
else:
458
  gyp_args = ['-f', 'make']
459

    
460
subprocess.call([sys.executable, 'tools/gyp_node'] + gyp_args)