]> git.cworth.org Git - apitrace/blob - SConstruct
Handle const wide strings correctly.
[apitrace] / SConstruct
1 #############################################################################
2 #
3 # Copyright 2008 Tungsten Graphics, 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(PathVariable('dxsdk', 'DirectX SDK installation dir', os.environ.get('DXSDK_DIR', 'C:\\DXSDK')))
57 vars.Add(EnumVariable('MSVS_VERSION', 'Microsoft Visual Studio version', None, allowed_values=('7.1', '8.0', '9.0')))
58
59 env = Environment(
60     variables = vars, 
61     ENV = os.environ)
62 Help(vars.GenerateHelpText(env))
63
64 Export(['env'])
65
66 env.Tool(env['toolchain'], ['scons'])
67
68 env['gcc'] = 'gcc' in os.path.basename(env['CC']).split('-')
69 env['msvc'] = env['CC'] == 'cl'
70
71 # C preprocessor options
72 cppdefines = []
73 if not env['debug']:
74     cppdefines += ['NDEBUG']
75 if env['platform'] == 'windows':
76     cppdefines += [
77         'WIN32',
78         '_WINDOWS', 
79         '_UNICODE',
80         'UNICODE',
81         '_CRT_SECURE_NO_DEPRECATE',
82         '_CRT_NON_CONFORMING_SWPRINTFS',
83         'WIN32_LEAN_AND_MEAN',
84         '_USRDLL',
85         ('_WIN32_WINNT', '0x0501'), # minimum required OS version
86     ]
87     if env['debug']:
88         cppdefines += ['_DEBUG']
89 env.Append(CPPDEFINES = cppdefines)
90
91 # C compiler options
92 cflags = [] # C
93 cxxflags = [] # C++
94 ccflags = [] # C & C++
95 if env['gcc']:
96     if env['debug']:
97         ccflags += ['-O0', '-g3']
98     else:
99         ccflags += ['-O3', '-g0']
100     if env['machine'] == 'x86':
101         ccflags += ['-m32']
102     if env['machine'] == 'x86_64':
103         ccflags += ['-m64']
104     # See also:
105     # - http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html
106     ccflags += [
107         '-Werror=declaration-after-statement',
108         '-Wall',
109         '-Wmissing-field-initializers',
110         '-Wpointer-arith',
111         '-fmessage-length=0', # be nice to Eclipse
112     ]
113     cflags += [
114         '-Wmissing-prototypes',
115     ]
116 if env['msvc']:
117     if env['debug']:
118         ccflags += [
119           '/Od', # disable optimizations
120           '/Oi', # enable intrinsic functions
121           '/Oy-', # disable frame pointer omission
122           '/GL-', # disable whole program optimization
123         ]
124     else:
125         ccflags += [
126           '/Ox', # maximum optimizations
127           '/Oi', # enable intrinsic functions
128           '/Ot', # favor code speed
129         ]
130     ccflags += [
131         '/EHsc', # set exception handling model
132         '/W4', # warning level
133         #'/Wp64', # enable 64 bit porting warnings
134     ]
135     # Automatic pdb generation
136     # See http://scons.tigris.org/issues/show_bug.cgi?id=1656
137     env.EnsureSConsVersion(0, 98, 0)
138     env['PDB'] = '${TARGET.base}.pdb'
139 env.Append(CCFLAGS = ccflags)
140 env.Append(CFLAGS = cflags)
141 env.Append(CXXFLAGS = cxxflags)
142
143 if env['platform'] == 'windows' and env['msvc']:
144     # Choose the appropriate MSVC CRT
145     # http://msdn.microsoft.com/en-us/library/2kzt1wy3.aspx
146     if env['debug']:
147         env.Append(CCFLAGS = ['/MTd'])
148         env.Append(SHCCFLAGS = ['/LDd'])
149     else:
150         env.Append(CCFLAGS = ['/MT'])
151         env.Append(SHCCFLAGS = ['/LD'])
152     
153 # Assembler options
154 if env['gcc']:
155     if env['machine'] == 'x86':
156         env.Append(ASFLAGS = ['-m32'])
157     if env['machine'] == 'x86_64':
158         env.Append(ASFLAGS = ['-m64'])
159
160 # Linker options
161 linkflags = []
162 if env['gcc']:
163     if env['machine'] == 'x86':
164         linkflags += ['-m32']
165     if env['machine'] == 'x86_64':
166         linkflags += ['-m64']
167 if env['platform'] == 'windows' and env['msvc']:
168     # See also:
169     # - http://msdn2.microsoft.com/en-us/library/y0zzbyt4.aspx
170     linkflags += [
171         '/fixed:no',
172         '/incremental:no',
173     ]
174 env.Append(LINKFLAGS = linkflags)
175
176 env.Prepend(LIBS = [
177     'kernel32',
178     'user32',
179     'gdi32',
180 ])
181
182 SConscript('zlib/SConscript')
183
184 try:
185     env.Append(CPPPATH = [os.path.join(os.environ['DXSDK'], 'Include'),]) 
186 except KeyError:
187     pass
188
189 conf = Configure(env)
190 has_d3d9 = conf.CheckCHeader('d3d9.h')
191 has_d3d8 = conf.CheckCHeader('d3d8.h')
192 has_d3d7 = conf.CheckCHeader('ddraw.h')
193 env = conf.Finish()
194
195 if has_d3d7:
196     env.Command(
197         target = 'ddraw.cpp', 
198         source = ['ddraw.py', 'd3d.py', 'd3dtypes.py', 'd3dcaps.py', 'windows.py', 'base.py'],
199         action = 'python $SOURCE > $TARGET',
200     )
201         
202     ddraw = env.SharedLibrary(
203         target = 'ddraw',
204         source = [
205             'ddraw.def',
206             'ddraw.cpp',
207             'log.cpp',
208         ]
209     )
210
211     env.Default(ddraw)
212
213 if has_d3d8:
214     env.Command(
215         target = 'd3d8.cpp', 
216         source = ['d3d8.py', 'd3d8types.py', 'd3d8caps.py', 'windows.py', 'base.py'],
217         action = 'python $SOURCE > $TARGET',
218     )
219         
220     d3d8 = env.SharedLibrary(
221         target = 'd3d8',
222         source = [
223             'd3d8.def',
224             'd3d8.cpp',
225             'log.cpp',
226         ]
227     )
228
229     env.Default(d3d8)
230
231 if has_d3d9:
232     env.Command(
233         target = 'd3d9.cpp', 
234         source = ['d3d9.py', 'd3d9types.py', 'd3d9caps.py', 'windows.py', 'base.py'],
235         action = 'python $SOURCE > $TARGET',
236     )
237         
238     d3d9 = env.SharedLibrary(
239         target = 'd3d9',
240         source = [
241             'd3d9.def',
242             'd3d9.cpp',
243             'log.cpp',
244         ]
245     )
246
247     env.Default(d3d9)
248
249 env.Command(
250     target = 'opengl32.cpp', 
251     source = ['opengl32.py', 'gl.py', 'windows.py', 'base.py'],
252     action = 'python $SOURCE > $TARGET',
253 )
254     
255 opengl32 = env.SharedLibrary(
256     target = 'opengl32',
257     source = [
258         'opengl32.def',
259         'opengl32.cpp',
260         'log.cpp',
261     ]
262 )
263
264 env.Default(opengl32)
265
266 env.Tool('packaging')
267
268 zip = env.Package(
269     NAME           = 'apitrace',
270     VERSION        = '0.3',
271     PACKAGEVERSION = 0,
272     PACKAGETYPE    = 'zip',
273     LICENSE        = 'lgpl',
274     SUMMARY        = 'Tool to trace Direct3D & OpenGL API calls from applications.',
275     SOURCE_URL     = 'http://cgit.freedesktop.org/~jrfonseca/apitrace/',
276     source = [
277         'README',
278         'COPYING',
279         'COPYING.LESSER',
280         'd3d8.dll',
281         'd3d9.dll',
282         'opengl32.dll',
283         'apitrace.xsl',
284         'xml2txt.py',
285     ],
286 )
287
288 env.Alias('zip', zip)