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