José Fonseca | b04aa71 | 2008-06-06 14:48:57 +0900 | [diff] [blame] | 1 | """gallium |
| 2 | |
| 3 | Frontend-tool for Gallium3D architecture. |
| 4 | |
| 5 | """ |
| 6 | |
José Fonseca | 381e348 | 2008-07-17 11:23:43 +0900 | [diff] [blame] | 7 | # |
José Fonseca | b04aa71 | 2008-06-06 14:48:57 +0900 | [diff] [blame] | 8 | # Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. |
| 9 | # All Rights Reserved. |
José Fonseca | 381e348 | 2008-07-17 11:23:43 +0900 | [diff] [blame] | 10 | # |
José Fonseca | b04aa71 | 2008-06-06 14:48:57 +0900 | [diff] [blame] | 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: |
José Fonseca | 381e348 | 2008-07-17 11:23:43 +0900 | [diff] [blame] | 18 | # |
José Fonseca | b04aa71 | 2008-06-06 14:48:57 +0900 | [diff] [blame] | 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. |
José Fonseca | 381e348 | 2008-07-17 11:23:43 +0900 | [diff] [blame] | 22 | # |
José Fonseca | b04aa71 | 2008-06-06 14:48:57 +0900 | [diff] [blame] | 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. |
José Fonseca | 381e348 | 2008-07-17 11:23:43 +0900 | [diff] [blame] | 30 | # |
José Fonseca | b04aa71 | 2008-06-06 14:48:57 +0900 | [diff] [blame] | 31 | |
| 32 | |
José Fonseca | 27d8d6f | 2008-07-03 12:42:23 +0900 | [diff] [blame] | 33 | import os |
José Fonseca | b04aa71 | 2008-06-06 14:48:57 +0900 | [diff] [blame] | 34 | import os.path |
José Fonseca | 27d8d6f | 2008-07-03 12:42:23 +0900 | [diff] [blame] | 35 | import re |
José Fonseca | b04aa71 | 2008-06-06 14:48:57 +0900 | [diff] [blame] | 36 | |
| 37 | import SCons.Action |
| 38 | import SCons.Builder |
José Fonseca | 27d8d6f | 2008-07-03 12:42:23 +0900 | [diff] [blame] | 39 | import SCons.Scanner |
José Fonseca | b04aa71 | 2008-06-06 14:48:57 +0900 | [diff] [blame] | 40 | |
| 41 | |
| 42 | def quietCommandLines(env): |
José Fonseca | 381e348 | 2008-07-17 11:23:43 +0900 | [diff] [blame] | 43 | # Quiet command lines |
| 44 | # See also http://www.scons.org/wiki/HidingCommandLinesInOutput |
| 45 | env['CCCOMSTR'] = "Compiling $SOURCE ..." |
| 46 | env['CXXCOMSTR'] = "Compiling $SOURCE ..." |
| 47 | env['ARCOMSTR'] = "Archiving $TARGET ..." |
| 48 | env['RANLIBCOMSTR'] = "" |
| 49 | env['LINKCOMSTR'] = "Linking $TARGET ..." |
José Fonseca | b04aa71 | 2008-06-06 14:48:57 +0900 | [diff] [blame] | 50 | |
| 51 | |
| 52 | def createConvenienceLibBuilder(env): |
| 53 | """This is a utility function that creates the ConvenienceLibrary |
| 54 | Builder in an Environment if it is not there already. |
| 55 | |
| 56 | If it is already there, we return the existing one. |
José Fonseca | 381e348 | 2008-07-17 11:23:43 +0900 | [diff] [blame] | 57 | |
José Fonseca | b04aa71 | 2008-06-06 14:48:57 +0900 | [diff] [blame] | 58 | Based on the stock StaticLibrary and SharedLibrary builders. |
| 59 | """ |
| 60 | |
| 61 | try: |
| 62 | convenience_lib = env['BUILDERS']['ConvenienceLibrary'] |
| 63 | except KeyError: |
| 64 | action_list = [ SCons.Action.Action("$ARCOM", "$ARCOMSTR") ] |
| 65 | if env.Detect('ranlib'): |
| 66 | ranlib_action = SCons.Action.Action("$RANLIBCOM", "$RANLIBCOMSTR") |
| 67 | action_list.append(ranlib_action) |
| 68 | |
| 69 | convenience_lib = SCons.Builder.Builder(action = action_list, |
| 70 | emitter = '$LIBEMITTER', |
| 71 | prefix = '$LIBPREFIX', |
| 72 | suffix = '$LIBSUFFIX', |
| 73 | src_suffix = '$SHOBJSUFFIX', |
| 74 | src_builder = 'SharedObject') |
| 75 | env['BUILDERS']['ConvenienceLibrary'] = convenience_lib |
José Fonseca | b04aa71 | 2008-06-06 14:48:57 +0900 | [diff] [blame] | 76 | |
| 77 | return convenience_lib |
| 78 | |
| 79 | |
José Fonseca | 27d8d6f | 2008-07-03 12:42:23 +0900 | [diff] [blame] | 80 | # TODO: handle import statements with multiple modules |
| 81 | # TODO: handle from import statements |
| 82 | import_re = re.compile(r'^import\s+(\S+)$', re.M) |
| 83 | |
| 84 | def python_scan(node, env, path): |
José Fonseca | 381e348 | 2008-07-17 11:23:43 +0900 | [diff] [blame] | 85 | # http://www.scons.org/doc/0.98.5/HTML/scons-user/c2781.html#AEN2789 |
| 86 | contents = node.get_contents() |
| 87 | source_dir = node.get_dir() |
| 88 | imports = import_re.findall(contents) |
| 89 | results = [] |
| 90 | for imp in imports: |
| 91 | for dir in path: |
| 92 | file = os.path.join(str(dir), imp.replace('.', os.sep) + '.py') |
| 93 | if os.path.exists(file): |
| 94 | results.append(env.File(file)) |
| 95 | break |
| 96 | file = os.path.join(str(dir), imp.replace('.', os.sep), '__init__.py') |
| 97 | if os.path.exists(file): |
| 98 | results.append(env.File(file)) |
| 99 | break |
| 100 | return results |
José Fonseca | 27d8d6f | 2008-07-03 12:42:23 +0900 | [diff] [blame] | 101 | |
| 102 | python_scanner = SCons.Scanner.Scanner(function = python_scan, skeys = ['.py']) |
| 103 | |
| 104 | |
| 105 | def code_generate(env, script, target, source, command): |
José Fonseca | 381e348 | 2008-07-17 11:23:43 +0900 | [diff] [blame] | 106 | """Method to simplify code generation via python scripts. |
José Fonseca | 27d8d6f | 2008-07-03 12:42:23 +0900 | [diff] [blame] | 107 | |
José Fonseca | 381e348 | 2008-07-17 11:23:43 +0900 | [diff] [blame] | 108 | http://www.scons.org/wiki/UsingCodeGenerators |
| 109 | http://www.scons.org/doc/0.98.5/HTML/scons-user/c2768.html |
| 110 | """ |
| 111 | |
| 112 | # We're generating code using Python scripts, so we have to be |
| 113 | # careful with our scons elements. This entry represents |
| 114 | # the generator file *in the source directory*. |
| 115 | script_src = env.File(script).srcnode() |
| 116 | |
| 117 | # This command creates generated code *in the build directory*. |
| 118 | command = command.replace('$SCRIPT', script_src.path) |
| 119 | code = env.Command(target, source, command) |
| 120 | |
| 121 | # Explicitly mark that the generated code depends on the generator, |
| 122 | # and on implicitly imported python modules |
| 123 | path = (script_src.get_dir(),) |
| 124 | deps = [script_src] |
| 125 | deps += script_src.get_implicit_deps(env, python_scanner, path) |
| 126 | env.Depends(code, deps) |
| 127 | |
| 128 | # Running the Python script causes .pyc files to be generated in the |
| 129 | # source directory. When we clean up, they should go too. So add side |
| 130 | # effects for .pyc files |
| 131 | for dep in deps: |
| 132 | pyc = env.File(str(dep) + 'c') |
| 133 | env.SideEffect(pyc, code) |
| 134 | |
| 135 | return code |
José Fonseca | 27d8d6f | 2008-07-03 12:42:23 +0900 | [diff] [blame] | 136 | |
| 137 | |
| 138 | def createCodeGenerateMethod(env): |
José Fonseca | 381e348 | 2008-07-17 11:23:43 +0900 | [diff] [blame] | 139 | env.Append(SCANNERS = python_scanner) |
| 140 | env.AddMethod(code_generate, 'CodeGenerate') |
José Fonseca | 27d8d6f | 2008-07-03 12:42:23 +0900 | [diff] [blame] | 141 | |
| 142 | |
José Fonseca | 52c2dd1 | 2008-09-08 07:54:15 +0900 | [diff] [blame] | 143 | def symlink(target, source, env): |
| 144 | target = str(target[0]) |
| 145 | source = str(source[0]) |
| 146 | if os.path.islink(target) or os.path.exists(target): |
| 147 | os.remove(target) |
| 148 | os.symlink(os.path.basename(source), target) |
| 149 | |
| 150 | def install_shared_library(env, source, version = ()): |
| 151 | source = str(source[0]) |
| 152 | version = tuple(map(str, version)) |
José Fonseca | 7cfc294 | 2008-09-08 21:50:50 +0900 | [diff] [blame] | 153 | target_dir = os.path.join(env.Dir('#.').srcnode().abspath, env['build'], 'lib') |
José Fonseca | 52c2dd1 | 2008-09-08 07:54:15 +0900 | [diff] [blame] | 154 | target_name = '.'.join((str(source),) + version) |
| 155 | last = env.InstallAs(os.path.join(target_dir, target_name), source) |
| 156 | while len(version): |
| 157 | version = version[:-1] |
| 158 | target_name = '.'.join((str(source),) + version) |
| 159 | action = SCons.Action.Action(symlink, "$TARGET -> $SOURCE") |
José Fonseca | 52c2dd1 | 2008-09-08 07:54:15 +0900 | [diff] [blame] | 160 | last = env.Command(os.path.join(target_dir, target_name), last, action) |
| 161 | |
| 162 | def createInstallMethods(env): |
| 163 | env.AddMethod(install_shared_library, 'InstallSharedLibrary') |
| 164 | |
| 165 | |
José Fonseca | 1e8177e | 2009-02-10 18:11:56 +0000 | [diff] [blame] | 166 | def num_jobs(): |
| 167 | try: |
| 168 | return int(os.environ['NUMBER_OF_PROCESSORS']) |
| 169 | except (ValueError, KeyError): |
| 170 | pass |
| 171 | |
| 172 | try: |
| 173 | return os.sysconf('SC_NPROCESSORS_ONLN') |
| 174 | except (ValueError, OSError, AttributeError): |
| 175 | pass |
| 176 | |
| 177 | try: |
| 178 | return int(os.popen2("sysctl -n hw.ncpu")[1].read()) |
| 179 | except ValueError: |
| 180 | pass |
| 181 | |
| 182 | return 1 |
| 183 | |
| 184 | |
José Fonseca | b04aa71 | 2008-06-06 14:48:57 +0900 | [diff] [blame] | 185 | def generate(env): |
José Fonseca | 381e348 | 2008-07-17 11:23:43 +0900 | [diff] [blame] | 186 | """Common environment generation code""" |
José Fonseca | b04aa71 | 2008-06-06 14:48:57 +0900 | [diff] [blame] | 187 | |
José Fonseca | 381e348 | 2008-07-17 11:23:43 +0900 | [diff] [blame] | 188 | # FIXME: this is already too late |
| 189 | #if env.get('quiet', False): |
| 190 | # quietCommandLines(env) |
José Fonseca | b04aa71 | 2008-06-06 14:48:57 +0900 | [diff] [blame] | 191 | |
José Fonseca | 6cf59e1 | 2008-11-18 19:13:32 +0900 | [diff] [blame] | 192 | # Toolchain |
| 193 | platform = env['platform'] |
| 194 | if env['toolchain'] == 'default': |
| 195 | if platform == 'winddk': |
Michal Krol | 4f3dcf3 | 2008-11-19 20:31:38 +0100 | [diff] [blame] | 196 | env['toolchain'] = 'winddk' |
José Fonseca | 6cf59e1 | 2008-11-18 19:13:32 +0900 | [diff] [blame] | 197 | elif platform == 'wince': |
Michal Krol | 4f3dcf3 | 2008-11-19 20:31:38 +0100 | [diff] [blame] | 198 | env['toolchain'] = 'wcesdk' |
José Fonseca | 6cf59e1 | 2008-11-18 19:13:32 +0900 | [diff] [blame] | 199 | env.Tool(env['toolchain']) |
| 200 | |
José Fonseca | 26e27ba | 2009-03-25 19:24:16 +0000 | [diff] [blame^] | 201 | env['gcc'] = 'gcc' in os.path.basename(env['CC']).split('-') |
| 202 | env['msvc'] = env['CC'] == 'cl' |
| 203 | |
José Fonseca | 381e348 | 2008-07-17 11:23:43 +0900 | [diff] [blame] | 204 | # shortcuts |
| 205 | debug = env['debug'] |
| 206 | machine = env['machine'] |
| 207 | platform = env['platform'] |
| 208 | x86 = env['machine'] == 'x86' |
Michel Dänzer | 6b69e3c | 2008-10-23 10:28:48 +0200 | [diff] [blame] | 209 | ppc = env['machine'] == 'ppc' |
José Fonseca | 26e27ba | 2009-03-25 19:24:16 +0000 | [diff] [blame^] | 210 | gcc = env['gcc'] |
| 211 | msvc = env['msvc'] |
José Fonseca | b04aa71 | 2008-06-06 14:48:57 +0900 | [diff] [blame] | 212 | |
José Fonseca | 381e348 | 2008-07-17 11:23:43 +0900 | [diff] [blame] | 213 | # Put build output in a separate dir, which depends on the current |
| 214 | # configuration. See also http://www.scons.org/wiki/AdvancedBuildExample |
| 215 | build_topdir = 'build' |
| 216 | build_subdir = env['platform'] |
José Fonseca | 381e348 | 2008-07-17 11:23:43 +0900 | [diff] [blame] | 217 | if env['llvm']: |
| 218 | build_subdir += "-llvm" |
| 219 | if env['machine'] != 'generic': |
| 220 | build_subdir += '-' + env['machine'] |
| 221 | if env['debug']: |
| 222 | build_subdir += "-debug" |
| 223 | if env['profile']: |
| 224 | build_subdir += "-profile" |
| 225 | build_dir = os.path.join(build_topdir, build_subdir) |
| 226 | # Place the .sconsign file in the build dir too, to avoid issues with |
| 227 | # different scons versions building the same source file |
| 228 | env['build'] = build_dir |
| 229 | env.SConsignFile(os.path.join(build_dir, '.sconsign')) |
José Fonseca | 18170bb | 2009-01-23 21:01:16 +0000 | [diff] [blame] | 230 | env.CacheDir('build/cache') |
José Fonseca | b04aa71 | 2008-06-06 14:48:57 +0900 | [diff] [blame] | 231 | |
José Fonseca | 1e8177e | 2009-02-10 18:11:56 +0000 | [diff] [blame] | 232 | # Parallel build |
| 233 | if env.GetOption('num_jobs') <= 1: |
| 234 | env.SetOption('num_jobs', num_jobs()) |
| 235 | |
José Fonseca | 381e348 | 2008-07-17 11:23:43 +0900 | [diff] [blame] | 236 | # C preprocessor options |
| 237 | cppdefines = [] |
| 238 | if debug: |
| 239 | cppdefines += ['DEBUG'] |
| 240 | else: |
| 241 | cppdefines += ['NDEBUG'] |
| 242 | if env['profile']: |
| 243 | cppdefines += ['PROFILE'] |
| 244 | if platform == 'windows': |
| 245 | cppdefines += [ |
| 246 | 'WIN32', |
| 247 | '_WINDOWS', |
José Fonseca | 42be010 | 2009-01-22 14:26:30 +0000 | [diff] [blame] | 248 | #'_UNICODE', |
| 249 | #'UNICODE', |
José Fonseca | 129c6ed | 2008-12-01 11:53:26 -0800 | [diff] [blame] | 250 | ('_WIN32_WINNT', '0x0501'), # minimum required OS version |
| 251 | ('WINVER', '0x0501'), |
José Fonseca | 381e348 | 2008-07-17 11:23:43 +0900 | [diff] [blame] | 252 | # http://msdn2.microsoft.com/en-us/library/6dwk3a1z.aspx, |
| 253 | 'WIN32_LEAN_AND_MEAN', |
| 254 | 'VC_EXTRALEAN', |
| 255 | '_CRT_SECURE_NO_DEPRECATE', |
| 256 | ] |
| 257 | if debug: |
| 258 | cppdefines += ['_DEBUG'] |
| 259 | if platform == 'winddk': |
| 260 | # Mimic WINDDK's builtin flags. See also: |
| 261 | # - WINDDK's bin/makefile.new i386mk.inc for more info. |
| 262 | # - buildchk_wxp_x86.log files, generated by the WINDDK's build |
| 263 | # - http://alter.org.ua/docs/nt_kernel/vc8_proj/ |
| 264 | cppdefines += [ |
| 265 | ('_X86_', '1'), |
| 266 | ('i386', '1'), |
| 267 | 'STD_CALL', |
| 268 | ('CONDITION_HANDLING', '1'), |
| 269 | ('NT_INST', '0'), |
| 270 | ('WIN32', '100'), |
| 271 | ('_NT1X_', '100'), |
| 272 | ('WINNT', '1'), |
| 273 | ('_WIN32_WINNT', '0x0501'), # minimum required OS version |
| 274 | ('WINVER', '0x0501'), |
| 275 | ('_WIN32_IE', '0x0603'), |
| 276 | ('WIN32_LEAN_AND_MEAN', '1'), |
| 277 | ('DEVL', '1'), |
| 278 | ('__BUILDMACHINE__', 'WinDDK'), |
| 279 | ('FPO', '0'), |
| 280 | ] |
| 281 | if debug: |
| 282 | cppdefines += [('DBG', 1)] |
| 283 | if platform == 'wince': |
| 284 | cppdefines += [ |
| 285 | '_CRT_SECURE_NO_DEPRECATE', |
| 286 | '_USE_32BIT_TIME_T', |
| 287 | 'UNICODE', |
| 288 | '_UNICODE', |
| 289 | ('UNDER_CE', '600'), |
| 290 | ('_WIN32_WCE', '0x600'), |
| 291 | 'WINCEOEM', |
| 292 | 'WINCEINTERNAL', |
| 293 | 'WIN32', |
| 294 | 'STRICT', |
| 295 | 'x86', |
| 296 | '_X86_', |
| 297 | 'INTERNATIONAL', |
| 298 | ('INTLMSG_CODEPAGE', '1252'), |
| 299 | ] |
| 300 | if platform == 'windows': |
| 301 | cppdefines += ['PIPE_SUBSYSTEM_WINDOWS_USER'] |
| 302 | if platform == 'winddk': |
| 303 | cppdefines += ['PIPE_SUBSYSTEM_WINDOWS_DISPLAY'] |
| 304 | if platform == 'wince': |
| 305 | cppdefines += ['PIPE_SUBSYSTEM_WINDOWS_CE'] |
José Fonseca | 40b3bb0 | 2008-11-04 10:53:02 +0900 | [diff] [blame] | 306 | cppdefines += ['PIPE_SUBSYSTEM_WINDOWS_CE_OGL'] |
José Fonseca | 381e348 | 2008-07-17 11:23:43 +0900 | [diff] [blame] | 307 | env.Append(CPPDEFINES = cppdefines) |
José Fonseca | b04aa71 | 2008-06-06 14:48:57 +0900 | [diff] [blame] | 308 | |
José Fonseca | 381e348 | 2008-07-17 11:23:43 +0900 | [diff] [blame] | 309 | # C preprocessor includes |
| 310 | if platform == 'winddk': |
| 311 | env.Append(CPPPATH = [ |
| 312 | env['SDK_INC_PATH'], |
| 313 | env['DDK_INC_PATH'], |
| 314 | env['WDM_INC_PATH'], |
| 315 | env['CRT_INC_PATH'], |
| 316 | ]) |
José Fonseca | 05cfb4c | 2008-06-27 13:41:23 +0900 | [diff] [blame] | 317 | |
José Fonseca | 381e348 | 2008-07-17 11:23:43 +0900 | [diff] [blame] | 318 | # C compiler options |
| 319 | cflags = [] |
| 320 | if gcc: |
| 321 | if debug: |
| 322 | cflags += ['-O0', '-g3'] |
| 323 | else: |
| 324 | cflags += ['-O3', '-g3'] |
| 325 | if env['profile']: |
| 326 | cflags += ['-pg'] |
| 327 | if env['machine'] == 'x86': |
| 328 | cflags += [ |
| 329 | '-m32', |
| 330 | #'-march=pentium4', |
| 331 | '-mmmx', '-msse', '-msse2', # enable SIMD intrinsics |
| 332 | #'-mfpmath=sse', |
| 333 | ] |
| 334 | if env['machine'] == 'x86_64': |
| 335 | cflags += ['-m64'] |
José Fonseca | 102cb5c | 2009-03-13 16:21:30 +0000 | [diff] [blame] | 336 | # See also: |
| 337 | # - http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html |
José Fonseca | 381e348 | 2008-07-17 11:23:43 +0900 | [diff] [blame] | 338 | cflags += [ |
José Fonseca | 102cb5c | 2009-03-13 16:21:30 +0000 | [diff] [blame] | 339 | '-Werror=declaration-after-statement', |
José Fonseca | 381e348 | 2008-07-17 11:23:43 +0900 | [diff] [blame] | 340 | '-Wall', |
| 341 | '-Wmissing-prototypes', |
José Fonseca | 102cb5c | 2009-03-13 16:21:30 +0000 | [diff] [blame] | 342 | '-Wmissing-field-initializers', |
| 343 | '-Wpointer-arith', |
José Fonseca | 381e348 | 2008-07-17 11:23:43 +0900 | [diff] [blame] | 344 | '-Wno-long-long', |
| 345 | '-ffast-math', |
José Fonseca | 47ca023 | 2009-01-14 13:03:09 +0000 | [diff] [blame] | 346 | '-std=gnu99', |
José Fonseca | 381e348 | 2008-07-17 11:23:43 +0900 | [diff] [blame] | 347 | '-fmessage-length=0', # be nice to Eclipse |
| 348 | ] |
| 349 | if msvc: |
| 350 | # See also: |
José Fonseca | a6c7258 | 2008-09-01 09:47:40 +0900 | [diff] [blame] | 351 | # - http://msdn.microsoft.com/en-us/library/19z1t1wy.aspx |
José Fonseca | 381e348 | 2008-07-17 11:23:43 +0900 | [diff] [blame] | 352 | # - cl /? |
| 353 | if debug: |
| 354 | cflags += [ |
| 355 | '/Od', # disable optimizations |
| 356 | '/Oi', # enable intrinsic functions |
| 357 | '/Oy-', # disable frame pointer omission |
José Fonseca | 73ccabc | 2009-02-12 11:57:45 +0000 | [diff] [blame] | 358 | '/GL-', # disable whole program optimization |
José Fonseca | 381e348 | 2008-07-17 11:23:43 +0900 | [diff] [blame] | 359 | ] |
| 360 | else: |
| 361 | cflags += [ |
| 362 | '/Ox', # maximum optimizations |
| 363 | '/Oi', # enable intrinsic functions |
José Fonseca | a6c7258 | 2008-09-01 09:47:40 +0900 | [diff] [blame] | 364 | '/Ot', # favor code speed |
| 365 | #'/fp:fast', # fast floating point |
José Fonseca | 381e348 | 2008-07-17 11:23:43 +0900 | [diff] [blame] | 366 | ] |
| 367 | if env['profile']: |
| 368 | cflags += [ |
| 369 | '/Gh', # enable _penter hook function |
| 370 | '/GH', # enable _pexit hook function |
| 371 | ] |
| 372 | cflags += [ |
| 373 | '/W3', # warning level |
| 374 | #'/Wp64', # enable 64 bit porting warnings |
| 375 | ] |
José Fonseca | a6c7258 | 2008-09-01 09:47:40 +0900 | [diff] [blame] | 376 | if env['machine'] == 'x86': |
| 377 | cflags += [ |
| 378 | #'/QIfist', # Suppress _ftol |
| 379 | #'/arch:SSE2', # use the SSE2 instructions |
| 380 | ] |
José Fonseca | 381e348 | 2008-07-17 11:23:43 +0900 | [diff] [blame] | 381 | if platform == 'windows': |
| 382 | cflags += [ |
| 383 | # TODO |
| 384 | ] |
| 385 | if platform == 'winddk': |
| 386 | cflags += [ |
| 387 | '/Zl', # omit default library name in .OBJ |
| 388 | '/Zp8', # 8bytes struct member alignment |
| 389 | '/Gy', # separate functions for linker |
| 390 | '/Gm-', # disable minimal rebuild |
| 391 | '/WX', # treat warnings as errors |
| 392 | '/Gz', # __stdcall Calling convention |
| 393 | '/GX-', # disable C++ EH |
| 394 | '/GR-', # disable C++ RTTI |
| 395 | '/GF', # enable read-only string pooling |
| 396 | '/G6', # optimize for PPro, P-II, P-III |
| 397 | '/Ze', # enable extensions |
| 398 | '/Gi-', # disable incremental compilation |
| 399 | '/QIfdiv-', # disable Pentium FDIV fix |
| 400 | '/hotpatch', # prepares an image for hotpatching. |
| 401 | #'/Z7', #enable old-style debug info |
| 402 | ] |
| 403 | if platform == 'wince': |
| 404 | # See also C:\WINCE600\public\common\oak\misc\makefile.def |
| 405 | cflags += [ |
| 406 | '/Zl', # omit default library name in .OBJ |
| 407 | '/GF', # enable read-only string pooling |
| 408 | '/GR-', # disable C++ RTTI |
| 409 | '/GS', # enable security checks |
| 410 | # Allow disabling language conformance to maintain backward compat |
| 411 | #'/Zc:wchar_t-', # don't force wchar_t as native type, instead of typedef |
| 412 | #'/Zc:forScope-', # don't enforce Standard C++ for scoping rules |
| 413 | #'/wd4867', |
| 414 | #'/wd4430', |
| 415 | #'/MT', |
| 416 | #'/U_MT', |
| 417 | ] |
| 418 | # Automatic pdb generation |
| 419 | # See http://scons.tigris.org/issues/show_bug.cgi?id=1656 |
| 420 | env.EnsureSConsVersion(0, 98, 0) |
| 421 | env['PDB'] = '${TARGET.base}.pdb' |
| 422 | env.Append(CFLAGS = cflags) |
| 423 | env.Append(CXXFLAGS = cflags) |
José Fonseca | b04aa71 | 2008-06-06 14:48:57 +0900 | [diff] [blame] | 424 | |
José Fonseca | 1781d7f | 2009-01-06 16:16:38 +0000 | [diff] [blame] | 425 | if env['platform'] == 'windows' and msvc: |
| 426 | # Choose the appropriate MSVC CRT |
| 427 | # http://msdn.microsoft.com/en-us/library/2kzt1wy3.aspx |
| 428 | if env['debug']: |
| 429 | env.Append(CCFLAGS = ['/MTd']) |
| 430 | env.Append(SHCCFLAGS = ['/LDd']) |
| 431 | else: |
| 432 | env.Append(CCFLAGS = ['/MT']) |
| 433 | env.Append(SHCCFLAGS = ['/LD']) |
| 434 | |
José Fonseca | 381e348 | 2008-07-17 11:23:43 +0900 | [diff] [blame] | 435 | # Assembler options |
| 436 | if gcc: |
| 437 | if env['machine'] == 'x86': |
| 438 | env.Append(ASFLAGS = ['-m32']) |
| 439 | if env['machine'] == 'x86_64': |
| 440 | env.Append(ASFLAGS = ['-m64']) |
José Fonseca | 27d8d6f | 2008-07-03 12:42:23 +0900 | [diff] [blame] | 441 | |
José Fonseca | 381e348 | 2008-07-17 11:23:43 +0900 | [diff] [blame] | 442 | # Linker options |
| 443 | linkflags = [] |
| 444 | if gcc: |
| 445 | if env['machine'] == 'x86': |
| 446 | linkflags += ['-m32'] |
| 447 | if env['machine'] == 'x86_64': |
| 448 | linkflags += ['-m64'] |
José Fonseca | 6fe421c | 2009-02-12 12:59:58 +0000 | [diff] [blame] | 449 | if platform == 'windows' and msvc: |
José Fonseca | 381e348 | 2008-07-17 11:23:43 +0900 | [diff] [blame] | 450 | # See also: |
| 451 | # - http://msdn2.microsoft.com/en-us/library/y0zzbyt4.aspx |
| 452 | linkflags += [ |
José Fonseca | 73ccabc | 2009-02-12 11:57:45 +0000 | [diff] [blame] | 453 | '/fixed:no', |
| 454 | '/incremental:no', |
| 455 | ] |
| 456 | if platform == 'winddk': |
| 457 | linkflags += [ |
José Fonseca | 381e348 | 2008-07-17 11:23:43 +0900 | [diff] [blame] | 458 | '/merge:_PAGE=PAGE', |
| 459 | '/merge:_TEXT=.text', |
| 460 | '/section:INIT,d', |
| 461 | '/opt:ref', |
| 462 | '/opt:icf', |
| 463 | '/ignore:4198,4010,4037,4039,4065,4070,4078,4087,4089,4221', |
| 464 | '/incremental:no', |
| 465 | '/fullbuild', |
| 466 | '/release', |
| 467 | '/nodefaultlib', |
| 468 | '/wx', |
| 469 | '/debug', |
| 470 | '/debugtype:cv', |
| 471 | '/version:5.1', |
| 472 | '/osversion:5.1', |
| 473 | '/functionpadmin:5', |
| 474 | '/safeseh', |
| 475 | '/pdbcompress', |
| 476 | '/stack:0x40000,0x1000', |
| 477 | '/driver', |
| 478 | '/align:0x80', |
| 479 | '/subsystem:native,5.01', |
| 480 | '/base:0x10000', |
| 481 | |
| 482 | '/entry:DrvEnableDriver', |
| 483 | ] |
José Fonseca | 4672803 | 2009-02-18 15:05:23 +0000 | [diff] [blame] | 484 | if env['debug'] or env['profile']: |
José Fonseca | 381e348 | 2008-07-17 11:23:43 +0900 | [diff] [blame] | 485 | linkflags += [ |
| 486 | '/MAP', # http://msdn.microsoft.com/en-us/library/k7xkk3e2.aspx |
| 487 | ] |
| 488 | if platform == 'wince': |
| 489 | linkflags += [ |
| 490 | '/nodefaultlib', |
| 491 | #'/incremental:no', |
| 492 | #'/fullbuild', |
| 493 | '/entry:_DllMainCRTStartup', |
| 494 | ] |
| 495 | env.Append(LINKFLAGS = linkflags) |
| 496 | |
José Fonseca | c76787a | 2008-07-17 11:25:20 +0900 | [diff] [blame] | 497 | # Default libs |
| 498 | env.Append(LIBS = []) |
| 499 | |
José Fonseca | 381e348 | 2008-07-17 11:23:43 +0900 | [diff] [blame] | 500 | # Custom builders and methods |
| 501 | createConvenienceLibBuilder(env) |
| 502 | createCodeGenerateMethod(env) |
José Fonseca | 52c2dd1 | 2008-09-08 07:54:15 +0900 | [diff] [blame] | 503 | createInstallMethods(env) |
José Fonseca | 381e348 | 2008-07-17 11:23:43 +0900 | [diff] [blame] | 504 | |
| 505 | # for debugging |
| 506 | #print env.Dump() |
José Fonseca | b04aa71 | 2008-06-06 14:48:57 +0900 | [diff] [blame] | 507 | |
| 508 | |
| 509 | def exists(env): |
José Fonseca | 381e348 | 2008-07-17 11:23:43 +0900 | [diff] [blame] | 510 | return 1 |