blob: 4dac16ee66eec067996ca45612472b1f630b31f5 [file] [log] [blame]
José Fonsecab215d7d2008-05-28 01:24:06 +09001"""winddk
2
3Tool-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
31import os.path
32import re
33import string
34
35import SCons.Action
36import SCons.Builder
37import SCons.Errors
38import SCons.Platform.win32
39import SCons.Tool
40import SCons.Util
41import SCons.Warnings
42
43import msvc_sa
44import mslib_sa
45import mslink_sa
46
José Fonseca71793e0f2009-04-14 21:39:54 +010047versions = [
48 '6001.18002',
49 '3790.1830',
50]
José Fonseca4ec4ea12008-07-24 20:09:54 +090051
José Fonseca71793e0f2009-04-14 21:39:54 +010052def cpu_bin(target_cpu):
53 if target_cpu == 'i386':
54 return 'x86'
55 else:
56 return target_cpu
José Fonseca4ec4ea12008-07-24 20:09:54 +090057
José Fonseca71793e0f2009-04-14 21:39:54 +010058def get_winddk_root(env, version):
José Fonseca4ec4ea12008-07-24 20:09:54 +090059 default_path = os.path.join(r'C:\WINDDK', version)
60 if os.path.exists(default_path):
61 return default_path
José Fonseca4ec4ea12008-07-24 20:09:54 +090062 return None
63
José Fonseca71793e0f2009-04-14 21:39:54 +010064def get_winddk_paths(env, version, root):
65 version_major, version_minor = map(int, version.split('.'))
José Fonsecab215d7d2008-05-28 01:24:06 +090066
José Fonseca71793e0f2009-04-14 21:39:54 +010067 if version_major >= 6000:
68 target_os = 'wlh'
69 else:
70 target_os = 'wxp'
José Fonsecab215d7d2008-05-28 01:24:06 +090071
José Fonseca71793e0f2009-04-14 21:39:54 +010072 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"
José Fonsecab215d7d2008-05-28 01:24:06 +090078
José Fonseca71793e0f2009-04-14 21:39:54 +010079 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))
José Fonsecab215d7d2008-05-28 01:24:06 +090088
José Fonseca71793e0f2009-04-14 21:39:54 +010089 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)
José Fonsecab215d7d2008-05-28 01:24:06 +090098
José Fonsecad3f5a2e2009-09-01 10:17:39 +010099 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 ])
José Fonseca71793e0f2009-04-14 21:39:54 +0100125
José Fonsecab215d7d2008-05-28 01:24:06 +0900126
127def generate(env):
José Fonseca71793e0f2009-04-14 21:39:54 +0100128 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
José Fonsecab215d7d2008-05-28 01:24:06 +0900136
José Fonsecad3f5a2e2009-09-01 10:17:39 +0100137 if env['toolchain'] == 'winddk':
138 msvc_sa.generate(env)
139 mslib_sa.generate(env)
140 mslink_sa.generate(env)
José Fonsecab215d7d2008-05-28 01:24:06 +0900141
José Fonsecab215d7d2008-05-28 01:24:06 +0900142def exists(env):
José Fonseca71793e0f2009-04-14 21:39:54 +0100143 for version in versions:
144 if get_winddk_root(env, version) is not None:
145 return True
146 return False
José Fonsecab215d7d2008-05-28 01:24:06 +0900147
148# vim:set ts=4 sw=4 et: