]> git.cworth.org Git - apitrace/blob - scons/scons/msvc_sa.py
Trace WGL_ARB_pbuffer calls.
[apitrace] / scons / scons / msvc_sa.py
1 """msvc_sa
2
3 Tool-specific initialization for Microsoft Visual C/C++.
4
5 Based on SCons.Tool.msvc, without the MSVS detection.
6
7 """
8
9 #
10 # Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 The SCons Foundation
11 #
12 # Permission is hereby granted, free of charge, to any person obtaining
13 # a copy of this software and associated documentation files (the
14 # "Software"), to deal in the Software without restriction, including
15 # without limitation the rights to use, copy, modify, merge, publish,
16 # distribute, sublicense, and/or sell copies of the Software, and to
17 # permit persons to whom the Software is furnished to do so, subject to
18 # the following conditions:
19 #
20 # The above copyright notice and this permission notice shall be included
21 # in all copies or substantial portions of the Software.
22 #
23 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
24 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
25 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 #
31
32 import os.path
33 import re
34 import string
35
36 import SCons.Action
37 import SCons.Builder
38 import SCons.Errors
39 import SCons.Platform.win32
40 import SCons.Tool
41 import SCons.Util
42 import SCons.Warnings
43
44 CSuffixes = ['.c', '.C']
45 CXXSuffixes = ['.cc', '.cpp', '.cxx', '.c++', '.C++']
46
47 def validate_vars(env):
48     """Validate the PCH and PCHSTOP construction variables."""
49     if env.has_key('PCH') and env['PCH']:
50         if not env.has_key('PCHSTOP'):
51             raise SCons.Errors.UserError, "The PCHSTOP construction must be defined if PCH is defined."
52         if not SCons.Util.is_String(env['PCHSTOP']):
53             raise SCons.Errors.UserError, "The PCHSTOP construction variable must be a string: %r"%env['PCHSTOP']
54
55 def pch_emitter(target, source, env):
56     """Adds the object file target."""
57
58     validate_vars(env)
59
60     pch = None
61     obj = None
62
63     for t in target:
64         if SCons.Util.splitext(str(t))[1] == '.pch':
65             pch = t
66         if SCons.Util.splitext(str(t))[1] == '.obj':
67             obj = t
68
69     if not obj:
70         obj = SCons.Util.splitext(str(pch))[0]+'.obj'
71
72     target = [pch, obj] # pch must be first, and obj second for the PCHCOM to work
73
74     return (target, source)
75
76 def object_emitter(target, source, env, parent_emitter):
77     """Sets up the PCH dependencies for an object file."""
78
79     validate_vars(env)
80
81     parent_emitter(target, source, env)
82
83     if env.has_key('PCH') and env['PCH']:
84         env.Depends(target, env['PCH'])
85
86     return (target, source)
87
88 def static_object_emitter(target, source, env):
89     return object_emitter(target, source, env,
90                           SCons.Defaults.StaticObjectEmitter)
91
92 def shared_object_emitter(target, source, env):
93     return object_emitter(target, source, env,
94                           SCons.Defaults.SharedObjectEmitter)
95
96 pch_action = SCons.Action.Action('$PCHCOM', '$PCHCOMSTR')
97 pch_builder = SCons.Builder.Builder(action=pch_action, suffix='.pch',
98                                     emitter=pch_emitter,
99                                     source_scanner=SCons.Tool.SourceFileScanner)
100 res_action = SCons.Action.Action('$RCCOM', '$RCCOMSTR')
101 res_builder = SCons.Builder.Builder(action=res_action,
102                                     src_suffix='.rc',
103                                     suffix='.res',
104                                     src_builder=[],
105                                     source_scanner=SCons.Tool.SourceFileScanner)
106 SCons.Tool.SourceFileScanner.add_scanner('.rc', SCons.Defaults.CScan)
107
108 def generate(env):
109     """Add Builders and construction variables for MSVC++ to an Environment."""
110     static_obj, shared_obj = SCons.Tool.createObjBuilders(env)
111
112     for suffix in CSuffixes:
113         static_obj.add_action(suffix, SCons.Defaults.CAction)
114         shared_obj.add_action(suffix, SCons.Defaults.ShCAction)
115         static_obj.add_emitter(suffix, static_object_emitter)
116         shared_obj.add_emitter(suffix, shared_object_emitter)
117
118     for suffix in CXXSuffixes:
119         static_obj.add_action(suffix, SCons.Defaults.CXXAction)
120         shared_obj.add_action(suffix, SCons.Defaults.ShCXXAction)
121         static_obj.add_emitter(suffix, static_object_emitter)
122         shared_obj.add_emitter(suffix, shared_object_emitter)
123
124     env['CCPDBFLAGS'] = SCons.Util.CLVar(['${(PDB and "/Z7") or ""}'])
125     env['CCPCHFLAGS'] = SCons.Util.CLVar(['${(PCH and "/Yu%s /Fp%s"%(PCHSTOP or "",File(PCH))) or ""}'])
126     env['CCCOMFLAGS'] = '$CPPFLAGS $_CPPDEFFLAGS $_CPPINCFLAGS /c $SOURCES /Fo$TARGET $CCPCHFLAGS $CCPDBFLAGS'
127     env['CC']         = 'cl'
128     env['CCFLAGS']    = SCons.Util.CLVar('/nologo')
129     env['CFLAGS']     = SCons.Util.CLVar('')
130     env['CCCOM']      = '$CC $CFLAGS $CCFLAGS $CCCOMFLAGS'
131     env['SHCC']       = '$CC'
132     env['SHCCFLAGS']  = SCons.Util.CLVar('$CCFLAGS')
133     env['SHCFLAGS']   = SCons.Util.CLVar('$CFLAGS')
134     env['SHCCCOM']    = '$SHCC $SHCFLAGS $SHCCFLAGS $CCCOMFLAGS'
135     env['CXX']        = '$CC'
136     env['CXXFLAGS']   = SCons.Util.CLVar('$CCFLAGS $( /TP $)')
137     env['CXXCOM']     = '$CXX $CXXFLAGS $CCCOMFLAGS'
138     env['SHCXX']      = '$CXX'
139     env['SHCXXFLAGS'] = SCons.Util.CLVar('$CXXFLAGS')
140     env['SHCXXCOM']   = '$SHCXX $SHCXXFLAGS $CCCOMFLAGS'
141     env['CPPDEFPREFIX']  = '/D'
142     env['CPPDEFSUFFIX']  = ''
143     env['INCPREFIX']  = '/I'
144     env['INCSUFFIX']  = ''
145 #    env.Append(OBJEMITTER = [static_object_emitter])
146 #    env.Append(SHOBJEMITTER = [shared_object_emitter])
147     env['STATIC_AND_SHARED_OBJECTS_ARE_THE_SAME'] = 1
148
149     env['RC'] = 'rc'
150     env['RCFLAGS'] = SCons.Util.CLVar('')
151     env['RCCOM'] = '$RC $_CPPDEFFLAGS $_CPPINCFLAGS $RCFLAGS /fo$TARGET $SOURCES'
152     env['BUILDERS']['RES'] = res_builder
153     env['OBJPREFIX']      = ''
154     env['OBJSUFFIX']      = '.obj'
155     env['SHOBJPREFIX']    = '$OBJPREFIX'
156     env['SHOBJSUFFIX']    = '$OBJSUFFIX'
157
158     env['CFILESUFFIX'] = '.c'
159     env['CXXFILESUFFIX'] = '.cc'
160
161     env['PCHPDBFLAGS'] = SCons.Util.CLVar(['${(PDB and "/Yd") or ""}'])
162     env['PCHCOM'] = '$CXX $CXXFLAGS $CPPFLAGS $_CPPDEFFLAGS $_CPPINCFLAGS /c $SOURCES /Fo${TARGETS[1]} /Yc$PCHSTOP /Fp${TARGETS[0]} $CCPDBFLAGS $PCHPDBFLAGS'
163     env['BUILDERS']['PCH'] = pch_builder
164
165     if not env.has_key('ENV'):
166         env['ENV'] = {}
167     if not env['ENV'].has_key('SystemRoot'):    # required for dlls in the winsxs folders
168         env['ENV']['SystemRoot'] = SCons.Platform.win32.get_system_root()
169
170 def exists(env):
171     return env.Detect('cl')
172
173 # vim:set ts=4 sw=4 et: