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