OSDN Git Service

scons: Set -static-libstdc++ on mingw-w64
[android-x86/external-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     crt_inc_dir = os.path.join(root, 'inc', 'crt')
90     if version_major >= 6000:
91         sdk_inc_dir = os.path.join(root, 'inc', 'api')
92         ddk_inc_dir = os.path.join(root, 'inc', 'ddk')
93         wdm_inc_dir = os.path.join(root, 'inc', 'ddk')
94     else:
95         ddk_inc_dir = os.path.join(root, 'inc', 'ddk', target_os)
96         sdk_inc_dir = os.path.join(root, 'inc', target_os)
97         wdm_inc_dir = os.path.join(root, 'inc', 'ddk', 'wdm', target_os)
98
99     if env['toolchain'] == 'winddk':
100         env.PrependENVPath('PATH', [bin_dir])
101         env.PrependENVPath('INCLUDE', [
102             wdm_inc_dir,
103             ddk_inc_dir,
104             crt_inc_dir,
105             sdk_inc_dir,
106         ])
107         env.PrependENVPath('LIB', [
108             os.path.join(root, 'lib', 'crt', target_cpu),
109             os.path.join(root, 'lib', target_os, target_cpu),
110         ])
111     elif env['toolchain'] == 'crossmingw':
112         env.Prepend(CPPFLAGS = [
113             '-isystem', ddk_inc_dir,
114             '-isystem', sdk_inc_dir,
115         ])
116     else:
117         env.Prepend(CPPPATH = [
118             wdm_inc_dir,
119             ddk_inc_dir,
120             sdk_inc_dir,
121         ])
122         env.Prepend(LIBPATH = [
123             os.path.join(root, 'lib', target_os, target_cpu),
124         ])
125
126
127 def generate(env):
128     if not env.has_key('ENV'):
129         env['ENV'] = {}
130
131     for version in versions:
132         root = get_winddk_root(env, version)
133         if root is not None:
134             get_winddk_paths(env, version, root)
135             break
136
137     if env['toolchain'] == 'winddk':
138         msvc_sa.generate(env)
139         mslib_sa.generate(env)
140         mslink_sa.generate(env)
141
142 def exists(env):
143     for version in versions:
144         if get_winddk_root(env, version) is not None:
145             return True
146     return False
147
148 # vim:set ts=4 sw=4 et: