blob: 217a1d61d360cf0ce7a47ba0c19b4cf22942bde2 [file] [log] [blame]
José Fonsecab04aa712008-06-06 14:48:57 +09001"""gallium
2
3Frontend-tool for Gallium3D architecture.
4
5"""
6
7#
8# Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
9# All Rights Reserved.
10#
11# Permission is hereby granted, free of charge, to any person obtaining a
12# copy of this software and associated documentation files (the
13# "Software"), to deal in the Software without restriction, including
14# without limitation the rights to use, copy, modify, merge, publish,
15# distribute, sub license, and/or sell copies of the Software, and to
16# permit persons to whom the Software is furnished to do so, subject to
17# the following conditions:
18#
19# The above copyright notice and this permission notice (including the
20# next paragraph) shall be included in all copies or substantial portions
21# of the Software.
22#
23# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
26# IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
27# ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
28# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
29# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30#
31
32
33import os.path
34
35import SCons.Action
36import SCons.Builder
37
38
39def quietCommandLines(env):
40 # Quiet command lines
41 # See also http://www.scons.org/wiki/HidingCommandLinesInOutput
42 env['CCCOMSTR'] = "Compiling $SOURCE ..."
43 env['CXXCOMSTR'] = "Compiling $SOURCE ..."
44 env['ARCOMSTR'] = "Archiving $TARGET ..."
45 env['RANLIBCOMSTR'] = ""
46 env['LINKCOMSTR'] = "Linking $TARGET ..."
47
48
49def createConvenienceLibBuilder(env):
50 """This is a utility function that creates the ConvenienceLibrary
51 Builder in an Environment if it is not there already.
52
53 If it is already there, we return the existing one.
54
55 Based on the stock StaticLibrary and SharedLibrary builders.
56 """
57
58 try:
59 convenience_lib = env['BUILDERS']['ConvenienceLibrary']
60 except KeyError:
61 action_list = [ SCons.Action.Action("$ARCOM", "$ARCOMSTR") ]
62 if env.Detect('ranlib'):
63 ranlib_action = SCons.Action.Action("$RANLIBCOM", "$RANLIBCOMSTR")
64 action_list.append(ranlib_action)
65
66 convenience_lib = SCons.Builder.Builder(action = action_list,
67 emitter = '$LIBEMITTER',
68 prefix = '$LIBPREFIX',
69 suffix = '$LIBSUFFIX',
70 src_suffix = '$SHOBJSUFFIX',
71 src_builder = 'SharedObject')
72 env['BUILDERS']['ConvenienceLibrary'] = convenience_lib
73 env['BUILDERS']['Library'] = convenience_lib
74
75 return convenience_lib
76
77
78def generate(env):
79 """Common environment generation code"""
80
81 # FIXME: this is already too late
82 #if env.get('quiet', False):
83 # quietCommandLines(env)
84
85 # shortcuts
86 debug = env['debug']
87 machine = env['machine']
88 platform = env['platform']
89 x86 = env['machine'] == 'x86'
90 gcc = env['platform'] in ('linux', 'freebsd', 'darwin')
91 msvc = env['platform'] in ('windows', 'winddk', 'wince')
92
93 # Tool
94 if platform == 'winddk':
95 env.Tool('winddk')
96 elif platform == 'wince':
José Fonsecaf78cc242008-06-23 12:49:45 +090097 env.Tool('wcesdk')
José Fonsecab04aa712008-06-06 14:48:57 +090098 else:
99 env.Tool('default')
100
101 # Put build output in a separate dir, which depends on the current
102 # configuration. See also http://www.scons.org/wiki/AdvancedBuildExample
103 build_topdir = 'build'
104 build_subdir = env['platform']
105 if env['dri']:
106 build_subdir += "-dri"
107 if env['llvm']:
108 build_subdir += "-llvm"
109 if env['machine'] != 'generic':
110 build_subdir += '-' + env['machine']
111 if env['debug']:
112 build_subdir += "-debug"
113 if env['profile']:
114 build_subdir += "-profile"
115 build_dir = os.path.join(build_topdir, build_subdir)
116 # Place the .sconsign file in the build dir too, to avoid issues with
117 # different scons versions building the same source file
118 env['build'] = build_dir
119 env.SConsignFile(os.path.join(build_dir, '.sconsign'))
120
121 # C preprocessor options
122 cppdefines = []
123 if debug:
124 cppdefines += ['DEBUG']
125 else:
126 cppdefines += ['NDEBUG']
127 if env['profile']:
128 cppdefines += ['PROFILE']
129 if platform == 'windows':
130 cppdefines += [
131 'WIN32',
132 '_WINDOWS',
133 '_UNICODE',
134 'UNICODE',
135 # http://msdn2.microsoft.com/en-us/library/6dwk3a1z.aspx,
136 'WIN32_LEAN_AND_MEAN',
137 'VC_EXTRALEAN',
138 '_CRT_SECURE_NO_DEPRECATE',
139 ]
140 if debug:
141 cppdefines += ['_DEBUG']
142 if platform == 'winddk':
143 # Mimic WINDDK's builtin flags. See also:
144 # - WINDDK's bin/makefile.new i386mk.inc for more info.
145 # - buildchk_wxp_x86.log files, generated by the WINDDK's build
146 # - http://alter.org.ua/docs/nt_kernel/vc8_proj/
147 cppdefines += [
148 ('_X86_', '1'),
149 ('i386', '1'),
150 'STD_CALL',
151 ('CONDITION_HANDLING', '1'),
152 ('NT_INST', '0'),
153 ('WIN32', '100'),
154 ('_NT1X_', '100'),
155 ('WINNT', '1'),
156 ('_WIN32_WINNT', '0x0501'), # minimum required OS version
157 ('WINVER', '0x0501'),
158 ('_WIN32_IE', '0x0603'),
159 ('WIN32_LEAN_AND_MEAN', '1'),
160 ('DEVL', '1'),
161 ('__BUILDMACHINE__', 'WinDDK'),
162 ('FPO', '0'),
163 ]
164 if debug:
165 cppdefines += [('DBG', 1)]
166 if platform == 'wince':
167 cppdefines += [
José Fonsecaf78cc242008-06-23 12:49:45 +0900168 '_CRT_SECURE_NO_DEPRECATE',
169 '_USE_32BIT_TIME_T',
José Fonsecab04aa712008-06-06 14:48:57 +0900170 'UNICODE',
171 '_UNICODE',
José Fonsecaf78cc242008-06-23 12:49:45 +0900172 ('UNDER_CE', '600'),
173 ('_WIN32_WCE', '0x600'),
174 'WINCEOEM',
175 'WINCEINTERNAL',
176 'WIN32',
177 'STRICT',
José Fonsecab04aa712008-06-06 14:48:57 +0900178 'x86',
José Fonsecaf78cc242008-06-23 12:49:45 +0900179 '_X86_',
180 'INTERNATIONAL',
181 ('INTLMSG_CODEPAGE', '1252'),
José Fonsecab04aa712008-06-06 14:48:57 +0900182 ]
183 if platform == 'windows':
184 cppdefines += ['PIPE_SUBSYSTEM_WINDOWS_USER']
185 if platform == 'winddk':
186 cppdefines += ['PIPE_SUBSYSTEM_WINDOWS_DISPLAY']
187 if platform == 'wince':
188 cppdefines += ['PIPE_SUBSYSTEM_WINDOWS_CE']
189 env.Append(CPPDEFINES = cppdefines)
190
191 # C preprocessor includes
192 if platform == 'winddk':
193 env.Append(CPPPATH = [
194 env['SDK_INC_PATH'],
195 env['DDK_INC_PATH'],
196 env['WDM_INC_PATH'],
197 env['CRT_INC_PATH'],
198 ])
199
200 # C compiler options
201 cflags = []
202 if gcc:
203 if debug:
204 cflags += ['-O0', '-g3']
205 else:
206 cflags += ['-O3', '-g3']
207 if env['profile']:
208 cflags += ['-pg']
209 if env['machine'] == 'x86':
210 cflags += ['-m32']
211 if env['machine'] == 'x86_64':
212 cflags += ['-m64']
213 cflags += [
214 '-Wall',
215 '-Wmissing-prototypes',
216 '-Wno-long-long',
217 '-ffast-math',
218 '-pedantic',
219 '-fmessage-length=0', # be nice to Eclipse
220 ]
221 if msvc:
222 # See also:
223 # - http://msdn2.microsoft.com/en-us/library/y0zzbyt4.aspx
224 # - cl /?
225 if debug:
226 cflags += [
227 '/Od', # disable optimizations
228 '/Oi', # enable intrinsic functions
229 '/Oy-', # disable frame pointer omission
230 ]
231 else:
232 cflags += [
233 '/Ox', # maximum optimizations
234 '/Oi', # enable intrinsic functions
235 '/Os', # favor code space
236 ]
237 if env['profile']:
238 cflags += [
239 '/Gh', # enable _penter hook function
240 '/GH', # enable _pexit hook function
241 ]
242 cflags += [
243 '/W3', # warning level
244 #'/Wp64', # enable 64 bit porting warnings
245 ]
246 if platform == 'windows':
247 cflags += [
248 # TODO
249 ]
250 if platform == 'winddk':
251 cflags += [
252 '/Zl', # omit default library name in .OBJ
253 '/Zp8', # 8bytes struct member alignment
254 '/Gy', # separate functions for linker
255 '/Gm-', # disable minimal rebuild
256 '/WX', # treat warnings as errors
257 '/Gz', # __stdcall Calling convention
258 '/GX-', # disable C++ EH
259 '/GR-', # disable C++ RTTI
260 '/GF', # enable read-only string pooling
261 '/G6', # optimize for PPro, P-II, P-III
262 '/Ze', # enable extensions
263 '/Gi-', # disable incremental compilation
264 '/QIfdiv-', # disable Pentium FDIV fix
265 '/hotpatch', # prepares an image for hotpatching.
266 #'/Z7', #enable old-style debug info
267 ]
268 if platform == 'wince':
José Fonsecaf78cc242008-06-23 12:49:45 +0900269 # See also C:\WINCE600\public\common\oak\misc\makefile.def
José Fonsecab04aa712008-06-06 14:48:57 +0900270 cflags += [
José Fonsecab04aa712008-06-06 14:48:57 +0900271 '/GF', # enable read-only string pooling
José Fonsecaf78cc242008-06-23 12:49:45 +0900272 '/GR-', # disable C++ RTTI
273 '/GS', # enable security checks
274 # Allow disabling language conformance to maintain backward compat
275 #'/Zc:wchar_t-', # don't force wchar_t as native type, instead of typedef
276 #'/Zc:forScope-', # don't enforce Standard C++ for scoping rules
277 #'/wd4867',
278 #'/wd4430',
279 #'/MT',
280 #'/U_MT',
José Fonsecab04aa712008-06-06 14:48:57 +0900281 ]
282 # Automatic pdb generation
283 # See http://scons.tigris.org/issues/show_bug.cgi?id=1656
284 env.EnsureSConsVersion(0, 98, 0)
285 env['PDB'] = '${TARGET.base}.pdb'
286 env.Append(CFLAGS = cflags)
287 env.Append(CXXFLAGS = cflags)
288
289 # Linker options
290 linkflags = []
291 if gcc:
292 if env['machine'] == 'x86':
293 linkflags += ['-m32']
294 if env['machine'] == 'x86_64':
295 linkflags += ['-m64']
296 if platform == 'winddk':
297 # See also:
298 # - http://msdn2.microsoft.com/en-us/library/y0zzbyt4.aspx
299 linkflags += [
300 '/merge:_PAGE=PAGE',
301 '/merge:_TEXT=.text',
302 '/section:INIT,d',
303 '/opt:ref',
304 '/opt:icf',
305 '/ignore:4198,4010,4037,4039,4065,4070,4078,4087,4089,4221',
306 '/incremental:no',
307 '/fullbuild',
308 '/release',
309 '/nodefaultlib',
310 '/wx',
311 '/debug',
312 '/debugtype:cv',
313 '/version:5.1',
314 '/osversion:5.1',
315 '/functionpadmin:5',
316 '/safeseh',
317 '/pdbcompress',
318 '/stack:0x40000,0x1000',
319 '/driver',
320 '/align:0x80',
321 '/subsystem:native,5.01',
322 '/base:0x10000',
323
324 '/entry:DrvEnableDriver',
325 ]
326 env.Append(LINKFLAGS = linkflags)
327
328 # Convenience Library Builder
329 createConvenienceLibBuilder(env)
330
331 # for debugging
332 #print env.Dump()
333
334
335def exists(env):
336 return 1