blob: 255f9c5a654dcaa6b39c0107bceb274052598519 [file] [log] [blame]
José Fonseca26e27ba2009-03-25 19:24:16 +00001"""winsdk
2
3Tool-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
32import os.path
33import platform
34
35import SCons.Errors
36import SCons.Util
37
38import msvc_sa
39import mslib_sa
40import mslink_sa
41
42
43def 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
48def 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
57def 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
62def 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 exe_path = os.path.join(vc_root, bin_dir)
81 include_path = os.path.join(vc_root, include_dir)
82 lib_path = os.path.join(vc_root, lib_dir)
83
84 env.PrependENVPath('INCLUDE', include_path)
85 env.PrependENVPath('LIB', lib_path)
86 env.PrependENVPath('PATH', exe_path)
87
88def get_sdk_root(env):
89 if SCons.Util.can_read_reg:
90 key = r'SOFTWARE\Microsoft\Microsoft SDKs\Windows\CurrentInstallFolder'
91 try:
92 path, t = SCons.Util.RegGetValue(SCons.Util.HKEY_LOCAL_MACHINE, key)
93 except SCons.Util.RegError:
94 pass
95 else:
96 return path
97
98 return None
99
100def get_sdk_paths(env):
101 sdk_root = get_sdk_root(env)
102 if sdk_root is None:
103 raise SCons.Errors.InternalError, "WINSDK not found"
104
105 target_cpu = env['machine']
106
107 bin_dir = 'Bin'
108 if target_cpu in ('generic', 'x86'):
109 lib_dir = 'Lib'
110 elif target_cpu == 'x86_64':
111 lib_dir = 'Lib/x64'
112 else:
113 raise SCons.Errors.InternalError, "Unsupported target machine"
114 include_dir = 'Include'
115
116 exe_path = os.path.join(sdk_root, bin_dir)
117 include_path = os.path.join(sdk_root, include_dir)
118 lib_path = os.path.join(sdk_root, lib_dir)
119
120 env.PrependENVPath('INCLUDE', include_path)
121 env.PrependENVPath('LIB', lib_path)
122 env.PrependENVPath('PATH', exe_path)
123
124def generate(env):
125 if not env.has_key('ENV'):
126 env['ENV'] = {}
127
128 get_vs_paths(env)
129 get_vc_paths(env)
130 get_sdk_paths(env)
131
132 msvc_sa.generate(env)
133 mslib_sa.generate(env)
134 mslink_sa.generate(env)
135
136def exists(env):
137 return get_vc_root(env) is not None and get_sdk_root(env) is not None
138
139# vim:set ts=4 sw=4 et: