~ubuntu-branches/ubuntu/vivid/nodejs/vivid

« back to all changes in this revision

Viewing changes to deps/uv/gyp_uv

  • Committer: Package Import Robot
  • Author(s): Jérémy Lal
  • Date: 2013-11-13 23:17:51 UTC
  • mfrom: (1.1.29)
  • mto: This revision was merged to the branch mainline in revision 33.
  • Revision ID: package-import@ubuntu.com-20131113231751-m6uqywp5dc4s4fxo
Tags: 0.10.22~dfsg1-1
* Upstream update. 
* Refresh patches.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env python
2
 
 
3
 
import glob
4
 
import platform
5
 
import os
6
 
import subprocess
7
 
import sys
8
 
 
9
 
CC = os.environ.get('CC', 'cc')
10
 
script_dir = os.path.dirname(__file__)
11
 
uv_root = os.path.normpath(script_dir)
12
 
output_dir = os.path.join(os.path.abspath(uv_root), 'out')
13
 
 
14
 
sys.path.insert(0, os.path.join(uv_root, 'build', 'gyp', 'pylib'))
15
 
try:
16
 
  import gyp
17
 
except ImportError:
18
 
  print('You need to install gyp in build/gyp first. See the README.')
19
 
  sys.exit(42)
20
 
 
21
 
 
22
 
def host_arch():
23
 
  machine = platform.machine()
24
 
  if machine == 'i386': return 'ia32'
25
 
  if machine == 'x86_64': return 'x64'
26
 
  if machine.startswith('arm'): return 'arm'
27
 
  if machine.startswith('mips'): return 'mips'
28
 
  return machine  # Return as-is and hope for the best.
29
 
 
30
 
 
31
 
def compiler_version():
32
 
  proc = subprocess.Popen(CC.split() + ['--version'], stdout=subprocess.PIPE)
33
 
  is_clang = 'clang' in proc.communicate()[0].split('\n')[0]
34
 
  proc = subprocess.Popen(CC.split() + ['-dumpversion'], stdout=subprocess.PIPE)
35
 
  version = proc.communicate()[0].split('.')
36
 
  version = map(int, version[:2])
37
 
  version = tuple(version)
38
 
  return (version, is_clang)
39
 
 
40
 
 
41
 
def run_gyp(args):
42
 
  rc = gyp.main(args)
43
 
  if rc != 0:
44
 
    print 'Error running GYP'
45
 
    sys.exit(rc)
46
 
 
47
 
 
48
 
if __name__ == '__main__':
49
 
  args = sys.argv[1:]
50
 
 
51
 
  # GYP bug.
52
 
  # On msvs it will crash if it gets an absolute path.
53
 
  # On Mac/make it will crash if it doesn't get an absolute path.
54
 
  if sys.platform == 'win32':
55
 
    args.append(os.path.join(uv_root, 'uv.gyp'))
56
 
    common_fn  = os.path.join(uv_root, 'common.gypi')
57
 
    options_fn = os.path.join(uv_root, 'options.gypi')
58
 
    # we force vs 2010 over 2008 which would otherwise be the default for gyp
59
 
    if not os.environ.get('GYP_MSVS_VERSION'):
60
 
      os.environ['GYP_MSVS_VERSION'] = '2010'
61
 
  else:
62
 
    args.append(os.path.join(os.path.abspath(uv_root), 'uv.gyp'))
63
 
    common_fn  = os.path.join(os.path.abspath(uv_root), 'common.gypi')
64
 
    options_fn = os.path.join(os.path.abspath(uv_root), 'options.gypi')
65
 
 
66
 
  if os.path.exists(common_fn):
67
 
    args.extend(['-I', common_fn])
68
 
 
69
 
  if os.path.exists(options_fn):
70
 
    args.extend(['-I', options_fn])
71
 
 
72
 
  args.append('--depth=' + uv_root)
73
 
 
74
 
  # There's a bug with windows which doesn't allow this feature.
75
 
  if sys.platform != 'win32':
76
 
    if '-f' not in args:
77
 
      args.extend('-f make'.split())
78
 
    if 'ninja' not in args:
79
 
      args.extend(['-Goutput_dir=' + output_dir])
80
 
      args.extend(['--generator-output', output_dir])
81
 
    (major, minor), is_clang = compiler_version()
82
 
    args.append('-Dgcc_version=%d' % (10 * major + minor))
83
 
    args.append('-Dclang=%d' % int(is_clang))
84
 
 
85
 
  if not any(a.startswith('-Dhost_arch=') for a in args):
86
 
    args.append('-Dhost_arch=%s' % host_arch())
87
 
 
88
 
  if not any(a.startswith('-Dtarget_arch=') for a in args):
89
 
    args.append('-Dtarget_arch=%s' % host_arch())
90
 
 
91
 
  if not any(a.startswith('-Dlibrary=') for a in args):
92
 
    args.append('-Dlibrary=static_library')
93
 
 
94
 
  if not any(a.startswith('-Dcomponent=') for a in args):
95
 
    args.append('-Dcomponent=static_library')
96
 
 
97
 
  gyp_args = list(args)
98
 
  print gyp_args
99
 
  run_gyp(gyp_args)