blob: b31e65ff4b840ed7a370fa0456c558803906780c [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:
67 if os == 'macos' and 'Kernel Version 8' in platform.version():
68 return 'gcc-darwin'
69 else:
70 return 'gcc'
71 elif 'msvc' in tools:
72 return 'msvc'
73 else:
kasper.lund212ac232008-07-16 07:07:30 +000074 return '<none>'
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000075
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()