]> git.cworth.org Git - apitrace/blob - SConstruct
Match GL specs.
[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 import time
31
32 _platform_map = {
33     'freebsd': 'freebsd',
34     'linux2': 'linux',
35     'win32': 'windows',
36 }
37
38 default_platform = _platform_map.get(sys.platform, 'unix')
39
40 _machine_map = {
41     'x86': 'x86',
42     'i386': 'x86',
43     'i486': 'x86',
44     'i586': 'x86',
45     'i686': 'x86',
46     'ppc' : 'ppc',
47     'x86_64': 'x86_64',
48 }
49 if 'PROCESSOR_ARCHITECTURE' in os.environ:
50     default_machine = os.environ['PROCESSOR_ARCHITECTURE']
51 else:
52     default_machine = platform.machine()
53 default_machine = _machine_map.get(default_machine, 'generic')
54
55 vars = Variables()
56 vars.Add(BoolVariable('debug', 'debug build', 'no'))
57 vars.Add(EnumVariable('platform', 'target platform', default_platform,
58                       allowed_values=('linux', 'freebsd', 'unix', 'other', 'windows')))
59 vars.Add(EnumVariable('machine', 'use machine-specific assembly code', default_machine,
60                       allowed_values=('generic', 'ppc', 'x86', 'x86_64')))
61 vars.Add(EnumVariable('toolchain', 'compiler toolchain', 'default',
62                       allowed_values=('default', 'crossmingw', 'winsdk')))
63 vars.Add(EnumVariable('MSVS_VERSION', 'Microsoft Visual Studio version', None, allowed_values=('7.1', '8.0', '9.0')))
64
65 env = Environment(
66     variables = vars, 
67     ENV = os.environ)
68 Help(vars.GenerateHelpText(env))
69
70 Export(['env'])
71
72 env.Tool(env['toolchain'])
73
74 env['gcc'] = 'gcc' in os.path.basename(env['CC']).split('-')
75 env['msvc'] = env['CC'] == 'cl'
76
77 # C preprocessor options
78 cppdefines = []
79 if not env['debug']:
80     cppdefines += ['NDEBUG']
81 if env['platform'] == 'windows':
82     cppdefines += [
83         'WIN32',
84         '_WINDOWS', 
85         '_UNICODE',
86         'UNICODE',
87         '_CRT_SECURE_NO_DEPRECATE',
88         '_CRT_NON_CONFORMING_SWPRINTFS',
89         'WIN32_LEAN_AND_MEAN',
90         '_USRDLL',
91         ('_WIN32_WINNT', '0x0501'), # minimum required OS version
92     ]
93     if env['debug']:
94         cppdefines += ['_DEBUG']
95 env.Append(CPPDEFINES = cppdefines)
96
97 # C compiler options
98 cflags = [] # C
99 cxxflags = [] # C++
100 ccflags = [] # C & C++
101 if env['gcc']:
102     if env['debug']:
103         ccflags += ['-O0', '-g3']
104     else:
105         ccflags += ['-O3', '-g0']
106     if env['machine'] == 'x86':
107         ccflags += ['-m32']
108     if env['machine'] == 'x86_64':
109         ccflags += ['-m64']
110     # See also:
111     # - http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html
112     ccflags += [
113         '-Werror=declaration-after-statement',
114         '-Wall',
115         '-Wmissing-field-initializers',
116         '-Wpointer-arith',
117         '-fmessage-length=0', # be nice to Eclipse
118     ]
119     cflags += [
120         '-Wmissing-prototypes',
121     ]
122 if env['msvc']:
123     if env['debug']:
124         ccflags += [
125           '/Od', # disable optimizations
126           '/Oi', # enable intrinsic functions
127           '/Oy-', # disable frame pointer omission
128           '/GL-', # disable whole program optimization
129         ]
130     else:
131         ccflags += [
132           '/Ox', # maximum optimizations
133           '/Oi', # enable intrinsic functions
134           '/Ot', # favor code speed
135         ]
136     ccflags += [
137         '/EHsc', # set exception handling model
138         '/W4', # warning level
139         #'/Wp64', # enable 64 bit porting warnings
140     ]
141     # Automatic pdb generation
142     # See http://scons.tigris.org/issues/show_bug.cgi?id=1656
143     env.EnsureSConsVersion(0, 98, 0)
144     env['PDB'] = '${TARGET.base}.pdb'
145 env.Append(CCFLAGS = ccflags)
146 env.Append(CFLAGS = cflags)
147 env.Append(CXXFLAGS = cxxflags)
148
149 if env['platform'] == 'windows' and env['msvc']:
150     # Choose the appropriate MSVC CRT
151     # http://msdn.microsoft.com/en-us/library/2kzt1wy3.aspx
152     if env['debug']:
153         env.Append(CCFLAGS = ['/MTd'])
154         env.Append(SHCCFLAGS = ['/LDd'])
155     else:
156         env.Append(CCFLAGS = ['/MT'])
157         env.Append(SHCCFLAGS = ['/LD'])
158     
159 # Assembler options
160 if env['gcc']:
161     if env['machine'] == 'x86':
162         env.Append(ASFLAGS = ['-m32'])
163     if env['machine'] == 'x86_64':
164         env.Append(ASFLAGS = ['-m64'])
165
166 # Linker options
167 linkflags = []
168 if env['gcc']:
169     if env['machine'] == 'x86':
170         linkflags += ['-m32']
171     if env['machine'] == 'x86_64':
172         linkflags += ['-m64']
173 if env['platform'] == 'windows' and env['msvc']:
174     # See also:
175     # - http://msdn2.microsoft.com/en-us/library/y0zzbyt4.aspx
176     linkflags += [
177         '/fixed:no',
178         '/incremental:no',
179     ]
180 env.Append(LINKFLAGS = linkflags)
181
182 env.Prepend(LIBS = [
183     'kernel32',
184     'user32',
185     'gdi32',
186 ])
187
188 SConscript('zlib/SConscript')
189
190 env.Tool('dxsdk')
191
192 conf = Configure(env)
193 has_d3d7 = conf.CheckCXXHeader('ddraw.h')
194 has_d3d8 = conf.CheckCXXHeader('d3d8.h')
195 has_d3d9 = conf.CheckCXXHeader('d3d9.h')
196 if env['toolchain'] != 'crossmingw':
197     has_d3d10 = conf.CheckCXXHeader('d3d10.h')
198     has_d3d10_1 = conf.CheckCXXHeader('d3d10_1.h')
199 else:
200     # The above checks do not give reliable results for MinGW
201     has_d3d10 = True
202     has_d3d10_1 = True
203 env = conf.Finish()
204
205 if has_d3d7 and False:
206     env.Command(
207         target = 'ddraw.cpp', 
208         source = ['ddraw.py', 'd3d.py', 'd3dtypes.py', 'd3dcaps.py', 'windows.py', 'base.py'],
209         action = 'python $SOURCE > $TARGET',
210     )
211         
212     ddraw = env.SharedLibrary(
213         target = 'ddraw',
214         source = [
215             'ddraw.def',
216             'ddraw.cpp',
217             'log.cpp',
218             'os_win32.cpp',
219         ]
220     )
221
222     env.Default(ddraw)
223
224 if has_d3d8:
225     env.Command(
226         target = 'd3d8.cpp', 
227         source = ['d3d8.py', 'd3d8types.py', 'd3d8caps.py', 'windows.py', 'base.py'],
228         action = 'python $SOURCE > $TARGET',
229     )
230         
231     d3d8 = env.SharedLibrary(
232         target = 'd3d8',
233         source = [
234             'd3d8.def',
235             'd3d8.cpp',
236             'log.cpp',
237             'os_win32.cpp',
238         ]
239     )
240
241     env.Default(d3d8)
242
243 if has_d3d9:
244     env.Command(
245         target = 'd3d9.cpp', 
246         source = ['d3d9.py', 'd3d9types.py', 'd3d9caps.py', 'd3dshader.py', 'windows.py', 'base.py'],
247         action = 'python $SOURCE > $TARGET',
248     )
249         
250     d3d9 = env.SharedLibrary(
251         target = 'd3d9',
252         source = [
253             'd3d9.def',
254             'd3d9.cpp',
255             'log.cpp',
256             'os_win32.cpp',
257         ]
258     )
259
260     env.Default(d3d9)
261
262 if has_d3d10:
263     env.Command(
264         target = 'd3d10.cpp', 
265         source = ['d3d10misc.py', 'windows.py', 'base.py'],
266         action = 'python $SOURCE > $TARGET',
267     )
268         
269     d3d10 = env.SharedLibrary(
270         target = 'd3d10',
271         source = [
272             'd3d10.def',
273             'd3d10.cpp',
274             'log.cpp',
275             'os_win32.cpp',
276         ]
277     )
278
279     env.Default(d3d10)
280
281 if has_d3d10_1:
282     env.Command(
283         target = 'd3d10_1.cpp', 
284         source = ['d3d10_1.py', 'windows.py', 'base.py'],
285         action = 'python $SOURCE > $TARGET',
286     )
287         
288     d3d10_1 = env.SharedLibrary(
289         target = 'd3d10_1',
290         source = [
291             'd3d10_1.def',
292             'd3d10_1.cpp',
293             'log.cpp',
294             'os_win32.cpp',
295         ]
296     )
297
298     env.Default(d3d10_1)
299
300 env.Command(
301     target = 'opengl32.cpp', 
302     source = ['opengl32.py', 'gl.py', 'windows.py', 'base.py'],
303     action = 'python $SOURCE > $TARGET',
304 )
305     
306 opengl32 = env.SharedLibrary(
307     target = 'opengl32',
308     source = [
309         'opengl32.def',
310         'opengl32.cpp',
311         'log.cpp',
312         'os_win32.cpp',
313     ]
314 )
315
316 env.Default(opengl32)
317
318 env.Tool('packaging')
319
320 zip = env.Package(
321     NAME           = 'apitrace',
322     VERSION        = time.strftime('%Y%m%d'),
323     PACKAGEVERSION = 0,
324     PACKAGETYPE    = 'zip',
325     LICENSE        = 'lgpl',
326     SUMMARY        = 'Tool to trace Direct3D & OpenGL API calls from applications.',
327     SOURCE_URL     = 'http://code.google.com/p/jrfonseca/source/browse?repo=apitrace',
328     source = [
329         'README',
330         'd3d8.dll',
331         'd3d9.dll',
332         'opengl32.dll',
333         'apitrace.xsl',
334         'xml2txt.py',
335     ],
336 )
337
338 env.Alias('dist', zip)