ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1 | # Copyright 2008 the V8 project authors. All rights reserved. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2 | # Redistribution and use in source and binary forms, with or without |
| 3 | # modification, are permitted provided that the following conditions are |
| 4 | # met: |
| 5 | # |
| 6 | # * Redistributions of source code must retain the above copyright |
| 7 | # notice, this list of conditions and the following disclaimer. |
| 8 | # * Redistributions in binary form must reproduce the above |
| 9 | # copyright notice, this list of conditions and the following |
| 10 | # disclaimer in the documentation and/or other materials provided |
| 11 | # with the distribution. |
| 12 | # * Neither the name of Google Inc. nor the names of its |
| 13 | # contributors may be used to endorse or promote products derived |
| 14 | # from this software without specific prior written permission. |
| 15 | # |
| 16 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
| 28 | import platform |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 29 | import re |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 30 | import sys |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 31 | import os |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 32 | from os.path import join, dirname, abspath |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame^] | 33 | from types import DictType, StringTypes |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 34 | root_dir = dirname(File('SConstruct').rfile().abspath) |
| 35 | sys.path.append(join(root_dir, 'tools')) |
ager@chromium.org | c27e4e7 | 2008-09-04 13:52:27 +0000 | [diff] [blame] | 36 | import js2c, utils |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 37 | |
| 38 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 39 | LIBRARY_FLAGS = { |
| 40 | 'all': { |
| 41 | 'CPPDEFINES': ['ENABLE_LOGGING_AND_PROFILING'] |
| 42 | }, |
| 43 | 'gcc': { |
| 44 | 'all': { |
| 45 | 'DIALECTFLAGS': ['-ansi'], |
| 46 | 'CCFLAGS': ['$DIALECTFLAGS', '$WARNINGFLAGS', |
| 47 | '-fno-strict-aliasing'], |
| 48 | 'CXXFLAGS': ['$CCFLAGS', '-fno-rtti', '-fno-exceptions'], |
| 49 | 'LIBS': ['pthread'] |
| 50 | }, |
| 51 | 'mode:debug': { |
| 52 | 'CCFLAGS': ['-g', '-O0'], |
| 53 | 'CPPDEFINES': ['ENABLE_DISASSEMBLER', 'DEBUG'] |
| 54 | }, |
| 55 | 'mode:release': { |
| 56 | 'CCFLAGS': ['-O2'] |
| 57 | }, |
| 58 | 'wordsize:64': { |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 59 | 'CCFLAGS': ['-m32'], |
| 60 | 'LINKFLAGS': ['-m32'] |
| 61 | } |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 62 | }, |
| 63 | 'msvc': { |
| 64 | 'all': { |
| 65 | 'DIALECTFLAGS': ['/nologo'], |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 66 | 'CCFLAGS': ['$DIALECTFLAGS', '$WARNINGFLAGS'], |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 67 | 'CXXFLAGS': ['$CCFLAGS', '/GR-', '/Gy'], |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 68 | 'CPPDEFINES': ['WIN32', '_USE_32BIT_TIME_T', 'PCRE_STATIC'], |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 69 | 'LINKFLAGS': ['/NOLOGO', '/MACHINE:X86', '/INCREMENTAL:NO', |
| 70 | '/NXCOMPAT', '/IGNORE:4221'], |
| 71 | 'ARFLAGS': ['/NOLOGO'], |
| 72 | 'CCPDBFLAGS': ['/Zi'] |
| 73 | }, |
| 74 | 'mode:debug': { |
| 75 | 'CCFLAGS': ['/Od', '/Gm', '/MTd'], |
| 76 | 'CPPDEFINES': ['_DEBUG', 'ENABLE_DISASSEMBLER', 'DEBUG'], |
| 77 | 'LINKFLAGS': ['/DEBUG'] |
| 78 | }, |
| 79 | 'mode:release': { |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame^] | 80 | 'CCFLAGS': ['/Ox', '/MT', '/GF'], |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 81 | 'LINKFLAGS': ['/OPT:REF', '/OPT:ICF'] |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 82 | } |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | |
| 87 | V8_EXTRA_FLAGS = { |
| 88 | 'gcc': { |
| 89 | 'all': { |
| 90 | 'CXXFLAGS': [], #['-fvisibility=hidden'], |
| 91 | 'WARNINGFLAGS': ['-pedantic', '-Wall', '-Werror', '-W', |
| 92 | '-Wno-unused-parameter'] |
| 93 | }, |
| 94 | 'arch:arm': { |
| 95 | 'CPPDEFINES': ['ARM'] |
| 96 | }, |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 97 | 'disassembler:on': { |
| 98 | 'CPPDEFINES': ['ENABLE_DISASSEMBLER'] |
| 99 | } |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 100 | }, |
| 101 | 'msvc': { |
| 102 | 'all': { |
| 103 | 'WARNINGFLAGS': ['/W3', '/WX', '/wd4355', '/wd4800'] |
| 104 | }, |
| 105 | 'library:shared': { |
| 106 | 'CPPDEFINES': ['BUILDING_V8_SHARED'] |
| 107 | }, |
| 108 | 'arch:arm': { |
| 109 | 'CPPDEFINES': ['ARM'] |
| 110 | }, |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 111 | 'disassembler:on': { |
| 112 | 'CPPDEFINES': ['ENABLE_DISASSEMBLER'] |
| 113 | } |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 114 | } |
| 115 | } |
| 116 | |
| 117 | |
| 118 | JSCRE_EXTRA_FLAGS = { |
| 119 | 'gcc': { |
| 120 | 'all': { |
| 121 | 'CPPDEFINES': ['SUPPORT_UTF8', 'NO_RECURSE', 'SUPPORT_UCP'], |
| 122 | 'WARNINGFLAGS': ['-w'] |
| 123 | }, |
| 124 | }, |
| 125 | 'msvc': { |
| 126 | 'all': { |
| 127 | 'CPPDEFINES': ['SUPPORT_UTF8', 'NO_RECURSE', 'SUPPORT_UCP'], |
| 128 | 'WARNINGFLAGS': ['/W3', '/WX', '/wd4355', '/wd4800'] |
| 129 | }, |
| 130 | 'library:shared': { |
| 131 | 'CPPDEFINES': ['BUILDING_V8_SHARED'] |
| 132 | } |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | |
| 137 | DTOA_EXTRA_FLAGS = { |
| 138 | 'gcc': { |
| 139 | 'all': { |
| 140 | 'WARNINGFLAGS': ['-Werror'] |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame^] | 141 | } |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 142 | }, |
| 143 | 'msvc': { |
| 144 | 'all': { |
| 145 | 'WARNINGFLAGS': ['/WX', '/wd4018', '/wd4244'] |
| 146 | } |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | |
| 151 | CCTEST_EXTRA_FLAGS = { |
| 152 | 'all': { |
| 153 | 'CPPPATH': [join(root_dir, 'src')], |
| 154 | 'LIBS': ['$LIBRARY'] |
| 155 | }, |
| 156 | 'gcc': { |
| 157 | 'all': { |
| 158 | 'LIBPATH': [abspath('.')] |
| 159 | }, |
| 160 | 'wordsize:64': { |
| 161 | 'CCFLAGS': ['-m32'], |
| 162 | 'LINKFLAGS': ['-m32'] |
| 163 | }, |
| 164 | }, |
| 165 | 'msvc': { |
| 166 | 'all': { |
| 167 | 'CPPDEFINES': ['_HAS_EXCEPTIONS=0'] |
| 168 | }, |
| 169 | 'library:shared': { |
| 170 | 'CPPDEFINES': ['USING_V8_SHARED'] |
| 171 | } |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | |
| 176 | SAMPLE_FLAGS = { |
| 177 | 'all': { |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 178 | 'CPPPATH': [join(abspath('.'), 'include')], |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 179 | 'LIBS': ['$LIBRARY'], |
| 180 | }, |
| 181 | 'gcc': { |
| 182 | 'all': { |
| 183 | 'LIBS': ['pthread'], |
| 184 | 'LIBPATH': ['.'] |
| 185 | }, |
| 186 | 'wordsize:64': { |
| 187 | 'CCFLAGS': ['-m32'], |
| 188 | 'LINKFLAGS': ['-m32'] |
| 189 | }, |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame^] | 190 | 'mode:release': { |
| 191 | 'CCFLAGS': ['-O2'] |
| 192 | }, |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 193 | 'mode:debug': { |
| 194 | 'CCFLAGS': ['-g', '-O0'] |
| 195 | } |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 196 | }, |
| 197 | 'msvc': { |
| 198 | 'all': { |
| 199 | 'CCFLAGS': ['/nologo'], |
| 200 | }, |
| 201 | 'library:shared': { |
| 202 | 'CPPDEFINES': ['USING_V8_SHARED'] |
| 203 | }, |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame^] | 204 | 'prof:on': { |
| 205 | 'LINKFLAGS': ['/MAP'] |
| 206 | }, |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 207 | 'mode:release': { |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame^] | 208 | 'CCFLAGS': ['/Ox', '/MT', '/GF'], |
| 209 | 'LINKFLAGS': ['/OPT:REF', '/OPT:ICF'] |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 210 | }, |
| 211 | 'mode:debug': { |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame^] | 212 | 'CCFLAGS': ['/Od', '/MTd'], |
| 213 | 'LINKFLAGS': ['/DEBUG'] |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 214 | } |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | |
| 219 | SUFFIXES = { |
| 220 | 'release': '', |
| 221 | 'debug': '_g' |
| 222 | } |
| 223 | |
| 224 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 225 | def Abort(message): |
| 226 | print message |
| 227 | sys.exit(1) |
| 228 | |
| 229 | |
| 230 | def GuessOS(): |
| 231 | id = platform.system() |
| 232 | if id == 'Linux': |
| 233 | return 'linux' |
| 234 | elif id == 'Darwin': |
| 235 | return 'macos' |
| 236 | elif id == 'Windows': |
| 237 | return 'win32' |
| 238 | else: |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 239 | return None |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 240 | |
| 241 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 242 | def GuessWordsize(): |
| 243 | if '64' in platform.machine(): |
| 244 | return '64' |
| 245 | else: |
| 246 | return '32' |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 247 | |
| 248 | |
| 249 | def GuessToolchain(os): |
| 250 | tools = Environment()['TOOLS'] |
| 251 | if 'gcc' in tools: |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 252 | return 'gcc' |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 253 | elif 'msvc' in tools: |
| 254 | return 'msvc' |
| 255 | else: |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 256 | return None |
| 257 | |
| 258 | |
| 259 | OS_GUESS = GuessOS() |
| 260 | TOOLCHAIN_GUESS = GuessToolchain(OS_GUESS) |
ager@chromium.org | c27e4e7 | 2008-09-04 13:52:27 +0000 | [diff] [blame] | 261 | ARCH_GUESS = utils.GuessArchitecture() |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 262 | WORDSIZE_GUESS = GuessWordsize() |
| 263 | |
| 264 | |
| 265 | SIMPLE_OPTIONS = { |
| 266 | 'toolchain': { |
| 267 | 'values': ['gcc', 'msvc'], |
| 268 | 'default': TOOLCHAIN_GUESS, |
| 269 | 'help': 'the toolchain to use' |
| 270 | }, |
| 271 | 'os': { |
| 272 | 'values': ['linux', 'macos', 'win32'], |
| 273 | 'default': OS_GUESS, |
| 274 | 'help': 'the os to build for' |
| 275 | }, |
| 276 | 'arch': { |
| 277 | 'values':['arm', 'ia32'], |
| 278 | 'default': ARCH_GUESS, |
| 279 | 'help': 'the architecture to build for' |
| 280 | }, |
| 281 | 'snapshot': { |
| 282 | 'values': ['on', 'off'], |
| 283 | 'default': 'off', |
| 284 | 'help': 'build using snapshots for faster start-up' |
| 285 | }, |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame^] | 286 | 'prof': { |
| 287 | 'values': ['on', 'off'], |
| 288 | 'default': 'off', |
| 289 | 'help': 'enable profiling of build target' |
| 290 | }, |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 291 | 'library': { |
| 292 | 'values': ['static', 'shared'], |
| 293 | 'default': 'static', |
| 294 | 'help': 'the type of library to produce' |
| 295 | }, |
| 296 | 'wordsize': { |
| 297 | 'values': ['64', '32'], |
| 298 | 'default': WORDSIZE_GUESS, |
| 299 | 'help': 'the word size' |
| 300 | }, |
| 301 | 'simulator': { |
| 302 | 'values': ['arm', 'none'], |
| 303 | 'default': 'none', |
| 304 | 'help': 'build with simulator' |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 305 | }, |
| 306 | 'disassembler': { |
| 307 | 'values': ['on', 'off'], |
| 308 | 'default': 'off', |
| 309 | 'help': 'enable the disassembler to inspect generated code' |
| 310 | }, |
| 311 | 'sourcesignatures': { |
| 312 | 'values': ['MD5', 'timestamp'], |
| 313 | 'default': 'MD5', |
| 314 | 'help': 'set how the build system detects file changes' |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 315 | } |
| 316 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 317 | |
| 318 | |
| 319 | def GetOptions(): |
| 320 | result = Options() |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 321 | result.Add('mode', 'compilation mode (debug, release)', 'release') |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 322 | result.Add('sample', 'build sample (shell, process)', '') |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 323 | result.Add('env', 'override environment settings (NAME1:value1,NAME2:value2)', '') |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame^] | 324 | for (name, option) in SIMPLE_OPTIONS.iteritems(): |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 325 | help = '%s (%s)' % (name, ", ".join(option['values'])) |
| 326 | result.Add(name, help, option.get('default')) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 327 | return result |
| 328 | |
| 329 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 330 | def SplitList(str): |
| 331 | return [ s for s in str.split(",") if len(s) > 0 ] |
| 332 | |
| 333 | |
| 334 | def IsLegal(env, option, values): |
| 335 | str = env[option] |
| 336 | for s in SplitList(str): |
| 337 | if not s in values: |
| 338 | Abort("Illegal value for option %s '%s'." % (option, s)) |
| 339 | return False |
| 340 | return True |
| 341 | |
| 342 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 343 | def VerifyOptions(env): |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 344 | if not IsLegal(env, 'mode', ['debug', 'release']): |
| 345 | return False |
| 346 | if not IsLegal(env, 'sample', ["shell", "process"]): |
| 347 | return False |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame^] | 348 | if env['os'] == 'win32' and env['library'] == 'shared' and env['prof'] == 'on': |
| 349 | Abort("Profiling on windows only supported for static library.") |
| 350 | for (name, option) in SIMPLE_OPTIONS.iteritems(): |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 351 | if (not option.get('default')) and (name not in ARGUMENTS): |
| 352 | message = ("A value for option %s must be specified (%s)." % |
| 353 | (name, ", ".join(option['values']))) |
| 354 | Abort(message) |
| 355 | if not env[name] in option['values']: |
| 356 | message = ("Unknown %s value '%s'. Possible values are (%s)." % |
| 357 | (name, env[name], ", ".join(option['values']))) |
| 358 | Abort(message) |
| 359 | |
| 360 | |
| 361 | class BuildContext(object): |
| 362 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 363 | def __init__(self, options, env_overrides, samples): |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 364 | self.library_targets = [] |
| 365 | self.cctest_targets = [] |
| 366 | self.sample_targets = [] |
| 367 | self.options = options |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 368 | self.env_overrides = env_overrides |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 369 | self.samples = samples |
| 370 | self.use_snapshot = (options['snapshot'] == 'on') |
| 371 | self.flags = None |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame^] | 372 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 373 | def AddRelevantFlags(self, initial, flags): |
| 374 | result = initial.copy() |
| 375 | self.AppendFlags(result, flags.get('all')) |
| 376 | toolchain = self.options['toolchain'] |
| 377 | self.AppendFlags(result, flags[toolchain].get('all')) |
| 378 | for option in sorted(self.options.keys()): |
| 379 | value = self.options[option] |
| 380 | self.AppendFlags(result, flags[toolchain].get(option + ':' + value)) |
| 381 | return result |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame^] | 382 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 383 | def GetRelevantSources(self, source): |
| 384 | result = [] |
| 385 | result += source.get('all', []) |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame^] | 386 | for (name, value) in self.options.iteritems(): |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 387 | result += source.get(name + ':' + value, []) |
| 388 | return sorted(result) |
| 389 | |
| 390 | def AppendFlags(self, options, added): |
| 391 | if not added: |
| 392 | return |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame^] | 393 | for (key, value) in added.iteritems(): |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 394 | if not key in options: |
| 395 | options[key] = value |
| 396 | else: |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame^] | 397 | prefix = options[key] |
| 398 | if isinstance(prefix, StringTypes): prefix = prefix.split() |
| 399 | options[key] = prefix + value |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 400 | |
| 401 | def ConfigureObject(self, env, input, **kw): |
| 402 | if self.options['library'] == 'static': |
| 403 | return env.StaticObject(input, **kw) |
| 404 | else: |
| 405 | return env.SharedObject(input, **kw) |
| 406 | |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 407 | def ApplyEnvOverrides(self, env): |
| 408 | if not self.env_overrides: |
| 409 | return |
| 410 | if type(env['ENV']) == DictType: |
| 411 | env['ENV'].update(**self.env_overrides) |
| 412 | else: |
| 413 | env['ENV'] = self.env_overrides |
| 414 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 415 | |
| 416 | def PostprocessOptions(options): |
| 417 | # Adjust architecture if the simulator option has been set |
| 418 | if (options['simulator'] != 'none') and (options['arch'] != options['simulator']): |
| 419 | if 'arch' in ARGUMENTS: |
| 420 | # Print a warning if arch has explicitly been set |
| 421 | print "Warning: forcing architecture to match simulator (%s)" % options['simulator'] |
| 422 | options['arch'] = options['simulator'] |
| 423 | |
| 424 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 425 | def ParseEnvOverrides(arg): |
| 426 | # The environment overrides are in the format NAME1:value1,NAME2:value2 |
| 427 | overrides = {} |
| 428 | for override in arg.split(','): |
| 429 | pos = override.find(':') |
| 430 | if pos == -1: |
| 431 | continue |
| 432 | overrides[override[:pos].strip()] = override[pos+1:].strip() |
| 433 | return overrides |
| 434 | |
| 435 | |
| 436 | def BuildSpecific(env, mode, env_overrides): |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 437 | options = {'mode': mode} |
| 438 | for option in SIMPLE_OPTIONS: |
| 439 | options[option] = env[option] |
| 440 | PostprocessOptions(options) |
| 441 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 442 | context = BuildContext(options, env_overrides, samples=SplitList(env['sample'])) |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 443 | |
| 444 | library_flags = context.AddRelevantFlags(os.environ, LIBRARY_FLAGS) |
| 445 | v8_flags = context.AddRelevantFlags(library_flags, V8_EXTRA_FLAGS) |
| 446 | jscre_flags = context.AddRelevantFlags(library_flags, JSCRE_EXTRA_FLAGS) |
| 447 | dtoa_flags = context.AddRelevantFlags(library_flags, DTOA_EXTRA_FLAGS) |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame^] | 448 | cctest_flags = context.AddRelevantFlags(v8_flags, CCTEST_EXTRA_FLAGS) |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 449 | sample_flags = context.AddRelevantFlags(os.environ, SAMPLE_FLAGS) |
| 450 | |
| 451 | context.flags = { |
| 452 | 'v8': v8_flags, |
| 453 | 'jscre': jscre_flags, |
| 454 | 'dtoa': dtoa_flags, |
| 455 | 'cctest': cctest_flags, |
| 456 | 'sample': sample_flags |
| 457 | } |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame^] | 458 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 459 | target_id = mode |
| 460 | suffix = SUFFIXES[target_id] |
| 461 | library_name = 'v8' + suffix |
| 462 | env['LIBRARY'] = library_name |
| 463 | |
| 464 | # Build the object files by invoking SCons recursively. |
| 465 | object_files = env.SConscript( |
| 466 | join('src', 'SConscript'), |
| 467 | build_dir=join('obj', target_id), |
| 468 | exports='context', |
| 469 | duplicate=False |
| 470 | ) |
| 471 | |
| 472 | # Link the object files into a library. |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 473 | env.Replace(**context.flags['v8']) |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 474 | context.ApplyEnvOverrides(env) |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 475 | if context.options['library'] == 'static': |
| 476 | library = env.StaticLibrary(library_name, object_files) |
| 477 | else: |
| 478 | # There seems to be a glitch in the way scons decides where to put |
| 479 | # PDB files when compiling using MSVC so we specify it manually. |
| 480 | # This should not affect any other platforms. |
| 481 | pdb_name = library_name + '.dll.pdb' |
| 482 | library = env.SharedLibrary(library_name, object_files, PDB=pdb_name) |
| 483 | context.library_targets.append(library) |
| 484 | |
| 485 | for sample in context.samples: |
| 486 | sample_env = Environment(LIBRARY=library_name) |
| 487 | sample_env.Replace(**context.flags['sample']) |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 488 | context.ApplyEnvOverrides(sample_env) |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 489 | sample_object = sample_env.SConscript( |
| 490 | join('samples', 'SConscript'), |
| 491 | build_dir=join('obj', 'sample', sample, target_id), |
| 492 | exports='sample context', |
| 493 | duplicate=False |
| 494 | ) |
| 495 | sample_name = sample + suffix |
| 496 | sample_program = sample_env.Program(sample_name, sample_object) |
| 497 | sample_env.Depends(sample_program, library) |
| 498 | context.sample_targets.append(sample_program) |
| 499 | |
| 500 | cctest_program = env.SConscript( |
| 501 | join('test', 'cctest', 'SConscript'), |
| 502 | build_dir=join('obj', 'test', target_id), |
| 503 | exports='context object_files', |
| 504 | duplicate=False |
| 505 | ) |
| 506 | context.cctest_targets.append(cctest_program) |
| 507 | |
| 508 | return context |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 509 | |
| 510 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 511 | def Build(): |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 512 | opts = GetOptions() |
| 513 | env = Environment(options=opts) |
| 514 | Help(opts.GenerateHelpText(env)) |
| 515 | VerifyOptions(env) |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 516 | env_overrides = ParseEnvOverrides(env['env']) |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 517 | |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 518 | SourceSignatures(env['sourcesignatures']) |
| 519 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 520 | libraries = [] |
| 521 | cctests = [] |
| 522 | samples = [] |
| 523 | modes = SplitList(env['mode']) |
| 524 | for mode in modes: |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 525 | context = BuildSpecific(env.Copy(), mode, env_overrides) |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 526 | libraries += context.library_targets |
| 527 | cctests += context.cctest_targets |
| 528 | samples += context.sample_targets |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 529 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 530 | env.Alias('library', libraries) |
| 531 | env.Alias('cctests', cctests) |
| 532 | env.Alias('sample', samples) |
| 533 | |
| 534 | if env['sample']: |
| 535 | env.Default('sample') |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 536 | else: |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 537 | env.Default('library') |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 538 | |
| 539 | |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 540 | # We disable deprecation warnings because we need to be able to use |
| 541 | # env.Copy without getting warnings for compatibility with older |
| 542 | # version of scons. Also, there's a bug in some revisions that |
| 543 | # doesn't allow this flag to be set, so we swallow any exceptions. |
| 544 | # Lovely. |
| 545 | try: |
| 546 | SetOption('warn', 'no-deprecated') |
| 547 | except: |
| 548 | pass |
| 549 | |
| 550 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 551 | Build() |