OSDN Git Service

Merge remote branch 'upstream/gallium-0.1' into nouveau-gallium-0.1
[android-x86/external-mesa.git] / scons / gallium.py
1 """gallium
2
3 Frontend-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
33 import os.path
34
35 import SCons.Action
36 import SCons.Builder
37
38
39 def 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
49 def 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
78 def 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':
97                 env.Tool('wcesdk')
98         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 += [
168                         '_CRT_SECURE_NO_DEPRECATE',
169                         '_USE_32BIT_TIME_T',
170                         'UNICODE',
171                         '_UNICODE',
172                         ('UNDER_CE', '600'),
173                         ('_WIN32_WCE', '0x600'),
174                         'WINCEOEM',
175                         'WINCEINTERNAL',
176                         'WIN32',
177                         'STRICT',
178                         'x86',
179                         '_X86_',
180                         'INTERNATIONAL',
181                         ('INTLMSG_CODEPAGE', '1252'),
182                 ]
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':
269                         # See also C:\WINCE600\public\common\oak\misc\makefile.def
270                         cflags += [
271                                 '/GF', # enable read-only string pooling
272                                 '/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',
281                         ]
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         # Assembler options
290         if gcc:
291                 if env['machine'] == 'x86':
292                         env.Append(ASFLAGS = ['-m32'])
293                 if env['machine'] == 'x86_64':
294                         env.Append(ASFLAGS = ['-m64'])
295
296         # Linker options
297         linkflags = []
298         if gcc:
299                 if env['machine'] == 'x86':
300                         linkflags += ['-m32']
301                 if env['machine'] == 'x86_64':
302                         linkflags += ['-m64']
303         if platform == 'winddk':
304                 # See also:
305                 # - http://msdn2.microsoft.com/en-us/library/y0zzbyt4.aspx
306                 linkflags += [
307                         '/merge:_PAGE=PAGE',
308                         '/merge:_TEXT=.text',
309                         '/section:INIT,d',
310                         '/opt:ref',
311                         '/opt:icf',
312                         '/ignore:4198,4010,4037,4039,4065,4070,4078,4087,4089,4221',
313                         '/incremental:no',
314                         '/fullbuild',
315                         '/release',
316                         '/nodefaultlib',
317                         '/wx',
318                         '/debug',
319                         '/debugtype:cv',
320                         '/version:5.1',
321                         '/osversion:5.1',
322                         '/functionpadmin:5',
323                         '/safeseh',
324                         '/pdbcompress',
325                         '/stack:0x40000,0x1000',
326                         '/driver', 
327                         '/align:0x80',
328                         '/subsystem:native,5.01',
329                         '/base:0x10000',
330                         
331                         '/entry:DrvEnableDriver',
332                 ]
333         env.Append(LINKFLAGS = linkflags)
334
335         # Convenience Library Builder
336         createConvenienceLibBuilder(env)
337         
338         # for debugging
339         #print env.Dump()
340
341
342 def exists(env):
343         return 1