blob: 221752e812858b2e3de2e45b96393ecdc3c8bee6 [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
kasper.lund212ac232008-07-16 07:07:30 +000029import re
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000030import sys
31from os.path import join, dirname, abspath
32root_dir = dirname(File('SConstruct').rfile().abspath)
33sys.path.append(join(root_dir, 'tools'))
34import js2c
35
36
37def Abort(message):
38 print message
39 sys.exit(1)
40
41
42def GuessOS():
43 id = platform.system()
44 if id == 'Linux':
45 return 'linux'
46 elif id == 'Darwin':
47 return 'macos'
48 elif id == 'Windows':
49 return 'win32'
50 else:
kasper.lund212ac232008-07-16 07:07:30 +000051 return '<none>'
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000052
53
54def GuessProcessor():
55 id = platform.machine()
56 if id.startswith('arm'):
57 return 'arm'
kasper.lund212ac232008-07-16 07:07:30 +000058 elif (not id) or (not re.match('(x|i[3-6])86', id) is None):
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000059 return 'ia32'
60 else:
kasper.lund212ac232008-07-16 07:07:30 +000061 return '<none>'
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000062
63
64def GuessToolchain(os):
65 tools = Environment()['TOOLS']
66 if 'gcc' in tools:
kasper.lund7276f142008-07-30 08:49:36 +000067 return 'gcc'
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000068 elif 'msvc' in tools:
69 return 'msvc'
70 else:
kasper.lund212ac232008-07-16 07:07:30 +000071 return '<none>'
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000072
73
74def GetOptions():
75 result = Options()
76 os_guess = GuessOS()
77 toolchain_guess = GuessToolchain(os_guess)
78 processor_guess = GuessProcessor()
kasper.lund7276f142008-07-30 08:49:36 +000079 result.Add('mode', 'compilation mode (debug, release)', 'release')
80 result.Add('toolchain', 'the toolchain to use (gcc, msvc)', toolchain_guess)
81 result.Add('os', 'the os to build for (linux, macos, win32)', os_guess)
82 result.Add('processor', 'the processor to build for (arm, ia32)', processor_guess)
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000083 result.Add('snapshot', 'build using snapshots for faster start-up (on, off)', 'off')
84 result.Add('library', 'which type of library to produce (static, shared, default)', 'default')
kasper.lund7276f142008-07-30 08:49:36 +000085 result.Add('sample', 'build sample (process, shell)', '')
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000086 return result
87
88
89def VerifyOptions(env):
90 if not env['mode'] in ['debug', 'release']:
91 Abort("Unknown build mode '%s'." % env['mode'])
kasper.lund7276f142008-07-30 08:49:36 +000092 if not env['toolchain'] in ['gcc', 'msvc']:
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000093 Abort("Unknown toolchain '%s'." % env['toolchain'])
94 if not env['os'] in ['linux', 'macos', 'win32']:
95 Abort("Unknown os '%s'." % env['os'])
96 if not env['processor'] in ['arm', 'ia32']:
97 Abort("Unknown processor '%s'." % env['processor'])
98 if not env['snapshot'] in ['on', 'off']:
99 Abort("Illegal value for option snapshot: '%s'." % env['snapshot'])
100 if not env['library'] in ['static', 'shared', 'default']:
101 Abort("Illegal value for option library: '%s'." % env['library'])
kasper.lund7276f142008-07-30 08:49:36 +0000102 if not env['sample'] in ['', 'process', 'shell']:
103 Abort("Illegal value for option sample: '%s'." % env['sample'])
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000104
105
kasper.lund7276f142008-07-30 08:49:36 +0000106def Build():
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000107 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
kasper.lund7276f142008-07-30 08:49:36 +0000119 # Build the object files by invoking SCons recursively.
120 object_files = env.SConscript(
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000121 join('src', 'SConscript'),
kasper.lund7276f142008-07-30 08:49:36 +0000122 build_dir='build',
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000123 exports='toolchain arch os mode use_snapshot library_type',
124 duplicate=False
125 )
126
kasper.lund7276f142008-07-30 08:49:36 +0000127 # Link the object files into a library.
128 if library_type == 'static':
129 library = env.StaticLibrary('v8', object_files)
130 elif library_type == 'shared':
131 # There seems to be a glitch in the way scons decides where to put
132 # PDB files when compiling using MSVC so we specify it manually.
133 # This should not affect any other platforms.
134 library = env.SharedLibrary('v8', object_files, PDB='v8.dll.pdb')
135 else:
136 library = env.Library('v8', object_files)
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000137
kasper.lund7276f142008-07-30 08:49:36 +0000138 # Bail out if we're not building any sample.
139 sample = env['sample']
140 if not sample: return
141
142 # Build the sample.
143 env.Replace(CPPPATH='public')
144 object_path = join('build', 'samples', sample)
145 source_path = join('samples', sample + '.cc')
146 object = env.Object(object_path, source_path)
147 if toolchain == 'gcc':
148 env.Program(sample, [object, library], LIBS='pthread')
149 else:
150 env.Program(sample, [object, library], LIBS='WS2_32')
151
152
153Build()