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'):
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', 'build debug version', 'no'))
56 #opts.Add(BoolOption('quiet', 'quiet command lines', 'no'))
57 opts.Add(EnumOption('machine', 'use machine-specific assembly code', default_machine,
58 allowed_values=('generic', 'x86', 'x86_64')))
59 opts.Add(EnumOption('platform', 'target platform', default_platform,
60 allowed_values=('linux', 'cell', 'windows', 'winddk')))
61 opts.Add(BoolOption('llvm', 'use LLVM', 'no'))
62 opts.Add(BoolOption('dri', 'build DRI drivers', default_dri))
65 #######################################################################
68 # See also http://www.scons.org/wiki/HidingCommandLinesInOutput
70 def quietCommandLines(env):
71 env['CCCOMSTR'] = "Compiling $SOURCE ..."
72 env['CXXCOMSTR'] = "Compiling $SOURCE ..."
73 env['ARCOMSTR'] = "Archiving $TARGET ..."
74 env['RANLIBCOMSTR'] = ""
75 env['LINKCOMSTR'] = "Linking $TARGET ..."
78 #######################################################################
79 # Convenience Library Builder
80 # based on the stock StaticLibrary and SharedLibrary builders
85 def createConvenienceLibBuilder(env):
86 """This is a utility function that creates the ConvenienceLibrary
87 Builder in an Environment if it is not there already.
89 If it is already there, we return the existing one.
93 convenience_lib = env['BUILDERS']['ConvenienceLibrary']
95 action_list = [ SCons.Action.Action("$ARCOM", "$ARCOMSTR") ]
96 if env.Detect('ranlib'):
97 ranlib_action = SCons.Action.Action("$RANLIBCOM", "$RANLIBCOMSTR")
98 action_list.append(ranlib_action)
100 convenience_lib = SCons.Builder.Builder(action = action_list,
101 emitter = '$LIBEMITTER',
102 prefix = '$LIBPREFIX',
103 suffix = '$LIBSUFFIX',
104 src_suffix = '$SHOBJSUFFIX',
105 src_builder = 'SharedObject')
106 env['BUILDERS']['ConvenienceLibrary'] = convenience_lib
107 env['BUILDERS']['Library'] = convenience_lib
109 return convenience_lib
112 #######################################################################
115 def make_build_dir(env):
116 # Put build output in a separate dir, which depends on the current configuration
117 # See also http://www.scons.org/wiki/AdvancedBuildExample
118 build_topdir = 'build'
119 build_subdir = env['platform']
121 build_subdir += "-dri"
123 build_subdir += "-llvm"
124 if env['machine'] != 'generic':
125 build_subdir += '-' + env['machine']
127 build_subdir += "-debug"
128 build_dir = os.path.join(build_topdir, build_subdir)
129 # Place the .sconsign file on the builddir too, to avoid issues with different scons
130 # versions building the same source file
131 env.SConsignFile(os.path.join(build_dir, '.sconsign'))
135 #######################################################################
136 # Common environment generation code
139 # FIXME: this is already too late
140 #if env.get('quiet', False):
141 # quietCommandLines(env)
145 machine = env['machine']
146 platform = env['platform']
147 x86 = env['machine'] == 'x86'
148 gcc = env['platform'] in ('linux', 'freebsd', 'darwin')
149 msvc = env['platform'] in ('windows', 'winddk')
151 # C preprocessor options
154 cppdefines += ['DEBUG']
156 cppdefines += ['NDEBUG']
157 if platform == 'windows':
163 # http://msdn2.microsoft.com/en-us/library/6dwk3a1z.aspx,
164 'WIN32_LEAN_AND_MEAN',
166 '_CRT_SECURE_NO_DEPRECATE',
169 cppdefines += ['_DEBUG']
170 if platform == 'winddk':
171 # Mimic WINDDK's builtin flags. See also:
172 # - WINDDK's bin/makefile.new i386mk.inc for more info.
173 # - buildchk_wxp_x86.log files, generated by the WINDDK's build
174 # - http://alter.org.ua/docs/nt_kernel/vc8_proj/
179 ('CONDITION_HANDLING', '1'),
184 ('_WIN32_WINNT', '0x0501'), # minimum required OS version
185 ('WINVER', '0x0501'),
186 ('_WIN32_IE', '0x0603'),
187 ('WIN32_LEAN_AND_MEAN', '1'),
189 ('__BUILDMACHINE__', 'WinDDK'),
193 cppdefines += [('DBG', 1)]
194 if platform == 'windows':
195 cppdefines += ['PIPE_SUBSYSTEM_USER']
196 if platform == 'winddk':
197 cppdefines += ['PIPE_SUBSYSTEM_KERNEL']
198 env.Append(CPPDEFINES = cppdefines)
204 cflags += ['-O0', '-g3']
206 cflags += ['-O3', '-g3']
209 '-Wmissing-prototypes',
213 '-fmessage-length=0', # be nice to Eclipse
217 # - http://msdn2.microsoft.com/en-us/library/y0zzbyt4.aspx
221 '/Od', # disable optimizations
222 '/Oi', # enable intrinsic functions
223 '/Oy-', # disable frame pointer omission
227 '/Ox', # maximum optimizations
228 '/Oi', # enable intrinsic functions
229 '/Os', # favor code space
231 if platform == 'windows':
234 #'/Wp64', # enable 64 bit porting warnings
236 if platform == 'winddk':
238 '/Zl', # omit default library name in .OBJ
239 '/Zp8', # 8bytes struct member alignment
240 '/Gy', # separate functions for linker
241 '/Gm-', # disable minimal rebuild
242 '/W3', # warning level
243 '/WX', # treat warnings as errors
244 '/Gz', # __stdcall Calling convention
245 '/GX-', # disable C++ EH
246 '/GR-', # disable C++ RTTI
247 '/GF', # enable read-only string pooling
248 '/G6', # optimize for PPro, P-II, P-III
249 '/Ze', # enable extensions
250 '/Gi-', # disable incremental compilation
251 '/QIfdiv-', # disable Pentium FDIV fix
252 '/hotpatch', # prepares an image for hotpatching.
253 #'/Z7', #enable old-style debug info
255 # Put debugging information in a separate .pdb file for each object file as
256 # descrived in the scons manpage
257 env['CCPDBFLAGS'] = '/Zi /Fd${TARGET}.pdb'
258 env.Append(CFLAGS = cflags)
259 env.Append(CXXFLAGS = cflags)
262 if platform == 'winddk':
264 # - http://msdn2.microsoft.com/en-us/library/y0zzbyt4.aspx
265 env.Append(LINKFLAGS = [
267 '/merge:_TEXT=.text',
271 '/ignore:4198,4010,4037,4039,4065,4070,4078,4087,4089,4221',
284 '/stack:0x40000,0x1000',
287 '/subsystem:native,5.01',
290 '/entry:DrvEnableDriver',
294 createConvenienceLibBuilder(env)