summaryrefslogtreecommitdiffstats
path: root/scons/winddk.py
blob: 4dac16ee66eec067996ca45612472b1f630b31f5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
"""winddk

Tool-specific initialization for Microsoft Windows DDK.

"""

#
# Copyright (c) 2001-2007 The SCons Foundation
# Copyright (c) 2008 Tungsten Graphics, Inc.
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#

import os.path
import re
import string

import SCons.Action
import SCons.Builder
import SCons.Errors
import SCons.Platform.win32
import SCons.Tool
import SCons.Util
import SCons.Warnings

import msvc_sa
import mslib_sa
import mslink_sa

versions = [
    '6001.18002',
    '3790.1830',
]

def cpu_bin(target_cpu):
    if target_cpu == 'i386':
        return 'x86'
    else:
        return target_cpu

def get_winddk_root(env, version):
    default_path = os.path.join(r'C:\WINDDK', version)
    if os.path.exists(default_path):
        return default_path
    return None 

def get_winddk_paths(env, version, root):
    version_major, version_minor = map(int, version.split('.'))
    
    if version_major >= 6000:
        target_os = 'wlh'
    else:
        target_os = 'wxp'

    if env['machine'] in ('generic', 'x86'):
        target_cpu = 'i386'
    elif env['machine'] == 'x86_64':
        target_cpu = 'amd64'
    else:
        raise SCons.Errors.InternalError, "Unsupported target machine"

    if version_major >= 6000:
        # TODO: take in consideration the host cpu
        bin_dir = os.path.join(root, 'bin', 'x86', cpu_bin(target_cpu))
    else:
        if target_cpu == 'i386':
            bin_dir = os.path.join(root, 'bin', 'x86')
        else:
            # TODO: take in consideration the host cpu
            bin_dir = os.path.join(root, 'bin', 'win64', 'x86', cpu_bin(target_cpu))
    
    crt_inc_dir = os.path.join(root, 'inc', 'crt')
    if version_major >= 6000:
        sdk_inc_dir = os.path.join(root, 'inc', 'api')
        ddk_inc_dir = os.path.join(root, 'inc', 'ddk')
        wdm_inc_dir = os.path.join(root, 'inc', 'ddk')
    else:
        ddk_inc_dir = os.path.join(root, 'inc', 'ddk', target_os)
        sdk_inc_dir = os.path.join(root, 'inc', target_os)
        wdm_inc_dir = os.path.join(root, 'inc', 'ddk', 'wdm', target_os)

    if env['toolchain'] == 'winddk':
        env.PrependENVPath('PATH', [bin_dir])
        env.PrependENVPath('INCLUDE', [
            wdm_inc_dir,
            ddk_inc_dir,
            crt_inc_dir,
            sdk_inc_dir,
        ])
        env.PrependENVPath('LIB', [
            os.path.join(root, 'lib', 'crt', target_cpu),
            os.path.join(root, 'lib', target_os, target_cpu),
        ])
    elif env['toolchain'] == 'crossmingw':
        env.Prepend(CPPFLAGS = [
            '-isystem', ddk_inc_dir,
            '-isystem', sdk_inc_dir,
        ])
    else:
        env.Prepend(CPPPATH = [
            wdm_inc_dir,
            ddk_inc_dir,
            sdk_inc_dir,
        ])
        env.Prepend(LIBPATH = [
            os.path.join(root, 'lib', target_os, target_cpu),
        ])


def generate(env):
    if not env.has_key('ENV'):
        env['ENV'] = {}

    for version in versions:
        root = get_winddk_root(env, version)
        if root is not None:
            get_winddk_paths(env, version, root)
            break

    if env['toolchain'] == 'winddk':
        msvc_sa.generate(env)
        mslib_sa.generate(env)
        mslink_sa.generate(env)

def exists(env):
    for version in versions:
        if get_winddk_root(env, version) is not None:
            return True
    return False

# vim:set ts=4 sw=4 et: