blob: 81f2bf0cb7e54cc02605d4b5bff8e764902e879d [file] [log] [blame]
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001# Copyright 2008 Google Inc. All rights reserved.
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
28import platform
29import sys
30from os.path import join, dirname, abspath
31root_dir = dirname(File('SConstruct').rfile().abspath)
32sys.path.append(join(root_dir, 'tools'))
33import js2c
34
35
36def Abort(message):
37 print message
38 sys.exit(1)
39
40
41def GuessOS():
42 id = platform.system()
43 if id == 'Linux':
44 return 'linux'
45 elif id == 'Darwin':
46 return 'macos'
47 elif id == 'Windows':
48 return 'win32'
49 else:
50 Abort("Don't know how to build v8 for OS '%s'." % id)
51
52
53def GuessProcessor():
54 id = platform.machine()
55 if id.startswith('arm'):
56 return 'arm'
57 elif (not id) or id.startswith('x86'):
58 return 'ia32'
59 else:
60 Abort("Don't know how to build v8 for processor '%s'." % id)
61
62
63def GuessToolchain(os):
64 tools = Environment()['TOOLS']
65 if 'gcc' in tools:
66 if os == 'macos' and 'Kernel Version 8' in platform.version():
67 return 'gcc-darwin'
68 else:
69 return 'gcc'
70 elif 'msvc' in tools:
71 return 'msvc'
72 else:
73 tools = ', '.join(tools)
74 Abort("Don't know how to build v8 using these tools: %s" % tools)
75
76
77def GetOptions():
78 result = Options()
79 os_guess = GuessOS()
80 toolchain_guess = GuessToolchain(os_guess)
81 processor_guess = GuessProcessor()
82 result.Add('mode', 'debug or release', 'release')
83 result.Add('toolchain', 'the toolchain to use (gcc, gcc-darwin or msvc)', toolchain_guess)
84 result.Add('os', 'the os to build for (linux, macos or win32)', os_guess)
85 result.Add('processor', 'the processor to build for (arm or ia32)', processor_guess)
86 result.Add('snapshot', 'build using snapshots for faster start-up (on, off)', 'off')
87 result.Add('library', 'which type of library to produce (static, shared, default)', 'default')
88 return result
89
90
91def VerifyOptions(env):
92 if not env['mode'] in ['debug', 'release']:
93 Abort("Unknown build mode '%s'." % env['mode'])
94 if not env['toolchain'] in ['gcc', 'gcc-darwin', 'msvc']:
95 Abort("Unknown toolchain '%s'." % env['toolchain'])
96 if not env['os'] in ['linux', 'macos', 'win32']:
97 Abort("Unknown os '%s'." % env['os'])
98 if not env['processor'] in ['arm', 'ia32']:
99 Abort("Unknown processor '%s'." % env['processor'])
100 if not env['snapshot'] in ['on', 'off']:
101 Abort("Illegal value for option snapshot: '%s'." % env['snapshot'])
102 if not env['library'] in ['static', 'shared', 'default']:
103 Abort("Illegal value for option library: '%s'." % env['library'])
104
105
106def Start():
107 opts = GetOptions()
108 env = Environment(options=opts)
109 Help(opts.GenerateHelpText(env))
110 VerifyOptions(env)
111
112 os = env['os']
113 arch = env['processor']
114 toolchain = env['toolchain']
115 mode = env['mode']
116 use_snapshot = (env['snapshot'] == 'on')
117 library_type = env['library']
118
119 env.SConscript(
120 join('src', 'SConscript'),
121 build_dir=mode,
122 exports='toolchain arch os mode use_snapshot library_type',
123 duplicate=False
124 )
125
126
127Start()