]> git.cworth.org Git - apitrace/blob - SConstruct
Pass-through TAB and CR characters.
[apitrace] / SConstruct
1 #############################################################################
2 #
3 # Copyright 2008-2009 VMware, Inc.
4 # All Rights Reserved.
5
6 # Permission is hereby granted, free of charge, to any person obtaining a copy
7 # of this software and associated documentation files (the "Software"), to deal
8 # in the Software without restriction, including without limitation the rights
9 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 # copies of the Software, and to permit persons to whom the Software is
11 # furnished to do so, subject to the following conditions:
12
13 # The above copyright notice and this permission notice shall be included in
14 # all copies or substantial portions of the Software.
15
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 # THE SOFTWARE.
23 #
24 #############################################################################
25
26 import os
27 import os.path
28 import platform
29 import sys
30
31 _platform_map = {
32     'freebsd': 'freebsd',
33     'linux2': 'linux',
34     'win32': 'windows',
35 }
36
37 default_platform = _platform_map.get(sys.platform, 'unix')
38
39 _machine_map = {
40     'x86': 'x86',
41     'i386': 'x86',
42     'i486': 'x86',
43     'i586': 'x86',
44     'i686': 'x86',
45     'ppc' : 'ppc',
46     'x86_64': 'x86_64',
47 }
48 if 'PROCESSOR_ARCHITECTURE' in os.environ:
49     default_machine = os.environ['PROCESSOR_ARCHITECTURE']
50 else:
51     default_machine = platform.machine()
52 default_machine = _machine_map.get(default_machine, 'generic')
53
54 vars = Variables()
55 vars.Add(BoolVariable('debug', 'debug build', 'no'))
56 vars.Add(EnumVariable('platform', 'target platform', default_platform,
57                       allowed_values=('linux', 'freebsd', 'unix', 'other', 'windows')))
58 vars.Add(EnumVariable('machine', 'use machine-specific assembly code', default_machine,
59                       allowed_values=('generic', 'ppc', 'x86', 'x86_64')))
60 vars.Add(EnumVariable('toolchain', 'compiler toolchain', 'default',
61                       allowed_values=('default', 'crossmingw', 'winsdk')))
62 vars.Add(EnumVariable('MSVS_VERSION', 'Microsoft Visual Studio version', None, allowed_values=('7.1', '8.0', '9.0')))
63
64 env = Environment(
65     variables = vars, 
66     ENV = os.environ)
67 Help(vars.GenerateHelpText(env))
68
69 Export(['env'])
70
71 env.Tool(env['toolchain'], toolpath = ['scons'])
72
73 env['gcc'] = 'gcc' in os.path.basename(env['CC']).split('-')
74 env['msvc'] = env['CC'] == 'cl'
75
76 # C preprocessor options
77 cppdefines = []
78 if not env['debug']:
79     cppdefines += ['NDEBUG']
80 if env['platform'] == 'windows':
81     cppdefines += [
82         'WIN32',
83         '_WINDOWS', 
84         '_UNICODE',
85         'UNICODE',
86         '_CRT_SECURE_NO_DEPRECATE',
87         '_CRT_NON_CONFORMING_SWPRINTFS',
88         'WIN32_LEAN_AND_MEAN',
89         '_USRDLL',
90         ('_WIN32_WINNT', '0x0501'), # minimum required OS version
91     ]
92     if env['debug']:
93         cppdefines += ['_DEBUG']
94 env.Append(CPPDEFINES = cppdefines)
95
96 # C compiler options
97 cflags = [] # C
98 cxxflags = [] # C++
99 ccflags = [] # C & C++
100 if env['gcc']:
101     if env['debug']:
102         ccflags += ['-O0', '-g3']
103     else:
104         ccflags += ['-O3', '-g0']
105     if env['machine'] == 'x86':
106         ccflags += ['-m32']
107     if env['machine'] == 'x86_64':
108         ccflags += ['-m64']
109     # See also:
110     # - http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html
111     ccflags += [
112         '-Werror=declaration-after-statement',
113         '-Wall',
114         '-Wmissing-field-initializers',
115         '-Wpointer-arith',
116         '-fmessage-length=0', # be nice to Eclipse
117     ]
118     cflags += [
119         '-Wmissing-prototypes',
120     ]
121 if env['msvc']:
122     if env['debug']:
123         ccflags += [
124           '/Od', # disable optimizations
125           '/Oi', # enable intrinsic functions
126           '/Oy-', # disable frame pointer omission
127           '/GL-', # disable whole program optimization
128         ]
129     else:
130         ccflags += [
131           '/Ox', # maximum optimizations
132           '/Oi', # enable intrinsic functions
133           '/Ot', # favor code speed
134         ]
135     ccflags += [
136         '/EHsc', # set exception handling model
137         '/W4', # warning level
138         #'/Wp64', # enable 64 bit porting warnings
139     ]
140     # Automatic pdb generation
141     # See http://scons.tigris.org/issues/show_bug.cgi?id=1656
142     env.EnsureSConsVersion(0, 98, 0)
143     env['PDB'] = '${TARGET.base}.pdb'
144 env.Append(CCFLAGS = ccflags)
145 env.Append(CFLAGS = cflags)
146 env.Append(CXXFLAGS = cxxflags)
147
148 if env['platform'] == 'windows' and env['msvc']:
149     # Choose the appropriate MSVC CRT
150     # http://msdn.microsoft.com/en-us/library/2kzt1wy3.aspx
151     if env['debug']:
152         env.Append(CCFLAGS = ['/MTd'])
153         env.Append(SHCCFLAGS = ['/LDd'])
154     else:
155         env.Append(CCFLAGS = ['/MT'])
156         env.Append(SHCCFLAGS = ['/LD'])
157     
158 # Assembler options
159 if env['gcc']:
160     if env['machine'] == 'x86':
161         env.Append(ASFLAGS = ['-m32'])
162     if env['machine'] == 'x86_64':
163         env.Append(ASFLAGS = ['-m64'])
164
165 # Linker options
166 linkflags = []
167 if env['gcc']:
168     if env['machine'] == 'x86':
169         linkflags += ['-m32']
170     if env['machine'] == 'x86_64':
171         linkflags += ['-m64']
172 if env['platform'] == 'windows' and env['msvc']:
173     # See also:
174     # - http://msdn2.microsoft.com/en-us/library/y0zzbyt4.aspx
175     linkflags += [
176         '/fixed:no',
177         '/incremental:no',
178     ]
179 env.Append(LINKFLAGS = linkflags)
180
181 env.Prepend(LIBS = [
182     'kernel32',
183     'user32',
184     'gdi32',
185 ])
186
187 SConscript('zlib/SConscript')
188
189 env.Tool('dxsdk', toolpath = ['scons'])
190
191 conf = Configure(env)
192 has_d3d7 = conf.CheckCXXHeader('ddraw.h')
193 has_d3d8 = conf.CheckCXXHeader('d3d8.h')
194 has_d3d9 = conf.CheckCXXHeader('d3d9.h')
195 if env['toolchain'] != 'crossmingw':
196     has_d3d10 = conf.CheckCXXHeader('d3d10.h')
197     has_d3d10_1 = conf.CheckCXXHeader('d3d10_1.h')
198 else:
199     # The above checks do not give reliable results for MinGW
200     has_d3d10 = True
201     has_d3d10_1 = True
202 env = conf.Finish()
203
204 if has_d3d7 and False:
205     env.Command(
206         target = 'ddraw.cpp', 
207         source = ['ddraw.py', 'd3d.py', 'd3dtypes.py', 'd3dcaps.py', 'windows.py', 'base.py'],
208         action = 'python $SOURCE > $TARGET',
209     )
210         
211     ddraw = env.SharedLibrary(
212         target = 'ddraw',
213         source = [
214             'ddraw.def',
215             'ddraw.cpp',
216             'log.cpp',
217         ]
218     )
219
220     env.Default(ddraw)
221
222 if has_d3d8:
223     env.Command(
224         target = 'd3d8.cpp', 
225         source = ['d3d8.py', 'd3d8types.py', 'd3d8caps.py', 'windows.py', 'base.py'],
226         action = 'python $SOURCE > $TARGET',
227     )
228         
229     d3d8 = env.SharedLibrary(
230         target = 'd3d8',
231         source = [
232             'd3d8.def',
233             'd3d8.cpp',
234             'log.cpp',
235         ]
236     )
237
238     env.Default(d3d8)
239
240 if has_d3d9:
241     env.Command(
242         target = 'd3d9.cpp', 
243         source = ['d3d9.py', 'd3d9types.py', 'd3d9caps.py', 'd3dshader.py', 'windows.py', 'base.py'],
244         action = 'python $SOURCE > $TARGET',
245     )
246         
247     d3d9 = env.SharedLibrary(
248         target = 'd3d9',
249         source = [
250             'd3d9.def',
251             'd3d9.cpp',
252             'log.cpp',
253         ]
254     )
255
256     env.Default(d3d9)
257
258 if has_d3d10:
259     env.Command(
260         target = 'd3d10.cpp', 
261         source = ['d3d10misc.py', 'windows.py', 'base.py'],
262         action = 'python $SOURCE > $TARGET',
263     )
264         
265     d3d10 = env.SharedLibrary(
266         target = 'd3d10',
267         source = [
268             'd3d10.def',
269             'd3d10.cpp',
270             'log.cpp',
271         ]
272     )
273
274     env.Default(d3d10)
275
276 if has_d3d10_1:
277     env.Command(
278         target = 'd3d10_1.cpp', 
279         source = ['d3d10_1.py', 'windows.py', 'base.py'],
280         action = 'python $SOURCE > $TARGET',
281     )
282         
283     d3d10_1 = env.SharedLibrary(
284         target = 'd3d10_1',
285         source = [
286             'd3d10_1.def',
287             'd3d10_1.cpp',
288             'log.cpp',
289         ]
290     )
291
292     env.Default(d3d10_1)
293
294 env.Command(
295     target = 'opengl32.cpp', 
296     source = ['opengl32.py', 'gl.py', 'windows.py', 'base.py'],
297     action = 'python $SOURCE > $TARGET',
298 )
299     
300 opengl32 = env.SharedLibrary(
301     target = 'opengl32',
302     source = [
303         'opengl32.def',
304         'opengl32.cpp',
305         'log.cpp',
306     ]
307 )
308
309 env.Default(opengl32)
310
311 env.Tool('packaging')
312
313 zip = env.Package(
314     NAME           = 'apitrace',
315     VERSION        = '0.3',
316     PACKAGEVERSION = 0,
317     PACKAGETYPE    = 'zip',
318     LICENSE        = 'lgpl',
319     SUMMARY        = 'Tool to trace Direct3D & OpenGL API calls from applications.',
320     SOURCE_URL     = 'http://code.google.com/p/jrfonseca/source/browse?repo=apitrace',
321     source = [
322         'README',
323         'd3d8.dll',
324         'd3d9.dll',
325         'opengl32.dll',
326         'apitrace.xsl',
327         'xml2txt.py',
328     ],
329 )
330
331 env.Alias('zip', zip)