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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
|
"""SCons.Defaults
Builders and other things for the local site. Here's where we'll
duplicate the functionality of autoconf until we move it into the
installation procedure or use something like qmconf.
The code that reads the registry to find MSVC components was borrowed
from distutils.msvccompiler.
"""
#
# Copyright (c) 2001 Steven Knight
#
# 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.
#
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
import os
import SCons.Action
import SCons.Builder
import SCons.Scanner.C
import SCons.Scanner.Prog
import string
import SCons.Errors
import SCons.Util
CFile = SCons.Builder.Builder(name = 'CFile',
action = { '.l' : '$LEXCOM',
'.y' : '$YACCCOM',
},
suffix = '.c')
CPlusPlusAction = SCons.Action.Action('$CXXCOM')
Object = SCons.Builder.Builder(name = 'Object',
action = { '.c' : '$CCCOM',
'.C' : CPlusPlusAction,
'.cc' : CPlusPlusAction,
'.cpp' : CPlusPlusAction,
'.cxx' : CPlusPlusAction,
'.c++' : CPlusPlusAction,
'.C++' : CPlusPlusAction,
},
prefix = '$OBJPREFIX',
suffix = '$OBJSUFFIX',
src_builder = CFile)
Program = SCons.Builder.Builder(name = 'Program',
action = '$LINKCOM',
prefix = '$PROGPREFIX',
suffix = '$PROGSUFFIX',
src_suffix = '$OBJSUFFIX',
src_builder = Object,
scanner = SCons.Scanner.Prog.ProgScan())
Library = SCons.Builder.Builder(name = 'Library',
action = '$ARCOM',
prefix = '$LIBPREFIX',
suffix = '$LIBSUFFIX',
src_suffix = '$OBJSUFFIX',
src_builder = Object)
CScan = SCons.Scanner.C.CScan()
def get_devstudio_versions ():
"""
Get list of devstudio versions from the Windows registry. Return a
list of strings containing version numbers; an exception will be raised
if we were unable to access the registry (eg. couldn't import
a registry-access module) or the appropriate registry keys weren't
found.
"""
if not SCons.Util.can_read_reg:
raise InternalError, "No Windows registry module was found"
K = 'Software\\Microsoft\\Devstudio'
L = []
for base in (SCons.Util.HKEY_CLASSES_ROOT,
SCons.Util.HKEY_LOCAL_MACHINE,
SCons.Util.HKEY_CURRENT_USER,
SCons.Util.HKEY_USERS):
try:
k = SCons.Util.RegOpenKeyEx(base,K)
i = 0
while 1:
try:
p = SCons.Util.RegEnumKey(k,i)
if p[0] in '123456789' and p not in L:
L.append(p)
except SCons.Util.RegError:
break
i = i + 1
except SCons.Util.RegError:
pass
if not L:
raise InternalError, "DevStudio was not found."
L.sort()
L.reverse()
return L
def get_msvc_path (path, version, platform='x86'):
"""
Get a list of devstudio directories (include, lib or path). Return
a string delimited by ';'. An exception will be raised if unable to
access the registry or appropriate registry keys not found.
"""
if not SCons.Util.can_read_reg:
raise InternalError, "No Windows registry module was found"
if path=='lib':
path= 'Library'
path = string.upper(path + ' Dirs')
K = ('Software\\Microsoft\\Devstudio\\%s\\' +
'Build System\\Components\\Platforms\\Win32 (%s)\\Directories') % \
(version,platform)
for base in (SCons.Util.HKEY_CLASSES_ROOT,
SCons.Util.HKEY_LOCAL_MACHINE,
SCons.Util.HKEY_CURRENT_USER,
SCons.Util.HKEY_USERS):
try:
k = SCons.Util.RegOpenKeyEx(base,K)
i = 0
while 1:
try:
(p,v,t) = SCons.Util.RegEnumValue(k,i)
if string.upper(p) == path:
return v
i = i + 1
except SCons.Util.RegError:
break
except SCons.Util.RegError:
pass
# if we got here, then we didn't find the registry entries:
raise InternalError, "%s was not found in the registry."%path
def make_win32_env_from_paths(include, lib, path):
"""
Build a dictionary of construction variables for a win32 platform.
include - include path
lib - library path
path - executable path
"""
return {
'CC' : 'cl',
'CCFLAGS' : '/nologo',
'CCCOM' : '$CC $CCFLAGS $_INCFLAGS /c $SOURCES /Fo$TARGET',
'CXX' : '$CC',
'CXXFLAGS' : '$CCFLAGS',
'CXXCOM' : '$CXX $CXXFLAGS $_INCFLAGS /c $SOURCES /Fo$TARGET',
'LINK' : 'link',
'LINKFLAGS' : '/nologo',
'LINKCOM' : '$LINK $LINKFLAGS /OUT:$TARGET $_LIBDIRFLAGS $_LIBFLAGS $SOURCES',
'AR' : 'lib',
'ARFLAGS' : '/nologo',
'ARCOM' : '$AR $ARFLAGS /OUT:$TARGET $SOURCES',
'LEX' : 'lex',
'LEXFLAGS' : '',
'LEXCOM' : '$LEX $LEXFLAGS -o$TARGET $SOURCES',
'YACC' : 'yacc',
'YACCFLAGS' : '',
'YACCCOM' : '$YACC $YACCFLAGS -o $TARGET $SOURCES',
'BUILDERS' : [CFile, Object, Program, Library],
'SCANNERS' : [CScan],
'OBJPREFIX' : '',
'OBJSUFFIX' : '.obj',
'PROGPREFIX' : '',
'PROGSUFFIX' : '.exe',
'LIBPREFIX' : '',
'LIBSUFFIX' : '.lib',
'LIBDIRPREFIX' : '/LIBPATH:',
'LIBDIRSUFFIX' : '',
'LIBLINKPREFIX' : '',
'LIBLINKSUFFIX' : '$LIBSUFFIX',
'INCPREFIX' : '/I',
'INCSUFFIX' : '',
'ENV' : {
'INCLUDE' : include,
'LIB' : lib,
'PATH' : path,
'PATHEXT' : '.COM;.EXE;.BAT;.CMD',
},
}
def make_win32_env(version):
"""
Build a dictionary of construction variables for a win32 platform.
ver - the version string of DevStudio to use (e.g. "6.0")
"""
return make_win32_env_from_paths(get_msvc_path("include", version),
get_msvc_path("lib", version),
get_msvc_path("path", version)
+ ";" + os.environ[PATH])
if os.name == 'posix':
ConstructionEnvironment = {
'CC' : 'cc',
'CCFLAGS' : '',
'CCCOM' : '$CC $CCFLAGS $_INCFLAGS -c -o $TARGET $SOURCES',
'CXX' : 'c++',
'CXXFLAGS' : '$CCFLAGS',
'CXXCOM' : '$CXX $CXXFLAGS $_INCFLAGS -c -o $TARGET $SOURCES',
'LINK' : '$CXX',
'LINKFLAGS' : '',
'LINKCOM' : '$LINK $LINKFLAGS -o $TARGET $SOURCES $_LIBDIRFLAGS $_LIBFLAGS',
'AR' : 'ar',
'ARFLAGS' : 'r',
'ARCOM' : '$AR $ARFLAGS $TARGET $SOURCES\nranlib $TARGET',
'LEX' : 'lex',
'LEXFLAGS' : '',
'LEXCOM' : '$LEX $LEXFLAGS -o$TARGET $SOURCES',
'YACC' : 'yacc',
'YACCFLAGS' : '',
'YACCCOM' : '$YACC $YACCFLAGS -o $TARGET $SOURCES',
'BUILDERS' : [CFile, Object, Program, Library],
'SCANNERS' : [CScan],
'OBJPREFIX' : '',
'OBJSUFFIX' : '.o',
'PROGPREFIX' : '',
'PROGSUFFIX' : '',
'LIBPREFIX' : 'lib',
'LIBSUFFIX' : '.a',
'LIBDIRPREFIX' : '-L',
'LIBDIRSUFFIX' : '',
'LIBLINKPREFIX' : '-l',
'LIBLINKSUFFIX' : '',
'INCPREFIX' : '-I',
'INCSUFFIX' : '',
'ENV' : { 'PATH' : '/usr/local/bin:/bin:/usr/bin' },
}
elif os.name == 'nt':
try:
versions = get_devstudio_versions()
ConstructionEnvironment = make_win32_env(versions[0]) #use highest version
except:
try:
# We failed to detect DevStudio, so fall back to the
# DevStudio environment variables:
ConstructionEnvironment = make_win32_env_from_paths(
os.environ["INCLUDE"], os.environ["LIB"], os.environ["PATH"])
except KeyError:
# The DevStudio environment variables don't exists,
# so fall back to a reasonable default:
MVSdir = r'C:\Program Files\Microsoft Visual Studio'
MVSVCdir = r'%s\VC98' % MVSdir
MVSCommondir = r'%s\Common' % MVSdir
ConstructionEnvironment = make_win32_env_from_paths(
r'%s\atl\include;%s\mfc\include;%s\include' % (MVSVCdir, MVSVCdir, MVSVCdir),
r'%s\mvc\lib;%s\lib' % (MVSVCdir, MVSVCdir),
(r'%s\MSDev98\Bin' % MVSCommondir) + os.pathsep + os.environ["PATH"])
|