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