Alexandre Rames | b78f139 | 2016-07-01 14:22:22 +0100 | [diff] [blame] | 1 | # Copyright 2015, VIXL authors |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 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 | |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 27 | import glob |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 28 | import os |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 29 | from os.path import join |
armvixl | c68cb64 | 2014-09-25 18:49:30 +0100 | [diff] [blame] | 30 | import platform |
armvixl | 4a102ba | 2014-07-14 09:02:40 +0100 | [diff] [blame] | 31 | import subprocess |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 32 | import sys |
Pierre Langlois | a3b2146 | 2016-08-04 16:01:51 +0100 | [diff] [blame] | 33 | from collections import OrderedDict |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 34 | |
armvixl | 4a102ba | 2014-07-14 09:02:40 +0100 | [diff] [blame] | 35 | root_dir = os.path.dirname(File('SConstruct').rfile().abspath) |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 36 | sys.path.insert(0, join(root_dir, 'tools')) |
| 37 | import config |
armvixl | 4a102ba | 2014-07-14 09:02:40 +0100 | [diff] [blame] | 38 | import util |
| 39 | |
armvixl | c68cb64 | 2014-09-25 18:49:30 +0100 | [diff] [blame] | 40 | |
| 41 | Help(''' |
| 42 | Build system for the VIXL project. |
| 43 | See README.md for documentation and details about the build system. |
armvixl | c68cb64 | 2014-09-25 18:49:30 +0100 | [diff] [blame] | 44 | ''') |
| 45 | |
| 46 | |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 47 | # We track top-level targets to automatically generate help and alias them. |
| 48 | class TopLevelTargets: |
| 49 | def __init__(self): |
| 50 | self.targets = [] |
| 51 | self.help_messages = [] |
| 52 | def Add(self, target, help_message): |
| 53 | self.targets.append(target) |
| 54 | self.help_messages.append(help_message) |
| 55 | def Help(self): |
armvixl | 684cd2a | 2015-10-23 13:38:33 +0100 | [diff] [blame] | 56 | res = "" |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 57 | for i in range(len(self.targets)): |
| 58 | res += '\t{0:<{1}}{2:<{3}}\n'.format( |
| 59 | 'scons ' + self.targets[i], |
| 60 | len('scons ') + max(map(len, self.targets)), |
| 61 | ' : ' + self.help_messages[i], |
| 62 | len(' : ') + max(map(len, self.help_messages))) |
| 63 | return res |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 64 | |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 65 | top_level_targets = TopLevelTargets() |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 66 | |
| 67 | |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 68 | |
| 69 | # Build options ---------------------------------------------------------------- |
| 70 | |
| 71 | # Store all the options in a dictionary. |
| 72 | # The SConstruct will check the build variables and construct the build |
| 73 | # environment as appropriate. |
| 74 | options = { |
| 75 | 'all' : { # Unconditionally processed. |
| 76 | 'CCFLAGS' : ['-Wall', |
| 77 | '-Werror', |
| 78 | '-fdiagnostics-show-option', |
| 79 | '-Wextra', |
| 80 | '-Wredundant-decls', |
| 81 | '-pedantic', |
armvixl | 684cd2a | 2015-10-23 13:38:33 +0100 | [diff] [blame] | 82 | '-Wmissing-noreturn', |
Alexandre Rames | fd09817 | 2016-08-09 10:29:53 +0100 | [diff] [blame] | 83 | '-Wwrite-strings', |
| 84 | '-Wunused'], |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 85 | 'CPPPATH' : [config.dir_src_vixl] |
| 86 | }, |
| 87 | # 'build_option:value' : { |
| 88 | # 'environment_key' : 'values to append' |
| 89 | # }, |
| 90 | 'mode:debug' : { |
| 91 | 'CCFLAGS' : ['-DVIXL_DEBUG', '-O0'] |
| 92 | }, |
| 93 | 'mode:release' : { |
Alexandre Rames | fa4a4bd | 2016-07-25 14:14:22 +0100 | [diff] [blame] | 94 | 'CCFLAGS' : ['-O3'], |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 95 | }, |
Alexandre Rames | d5bfa5a | 2016-10-25 09:55:51 +0100 | [diff] [blame] | 96 | 'target_arch:aarch32' : { |
Alexandre Rames | 586c6b9 | 2016-10-24 11:59:33 +0100 | [diff] [blame] | 97 | 'CCFLAGS' : ['-DVIXL_INCLUDE_TARGET_AARCH32'] |
| 98 | }, |
Alexandre Rames | d5bfa5a | 2016-10-25 09:55:51 +0100 | [diff] [blame] | 99 | 'target_arch:aarch64' : { |
Alexandre Rames | 586c6b9 | 2016-10-24 11:59:33 +0100 | [diff] [blame] | 100 | 'CCFLAGS' : ['-DVIXL_INCLUDE_TARGET_AARCH64'] |
| 101 | }, |
Alexandre Rames | d5bfa5a | 2016-10-25 09:55:51 +0100 | [diff] [blame] | 102 | 'target_arch:both' : { |
Alexandre Rames | a3aef4f | 2016-10-28 15:39:51 +0100 | [diff] [blame] | 103 | 'CCFLAGS' : ['-DVIXL_INCLUDE_TARGET_AARCH32', |
| 104 | '-DVIXL_INCLUDE_TARGET_AARCH64'] |
Alexandre Rames | 586c6b9 | 2016-10-24 11:59:33 +0100 | [diff] [blame] | 105 | }, |
Pierre Langlois | a3b2146 | 2016-08-04 16:01:51 +0100 | [diff] [blame] | 106 | 'simulator:aarch64' : { |
Pierre Langlois | 1e85b7f | 2016-08-05 14:20:36 +0100 | [diff] [blame] | 107 | 'CCFLAGS' : ['-DVIXL_INCLUDE_SIMULATOR_AARCH64'], |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 108 | }, |
| 109 | 'symbols:on' : { |
| 110 | 'CCFLAGS' : ['-g'], |
| 111 | 'LINKFLAGS' : ['-g'] |
| 112 | }, |
| 113 | } |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 114 | |
| 115 | |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 116 | # A `DefaultVariable` has a default value that depends on elements not known |
| 117 | # when variables are first evaluated. |
| 118 | # Each `DefaultVariable` has a handler that will compute the default value for |
| 119 | # the given environment. |
| 120 | def modifiable_flags_handler(env): |
| 121 | env['modifiable_flags'] = \ |
| 122 | 'on' if 'mode' in env and env['mode'] == 'debug' else 'off' |
armvixl | 6e2c827 | 2015-03-31 11:04:14 +0100 | [diff] [blame] | 123 | |
| 124 | |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 125 | def symbols_handler(env): |
| 126 | env['symbols'] = 'on' if 'mode' in env and env['mode'] == 'debug' else 'off' |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 127 | |
| 128 | |
Pierre Langlois | a3b2146 | 2016-08-04 16:01:51 +0100 | [diff] [blame] | 129 | # The architecture targeted by default will depend on the compiler being |
| 130 | # used. 'host_arch' is extracted from the compiler while 'target_arch' can be |
| 131 | # set by the user. |
| 132 | # By default, we target both AArch32 and AArch64 unless the compiler |
| 133 | # targets AArch32. At the moment, we cannot build VIXL's AArch64 support on a 32 |
| 134 | # bit platform. |
| 135 | # TODO: Port VIXL to build on a 32 bit platform. |
| 136 | def target_arch_handler(env): |
| 137 | if env['host_arch'] == 'aarch32': |
| 138 | env['target_arch'] = 'aarch32' |
| 139 | else: |
| 140 | env['target_arch'] = 'both' |
| 141 | |
| 142 | |
| 143 | # By default, include the simulator only if AArch64 is targeted and we are not |
| 144 | # building VIXL natively for AArch64. |
| 145 | def simulator_handler(env): |
| 146 | if env['host_arch'] != 'aarch64' and \ |
| 147 | env['target_arch'] in ['aarch64', 'both']: |
| 148 | env['simulator'] = 'aarch64' |
| 149 | else: |
| 150 | env['simulator'] = 'none' |
| 151 | |
| 152 | |
| 153 | # Default variables may depend on each other, therefore we need this dictionnary |
| 154 | # to be ordered. |
| 155 | vars_default_handlers = OrderedDict({ |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 156 | # variable_name : [ 'default val', 'handler' ] |
| 157 | 'symbols' : [ 'mode==debug', symbols_handler ], |
Pierre Langlois | a3b2146 | 2016-08-04 16:01:51 +0100 | [diff] [blame] | 158 | 'modifiable_flags' : [ 'mode==debug', modifiable_flags_handler ], |
| 159 | 'target_arch' : [ 'same as host architecture if running on AArch32 - ' |
| 160 | 'otherwise both', |
| 161 | target_arch_handler ], |
| 162 | 'simulator' : ['on if the target architectures include AArch64 but ' |
| 163 | 'the host is not AArch64, else off', |
| 164 | simulator_handler ] |
| 165 | }) |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 166 | |
| 167 | |
Pierre Langlois | a3b2146 | 2016-08-04 16:01:51 +0100 | [diff] [blame] | 168 | def DefaultVariable(name, help, allowed_values): |
| 169 | help = '%s (%s)' % (help, '|'.join(allowed_values)) |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 170 | default_value = vars_default_handlers[name][0] |
Pierre Langlois | a3b2146 | 2016-08-04 16:01:51 +0100 | [diff] [blame] | 171 | def validator(name, value, env): |
| 172 | if value != default_value and value not in allowed_values: |
| 173 | raise SCons.Errors.UserError( |
| 174 | 'Invalid value for option {name}: {value}. ' |
| 175 | 'Valid values are: {allowed_values}'.format(name, |
| 176 | value, |
| 177 | allowed_values)) |
| 178 | return (name, help, default_value, validator) |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 179 | |
| 180 | |
| 181 | vars = Variables() |
| 182 | # Define command line build options. |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 183 | vars.AddVariables( |
| 184 | EnumVariable('mode', 'Build mode', |
| 185 | 'release', allowed_values=config.build_options_modes), |
| 186 | DefaultVariable('symbols', 'Include debugging symbols in the binaries', |
| 187 | ['on', 'off']), |
Pierre Langlois | a3b2146 | 2016-08-04 16:01:51 +0100 | [diff] [blame] | 188 | DefaultVariable('target_arch', 'Target architecture', |
| 189 | ['aarch32', 'aarch64', 'both']), |
| 190 | DefaultVariable('simulator', 'Simulators to include', ['aarch64', 'none']), |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 191 | ('std', 'C++ standard. The standards tested are: %s.' % \ |
| 192 | ', '.join(config.tested_cpp_standards)) |
| 193 | ) |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 194 | |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 195 | # We use 'variant directories' to avoid recompiling multiple times when build |
| 196 | # options are changed, different build paths are used depending on the options |
| 197 | # set. These are the options that should be reflected in the build directory |
| 198 | # path. |
Pierre Langlois | a3b2146 | 2016-08-04 16:01:51 +0100 | [diff] [blame] | 199 | options_influencing_build_path = [ |
| 200 | 'target_arch', 'mode', 'symbols', 'CXX', 'std', 'simulator' |
| 201 | ] |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 202 | |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 203 | |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 204 | |
| 205 | # Build helpers ---------------------------------------------------------------- |
| 206 | |
| 207 | def RetrieveEnvironmentVariables(env): |
Pierre Langlois | 88c46b8 | 2016-06-02 18:15:32 +0100 | [diff] [blame] | 208 | for key in ['CC', 'CXX', 'AR', 'RANLIB', 'LD']: |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 209 | if os.getenv(key): env[key] = os.getenv(key) |
| 210 | if os.getenv('LD_LIBRARY_PATH'): env['LIBPATH'] = os.getenv('LD_LIBRARY_PATH') |
Pierre Langlois | 88c46b8 | 2016-06-02 18:15:32 +0100 | [diff] [blame] | 211 | if os.getenv('CCFLAGS'): |
| 212 | env.Append(CCFLAGS = os.getenv('CCFLAGS').split()) |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 213 | if os.getenv('CXXFLAGS'): |
| 214 | env.Append(CXXFLAGS = os.getenv('CXXFLAGS').split()) |
| 215 | if os.getenv('LINKFLAGS'): |
| 216 | env.Append(LINKFLAGS = os.getenv('LINKFLAGS').split()) |
| 217 | # This allows colors to be displayed when using with clang. |
| 218 | env['ENV']['TERM'] = os.getenv('TERM') |
armvixl | 4a102ba | 2014-07-14 09:02:40 +0100 | [diff] [blame] | 219 | |
| 220 | |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 221 | def ProcessBuildOptions(env): |
| 222 | # 'all' is unconditionally processed. |
| 223 | if 'all' in options: |
| 224 | for var in options['all']: |
| 225 | if var in env and env[var]: |
| 226 | env[var] += options['all'][var] |
| 227 | else: |
| 228 | env[var] = options['all'][var] |
Pierre Langlois | a3b2146 | 2016-08-04 16:01:51 +0100 | [diff] [blame] | 229 | |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 230 | # Other build options must match 'option:value' |
| 231 | env_dict = env.Dictionary() |
Pierre Langlois | a3b2146 | 2016-08-04 16:01:51 +0100 | [diff] [blame] | 232 | |
| 233 | # First apply the default variables handlers in order. |
| 234 | for key, value in vars_default_handlers.items(): |
| 235 | default = value[0] |
| 236 | handler = value[1] |
| 237 | if env_dict.get(key) == default: |
| 238 | handler(env_dict) |
| 239 | |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 240 | for key in env_dict.keys(): |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 241 | # Then update the environment according to the value of the variable. |
| 242 | key_val_couple = key + ':%s' % env_dict[key] |
| 243 | if key_val_couple in options: |
| 244 | for var in options[key_val_couple]: |
| 245 | env[var] += options[key_val_couple][var] |
| 246 | |
| 247 | |
| 248 | def ConfigureEnvironmentForCompiler(env): |
Pierre Langlois | f737e0a | 2016-11-02 13:08:11 +0000 | [diff] [blame] | 249 | compiler = util.CompilerInformation(env['CXX']) |
| 250 | if compiler == 'clang': |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 251 | # These warnings only work for Clang. |
| 252 | # -Wimplicit-fallthrough only works when compiling the code base as C++11 or |
| 253 | # newer. The compiler does not complain if the option is passed when |
| 254 | # compiling earlier C++ standards. |
| 255 | env.Append(CPPFLAGS = ['-Wimplicit-fallthrough', '-Wshorten-64-to-32']) |
| 256 | |
| 257 | # The '-Wunreachable-code' flag breaks builds for clang 3.4. |
Jacob Bramley | 176a379 | 2016-11-09 14:44:39 +0000 | [diff] [blame^] | 258 | if compiler != 'clang-3.4': |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 259 | env.Append(CPPFLAGS = ['-Wunreachable-code']) |
| 260 | |
| 261 | # GCC 4.8 has a bug which produces a warning saying that an anonymous Operand |
| 262 | # object might be used uninitialized: |
| 263 | # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57045 |
| 264 | # The bug does not seem to appear in GCC 4.7, or in debug builds with GCC 4.8. |
| 265 | if env['mode'] == 'release': |
Pierre Langlois | f737e0a | 2016-11-02 13:08:11 +0000 | [diff] [blame] | 266 | if compiler == 'gcc-4.8': |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 267 | env.Append(CPPFLAGS = ['-Wno-maybe-uninitialized']) |
Pierre Langlois | f737e0a | 2016-11-02 13:08:11 +0000 | [diff] [blame] | 268 | |
Pierre Langlois | c125307 | 2016-06-15 14:36:10 +0100 | [diff] [blame] | 269 | # When compiling with c++98 (the default), allow long long constants. |
armvixl | 0f35e36 | 2016-05-10 13:57:58 +0100 | [diff] [blame] | 270 | if 'std' not in env or env['std'] == 'c++98': |
Pierre Langlois | c125307 | 2016-06-15 14:36:10 +0100 | [diff] [blame] | 271 | env.Append(CPPFLAGS = ['-Wno-long-long']) |
Pierre Langlois | 3fac43c | 2016-10-31 13:38:47 +0000 | [diff] [blame] | 272 | # When compiling with c++11, suggest missing override keywords on methods. |
| 273 | if 'std' in env and env['std'] in ['c++11', 'c++14']: |
Pierre Langlois | f737e0a | 2016-11-02 13:08:11 +0000 | [diff] [blame] | 274 | if compiler >= 'gcc-5': |
Pierre Langlois | 3fac43c | 2016-10-31 13:38:47 +0000 | [diff] [blame] | 275 | env.Append(CPPFLAGS = ['-Wsuggest-override']) |
Pierre Langlois | f737e0a | 2016-11-02 13:08:11 +0000 | [diff] [blame] | 276 | elif compiler >= 'clang-3.6': |
Pierre Langlois | 3fac43c | 2016-10-31 13:38:47 +0000 | [diff] [blame] | 277 | env.Append(CPPFLAGS = ['-Winconsistent-missing-override']) |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 278 | |
| 279 | |
| 280 | def ConfigureEnvironment(env): |
| 281 | RetrieveEnvironmentVariables(env) |
Pierre Langlois | a3b2146 | 2016-08-04 16:01:51 +0100 | [diff] [blame] | 282 | env['host_arch'] = util.GetHostArch(env['CXX']) |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 283 | ProcessBuildOptions(env) |
| 284 | if 'std' in env: |
| 285 | env.Append(CPPFLAGS = ['-std=' + env['std']]) |
| 286 | std_path = env['std'] |
| 287 | ConfigureEnvironmentForCompiler(env) |
| 288 | |
| 289 | |
| 290 | def TargetBuildDir(env): |
| 291 | # Build-time option values are embedded in the build path to avoid requiring a |
| 292 | # full build when an option changes. |
| 293 | build_dir = config.dir_build |
| 294 | for option in options_influencing_build_path: |
| 295 | option_value = env[option] if option in env else '' |
| 296 | build_dir = join(build_dir, option + '_'+ option_value) |
| 297 | return build_dir |
| 298 | |
| 299 | |
| 300 | def PrepareVariantDir(location, build_dir): |
| 301 | location_build_dir = join(build_dir, location) |
| 302 | VariantDir(location_build_dir, location) |
| 303 | return location_build_dir |
| 304 | |
| 305 | |
| 306 | def VIXLLibraryTarget(env): |
| 307 | build_dir = TargetBuildDir(env) |
| 308 | # Create a link to the latest build directory. |
Alexandre Rames | 4e24193 | 2016-06-08 21:32:03 +0100 | [diff] [blame] | 309 | # Use `-r` to avoid failure when `latest` exists and is a directory. |
| 310 | subprocess.check_call(["rm", "-rf", config.dir_build_latest]) |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 311 | util.ensure_dir(build_dir) |
| 312 | subprocess.check_call(["ln", "-s", build_dir, config.dir_build_latest]) |
Alexandre Rames | d383296 | 2016-07-04 15:03:43 +0100 | [diff] [blame] | 313 | # Source files are in `src` and in `src/aarch64/`. |
Alexandre Rames | 39c32a6 | 2016-05-23 15:47:22 +0100 | [diff] [blame] | 314 | variant_dir_vixl = PrepareVariantDir(join('src'), build_dir) |
Pierre Langlois | a3b2146 | 2016-08-04 16:01:51 +0100 | [diff] [blame] | 315 | sources = [Glob(join(variant_dir_vixl, '*.cc'))] |
| 316 | if env['target_arch'] in ['aarch32', 'both']: |
| 317 | variant_dir_aarch32 = PrepareVariantDir(join('src', 'aarch32'), build_dir) |
| 318 | sources.append(Glob(join(variant_dir_aarch32, '*.cc'))) |
| 319 | if env['target_arch'] in ['aarch64', 'both']: |
| 320 | variant_dir_aarch64 = PrepareVariantDir(join('src', 'aarch64'), build_dir) |
| 321 | sources.append(Glob(join(variant_dir_aarch64, '*.cc'))) |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 322 | return env.Library(join(build_dir, 'vixl'), sources) |
| 323 | |
| 324 | |
| 325 | |
| 326 | # Build ------------------------------------------------------------------------ |
| 327 | |
| 328 | # The VIXL library, built by default. |
| 329 | env = Environment(variables = vars) |
Alexandre Rames | f5de33d | 2016-10-25 09:51:11 +0100 | [diff] [blame] | 330 | # Abort the build if any command line option is unknown or invalid. |
| 331 | unknown_build_options = vars.UnknownVariables() |
| 332 | if unknown_build_options: |
| 333 | print 'Unknown build options:', unknown_build_options.keys() |
| 334 | Exit(1) |
| 335 | |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 336 | ConfigureEnvironment(env) |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 337 | Help(vars.GenerateHelpText(env)) |
| 338 | libvixl = VIXLLibraryTarget(env) |
| 339 | Default(libvixl) |
| 340 | env.Alias('libvixl', libvixl) |
| 341 | top_level_targets.Add('', 'Build the VIXL library.') |
| 342 | |
armvixl | 4a102ba | 2014-07-14 09:02:40 +0100 | [diff] [blame] | 343 | |
Pierre Langlois | a3b2146 | 2016-08-04 16:01:51 +0100 | [diff] [blame] | 344 | # Common test code. |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 345 | test_build_dir = PrepareVariantDir('test', TargetBuildDir(env)) |
Pierre Langlois | 88c46b8 | 2016-06-02 18:15:32 +0100 | [diff] [blame] | 346 | test_objects = [env.Object(Glob(join(test_build_dir, '*.cc')))] |
| 347 | |
Pierre Langlois | a3b2146 | 2016-08-04 16:01:51 +0100 | [diff] [blame] | 348 | # AArch32 support |
| 349 | if env['target_arch'] in ['aarch32', 'both']: |
| 350 | # The examples. |
| 351 | aarch32_example_names = util.ListCCFilesWithoutExt(config.dir_aarch32_examples) |
| 352 | aarch32_examples_build_dir = PrepareVariantDir('examples/aarch32', TargetBuildDir(env)) |
| 353 | aarch32_example_targets = [] |
| 354 | for example in aarch32_example_names: |
| 355 | prog = env.Program(join(aarch32_examples_build_dir, example), |
| 356 | join(aarch32_examples_build_dir, example + '.cc'), |
| 357 | LIBS=[libvixl]) |
| 358 | aarch32_example_targets.append(prog) |
| 359 | env.Alias('aarch32_examples', aarch32_example_targets) |
| 360 | top_level_targets.Add('aarch32_examples', 'Build the examples for AArch32.') |
Pierre Langlois | 88c46b8 | 2016-06-02 18:15:32 +0100 | [diff] [blame] | 361 | |
Vincent Belliard | 32cf254 | 2016-07-14 10:04:09 -0700 | [diff] [blame] | 362 | # The benchmarks |
| 363 | aarch32_benchmark_names = util.ListCCFilesWithoutExt(config.dir_aarch32_benchmarks) |
| 364 | aarch32_benchmarks_build_dir = PrepareVariantDir('benchmarks/aarch32', TargetBuildDir(env)) |
| 365 | aarch32_benchmark_targets = [] |
| 366 | for bench in aarch32_benchmark_names: |
| 367 | prog = env.Program(join(aarch32_benchmarks_build_dir, bench), |
| 368 | join(aarch32_benchmarks_build_dir, bench + '.cc'), |
| 369 | LIBS=[libvixl]) |
| 370 | aarch32_benchmark_targets.append(prog) |
| 371 | env.Alias('aarch32_benchmarks', aarch32_benchmark_targets) |
| 372 | top_level_targets.Add('aarch32_benchmarks', 'Build the benchmarks for AArch32.') |
| 373 | |
Pierre Langlois | a3b2146 | 2016-08-04 16:01:51 +0100 | [diff] [blame] | 374 | # The tests. |
| 375 | test_aarch32_build_dir = PrepareVariantDir(join('test', 'aarch32'), TargetBuildDir(env)) |
| 376 | test_objects.append(env.Object( |
| 377 | Glob(join(test_aarch32_build_dir, '*.cc')), |
| 378 | CPPPATH = env['CPPPATH'] + [config.dir_tests])) |
Pierre Langlois | 88c46b8 | 2016-06-02 18:15:32 +0100 | [diff] [blame] | 379 | |
Pierre Langlois | a3b2146 | 2016-08-04 16:01:51 +0100 | [diff] [blame] | 380 | # AArch64 support |
| 381 | if env['target_arch'] in ['aarch64', 'both']: |
| 382 | # The benchmarks. |
| 383 | aarch64_benchmark_names = util.ListCCFilesWithoutExt(config.dir_aarch64_benchmarks) |
| 384 | aarch64_benchmarks_build_dir = PrepareVariantDir('benchmarks/aarch64', TargetBuildDir(env)) |
| 385 | aarch64_benchmark_targets = [] |
| 386 | for bench in aarch64_benchmark_names: |
| 387 | prog = env.Program(join(aarch64_benchmarks_build_dir, bench), |
| 388 | join(aarch64_benchmarks_build_dir, bench + '.cc'), |
| 389 | LIBS=[libvixl]) |
| 390 | aarch64_benchmark_targets.append(prog) |
| 391 | env.Alias('aarch64_benchmarks', aarch64_benchmark_targets) |
| 392 | top_level_targets.Add('aarch64_benchmarks', 'Build the benchmarks for AArch64.') |
| 393 | |
| 394 | # The examples. |
| 395 | aarch64_example_names = util.ListCCFilesWithoutExt(config.dir_aarch64_examples) |
| 396 | aarch64_examples_build_dir = PrepareVariantDir('examples/aarch64', TargetBuildDir(env)) |
| 397 | aarch64_example_targets = [] |
| 398 | for example in aarch64_example_names: |
| 399 | prog = env.Program(join(aarch64_examples_build_dir, example), |
| 400 | join(aarch64_examples_build_dir, example + '.cc'), |
| 401 | LIBS=[libvixl]) |
| 402 | aarch64_example_targets.append(prog) |
| 403 | env.Alias('aarch64_examples', aarch64_example_targets) |
| 404 | top_level_targets.Add('aarch64_examples', 'Build the examples for AArch64.') |
| 405 | |
| 406 | # The tests. |
| 407 | test_aarch64_build_dir = PrepareVariantDir(join('test', 'aarch64'), TargetBuildDir(env)) |
| 408 | test_objects.append(env.Object( |
| 409 | Glob(join(test_aarch64_build_dir, '*.cc')), |
| 410 | CPPPATH = env['CPPPATH'] + [config.dir_tests])) |
| 411 | |
| 412 | # The test requires building the example files with specific options, so we |
| 413 | # create a separate variant dir for the example objects built this way. |
| 414 | test_aarch64_examples_vdir = join(TargetBuildDir(env), 'test', 'aarch64', 'test_examples') |
| 415 | VariantDir(test_aarch64_examples_vdir, '.') |
| 416 | test_aarch64_examples_obj = env.Object( |
| 417 | [Glob(join(test_aarch64_examples_vdir, join('test', 'aarch64', 'examples/aarch64', '*.cc'))), |
| 418 | Glob(join(test_aarch64_examples_vdir, join('examples/aarch64', '*.cc')))], |
| 419 | CCFLAGS = env['CCFLAGS'] + ['-DTEST_EXAMPLES'], |
| 420 | CPPPATH = env['CPPPATH'] + [config.dir_aarch64_examples] + [config.dir_tests]) |
| 421 | test_objects.append(test_aarch64_examples_obj) |
Pierre Langlois | 88c46b8 | 2016-06-02 18:15:32 +0100 | [diff] [blame] | 422 | |
| 423 | test = env.Program(join(test_build_dir, 'test-runner'), test_objects, |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 424 | LIBS=[libvixl]) |
| 425 | env.Alias('tests', test) |
| 426 | top_level_targets.Add('tests', 'Build the tests.') |
armvixl | 4a102ba | 2014-07-14 09:02:40 +0100 | [diff] [blame] | 427 | |
armvixl | 4a102ba | 2014-07-14 09:02:40 +0100 | [diff] [blame] | 428 | |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 429 | env.Alias('all', top_level_targets.targets) |
| 430 | top_level_targets.Add('all', 'Build all the targets above.') |
| 431 | |
| 432 | Help('\n\nAvailable top level targets:\n' + top_level_targets.Help()) |