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