]> git.proxmox.com Git - rustc.git/blob - src/libuv/gyp_uv
Imported Upstream version 0.6
[rustc.git] / src / libuv / gyp_uv
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 return machine # Return as-is and hope for the best.
28
29
30 def compiler_version():
31 proc = subprocess.Popen(CC.split() + ['--version'], stdout=subprocess.PIPE)
32 is_clang = 'clang' in proc.communicate()[0].split('\n')[0]
33 proc = subprocess.Popen(CC.split() + ['-dumpversion'], stdout=subprocess.PIPE)
34 version = proc.communicate()[0].split('.')
35 version = map(int, version[:2])
36 version = tuple(version)
37 return (version, is_clang)
38
39
40 def run_gyp(args):
41 rc = gyp.main(args)
42 if rc != 0:
43 print 'Error running GYP'
44 sys.exit(rc)
45
46
47 if __name__ == '__main__':
48 args = sys.argv[1:]
49
50 # GYP bug.
51 # On msvs it will crash if it gets an absolute path.
52 # On Mac/make it will crash if it doesn't get an absolute path.
53 if sys.platform == 'win32':
54 args.append(os.path.join(uv_root, 'uv.gyp'))
55 common_fn = os.path.join(uv_root, 'common.gypi')
56 options_fn = os.path.join(uv_root, 'options.gypi')
57 # we force vs 2010 over 2008 which would otherwise be the default for gyp
58 if not os.environ.get('GYP_MSVS_VERSION'):
59 os.environ['GYP_MSVS_VERSION'] = '2010'
60 else:
61 args.append(os.path.join(os.path.abspath(uv_root), 'uv.gyp'))
62 common_fn = os.path.join(os.path.abspath(uv_root), 'common.gypi')
63 options_fn = os.path.join(os.path.abspath(uv_root), 'options.gypi')
64
65 if os.path.exists(common_fn):
66 args.extend(['-I', common_fn])
67
68 if os.path.exists(options_fn):
69 args.extend(['-I', options_fn])
70
71 args.append('--depth=' + uv_root)
72
73 # There's a bug with windows which doesn't allow this feature.
74 if sys.platform != 'win32':
75 if '-f' not in args:
76 args.extend('-f make'.split())
77 if 'ninja' not in args:
78 args.extend(['-Goutput_dir=' + output_dir])
79 args.extend(['--generator-output', output_dir])
80 (major, minor), is_clang = compiler_version()
81 args.append('-Dgcc_version=%d' % (10 * major + minor))
82 args.append('-Dclang=%d' % int(is_clang))
83
84 if not any(a.startswith('-Dhost_arch=') for a in args):
85 args.append('-Dhost_arch=%s' % host_arch())
86
87 if not any(a.startswith('-Dtarget_arch=') for a in args):
88 args.append('-Dtarget_arch=%s' % host_arch())
89
90 if not any(a.startswith('-Dlibrary=') for a in args):
91 args.append('-Dlibrary=static_library')
92
93 if not any(a.startswith('-Dcomponent=') for a in args):
94 args.append('-Dcomponent=static_library')
95
96 gyp_args = list(args)
97 print gyp_args
98 run_gyp(gyp_args)