Merge remote branch 'origin/master' into pipe-video
[mesa.git] / scons / winsdk.py
1 """winsdk
2
3 Tool-specific initialization for Microsoft Windows SDK.
4
5 """
6
7 #
8 # Copyright (c) 2001-2007 The SCons Foundation
9 # Copyright (c) 2008 Tungsten Graphics, Inc.
10 # Copyright (c) 2009 VMware, Inc.
11 #
12 # Permission is hereby granted, free of charge, to any person obtaining
13 # a copy of this software and associated documentation files (the
14 # "Software"), to deal in the Software without restriction, including
15 # without limitation the rights to use, copy, modify, merge, publish,
16 # distribute, sublicense, and/or sell copies of the Software, and to
17 # permit persons to whom the Software is furnished to do so, subject to
18 # the following conditions:
19 #
20 # The above copyright notice and this permission notice shall be included
21 # in all copies or substantial portions of the Software.
22 #
23 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
24 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
25 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 #
31
32 import os.path
33 import platform
34
35 import SCons.Errors
36 import SCons.Util
37
38 import msvc_sa
39 import mslib_sa
40 import mslink_sa
41
42
43 def get_vs_root(env):
44 # TODO: Check HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\SxS\VS7
45 path = os.path.join(os.getenv('ProgramFiles', r'C:\Program Files'), 'Microsoft Visual Studio 9.0')
46 return path
47
48 def get_vs_paths(env):
49 vs_root = get_vs_root(env)
50 if vs_root is None:
51 raise SCons.Errors.InternalError, "WINSDK compiler not found"
52
53 tool_path = os.path.join(vs_root, 'Common7', 'IDE')
54
55 env.PrependENVPath('PATH', tool_path)
56
57 def get_vc_root(env):
58 # TODO: Check HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\SxS\VC7
59 path = os.path.join(os.getenv('ProgramFiles', r'C:\Program Files'), 'Microsoft Visual Studio 9.0', 'VC')
60 return path
61
62 def get_vc_paths(env):
63 vc_root = get_vc_root(env)
64 if vc_root is None:
65 raise SCons.Errors.InternalError, "WINSDK compiler not found"
66
67 target_cpu = env['machine']
68
69 if target_cpu in ('generic', 'x86'):
70 bin_dir = 'bin'
71 lib_dir = 'lib'
72 elif target_cpu == 'x86_64':
73 # TODO: take in consideration the host cpu
74 bin_dir = r'bin\x86_amd64'
75 lib_dir = r'lib\amd64'
76 else:
77 raise SCons.Errors.InternalError, "Unsupported target machine"
78 include_dir = 'include'
79
80 env.PrependENVPath('PATH', os.path.join(vc_root, bin_dir))
81 env.PrependENVPath('INCLUDE', os.path.join(vc_root, include_dir))
82 env.PrependENVPath('LIB', os.path.join(vc_root, lib_dir))
83
84 def get_sdk_root(env):
85 if SCons.Util.can_read_reg:
86 key = r'SOFTWARE\Microsoft\Microsoft SDKs\Windows\CurrentInstallFolder'
87 try:
88 path, t = SCons.Util.RegGetValue(SCons.Util.HKEY_LOCAL_MACHINE, key)
89 except SCons.Util.RegError:
90 pass
91 else:
92 return path
93
94 return None
95
96 def get_sdk_paths(env):
97 sdk_root = get_sdk_root(env)
98 if sdk_root is None:
99 raise SCons.Errors.InternalError, "WINSDK not found"
100
101 target_cpu = env['machine']
102
103 bin_dir = 'Bin'
104 if target_cpu in ('generic', 'x86'):
105 lib_dir = 'Lib'
106 elif target_cpu == 'x86_64':
107 lib_dir = r'Lib\x64'
108 else:
109 raise SCons.Errors.InternalError, "Unsupported target machine"
110 include_dir = 'Include'
111
112 env.PrependENVPath('PATH', os.path.join(sdk_root, bin_dir))
113 env.PrependENVPath('INCLUDE', os.path.join(sdk_root, include_dir))
114 env.PrependENVPath('LIB', os.path.join(sdk_root, lib_dir))
115
116 def generate(env):
117 if not env.has_key('ENV'):
118 env['ENV'] = {}
119
120 get_vs_paths(env)
121 get_vc_paths(env)
122 get_sdk_paths(env)
123
124 msvc_sa.generate(env)
125 mslib_sa.generate(env)
126 mslink_sa.generate(env)
127
128 def exists(env):
129 return get_vc_root(env) is not None and get_sdk_root(env) is not None
130
131 # vim:set ts=4 sw=4 et: