b6251d3960d8c804a3dd74199bfca64f46392fb6
1 #######################################################################
7 import platform
as _platform
10 #######################################################################
18 default_platform
= sys
.platform
19 default_platform
= _platform_map
.get(default_platform
, default_platform
)
29 if 'PROCESSOR_ARCHITECTURE' in os
.environ
:
30 default_machine
= os
.environ
['PROCESSOR_ARCHITECTURE']
32 default_machine
= _platform
.machine()
33 default_machine
= _machine_map
.get(default_machine
, 'generic')
35 if default_platform
in ('linux', 'freebsd', 'darwin'):
37 elif default_platform
in ('winddk', 'windows', 'wince'):
43 #######################################################################
48 from SCons
.Options
.BoolOption
import BoolOption
50 from SCons
.Variables
.BoolVariable
import BoolVariable
as BoolOption
52 from SCons
.Options
.EnumOption
import EnumOption
54 from SCons
.Variables
.EnumVariable
import EnumVariable
as EnumOption
55 opts
.Add(BoolOption('debug', 'debug build', 'no'))
56 opts
.Add(BoolOption('profile', 'profile build', 'no'))
57 #opts.Add(BoolOption('quiet', 'quiet command lines', 'no'))
58 opts
.Add(EnumOption('machine', 'use machine-specific assembly code', default_machine
,
59 allowed_values
=('generic', 'x86', 'x86_64')))
60 opts
.Add(EnumOption('platform', 'target platform', default_platform
,
61 allowed_values
=('linux', 'cell', 'windows', 'winddk', 'wince')))
62 opts
.Add(BoolOption('llvm', 'use LLVM', 'no'))
63 opts
.Add(BoolOption('dri', 'build DRI drivers', default_dri
))
66 #######################################################################
69 # See also http://www.scons.org/wiki/HidingCommandLinesInOutput
71 def quietCommandLines(env
):
72 env
['CCCOMSTR'] = "Compiling $SOURCE ..."
73 env
['CXXCOMSTR'] = "Compiling $SOURCE ..."
74 env
['ARCOMSTR'] = "Archiving $TARGET ..."
75 env
['RANLIBCOMSTR'] = ""
76 env
['LINKCOMSTR'] = "Linking $TARGET ..."
79 #######################################################################
80 # Convenience Library Builder
81 # based on the stock StaticLibrary and SharedLibrary builders
86 def createConvenienceLibBuilder(env
):
87 """This is a utility function that creates the ConvenienceLibrary
88 Builder in an Environment if it is not there already.
90 If it is already there, we return the existing one.
94 convenience_lib
= env
['BUILDERS']['ConvenienceLibrary']
96 action_list
= [ SCons
.Action
.Action("$ARCOM", "$ARCOMSTR") ]
97 if env
.Detect('ranlib'):
98 ranlib_action
= SCons
.Action
.Action("$RANLIBCOM", "$RANLIBCOMSTR")
99 action_list
.append(ranlib_action
)
101 convenience_lib
= SCons
.Builder
.Builder(action
= action_list
,
102 emitter
= '$LIBEMITTER',
103 prefix
= '$LIBPREFIX',
104 suffix
= '$LIBSUFFIX',
105 src_suffix
= '$SHOBJSUFFIX',
106 src_builder
= 'SharedObject')
107 env
['BUILDERS']['ConvenienceLibrary'] = convenience_lib
108 env
['BUILDERS']['Library'] = convenience_lib
110 return convenience_lib
113 #######################################################################
116 def make_build_dir(env
):
117 # Put build output in a separate dir, which depends on the current configuration
118 # See also http://www.scons.org/wiki/AdvancedBuildExample
119 build_topdir
= 'build'
120 build_subdir
= env
['platform']
122 build_subdir
+= "-dri"
124 build_subdir
+= "-llvm"
125 if env
['machine'] != 'generic':
126 build_subdir
+= '-' + env
['machine']
128 build_subdir
+= "-debug"
130 build_subdir
+= "-profile"
131 build_dir
= os
.path
.join(build_topdir
, build_subdir
)
132 # Place the .sconsign file on the builddir too, to avoid issues with different scons
133 # versions building the same source file
134 env
.SConsignFile(os
.path
.join(build_dir
, '.sconsign'))
138 #######################################################################
139 # Common environment generation code
142 # FIXME: this is already too late
143 #if env.get('quiet', False):
144 # quietCommandLines(env)
148 machine
= env
['machine']
149 platform
= env
['platform']
150 x86
= env
['machine'] == 'x86'
151 gcc
= env
['platform'] in ('linux', 'freebsd', 'darwin')
152 msvc
= env
['platform'] in ('windows', 'winddk', 'wince')
154 # C preprocessor options
157 cppdefines
+= ['DEBUG']
159 cppdefines
+= ['NDEBUG']
161 cppdefines
+= ['PROFILE']
162 if platform
== 'windows':
168 # http://msdn2.microsoft.com/en-us/library/6dwk3a1z.aspx,
169 'WIN32_LEAN_AND_MEAN',
171 '_CRT_SECURE_NO_DEPRECATE',
174 cppdefines
+= ['_DEBUG']
175 if platform
== 'winddk':
176 # Mimic WINDDK's builtin flags. See also:
177 # - WINDDK's bin/makefile.new i386mk.inc for more info.
178 # - buildchk_wxp_x86.log files, generated by the WINDDK's build
179 # - http://alter.org.ua/docs/nt_kernel/vc8_proj/
184 ('CONDITION_HANDLING', '1'),
189 ('_WIN32_WINNT', '0x0501'), # minimum required OS version
190 ('WINVER', '0x0501'),
191 ('_WIN32_IE', '0x0603'),
192 ('WIN32_LEAN_AND_MEAN', '1'),
194 ('__BUILDMACHINE__', 'WinDDK'),
198 cppdefines
+= [('DBG', 1)]
199 if platform
== 'wince':
201 ('_WIN32_WCE', '500'),
202 'WCE_PLATFORM_STANDARDSDK_500',
212 if platform
== 'windows':
213 cppdefines
+= ['PIPE_SUBSYSTEM_WINDOWS_USER']
214 if platform
== 'winddk':
215 cppdefines
+= ['PIPE_SUBSYSTEM_WINDOWS_DISPLAY']
216 if platform
== 'wince':
217 cppdefines
+= ['PIPE_SUBSYSTEM_WINDOWS_CE']
218 env
.Append(CPPDEFINES
= cppdefines
)
224 cflags
+= ['-O0', '-g3']
226 cflags
+= ['-O3', '-g3']
231 '-Wmissing-prototypes',
235 '-fmessage-length=0', # be nice to Eclipse
239 # - http://msdn2.microsoft.com/en-us/library/y0zzbyt4.aspx
243 '/Od', # disable optimizations
244 '/Oi', # enable intrinsic functions
245 '/Oy-', # disable frame pointer omission
249 '/Ox', # maximum optimizations
250 '/Oi', # enable intrinsic functions
251 '/Os', # favor code space
255 '/Gh', # enable _penter hook function
256 '/GH', # enable _pexit hook function
259 '/W3', # warning level
260 #'/Wp64', # enable 64 bit porting warnings
262 if platform
== 'windows':
266 if platform
== 'winddk':
268 '/Zl', # omit default library name in .OBJ
269 '/Zp8', # 8bytes struct member alignment
270 '/Gy', # separate functions for linker
271 '/Gm-', # disable minimal rebuild
272 '/WX', # treat warnings as errors
273 '/Gz', # __stdcall Calling convention
274 '/GX-', # disable C++ EH
275 '/GR-', # disable C++ RTTI
276 '/GF', # enable read-only string pooling
277 '/G6', # optimize for PPro, P-II, P-III
278 '/Ze', # enable extensions
279 '/Gi-', # disable incremental compilation
280 '/QIfdiv-', # disable Pentium FDIV fix
281 '/hotpatch', # prepares an image for hotpatching.
282 #'/Z7', #enable old-style debug info
284 if platform
== 'wince':
287 '/GF', # enable read-only string pooling
289 # Put debugging information in a separate .pdb file for each object file as
290 # described in the scons manpage
291 env
['CCPDBFLAGS'] = '/Zi /Fd${TARGET}.pdb'
292 env
.Append(CFLAGS
= cflags
)
293 env
.Append(CXXFLAGS
= cflags
)
296 if platform
== 'winddk':
298 # - http://msdn2.microsoft.com/en-us/library/y0zzbyt4.aspx
299 env
.Append(LINKFLAGS
= [
301 '/merge:_TEXT=.text',
305 '/ignore:4198,4010,4037,4039,4065,4070,4078,4087,4089,4221',
318 '/stack:0x40000,0x1000',
321 '/subsystem:native,5.01',
324 '/entry:DrvEnableDriver',
328 createConvenienceLibBuilder(env
)