blob: bca56515a41da49c5efc350244f61b8d8a8d3508 [file] [log] [blame]
armvixlad96eda2013-06-14 11:42:37 +01001# Copyright 2013, ARM Limited
2# All rights reserved.
3#
4# Redistribution and use in source and binary forms, with or without
5# modification, are permitted provided that the following conditions are met:
6#
7# * Redistributions of source code must retain the above copyright notice,
8# this list of conditions and the following disclaimer.
9# * Redistributions in binary form must reproduce the above copyright notice,
10# this list of conditions and the following disclaimer in the documentation
11# and/or other materials provided with the distribution.
12# * Neither the name of ARM Limited nor the names of its contributors may be
13# used to endorse or promote products derived from this software without
14# specific prior written permission.
15#
16# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS CONTRIBUTORS "AS IS" AND
17# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
20# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
27import os
28import os.path
armvixlc68cb642014-09-25 18:49:30 +010029import platform
armvixl4a102ba2014-07-14 09:02:40 +010030import subprocess
armvixlad96eda2013-06-14 11:42:37 +010031import sys
32
armvixl4a102ba2014-07-14 09:02:40 +010033root_dir = os.path.dirname(File('SConstruct').rfile().abspath)
34sys.path.insert(0, os.path.join(root_dir, 'tools'))
35import util
36
armvixlc68cb642014-09-25 18:49:30 +010037
38Help('''
39Build system for the VIXL project.
40See README.md for documentation and details about the build system.
41Some common build targets are:
42 scons # Build the VIXL library and test utility.
43 scons examples # Build all the examples.
44 scons benchmarks # Build all the benchmarks.
45 scons all # Build everything.
46
47''')
48
49
armvixlad96eda2013-06-14 11:42:37 +010050# Global configuration.
51PROJ_SRC_DIR = 'src'
52PROJ_SRC_FILES = '''
53src/utils.cc
armvixlc68cb642014-09-25 18:49:30 +010054src/code-buffer.cc
armvixlad96eda2013-06-14 11:42:37 +010055src/a64/assembler-a64.cc
56src/a64/macro-assembler-a64.cc
57src/a64/instructions-a64.cc
58src/a64/decoder-a64.cc
59src/a64/debugger-a64.cc
60src/a64/disasm-a64.cc
61src/a64/cpu-a64.cc
62src/a64/simulator-a64.cc
armvixl578645f2013-08-15 17:21:42 +010063src/a64/instrument-a64.cc
armvixlad96eda2013-06-14 11:42:37 +010064'''.split()
65PROJ_EXAMPLES_DIR = 'examples'
66PROJ_EXAMPLES_SRC_FILES = '''
67examples/debugger.cc
68examples/add3-double.cc
69examples/add4-double.cc
70examples/factorial-rec.cc
71examples/factorial.cc
72examples/sum-array.cc
73examples/abs.cc
74examples/swap4.cc
75examples/swap-int32.cc
76examples/check-bounds.cc
77examples/getting-started.cc
armvixlc68cb642014-09-25 18:49:30 +010078examples/non-const-visitor.cc
79examples/custom-disassembler.cc
armvixlad96eda2013-06-14 11:42:37 +010080'''.split()
81# List target specific files.
82# Target names are used as dictionary entries.
83TARGET_SRC_DIR = {
84 'cctest': 'test',
armvixl4a102ba2014-07-14 09:02:40 +010085 'bench-dataop': 'benchmarks',
86 'bench-branch': 'benchmarks',
87 'bench-branch-link': 'benchmarks',
armvixlad96eda2013-06-14 11:42:37 +010088 'examples': 'examples'
89}
90TARGET_SRC_FILES = {
91 'cctest': '''
92 test/cctest.cc
93 test/test-utils-a64.cc
94 test/test-assembler-a64.cc
armvixlb0c8ae22014-03-21 14:03:59 +000095 test/test-simulator-a64.cc
armvixlad96eda2013-06-14 11:42:37 +010096 test/test-disasm-a64.cc
armvixl578645f2013-08-15 17:21:42 +010097 test/test-fuzz-a64.cc
armvixlad96eda2013-06-14 11:42:37 +010098 test/examples/test-examples.cc
armvixl4a102ba2014-07-14 09:02:40 +010099 '''.split(),
100 'bench-dataop': '''
armvixlad96eda2013-06-14 11:42:37 +0100101 benchmarks/bench-dataop.cc
102 '''.split(),
armvixl4a102ba2014-07-14 09:02:40 +0100103 'bench-branch': '''
armvixlad96eda2013-06-14 11:42:37 +0100104 benchmarks/bench-branch.cc
armvixl4a102ba2014-07-14 09:02:40 +0100105 '''.split(),
106 'bench-branch-link': '''
107 benchmarks/bench-branch-link.cc
armvixlad96eda2013-06-14 11:42:37 +0100108 '''.split()
109}
110RELEASE_OBJ_DIR = 'obj/release'
111DEBUG_OBJ_DIR = 'obj/debug'
armvixlad96eda2013-06-14 11:42:37 +0100112
113
114# Helper functions.
115def abort(message):
116 print('ABORTING: ' + message)
117 sys.exit(1)
118
119
120def list_target(obj_dir, src_files):
121 return map(lambda x: os.path.join(obj_dir, x), src_files)
122
123
124def create_variant(obj_dir, targets_dir):
125 VariantDir(os.path.join(obj_dir, PROJ_SRC_DIR), PROJ_SRC_DIR)
126 for directory in targets_dir.itervalues():
127 VariantDir(os.path.join(obj_dir, directory), directory)
128
129
130# Build arguments.
131args = Variables()
132args.Add(EnumVariable('mode', 'Build mode', 'release',
armvixl4a102ba2014-07-14 09:02:40 +0100133 allowed_values = ['release', 'debug']))
armvixlc68cb642014-09-25 18:49:30 +0100134sim_default = 'off' if platform.machine() == 'aarch64' else 'on'
135args.Add(EnumVariable('simulator', 'build for the simulator', sim_default,
armvixlad96eda2013-06-14 11:42:37 +0100136 allowed_values = ['on', 'off']))
137
138# Configure the environment.
139create_variant(RELEASE_OBJ_DIR, TARGET_SRC_DIR)
140create_variant(DEBUG_OBJ_DIR, TARGET_SRC_DIR)
armvixlad96eda2013-06-14 11:42:37 +0100141env = Environment(variables=args)
142
143# Commandline help.
armvixlc68cb642014-09-25 18:49:30 +0100144Help(args.GenerateHelpText(env) + '\n')
armvixlad96eda2013-06-14 11:42:37 +0100145
146# Abort if any invalid argument was passed.
147# This check must happened after an environment is created.
148unknown_arg = args.UnknownVariables()
149if unknown_arg:
150 abort('Unknown variable(s): ' + str(unknown_arg.keys()))
151
152# Setup tools.
153# This is necessary for cross-compilation.
154env['CXX'] = os.environ.get('CXX', env.get('CXX'))
155env['AR'] = os.environ.get('AR', env.get('AR'))
156env['RANLIB'] = os.environ.get('RANLIB', env.get('RANLIB'))
157env['CC'] = os.environ.get('CC', env.get('CC'))
158env['LD'] = os.environ.get('LD', env.get('LD'))
159
armvixlb0c8ae22014-03-21 14:03:59 +0000160if os.environ.get('CPPFLAGS'):
161 env.Append(CPPFLAGS = os.environ.get('CPPFLAGS').split())
162if os.environ.get('LINKFLAGS'):
163 env.Append(LINKFLAGS = os.environ.get('LINKFLAGS').split())
armvixlad96eda2013-06-14 11:42:37 +0100164
165# Always look in 'src' for include files.
166env.Append(CPPPATH = [PROJ_SRC_DIR])
167env.Append(CPPFLAGS = ['-Wall',
168 '-Werror',
169 '-fdiagnostics-show-option',
170 '-Wextra',
171 '-pedantic',
172 # Explicitly enable the write-strings warning. VIXL uses
173 # const correctly when handling string constants.
174 '-Wwrite-strings'])
175
armvixlad96eda2013-06-14 11:42:37 +0100176build_suffix = ''
177
armvixl4a102ba2014-07-14 09:02:40 +0100178
armvixlad96eda2013-06-14 11:42:37 +0100179if env['simulator'] == 'on':
180 env.Append(CPPFLAGS = ['-DUSE_SIMULATOR'])
181 build_suffix += '_sim'
182
183if env['mode'] == 'debug':
184 env.Append(CPPFLAGS = ['-g', '-DDEBUG'])
185 # Append the debug mode suffix to the executable name.
186 build_suffix += '_g'
187 build_dir = DEBUG_OBJ_DIR
armvixlad96eda2013-06-14 11:42:37 +0100188else:
189 # Release mode.
190 env.Append(CPPFLAGS = ['-O3'])
191 build_dir = RELEASE_OBJ_DIR
armvixl4a102ba2014-07-14 09:02:40 +0100192 process = subprocess.Popen(env['CXX'] + ' --version | grep "gnu.*4\.8"',
193 shell = True,
194 stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
195 stdout, stderr = process.communicate()
196 using_gcc48 = stdout != ''
197 if using_gcc48:
198 # GCC 4.8 has a bug which produces a warning saying that an anonymous
199 # Operand object might be used uninitialized:
200 # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57045
201 # The bug does not seem to appear in GCC 4.7, or in debug builds with
202 # GCC 4.8.
203 env.Append(CPPFLAGS = ['-Wno-maybe-uninitialized'])
armvixlad96eda2013-06-14 11:42:37 +0100204
205
armvixl4a102ba2014-07-14 09:02:40 +0100206# The lists of available targets and target names.
207targets = []
208target_alias_names = []
209# Helper to create aliases.
210def create_alias(name, target):
211 env.Alias(name, target)
212 targets.append(target)
213 target_alias_names.append(name)
armvixlad96eda2013-06-14 11:42:37 +0100214
armvixlad96eda2013-06-14 11:42:37 +0100215
armvixl4a102ba2014-07-14 09:02:40 +0100216# The vixl library.
217libvixl = env.Library('vixl' + build_suffix,
218 list_target(build_dir, PROJ_SRC_FILES))
219create_alias('libvixl', libvixl)
220
221
222# The cctest executable.
223# The cctest requires building the example files with specific options, so we
224# create a separate variant dir for the example objects built this way.
225cctest_ex_vdir = os.path.join(build_dir, 'cctest_examples')
226VariantDir(cctest_ex_vdir, '.')
227cctest_ex_obj = env.Object(list_target(cctest_ex_vdir, PROJ_EXAMPLES_SRC_FILES),
228 CPPFLAGS = env['CPPFLAGS'] + ['-DTEST_EXAMPLES'])
229cctest = env.Program('cctest' + build_suffix,
230 list_target(build_dir, TARGET_SRC_FILES['cctest']) +
231 cctest_ex_obj + libvixl,
232 CPPPATH = env['CPPPATH'] + [PROJ_EXAMPLES_DIR])
233create_alias('cctest', cctest)
234
235# The benchmarks.
236for bench in ['bench-dataop', 'bench-branch', 'bench-branch-link']:
237 prog = env.Program(bench + build_suffix,
238 list_target(build_dir, TARGET_SRC_FILES[bench]) + libvixl)
239 create_alias(bench, prog)
240
241# The examples.
242examples = []
243for example in PROJ_EXAMPLES_SRC_FILES:
244 example_name = "example-" + os.path.splitext(os.path.basename(example))[0]
245 prog = env.Program(example_name,
246 [os.path.join(build_dir, example)] + libvixl,
247 CPPPATH = env['CPPPATH'] + [PROJ_EXAMPLES_DIR])
248 create_alias(example_name, prog)
249 examples.append(prog)
250# Alias to build all examples.
251create_alias('examples', examples)
252
253
254# Create a simple alias to build everything with the current options.
255create_alias('all', targets)
256
armvixlc68cb642014-09-25 18:49:30 +0100257Help('Available top level targets:\n' + '\t' + '\n\t'.join(target_alias_names) + '\n')
armvixl4a102ba2014-07-14 09:02:40 +0100258
259# By default, only build the cctests.
260Default(libvixl, cctest)