Merge commit 'origin/gallium-master-merge'
[mesa.git] / scons / winddk.py
1 """winddk
2
3 Tool-specific initialization for Microsoft Windows DDK.
4
5 """
6
7 #
8 # Copyright (c) 2001-2007 The SCons Foundation
9 # Copyright (c) 2008 Tungsten Graphics, Inc.
10 #
11 # Permission is hereby granted, free of charge, to any person obtaining
12 # a copy of this software and associated documentation files (the
13 # "Software"), to deal in the Software without restriction, including
14 # without limitation the rights to use, copy, modify, merge, publish,
15 # distribute, sublicense, and/or sell copies of the Software, and to
16 # permit persons to whom the Software is furnished to do so, subject to
17 # the following conditions:
18 #
19 # The above copyright notice and this permission notice shall be included
20 # in all copies or substantial portions of the Software.
21 #
22 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
23 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
24 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 #
30
31 import os.path
32 import re
33 import string
34
35 import SCons.Action
36 import SCons.Builder
37 import SCons.Errors
38 import SCons.Platform.win32
39 import SCons.Tool
40 import SCons.Util
41 import SCons.Warnings
42
43 import msvc_sa
44 import mslib_sa
45 import mslink_sa
46
47 def get_winddk_root(env):
48 try:
49 return os.environ['BASEDIR']
50 except KeyError:
51 pass
52
53 version = "3790.1830"
54
55 if SCons.Util.can_read_reg:
56 key = r'SOFTWARE\Microsoft\WINDDK\%s\LFNDirectory' % version
57 try:
58 path, t = SCons.Util.RegGetValue(SCons.Util.HKEY_LOCAL_MACHINE, key)
59 except SCons.Util.RegError:
60 pass
61 else:
62 return path
63
64 default_path = os.path.join(r'C:\WINDDK', version)
65 if os.path.exists(default_path):
66 return default_path
67
68 return None
69
70 def get_winddk_paths(env):
71 """Return a 3-tuple of (INCLUDE, LIB, PATH) as the values
72 of those three environment variables that should be set
73 in order to execute the MSVC tools properly."""
74
75 WINDDKdir = None
76 exe_paths = []
77 lib_paths = []
78 include_paths = []
79
80 WINDDKdir = get_winddk_root(env)
81 if WINDDKdir is None:
82 raise SCons.Errors.InternalError, "WINDDK not found"
83
84 exe_paths.append( os.path.join(WINDDKdir, 'bin') )
85 exe_paths.append( os.path.join(WINDDKdir, 'bin', 'x86') )
86 include_paths.append( os.path.join(WINDDKdir, 'inc', 'wxp') )
87 lib_paths.append( os.path.join(WINDDKdir, 'lib') )
88
89 target_os = 'wxp'
90 target_cpu = 'i386'
91
92 env['SDK_INC_PATH'] = os.path.join(WINDDKdir, 'inc', target_os)
93 env['CRT_INC_PATH'] = os.path.join(WINDDKdir, 'inc', 'crt')
94 env['DDK_INC_PATH'] = os.path.join(WINDDKdir, 'inc', 'ddk', target_os)
95 env['WDM_INC_PATH'] = os.path.join(WINDDKdir, 'inc', 'ddk', 'wdm', target_os)
96
97 env['SDK_LIB_PATH'] = os.path.join(WINDDKdir, 'lib', target_os, target_cpu)
98 env['CRT_LIB_PATH'] = os.path.join(WINDDKdir, 'lib', 'crt', target_cpu)
99 env['DDK_LIB_PATH'] = os.path.join(WINDDKdir, 'lib', target_os, target_cpu)
100 env['WDM_LIB_PATH'] = os.path.join(WINDDKdir, 'lib', target_os, target_cpu)
101
102 include_path = string.join( include_paths, os.pathsep )
103 lib_path = string.join(lib_paths, os.pathsep )
104 exe_path = string.join(exe_paths, os.pathsep )
105 return (include_path, lib_path, exe_path)
106
107 def generate(env):
108
109 msvc_sa.generate(env)
110 mslib_sa.generate(env)
111 mslink_sa.generate(env)
112
113 if not env.has_key('ENV'):
114 env['ENV'] = {}
115
116 try:
117 include_path, lib_path, exe_path = get_winddk_paths(env)
118
119 # since other tools can set these, we just make sure that the
120 # relevant stuff from WINDDK is in there somewhere.
121 env.PrependENVPath('INCLUDE', include_path)
122 env.PrependENVPath('LIB', lib_path)
123 env.PrependENVPath('PATH', exe_path)
124 except (SCons.Util.RegError, SCons.Errors.InternalError):
125 pass
126
127 def exists(env):
128 return get_winddk_root(env) is not None
129
130 # vim:set ts=4 sw=4 et: