Merge branch 'mesa_7_5_branch'
[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 versions = [
48 '6001.18002',
49 '3790.1830',
50 ]
51
52 def cpu_bin(target_cpu):
53 if target_cpu == 'i386':
54 return 'x86'
55 else:
56 return target_cpu
57
58 def get_winddk_root(env, version):
59 default_path = os.path.join(r'C:\WINDDK', version)
60 if os.path.exists(default_path):
61 return default_path
62 return None
63
64 def get_winddk_paths(env, version, root):
65 version_major, version_minor = map(int, version.split('.'))
66
67 if version_major >= 6000:
68 target_os = 'wlh'
69 else:
70 target_os = 'wxp'
71
72 if env['machine'] in ('generic', 'x86'):
73 target_cpu = 'i386'
74 elif env['machine'] == 'x86_64':
75 target_cpu = 'amd64'
76 else:
77 raise SCons.Errors.InternalError, "Unsupported target machine"
78
79 if version_major >= 6000:
80 # TODO: take in consideration the host cpu
81 bin_dir = os.path.join(root, 'bin', 'x86', cpu_bin(target_cpu))
82 else:
83 if target_cpu == 'i386':
84 bin_dir = os.path.join(root, 'bin', 'x86')
85 else:
86 # TODO: take in consideration the host cpu
87 bin_dir = os.path.join(root, 'bin', 'win64', 'x86', cpu_bin(target_cpu))
88
89 env.PrependENVPath('PATH', [bin_dir])
90
91 crt_inc_dir = os.path.join(root, 'inc', 'crt')
92 if version_major >= 6000:
93 sdk_inc_dir = os.path.join(root, 'inc', 'api')
94 ddk_inc_dir = os.path.join(root, 'inc', 'ddk')
95 wdm_inc_dir = os.path.join(root, 'inc', 'ddk')
96 else:
97 ddk_inc_dir = os.path.join(root, 'inc', 'ddk', target_os)
98 sdk_inc_dir = os.path.join(root, 'inc', target_os)
99 wdm_inc_dir = os.path.join(root, 'inc', 'ddk', 'wdm', target_os)
100
101 env.PrependENVPath('INCLUDE', [
102 wdm_inc_dir,
103 ddk_inc_dir,
104 crt_inc_dir,
105 sdk_inc_dir,
106 ])
107
108 env.PrependENVPath('LIB', [
109 os.path.join(root, 'lib', 'crt', target_cpu),
110 os.path.join(root, 'lib', target_os, target_cpu),
111 ])
112
113 def generate(env):
114 if not env.has_key('ENV'):
115 env['ENV'] = {}
116
117 for version in versions:
118 root = get_winddk_root(env, version)
119 if root is not None:
120 get_winddk_paths(env, version, root)
121 break
122
123 msvc_sa.generate(env)
124 mslib_sa.generate(env)
125 mslink_sa.generate(env)
126
127 def exists(env):
128 for version in versions:
129 if get_winddk_root(env, version) is not None:
130 return True
131 return False
132
133 # vim:set ts=4 sw=4 et: