Clone of official tools

Committer:
theotherjimmy
Date:
Tue Oct 10 16:56:30 2017 -0500
Revision:
40:7d3fa6b99b2b
Child:
43:2a7da56ebd24
Update to tools release 5.6.1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
theotherjimmy 40:7d3fa6b99b2b 1 """
theotherjimmy 40:7d3fa6b99b2b 2 mbed SDK
theotherjimmy 40:7d3fa6b99b2b 3 Copyright (c) 2011-2016 ARM Limited
theotherjimmy 40:7d3fa6b99b2b 4
theotherjimmy 40:7d3fa6b99b2b 5 Licensed under the Apache License, Version 2.0 (the "License");
theotherjimmy 40:7d3fa6b99b2b 6 you may not use this file except in compliance with the License.
theotherjimmy 40:7d3fa6b99b2b 7 You may obtain a copy of the License at
theotherjimmy 40:7d3fa6b99b2b 8
theotherjimmy 40:7d3fa6b99b2b 9 http://www.apache.org/licenses/LICENSE-2.0
theotherjimmy 40:7d3fa6b99b2b 10
theotherjimmy 40:7d3fa6b99b2b 11 Unless required by applicable law or agreed to in writing, software
theotherjimmy 40:7d3fa6b99b2b 12 distributed under the License is distributed on an "AS IS" BASIS,
theotherjimmy 40:7d3fa6b99b2b 13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
theotherjimmy 40:7d3fa6b99b2b 14 See the License for the specific language governing permissions and
theotherjimmy 40:7d3fa6b99b2b 15 limitations under the License.
theotherjimmy 40:7d3fa6b99b2b 16
theotherjimmy 40:7d3fa6b99b2b 17 Title: MCUXpresso exporter.
theotherjimmy 40:7d3fa6b99b2b 18
theotherjimmy 40:7d3fa6b99b2b 19 Description: Creates a managed build project that can be imported by
theotherjimmy 40:7d3fa6b99b2b 20 the MCUXpresso IDE from NXP
theotherjimmy 40:7d3fa6b99b2b 21
theotherjimmy 40:7d3fa6b99b2b 22 Based on GNU ARM Eclipse Exporter from Liviu Ionescu <ilg@livius.net>
theotherjimmy 40:7d3fa6b99b2b 23 modified for MCUXpresso by Johannes Stratmann <jojos62@online.de>
theotherjimmy 40:7d3fa6b99b2b 24 """
theotherjimmy 40:7d3fa6b99b2b 25
theotherjimmy 40:7d3fa6b99b2b 26 import copy
theotherjimmy 40:7d3fa6b99b2b 27 import tempfile
theotherjimmy 40:7d3fa6b99b2b 28 import shutil
theotherjimmy 40:7d3fa6b99b2b 29
theotherjimmy 40:7d3fa6b99b2b 30 from subprocess import Popen, PIPE
theotherjimmy 40:7d3fa6b99b2b 31 from os import getcwd, remove
theotherjimmy 40:7d3fa6b99b2b 32 from os.path import splitext, basename, exists
theotherjimmy 40:7d3fa6b99b2b 33 from random import randint
theotherjimmy 40:7d3fa6b99b2b 34
theotherjimmy 40:7d3fa6b99b2b 35 from tools.export.gnuarmeclipse import GNUARMEclipse, UID
theotherjimmy 40:7d3fa6b99b2b 36 from tools.export.exporters import apply_supported_whitelist
theotherjimmy 40:7d3fa6b99b2b 37 from tools.targets import TARGET_MAP
theotherjimmy 40:7d3fa6b99b2b 38 from tools.utils import NotSupportedException
theotherjimmy 40:7d3fa6b99b2b 39 from tools.build_api import prepare_toolchain
theotherjimmy 40:7d3fa6b99b2b 40
theotherjimmy 40:7d3fa6b99b2b 41
theotherjimmy 40:7d3fa6b99b2b 42 # =============================================================================
theotherjimmy 40:7d3fa6b99b2b 43
theotherjimmy 40:7d3fa6b99b2b 44
theotherjimmy 40:7d3fa6b99b2b 45 POST_BINARY_WHITELIST = set([
theotherjimmy 40:7d3fa6b99b2b 46 "TEENSY3_1Code.binary_hook",
theotherjimmy 40:7d3fa6b99b2b 47 "MCU_NRF51Code.binary_hook",
theotherjimmy 40:7d3fa6b99b2b 48 "LPCTargetCode.lpc_patch",
theotherjimmy 40:7d3fa6b99b2b 49 "LPC4088Code.binary_hook"
theotherjimmy 40:7d3fa6b99b2b 50 ])
theotherjimmy 40:7d3fa6b99b2b 51
theotherjimmy 40:7d3fa6b99b2b 52 class MCUXpresso(GNUARMEclipse):
theotherjimmy 40:7d3fa6b99b2b 53 NAME = 'MCUXpresso'
theotherjimmy 40:7d3fa6b99b2b 54 TOOLCHAIN = 'GCC_ARM'
theotherjimmy 40:7d3fa6b99b2b 55
theotherjimmy 40:7d3fa6b99b2b 56 MBED_CONFIG_HEADER_SUPPORTED = True
theotherjimmy 40:7d3fa6b99b2b 57
theotherjimmy 40:7d3fa6b99b2b 58 @classmethod
theotherjimmy 40:7d3fa6b99b2b 59 def is_target_supported(cls, target_name):
theotherjimmy 40:7d3fa6b99b2b 60 # targes suppoerted when .cproject templatefile exists
theotherjimmy 40:7d3fa6b99b2b 61 if exists(cls.TEMPLATE_DIR + '/mcuxpresso/' + target_name + '_cproject.tmpl'):
theotherjimmy 40:7d3fa6b99b2b 62 target = TARGET_MAP[target_name]
theotherjimmy 40:7d3fa6b99b2b 63 return apply_supported_whitelist(
theotherjimmy 40:7d3fa6b99b2b 64 cls.TOOLCHAIN, POST_BINARY_WHITELIST, target)
theotherjimmy 40:7d3fa6b99b2b 65 else:
theotherjimmy 40:7d3fa6b99b2b 66 return False
theotherjimmy 40:7d3fa6b99b2b 67
theotherjimmy 40:7d3fa6b99b2b 68 # override
theotherjimmy 40:7d3fa6b99b2b 69 def generate(self):
theotherjimmy 40:7d3fa6b99b2b 70 """
theotherjimmy 40:7d3fa6b99b2b 71 Generate the .project and .cproject files.
theotherjimmy 40:7d3fa6b99b2b 72 """
theotherjimmy 40:7d3fa6b99b2b 73 if not self.resources.linker_script:
theotherjimmy 40:7d3fa6b99b2b 74 raise NotSupportedException("No linker script found.")
theotherjimmy 40:7d3fa6b99b2b 75
theotherjimmy 40:7d3fa6b99b2b 76 print
theotherjimmy 40:7d3fa6b99b2b 77 print 'Create a GNU ARM Eclipse C++ managed project'
theotherjimmy 40:7d3fa6b99b2b 78 print 'Project name: {0}'.format(self.project_name)
theotherjimmy 40:7d3fa6b99b2b 79 print 'Target: {0}'.format(self.toolchain.target.name)
theotherjimmy 40:7d3fa6b99b2b 80 print 'Toolchain: {0}'.format(self.TOOLCHAIN)
theotherjimmy 40:7d3fa6b99b2b 81
theotherjimmy 40:7d3fa6b99b2b 82 self.resources.win_to_unix()
theotherjimmy 40:7d3fa6b99b2b 83
theotherjimmy 40:7d3fa6b99b2b 84 # TODO: use some logger to display additional info if verbose
theotherjimmy 40:7d3fa6b99b2b 85
theotherjimmy 40:7d3fa6b99b2b 86 self.libraries = []
theotherjimmy 40:7d3fa6b99b2b 87 # print 'libraries'
theotherjimmy 40:7d3fa6b99b2b 88 # print self.resources.libraries
theotherjimmy 40:7d3fa6b99b2b 89 for lib in self.resources.libraries:
theotherjimmy 40:7d3fa6b99b2b 90 l, _ = splitext(basename(lib))
theotherjimmy 40:7d3fa6b99b2b 91 self.libraries.append(l[3:])
theotherjimmy 40:7d3fa6b99b2b 92
theotherjimmy 40:7d3fa6b99b2b 93 self.system_libraries = [
theotherjimmy 40:7d3fa6b99b2b 94 'stdc++', 'supc++', 'm', 'c', 'gcc', 'nosys'
theotherjimmy 40:7d3fa6b99b2b 95 ]
theotherjimmy 40:7d3fa6b99b2b 96
theotherjimmy 40:7d3fa6b99b2b 97 # Read in all profiles, we'll extract compiler options.
theotherjimmy 40:7d3fa6b99b2b 98 profiles = self.get_all_profiles()
theotherjimmy 40:7d3fa6b99b2b 99
theotherjimmy 40:7d3fa6b99b2b 100 profile_ids = [s.lower() for s in profiles]
theotherjimmy 40:7d3fa6b99b2b 101 profile_ids.sort()
theotherjimmy 40:7d3fa6b99b2b 102
theotherjimmy 40:7d3fa6b99b2b 103 # TODO: get the list from existing .cproject
theotherjimmy 40:7d3fa6b99b2b 104 build_folders = [s.capitalize() for s in profile_ids]
theotherjimmy 40:7d3fa6b99b2b 105 build_folders.append('BUILD')
theotherjimmy 40:7d3fa6b99b2b 106 # print build_folders
theotherjimmy 40:7d3fa6b99b2b 107
theotherjimmy 40:7d3fa6b99b2b 108 objects = [self.filter_dot(s) for s in self.resources.objects]
theotherjimmy 40:7d3fa6b99b2b 109 for bf in build_folders:
theotherjimmy 40:7d3fa6b99b2b 110 objects = [o for o in objects if not o.startswith(bf + '/')]
theotherjimmy 40:7d3fa6b99b2b 111 # print 'objects'
theotherjimmy 40:7d3fa6b99b2b 112 # print objects
theotherjimmy 40:7d3fa6b99b2b 113
theotherjimmy 40:7d3fa6b99b2b 114 self.compute_exclusions()
theotherjimmy 40:7d3fa6b99b2b 115
theotherjimmy 40:7d3fa6b99b2b 116 self.include_path = [
theotherjimmy 40:7d3fa6b99b2b 117 self.filter_dot(s) for s in self.resources.inc_dirs]
theotherjimmy 40:7d3fa6b99b2b 118 print 'Include folders: {0}'.format(len(self.include_path))
theotherjimmy 40:7d3fa6b99b2b 119
theotherjimmy 40:7d3fa6b99b2b 120 self.as_defines = self.toolchain.get_symbols(True)
theotherjimmy 40:7d3fa6b99b2b 121 self.c_defines = self.toolchain.get_symbols()
theotherjimmy 40:7d3fa6b99b2b 122 self.cpp_defines = self.c_defines
theotherjimmy 40:7d3fa6b99b2b 123 print 'Symbols: {0}'.format(len(self.c_defines))
theotherjimmy 40:7d3fa6b99b2b 124
theotherjimmy 40:7d3fa6b99b2b 125 self.ld_script = self.filter_dot(
theotherjimmy 40:7d3fa6b99b2b 126 self.resources.linker_script)
theotherjimmy 40:7d3fa6b99b2b 127 print 'Linker script: {0}'.format(self.ld_script)
theotherjimmy 40:7d3fa6b99b2b 128
theotherjimmy 40:7d3fa6b99b2b 129 self.options = {}
theotherjimmy 40:7d3fa6b99b2b 130 profile_ids.remove('develop')
theotherjimmy 40:7d3fa6b99b2b 131 for id in profile_ids:
theotherjimmy 40:7d3fa6b99b2b 132
theotherjimmy 40:7d3fa6b99b2b 133 # There are 4 categories of options, a category common too
theotherjimmy 40:7d3fa6b99b2b 134 # all tools and a specific category for each of the tools.
theotherjimmy 40:7d3fa6b99b2b 135 opts = {}
theotherjimmy 40:7d3fa6b99b2b 136 opts['common'] = {}
theotherjimmy 40:7d3fa6b99b2b 137 opts['as'] = {}
theotherjimmy 40:7d3fa6b99b2b 138 opts['c'] = {}
theotherjimmy 40:7d3fa6b99b2b 139 opts['cpp'] = {}
theotherjimmy 40:7d3fa6b99b2b 140 opts['ld'] = {}
theotherjimmy 40:7d3fa6b99b2b 141
theotherjimmy 40:7d3fa6b99b2b 142 opts['id'] = id
theotherjimmy 40:7d3fa6b99b2b 143 opts['name'] = opts['id'].capitalize()
theotherjimmy 40:7d3fa6b99b2b 144
theotherjimmy 40:7d3fa6b99b2b 145 print
theotherjimmy 40:7d3fa6b99b2b 146 print 'Build configuration: {0}'.format(opts['name'])
theotherjimmy 40:7d3fa6b99b2b 147
theotherjimmy 40:7d3fa6b99b2b 148 profile = profiles[id]
theotherjimmy 40:7d3fa6b99b2b 149
theotherjimmy 40:7d3fa6b99b2b 150 # A small hack, do not bother with src_path again,
theotherjimmy 40:7d3fa6b99b2b 151 # pass an empty string to avoid crashing.
theotherjimmy 40:7d3fa6b99b2b 152 src_paths = ['']
theotherjimmy 40:7d3fa6b99b2b 153 target_name = self.toolchain.target.name
theotherjimmy 40:7d3fa6b99b2b 154 toolchain = prepare_toolchain(
theotherjimmy 40:7d3fa6b99b2b 155 src_paths, "", target_name, self.TOOLCHAIN, build_profile=[profile])
theotherjimmy 40:7d3fa6b99b2b 156
theotherjimmy 40:7d3fa6b99b2b 157 # Hack to fill in build_dir
theotherjimmy 40:7d3fa6b99b2b 158 toolchain.build_dir = self.toolchain.build_dir
theotherjimmy 40:7d3fa6b99b2b 159
theotherjimmy 40:7d3fa6b99b2b 160 flags = self.toolchain_flags(toolchain)
theotherjimmy 40:7d3fa6b99b2b 161
theotherjimmy 40:7d3fa6b99b2b 162 print 'Common flags:', ' '.join(flags['common_flags'])
theotherjimmy 40:7d3fa6b99b2b 163 print 'C++ flags:', ' '.join(flags['cxx_flags'])
theotherjimmy 40:7d3fa6b99b2b 164 print 'C flags:', ' '.join(flags['c_flags'])
theotherjimmy 40:7d3fa6b99b2b 165 print 'ASM flags:', ' '.join(flags['asm_flags'])
theotherjimmy 40:7d3fa6b99b2b 166 print 'Linker flags:', ' '.join(flags['ld_flags'])
theotherjimmy 40:7d3fa6b99b2b 167
theotherjimmy 40:7d3fa6b99b2b 168 # Most GNU ARM Eclipse options have a parent,
theotherjimmy 40:7d3fa6b99b2b 169 # either debug or release.
theotherjimmy 40:7d3fa6b99b2b 170 if '-O0' in flags['common_flags'] or '-Og' in flags['common_flags']:
theotherjimmy 40:7d3fa6b99b2b 171 opts['parent_id'] = 'debug'
theotherjimmy 40:7d3fa6b99b2b 172 else:
theotherjimmy 40:7d3fa6b99b2b 173 opts['parent_id'] = 'release'
theotherjimmy 40:7d3fa6b99b2b 174
theotherjimmy 40:7d3fa6b99b2b 175 self.process_options(opts, flags)
theotherjimmy 40:7d3fa6b99b2b 176
theotherjimmy 40:7d3fa6b99b2b 177 opts['as']['defines'] = self.as_defines
theotherjimmy 40:7d3fa6b99b2b 178 opts['c']['defines'] = self.c_defines
theotherjimmy 40:7d3fa6b99b2b 179 opts['cpp']['defines'] = self.cpp_defines
theotherjimmy 40:7d3fa6b99b2b 180
theotherjimmy 40:7d3fa6b99b2b 181 opts['common']['include_paths'] = self.include_path
theotherjimmy 40:7d3fa6b99b2b 182 opts['common']['excluded_folders'] = '|'.join(
theotherjimmy 40:7d3fa6b99b2b 183 self.excluded_folders)
theotherjimmy 40:7d3fa6b99b2b 184 self.excluded_folders = [item.replace("\\", "/") for item in self.excluded_folders]
theotherjimmy 40:7d3fa6b99b2b 185
theotherjimmy 40:7d3fa6b99b2b 186 opts['ld']['library_paths'] = [
theotherjimmy 40:7d3fa6b99b2b 187 self.filter_dot(s) for s in self.resources.lib_dirs]
theotherjimmy 40:7d3fa6b99b2b 188
theotherjimmy 40:7d3fa6b99b2b 189 opts['ld']['object_files'] = objects
theotherjimmy 40:7d3fa6b99b2b 190 opts['ld']['user_libraries'] = self.libraries
theotherjimmy 40:7d3fa6b99b2b 191 opts['ld']['system_libraries'] = self.system_libraries
theotherjimmy 40:7d3fa6b99b2b 192 opts['ld']['script'] = "linker-script-%s.ld" % id
theotherjimmy 40:7d3fa6b99b2b 193 opts['cpp_cmd'] = " ".join(toolchain.preproc)
theotherjimmy 40:7d3fa6b99b2b 194
theotherjimmy 40:7d3fa6b99b2b 195 # Unique IDs used in multiple places.
theotherjimmy 40:7d3fa6b99b2b 196 # Those used only once are implemented with {{u.id}}.
theotherjimmy 40:7d3fa6b99b2b 197 u = UID()
theotherjimmy 40:7d3fa6b99b2b 198 uid = {}
theotherjimmy 40:7d3fa6b99b2b 199 uid['config'] = u.id
theotherjimmy 40:7d3fa6b99b2b 200 uid['tool_c_compiler'] = u.id
theotherjimmy 40:7d3fa6b99b2b 201 uid['tool_c_compiler_input'] = u.id
theotherjimmy 40:7d3fa6b99b2b 202 uid['tool_cpp_compiler'] = u.id
theotherjimmy 40:7d3fa6b99b2b 203 uid['tool_cpp_compiler_input'] = u.id
theotherjimmy 40:7d3fa6b99b2b 204
theotherjimmy 40:7d3fa6b99b2b 205 opts['uid'] = uid
theotherjimmy 40:7d3fa6b99b2b 206
theotherjimmy 40:7d3fa6b99b2b 207 self.options[id] = opts
theotherjimmy 40:7d3fa6b99b2b 208
theotherjimmy 40:7d3fa6b99b2b 209 jinja_ctx = {
theotherjimmy 40:7d3fa6b99b2b 210 'name': self.project_name,
theotherjimmy 40:7d3fa6b99b2b 211 'ld_script': self.ld_script,
theotherjimmy 40:7d3fa6b99b2b 212
theotherjimmy 40:7d3fa6b99b2b 213 # Compiler & linker command line options
theotherjimmy 40:7d3fa6b99b2b 214 'options': self.options,
theotherjimmy 40:7d3fa6b99b2b 215
theotherjimmy 40:7d3fa6b99b2b 216 # Must be an object with an `id` property, which
theotherjimmy 40:7d3fa6b99b2b 217 # will be called repeatedly, to generate multiple UIDs.
theotherjimmy 40:7d3fa6b99b2b 218 'u': u,
theotherjimmy 40:7d3fa6b99b2b 219 }
theotherjimmy 40:7d3fa6b99b2b 220
theotherjimmy 40:7d3fa6b99b2b 221 self.gen_file('mcuxpresso/.project.tmpl', jinja_ctx,
theotherjimmy 40:7d3fa6b99b2b 222 '.project', trim_blocks=True, lstrip_blocks=True)
theotherjimmy 40:7d3fa6b99b2b 223 self.gen_file('mcuxpresso/{0}_cproject.tmpl'.format(target_name), jinja_ctx,
theotherjimmy 40:7d3fa6b99b2b 224 '.cproject', trim_blocks=True, lstrip_blocks=True)
theotherjimmy 40:7d3fa6b99b2b 225 self.gen_file('mcuxpresso/makefile.targets.tmpl', jinja_ctx,
theotherjimmy 40:7d3fa6b99b2b 226 'makefile.targets', trim_blocks=True, lstrip_blocks=True)
theotherjimmy 40:7d3fa6b99b2b 227 self.gen_file('mcuxpresso/mbedignore.tmpl', jinja_ctx, '.mbedignore')
theotherjimmy 40:7d3fa6b99b2b 228
theotherjimmy 40:7d3fa6b99b2b 229 print
theotherjimmy 40:7d3fa6b99b2b 230 print 'Done. Import the \'{0}\' project in Eclipse.'.format(self.project_name)
theotherjimmy 40:7d3fa6b99b2b 231
theotherjimmy 40:7d3fa6b99b2b 232 # override
theotherjimmy 40:7d3fa6b99b2b 233 @staticmethod
theotherjimmy 40:7d3fa6b99b2b 234 def build(project_name, log_name="build_log.txt", cleanup=True):
theotherjimmy 40:7d3fa6b99b2b 235 """
theotherjimmy 40:7d3fa6b99b2b 236 Headless build an Eclipse project.
theotherjimmy 40:7d3fa6b99b2b 237
theotherjimmy 40:7d3fa6b99b2b 238 The following steps are performed:
theotherjimmy 40:7d3fa6b99b2b 239 - a temporary workspace is created,
theotherjimmy 40:7d3fa6b99b2b 240 - the project is imported,
theotherjimmy 40:7d3fa6b99b2b 241 - a clean build of all configurations is performed and
theotherjimmy 40:7d3fa6b99b2b 242 - the temporary workspace is removed.
theotherjimmy 40:7d3fa6b99b2b 243
theotherjimmy 40:7d3fa6b99b2b 244 The build results are in the Debug & Release folders.
theotherjimmy 40:7d3fa6b99b2b 245
theotherjimmy 40:7d3fa6b99b2b 246 All executables (eclipse & toolchain) must be in the PATH.
theotherjimmy 40:7d3fa6b99b2b 247
theotherjimmy 40:7d3fa6b99b2b 248 The general method to start a headless Eclipse build is:
theotherjimmy 40:7d3fa6b99b2b 249
theotherjimmy 40:7d3fa6b99b2b 250 $ eclipse \
theotherjimmy 40:7d3fa6b99b2b 251 --launcher.suppressErrors \
theotherjimmy 40:7d3fa6b99b2b 252 -nosplash \
theotherjimmy 40:7d3fa6b99b2b 253 -application org.eclipse.cdt.managedbuilder.core.headlessbuild \
theotherjimmy 40:7d3fa6b99b2b 254 -data /path/to/workspace \
theotherjimmy 40:7d3fa6b99b2b 255 -import /path/to/project \
theotherjimmy 40:7d3fa6b99b2b 256 -cleanBuild "project[/configuration] | all"
theotherjimmy 40:7d3fa6b99b2b 257 """
theotherjimmy 40:7d3fa6b99b2b 258
theotherjimmy 40:7d3fa6b99b2b 259 # TODO: possibly use the log file.
theotherjimmy 40:7d3fa6b99b2b 260
theotherjimmy 40:7d3fa6b99b2b 261 # Create a temporary folder for the workspace.
theotherjimmy 40:7d3fa6b99b2b 262 tmp_folder = tempfile.mkdtemp()
theotherjimmy 40:7d3fa6b99b2b 263
theotherjimmy 40:7d3fa6b99b2b 264 cmd = [
theotherjimmy 40:7d3fa6b99b2b 265 'mcuxpressoide',
theotherjimmy 40:7d3fa6b99b2b 266 '--launcher.suppressErrors',
theotherjimmy 40:7d3fa6b99b2b 267 '-nosplash',
theotherjimmy 40:7d3fa6b99b2b 268 '-application org.eclipse.cdt.managedbuilder.core.headlessbuild',
theotherjimmy 40:7d3fa6b99b2b 269 '-data', tmp_folder,
theotherjimmy 40:7d3fa6b99b2b 270 '-import', getcwd(),
theotherjimmy 40:7d3fa6b99b2b 271 '-cleanBuild', project_name
theotherjimmy 40:7d3fa6b99b2b 272 ]
theotherjimmy 40:7d3fa6b99b2b 273
theotherjimmy 40:7d3fa6b99b2b 274 p = Popen(' '.join(cmd), shell=True, stdout=PIPE, stderr=PIPE)
theotherjimmy 40:7d3fa6b99b2b 275 out, err = p.communicate()
theotherjimmy 40:7d3fa6b99b2b 276 ret_code = p.returncode
theotherjimmy 40:7d3fa6b99b2b 277 stdout_string = "=" * 10 + "STDOUT" + "=" * 10 + "\n"
theotherjimmy 40:7d3fa6b99b2b 278 err_string = "=" * 10 + "STDERR" + "=" * 10 + "\n"
theotherjimmy 40:7d3fa6b99b2b 279 err_string += err
theotherjimmy 40:7d3fa6b99b2b 280 success = any(l.startswith("Finished building target:") for l in out.split("\n"))
theotherjimmy 40:7d3fa6b99b2b 281
theotherjimmy 40:7d3fa6b99b2b 282 if success:
theotherjimmy 40:7d3fa6b99b2b 283 ret_string = "SUCCESS\n"
theotherjimmy 40:7d3fa6b99b2b 284 else:
theotherjimmy 40:7d3fa6b99b2b 285 ret_string = "FAILURE: build returned %s \n" % ret_code
theotherjimmy 40:7d3fa6b99b2b 286
theotherjimmy 40:7d3fa6b99b2b 287 print "%s\n%s\n%s\n%s" % (stdout_string, out, err_string, ret_string)
theotherjimmy 40:7d3fa6b99b2b 288
theotherjimmy 40:7d3fa6b99b2b 289 if log_name:
theotherjimmy 40:7d3fa6b99b2b 290 # Write the output to the log file
theotherjimmy 40:7d3fa6b99b2b 291 with open(log_name, 'w+') as f:
theotherjimmy 40:7d3fa6b99b2b 292 f.write(stdout_string)
theotherjimmy 40:7d3fa6b99b2b 293 f.write(out)
theotherjimmy 40:7d3fa6b99b2b 294 f.write(err_string)
theotherjimmy 40:7d3fa6b99b2b 295 f.write(ret_string)
theotherjimmy 40:7d3fa6b99b2b 296
theotherjimmy 40:7d3fa6b99b2b 297 # Cleanup the exported and built files
theotherjimmy 40:7d3fa6b99b2b 298 if cleanup:
theotherjimmy 40:7d3fa6b99b2b 299 if exists(log_name):
theotherjimmy 40:7d3fa6b99b2b 300 remove(log_name)
theotherjimmy 40:7d3fa6b99b2b 301 remove('.project')
theotherjimmy 40:7d3fa6b99b2b 302 remove('.cproject')
theotherjimmy 40:7d3fa6b99b2b 303 if exists('Debug'):
theotherjimmy 40:7d3fa6b99b2b 304 shutil.rmtree('Debug')
theotherjimmy 40:7d3fa6b99b2b 305 if exists('Release'):
theotherjimmy 40:7d3fa6b99b2b 306 shutil.rmtree('Release')
theotherjimmy 40:7d3fa6b99b2b 307 if exists('makefile.targets'):
theotherjimmy 40:7d3fa6b99b2b 308 remove('makefile.targets')
theotherjimmy 40:7d3fa6b99b2b 309
theotherjimmy 40:7d3fa6b99b2b 310 # Always remove the temporary folder.
theotherjimmy 40:7d3fa6b99b2b 311 if exists(tmp_folder):
theotherjimmy 40:7d3fa6b99b2b 312 shutil.rmtree(tmp_folder)
theotherjimmy 40:7d3fa6b99b2b 313
theotherjimmy 40:7d3fa6b99b2b 314 return not(success)
theotherjimmy 40:7d3fa6b99b2b 315
theotherjimmy 40:7d3fa6b99b2b 316
theotherjimmy 40:7d3fa6b99b2b 317 # -------------------------------------------------------------------------
theotherjimmy 40:7d3fa6b99b2b 318
theotherjimmy 40:7d3fa6b99b2b 319 def process_options(self, opts, flags_in):
theotherjimmy 40:7d3fa6b99b2b 320 """
theotherjimmy 40:7d3fa6b99b2b 321 CDT managed projects store lots of build options in separate
theotherjimmy 40:7d3fa6b99b2b 322 variables, with separate IDs in the .cproject file.
theotherjimmy 40:7d3fa6b99b2b 323 When the CDT build is started, all these options are brought
theotherjimmy 40:7d3fa6b99b2b 324 together to compose the compiler and linker command lines.
theotherjimmy 40:7d3fa6b99b2b 325
theotherjimmy 40:7d3fa6b99b2b 326 Here the process is reversed, from the compiler and linker
theotherjimmy 40:7d3fa6b99b2b 327 command lines, the options are identified and various flags are
theotherjimmy 40:7d3fa6b99b2b 328 set to control the template generation process.
theotherjimmy 40:7d3fa6b99b2b 329
theotherjimmy 40:7d3fa6b99b2b 330 Once identified, the options are removed from the command lines.
theotherjimmy 40:7d3fa6b99b2b 331
theotherjimmy 40:7d3fa6b99b2b 332 The options that were not identified are options that do not
theotherjimmy 40:7d3fa6b99b2b 333 have CDT equivalents and will be passed in the 'Other options'
theotherjimmy 40:7d3fa6b99b2b 334 categories.
theotherjimmy 40:7d3fa6b99b2b 335
theotherjimmy 40:7d3fa6b99b2b 336 Although this process does not have a very complicated logic,
theotherjimmy 40:7d3fa6b99b2b 337 given the large number of explicit configuration options
theotherjimmy 40:7d3fa6b99b2b 338 used by the GNU ARM Eclipse managed build plug-in, it is tedious...
theotherjimmy 40:7d3fa6b99b2b 339 """
theotherjimmy 40:7d3fa6b99b2b 340
theotherjimmy 40:7d3fa6b99b2b 341 # Make a copy of the flags, to be one by one removed after processing.
theotherjimmy 40:7d3fa6b99b2b 342 flags = copy.deepcopy(flags_in)
theotherjimmy 40:7d3fa6b99b2b 343
theotherjimmy 40:7d3fa6b99b2b 344 if False:
theotherjimmy 40:7d3fa6b99b2b 345 print
theotherjimmy 40:7d3fa6b99b2b 346 print 'common_flags', flags['common_flags']
theotherjimmy 40:7d3fa6b99b2b 347 print 'asm_flags', flags['asm_flags']
theotherjimmy 40:7d3fa6b99b2b 348 print 'c_flags', flags['c_flags']
theotherjimmy 40:7d3fa6b99b2b 349 print 'cxx_flags', flags['cxx_flags']
theotherjimmy 40:7d3fa6b99b2b 350 print 'ld_flags', flags['ld_flags']
theotherjimmy 40:7d3fa6b99b2b 351
theotherjimmy 40:7d3fa6b99b2b 352 # Initialise the 'last resort' options where all unrecognised
theotherjimmy 40:7d3fa6b99b2b 353 # options will be collected.
theotherjimmy 40:7d3fa6b99b2b 354 opts['as']['other'] = ''
theotherjimmy 40:7d3fa6b99b2b 355 opts['c']['other'] = ''
theotherjimmy 40:7d3fa6b99b2b 356 opts['cpp']['other'] = ''
theotherjimmy 40:7d3fa6b99b2b 357 opts['ld']['other'] = ''
theotherjimmy 40:7d3fa6b99b2b 358
theotherjimmy 40:7d3fa6b99b2b 359 MCPUS = {
theotherjimmy 40:7d3fa6b99b2b 360 'Cortex-M0': {'mcpu': 'cortex-m0', 'fpu_unit': None},
theotherjimmy 40:7d3fa6b99b2b 361 'Cortex-M0+': {'mcpu': 'cortex-m0plus', 'fpu_unit': None},
theotherjimmy 40:7d3fa6b99b2b 362 'Cortex-M1': {'mcpu': 'cortex-m1', 'fpu_unit': None},
theotherjimmy 40:7d3fa6b99b2b 363 'Cortex-M3': {'mcpu': 'cortex-m3', 'fpu_unit': None},
theotherjimmy 40:7d3fa6b99b2b 364 'Cortex-M4': {'mcpu': 'cortex-m4', 'fpu_unit': None},
theotherjimmy 40:7d3fa6b99b2b 365 'Cortex-M4F': {'mcpu': 'cortex-m4', 'fpu_unit': 'fpv4spd16'},
theotherjimmy 40:7d3fa6b99b2b 366 'Cortex-M7': {'mcpu': 'cortex-m7', 'fpu_unit': None},
theotherjimmy 40:7d3fa6b99b2b 367 'Cortex-M7F': {'mcpu': 'cortex-m7', 'fpu_unit': 'fpv4spd16'},
theotherjimmy 40:7d3fa6b99b2b 368 'Cortex-M7FD': {'mcpu': 'cortex-m7', 'fpu_unit': 'fpv5d16'},
theotherjimmy 40:7d3fa6b99b2b 369 'Cortex-A9': {'mcpu': 'cortex-a9', 'fpu_unit': 'vfpv3'}
theotherjimmy 40:7d3fa6b99b2b 370 }
theotherjimmy 40:7d3fa6b99b2b 371
theotherjimmy 40:7d3fa6b99b2b 372 MCPU_NXP = {
theotherjimmy 40:7d3fa6b99b2b 373 'cortex-m7' : 'cm7',
theotherjimmy 40:7d3fa6b99b2b 374 'cortex-m4' : 'cm4',
theotherjimmy 40:7d3fa6b99b2b 375 'cortex-m3' : 'cm3',
theotherjimmy 40:7d3fa6b99b2b 376 'cortex-m1' : 'cm1',
theotherjimmy 40:7d3fa6b99b2b 377 'cortex-m0' : 'cm0',
theotherjimmy 40:7d3fa6b99b2b 378 'cortex-m0.small-multiply' : 'cm0.smallmul',
theotherjimmy 40:7d3fa6b99b2b 379 'cortex-m0plus' : 'cm0plus',
theotherjimmy 40:7d3fa6b99b2b 380 'cortex-m0plus.small-multiply' : 'cm0plus.smallmul'
theotherjimmy 40:7d3fa6b99b2b 381 }
theotherjimmy 40:7d3fa6b99b2b 382
theotherjimmy 40:7d3fa6b99b2b 383 # Remove options that are supplied by CDT
theotherjimmy 40:7d3fa6b99b2b 384 self.remove_option(flags['common_flags'], '-c')
theotherjimmy 40:7d3fa6b99b2b 385 self.remove_option(flags['common_flags'], '-MMD')
theotherjimmy 40:7d3fa6b99b2b 386
theotherjimmy 40:7d3fa6b99b2b 387 # As 'plan B', get the CPU from the target definition.
theotherjimmy 40:7d3fa6b99b2b 388 core = self.toolchain.target.core
theotherjimmy 40:7d3fa6b99b2b 389
theotherjimmy 40:7d3fa6b99b2b 390 opts['common']['arm.target.family'] = None
theotherjimmy 40:7d3fa6b99b2b 391
theotherjimmy 40:7d3fa6b99b2b 392 # cortex-m0, cortex-m0-small-multiply, cortex-m0plus,
theotherjimmy 40:7d3fa6b99b2b 393 # cortex-m0plus-small-multiply, cortex-m1, cortex-m1-small-multiply,
theotherjimmy 40:7d3fa6b99b2b 394 # cortex-m3, cortex-m4, cortex-m7.
theotherjimmy 40:7d3fa6b99b2b 395 str = self.find_options(flags['common_flags'], '-mcpu=')
theotherjimmy 40:7d3fa6b99b2b 396 if str != None:
theotherjimmy 40:7d3fa6b99b2b 397 opts['common']['arm.target.family'] = str[len('-mcpu='):]
theotherjimmy 40:7d3fa6b99b2b 398 opts['common']['arm.target.family_nxp'] = MCPU_NXP[str[len('-mcpu='):]]
theotherjimmy 40:7d3fa6b99b2b 399 self.remove_option(flags['common_flags'], str)
theotherjimmy 40:7d3fa6b99b2b 400 self.remove_option(flags['ld_flags'], str)
theotherjimmy 40:7d3fa6b99b2b 401 else:
theotherjimmy 40:7d3fa6b99b2b 402 if core not in MCPUS:
theotherjimmy 40:7d3fa6b99b2b 403 raise NotSupportedException(
theotherjimmy 40:7d3fa6b99b2b 404 'Target core {0} not supported.'.format(core))
theotherjimmy 40:7d3fa6b99b2b 405 opts['common']['arm.target.family'] = MCPUS[core]['mcpu']
theotherjimmy 40:7d3fa6b99b2b 406
theotherjimmy 40:7d3fa6b99b2b 407 opts['common']['arm.target.arch'] = 'none'
theotherjimmy 40:7d3fa6b99b2b 408 str = self.find_options(flags['common_flags'], '-march=')
theotherjimmy 40:7d3fa6b99b2b 409 arch = str[len('-march='):]
theotherjimmy 40:7d3fa6b99b2b 410 archs = {'armv6-m': 'armv6-m', 'armv7-m': 'armv7-m', 'armv7-a': 'armv7-a'}
theotherjimmy 40:7d3fa6b99b2b 411 if arch in archs:
theotherjimmy 40:7d3fa6b99b2b 412 opts['common']['arm.target.arch'] = archs[arch]
theotherjimmy 40:7d3fa6b99b2b 413 self.remove_option(flags['common_flags'], str)
theotherjimmy 40:7d3fa6b99b2b 414
theotherjimmy 40:7d3fa6b99b2b 415 opts['common']['arm.target.instructionset'] = 'thumb'
theotherjimmy 40:7d3fa6b99b2b 416 if '-mthumb' in flags['common_flags']:
theotherjimmy 40:7d3fa6b99b2b 417 self.remove_option(flags['common_flags'], '-mthumb')
theotherjimmy 40:7d3fa6b99b2b 418 self.remove_option(flags['ld_flags'], '-mthumb')
theotherjimmy 40:7d3fa6b99b2b 419 elif '-marm' in flags['common_flags']:
theotherjimmy 40:7d3fa6b99b2b 420 opts['common']['arm.target.instructionset'] = 'arm'
theotherjimmy 40:7d3fa6b99b2b 421 self.remove_option(flags['common_flags'], '-marm')
theotherjimmy 40:7d3fa6b99b2b 422 self.remove_option(flags['ld_flags'], '-marm')
theotherjimmy 40:7d3fa6b99b2b 423
theotherjimmy 40:7d3fa6b99b2b 424 opts['common']['arm.target.thumbinterwork'] = False
theotherjimmy 40:7d3fa6b99b2b 425 if '-mthumb-interwork' in flags['common_flags']:
theotherjimmy 40:7d3fa6b99b2b 426 opts['common']['arm.target.thumbinterwork'] = True
theotherjimmy 40:7d3fa6b99b2b 427 self.remove_option(flags['common_flags'], '-mthumb-interwork')
theotherjimmy 40:7d3fa6b99b2b 428
theotherjimmy 40:7d3fa6b99b2b 429 opts['common']['arm.target.endianness'] = None
theotherjimmy 40:7d3fa6b99b2b 430 if '-mlittle-endian' in flags['common_flags']:
theotherjimmy 40:7d3fa6b99b2b 431 opts['common']['arm.target.endianness'] = 'little'
theotherjimmy 40:7d3fa6b99b2b 432 self.remove_option(flags['common_flags'], '-mlittle-endian')
theotherjimmy 40:7d3fa6b99b2b 433 elif '-mbig-endian' in flags['common_flags']:
theotherjimmy 40:7d3fa6b99b2b 434 opts['common']['arm.target.endianness'] = 'big'
theotherjimmy 40:7d3fa6b99b2b 435 self.remove_option(flags['common_flags'], '-mbig-endian')
theotherjimmy 40:7d3fa6b99b2b 436
theotherjimmy 40:7d3fa6b99b2b 437 opts['common']['arm.target.fpu.unit'] = None
theotherjimmy 40:7d3fa6b99b2b 438 opts['common']['arm.target.fpu.unit_nxp'] = None
theotherjimmy 40:7d3fa6b99b2b 439 # default, fpv4spd16, fpv5d16, fpv5spd16
theotherjimmy 40:7d3fa6b99b2b 440 str = self.find_options(flags['common_flags'], '-mfpu=')
theotherjimmy 40:7d3fa6b99b2b 441 if str != None:
theotherjimmy 40:7d3fa6b99b2b 442 fpu = str[len('-mfpu='):]
theotherjimmy 40:7d3fa6b99b2b 443 fpus = {
theotherjimmy 40:7d3fa6b99b2b 444 'fpv4-sp-d16': 'fpv4spd16',
theotherjimmy 40:7d3fa6b99b2b 445 'fpv5-d16': 'fpv5d16',
theotherjimmy 40:7d3fa6b99b2b 446 'fpv5-sp-d16': 'fpv5spd16'
theotherjimmy 40:7d3fa6b99b2b 447 }
theotherjimmy 40:7d3fa6b99b2b 448 fpus_nxp = {
theotherjimmy 40:7d3fa6b99b2b 449 'fpv4-sp-d16': 'fpv4',
theotherjimmy 40:7d3fa6b99b2b 450 'fpv5-d16': 'fpv5dp',
theotherjimmy 40:7d3fa6b99b2b 451 'fpv5-sp-d16': 'fpv5sp'
theotherjimmy 40:7d3fa6b99b2b 452 }
theotherjimmy 40:7d3fa6b99b2b 453 if fpu in fpus:
theotherjimmy 40:7d3fa6b99b2b 454 opts['common']['arm.target.fpu.unit'] = fpus[fpu]
theotherjimmy 40:7d3fa6b99b2b 455 opts['common']['arm.target.fpu.unit_nxp'] = fpus_nxp[fpu]
theotherjimmy 40:7d3fa6b99b2b 456
theotherjimmy 40:7d3fa6b99b2b 457 self.remove_option(flags['common_flags'], str)
theotherjimmy 40:7d3fa6b99b2b 458 self.remove_option(flags['ld_flags'], str)
theotherjimmy 40:7d3fa6b99b2b 459 if opts['common']['arm.target.fpu.unit'] == None:
theotherjimmy 40:7d3fa6b99b2b 460 if core not in MCPUS:
theotherjimmy 40:7d3fa6b99b2b 461 raise NotSupportedException(
theotherjimmy 40:7d3fa6b99b2b 462 'Target core {0} not supported.'.format(core))
theotherjimmy 40:7d3fa6b99b2b 463 if MCPUS[core]['fpu_unit']:
theotherjimmy 40:7d3fa6b99b2b 464 opts['common'][
theotherjimmy 40:7d3fa6b99b2b 465 'arm.target.fpu.unit'] = MCPUS[core]['fpu_unit']
theotherjimmy 40:7d3fa6b99b2b 466
theotherjimmy 40:7d3fa6b99b2b 467 # soft, softfp, hard.
theotherjimmy 40:7d3fa6b99b2b 468 str = self.find_options(flags['common_flags'], '-mfloat-abi=')
theotherjimmy 40:7d3fa6b99b2b 469 if str != None:
theotherjimmy 40:7d3fa6b99b2b 470 opts['common']['arm.target.fpu.abi'] = str[
theotherjimmy 40:7d3fa6b99b2b 471 len('-mfloat-abi='):]
theotherjimmy 40:7d3fa6b99b2b 472 self.remove_option(flags['common_flags'], str)
theotherjimmy 40:7d3fa6b99b2b 473 self.remove_option(flags['ld_flags'], str)
theotherjimmy 40:7d3fa6b99b2b 474 if opts['common']['arm.target.fpu.abi'] == 'hard':
theotherjimmy 40:7d3fa6b99b2b 475 opts['common']['arm.target.fpu.unit_nxp'] += '.hard'
theotherjimmy 40:7d3fa6b99b2b 476
theotherjimmy 40:7d3fa6b99b2b 477 # Default optimisation level for Release.
theotherjimmy 40:7d3fa6b99b2b 478 opts['common']['optimization.level'] = '-Os'
theotherjimmy 40:7d3fa6b99b2b 479
theotherjimmy 40:7d3fa6b99b2b 480 # If the project defines an optimisation level, it is used
theotherjimmy 40:7d3fa6b99b2b 481 # only for the Release configuration, the Debug one used '-Og'.
theotherjimmy 40:7d3fa6b99b2b 482 str = self.find_options(flags['common_flags'], '-O')
theotherjimmy 40:7d3fa6b99b2b 483 if str != None:
theotherjimmy 40:7d3fa6b99b2b 484 levels = {
theotherjimmy 40:7d3fa6b99b2b 485 '-O0': 'none', '-O1': 'optimize', '-O2': 'more',
theotherjimmy 40:7d3fa6b99b2b 486 '-O3': 'most', '-Os': 'size', '-Og': 'debug'
theotherjimmy 40:7d3fa6b99b2b 487 }
theotherjimmy 40:7d3fa6b99b2b 488 if str in levels:
theotherjimmy 40:7d3fa6b99b2b 489 opts['common']['optimization.level'] = levels[str]
theotherjimmy 40:7d3fa6b99b2b 490 self.remove_option(flags['common_flags'], str)
theotherjimmy 40:7d3fa6b99b2b 491
theotherjimmy 40:7d3fa6b99b2b 492 include_files = []
theotherjimmy 40:7d3fa6b99b2b 493 for all_flags in [flags['common_flags'], flags['c_flags'], flags['cxx_flags']]:
theotherjimmy 40:7d3fa6b99b2b 494 while '-include' in all_flags:
theotherjimmy 40:7d3fa6b99b2b 495 ix = all_flags.index('-include')
theotherjimmy 40:7d3fa6b99b2b 496 str = all_flags[ix + 1]
theotherjimmy 40:7d3fa6b99b2b 497 if str not in include_files:
theotherjimmy 40:7d3fa6b99b2b 498 include_files.append(str)
theotherjimmy 40:7d3fa6b99b2b 499 self.remove_option(all_flags, '-include')
theotherjimmy 40:7d3fa6b99b2b 500 self.remove_option(all_flags, str)
theotherjimmy 40:7d3fa6b99b2b 501
theotherjimmy 40:7d3fa6b99b2b 502 opts['common']['include_files'] = include_files
theotherjimmy 40:7d3fa6b99b2b 503
theotherjimmy 40:7d3fa6b99b2b 504 if '-ansi' in flags['c_flags']:
theotherjimmy 40:7d3fa6b99b2b 505 opts['c']['compiler.std'] = '-ansi'
theotherjimmy 40:7d3fa6b99b2b 506 self.remove_option(flags['c_flags'], str)
theotherjimmy 40:7d3fa6b99b2b 507 else:
theotherjimmy 40:7d3fa6b99b2b 508 str = self.find_options(flags['c_flags'], '-std')
theotherjimmy 40:7d3fa6b99b2b 509 std = str[len('-std='):]
theotherjimmy 40:7d3fa6b99b2b 510 c_std = {
theotherjimmy 40:7d3fa6b99b2b 511 'c90': 'c90', 'c89': 'c90', 'gnu90': 'gnu90', 'gnu89': 'gnu90',
theotherjimmy 40:7d3fa6b99b2b 512 'c99': 'c99', 'c9x': 'c99', 'gnu99': 'gnu99', 'gnu9x': 'gnu98',
theotherjimmy 40:7d3fa6b99b2b 513 'c11': 'c11', 'c1x': 'c11', 'gnu11': 'gnu11', 'gnu1x': 'gnu11'
theotherjimmy 40:7d3fa6b99b2b 514 }
theotherjimmy 40:7d3fa6b99b2b 515 if std in c_std:
theotherjimmy 40:7d3fa6b99b2b 516 opts['c']['compiler.std'] = c_std[std]
theotherjimmy 40:7d3fa6b99b2b 517 self.remove_option(flags['c_flags'], str)
theotherjimmy 40:7d3fa6b99b2b 518
theotherjimmy 40:7d3fa6b99b2b 519 if '-ansi' in flags['cxx_flags']:
theotherjimmy 40:7d3fa6b99b2b 520 opts['cpp']['compiler.std'] = '-ansi'
theotherjimmy 40:7d3fa6b99b2b 521 self.remove_option(flags['cxx_flags'], str)
theotherjimmy 40:7d3fa6b99b2b 522 else:
theotherjimmy 40:7d3fa6b99b2b 523 str = self.find_options(flags['cxx_flags'], '-std')
theotherjimmy 40:7d3fa6b99b2b 524 std = str[len('-std='):]
theotherjimmy 40:7d3fa6b99b2b 525 cpp_std = {
theotherjimmy 40:7d3fa6b99b2b 526 'c++98': 'cpp98', 'c++03': 'cpp03',
theotherjimmy 40:7d3fa6b99b2b 527 'gnu++98': 'gnupp98', 'gnu++03': 'gnupp03',
theotherjimmy 40:7d3fa6b99b2b 528 'c++0x': 'cpp03', 'gnu++0x': 'gnupp03',
theotherjimmy 40:7d3fa6b99b2b 529 'c++11': 'cpp11', 'gnu++11': 'gnupp11',
theotherjimmy 40:7d3fa6b99b2b 530 'c++1y': 'cpp11', 'gnu++1y': 'gnupp11',
theotherjimmy 40:7d3fa6b99b2b 531 'c++14': 'cpp14', 'gnu++14': 'gnupp14',
theotherjimmy 40:7d3fa6b99b2b 532 'c++1z': 'cpp1z', 'gnu++1z': 'gnupp1z',
theotherjimmy 40:7d3fa6b99b2b 533 }
theotherjimmy 40:7d3fa6b99b2b 534 if std in cpp_std:
theotherjimmy 40:7d3fa6b99b2b 535 opts['cpp']['compiler.std'] = cpp_std[std]
theotherjimmy 40:7d3fa6b99b2b 536 self.remove_option(flags['cxx_flags'], str)
theotherjimmy 40:7d3fa6b99b2b 537
theotherjimmy 40:7d3fa6b99b2b 538 # Common optimisation options.
theotherjimmy 40:7d3fa6b99b2b 539 optimization_options = {
theotherjimmy 40:7d3fa6b99b2b 540 '-flto': 'optimization.lto',
theotherjimmy 40:7d3fa6b99b2b 541 '--ffat-lto-objects': 'optimization.lto_objects'
theotherjimmy 40:7d3fa6b99b2b 542 }
theotherjimmy 40:7d3fa6b99b2b 543 for option in optimization_options:
theotherjimmy 40:7d3fa6b99b2b 544 opts['common'][optimization_options[option]] = False
theotherjimmy 40:7d3fa6b99b2b 545 if option in flags['common_flags']:
theotherjimmy 40:7d3fa6b99b2b 546 opts['common'][optimization_options[option]] = True
theotherjimmy 40:7d3fa6b99b2b 547 self.remove_option(flags['common_flags'], option)
theotherjimmy 40:7d3fa6b99b2b 548
theotherjimmy 40:7d3fa6b99b2b 549 # Common warning options.
theotherjimmy 40:7d3fa6b99b2b 550 warning_options = {
theotherjimmy 40:7d3fa6b99b2b 551 '-fsyntax-only': 'warnings.syntaxonly',
theotherjimmy 40:7d3fa6b99b2b 552 '-pedantic': 'warnings.pedantic',
theotherjimmy 40:7d3fa6b99b2b 553 '-pedantic-errors': 'warnings.pedanticerrors',
theotherjimmy 40:7d3fa6b99b2b 554 '-w': 'warnings.nowarn',
theotherjimmy 40:7d3fa6b99b2b 555 '-Wall': 'warnings.allwarn',
theotherjimmy 40:7d3fa6b99b2b 556 '-Wextra': 'warnings.extrawarn',
theotherjimmy 40:7d3fa6b99b2b 557 '-Wconversion': 'warnings.conversion',
theotherjimmy 40:7d3fa6b99b2b 558 '-Werror': 'warnings.toerrors',
theotherjimmy 40:7d3fa6b99b2b 559 }
theotherjimmy 40:7d3fa6b99b2b 560
theotherjimmy 40:7d3fa6b99b2b 561 for option in warning_options:
theotherjimmy 40:7d3fa6b99b2b 562 opts['common'][warning_options[option]] = False
theotherjimmy 40:7d3fa6b99b2b 563 if option in flags['common_flags']:
theotherjimmy 40:7d3fa6b99b2b 564 opts['common'][warning_options[option]] = True
theotherjimmy 40:7d3fa6b99b2b 565 self.remove_option(flags['common_flags'], option)
theotherjimmy 40:7d3fa6b99b2b 566
theotherjimmy 40:7d3fa6b99b2b 567 # Common debug options.
theotherjimmy 40:7d3fa6b99b2b 568 debug_levels = {
theotherjimmy 40:7d3fa6b99b2b 569 '-g': 'default',
theotherjimmy 40:7d3fa6b99b2b 570 '-g1': 'minimal',
theotherjimmy 40:7d3fa6b99b2b 571 '-g3': 'max',
theotherjimmy 40:7d3fa6b99b2b 572 }
theotherjimmy 40:7d3fa6b99b2b 573 opts['common']['debugging.level'] = 'none'
theotherjimmy 40:7d3fa6b99b2b 574 for option in debug_levels:
theotherjimmy 40:7d3fa6b99b2b 575 if option in flags['common_flags']:
theotherjimmy 40:7d3fa6b99b2b 576 opts['common'][
theotherjimmy 40:7d3fa6b99b2b 577 'debugging.level'] = debug_levels[option]
theotherjimmy 40:7d3fa6b99b2b 578 self.remove_option(flags['common_flags'], option)
theotherjimmy 40:7d3fa6b99b2b 579
theotherjimmy 40:7d3fa6b99b2b 580
theotherjimmy 40:7d3fa6b99b2b 581 opts['common']['debugging.prof'] = False
theotherjimmy 40:7d3fa6b99b2b 582 if '-p' in flags['common_flags']:
theotherjimmy 40:7d3fa6b99b2b 583 opts['common']['debugging.prof'] = True
theotherjimmy 40:7d3fa6b99b2b 584 self.remove_option(flags['common_flags'], '-p')
theotherjimmy 40:7d3fa6b99b2b 585
theotherjimmy 40:7d3fa6b99b2b 586 opts['common']['debugging.gprof'] = False
theotherjimmy 40:7d3fa6b99b2b 587 if '-pg' in flags['common_flags']:
theotherjimmy 40:7d3fa6b99b2b 588 opts['common']['debugging.gprof'] = True
theotherjimmy 40:7d3fa6b99b2b 589 self.remove_option(flags['common_flags'], '-gp')
theotherjimmy 40:7d3fa6b99b2b 590
theotherjimmy 40:7d3fa6b99b2b 591 # Assembler options.
theotherjimmy 40:7d3fa6b99b2b 592 opts['as']['usepreprocessor'] = False
theotherjimmy 40:7d3fa6b99b2b 593 while '-x' in flags['asm_flags']:
theotherjimmy 40:7d3fa6b99b2b 594 ix = flags['asm_flags'].index('-x')
theotherjimmy 40:7d3fa6b99b2b 595 str = flags['asm_flags'][ix + 1]
theotherjimmy 40:7d3fa6b99b2b 596
theotherjimmy 40:7d3fa6b99b2b 597 if str == 'assembler-with-cpp':
theotherjimmy 40:7d3fa6b99b2b 598 opts['as']['usepreprocessor'] = True
theotherjimmy 40:7d3fa6b99b2b 599 else:
theotherjimmy 40:7d3fa6b99b2b 600 # Collect all other assembler options.
theotherjimmy 40:7d3fa6b99b2b 601 opts['as']['other'] += ' -x ' + str
theotherjimmy 40:7d3fa6b99b2b 602
theotherjimmy 40:7d3fa6b99b2b 603 self.remove_option(flags['asm_flags'], '-x')
theotherjimmy 40:7d3fa6b99b2b 604 self.remove_option(flags['asm_flags'], 'assembler-with-cpp')
theotherjimmy 40:7d3fa6b99b2b 605
theotherjimmy 40:7d3fa6b99b2b 606 opts['as']['nostdinc'] = False
theotherjimmy 40:7d3fa6b99b2b 607 if '-nostdinc' in flags['asm_flags']:
theotherjimmy 40:7d3fa6b99b2b 608 opts['as']['nostdinc'] = True
theotherjimmy 40:7d3fa6b99b2b 609 self.remove_option(flags['asm_flags'], '-nostdinc')
theotherjimmy 40:7d3fa6b99b2b 610
theotherjimmy 40:7d3fa6b99b2b 611 opts['as']['verbose'] = False
theotherjimmy 40:7d3fa6b99b2b 612 if '-v' in flags['asm_flags']:
theotherjimmy 40:7d3fa6b99b2b 613 opts['as']['verbose'] = True
theotherjimmy 40:7d3fa6b99b2b 614 self.remove_option(flags['asm_flags'], '-v')
theotherjimmy 40:7d3fa6b99b2b 615
theotherjimmy 40:7d3fa6b99b2b 616 # C options.
theotherjimmy 40:7d3fa6b99b2b 617 opts['c']['nostdinc'] = False
theotherjimmy 40:7d3fa6b99b2b 618 if '-nostdinc' in flags['c_flags']:
theotherjimmy 40:7d3fa6b99b2b 619 opts['c']['nostdinc'] = True
theotherjimmy 40:7d3fa6b99b2b 620 self.remove_option(flags['c_flags'], '-nostdinc')
theotherjimmy 40:7d3fa6b99b2b 621
theotherjimmy 40:7d3fa6b99b2b 622 opts['c']['verbose'] = False
theotherjimmy 40:7d3fa6b99b2b 623 if '-v' in flags['c_flags']:
theotherjimmy 40:7d3fa6b99b2b 624 opts['c']['verbose'] = True
theotherjimmy 40:7d3fa6b99b2b 625 self.remove_option(flags['c_flags'], '-v')
theotherjimmy 40:7d3fa6b99b2b 626
theotherjimmy 40:7d3fa6b99b2b 627
theotherjimmy 40:7d3fa6b99b2b 628 # C++ options.
theotherjimmy 40:7d3fa6b99b2b 629 opts['cpp']['nostdinc'] = False
theotherjimmy 40:7d3fa6b99b2b 630 if '-nostdinc' in flags['cxx_flags']:
theotherjimmy 40:7d3fa6b99b2b 631 opts['cpp']['nostdinc'] = True
theotherjimmy 40:7d3fa6b99b2b 632 self.remove_option(flags['cxx_flags'], '-nostdinc')
theotherjimmy 40:7d3fa6b99b2b 633
theotherjimmy 40:7d3fa6b99b2b 634 opts['cpp']['nostdincpp'] = False
theotherjimmy 40:7d3fa6b99b2b 635 if '-nostdinc++' in flags['cxx_flags']:
theotherjimmy 40:7d3fa6b99b2b 636 opts['cpp']['nostdincpp'] = True
theotherjimmy 40:7d3fa6b99b2b 637 self.remove_option(flags['cxx_flags'], '-nostdinc++')
theotherjimmy 40:7d3fa6b99b2b 638
theotherjimmy 40:7d3fa6b99b2b 639 optimization_options = {
theotherjimmy 40:7d3fa6b99b2b 640 '-fno-exceptions': 'optimization.noexceptions',
theotherjimmy 40:7d3fa6b99b2b 641 '-fno-rtti': 'optimization.nortti',
theotherjimmy 40:7d3fa6b99b2b 642 '-fno-use-cxa-atexit': 'optimization.nousecxaatexit',
theotherjimmy 40:7d3fa6b99b2b 643 '-fno-threadsafe-statics': 'optimization.nothreadsafestatics',
theotherjimmy 40:7d3fa6b99b2b 644 }
theotherjimmy 40:7d3fa6b99b2b 645
theotherjimmy 40:7d3fa6b99b2b 646 for option in optimization_options:
theotherjimmy 40:7d3fa6b99b2b 647 opts['cpp'][optimization_options[option]] = False
theotherjimmy 40:7d3fa6b99b2b 648 if option in flags['cxx_flags']:
theotherjimmy 40:7d3fa6b99b2b 649 opts['cpp'][optimization_options[option]] = True
theotherjimmy 40:7d3fa6b99b2b 650 if option in flags['common_flags']:
theotherjimmy 40:7d3fa6b99b2b 651 opts['cpp'][optimization_options[option]] = True
theotherjimmy 40:7d3fa6b99b2b 652
theotherjimmy 40:7d3fa6b99b2b 653 opts['cpp']['verbose'] = False
theotherjimmy 40:7d3fa6b99b2b 654 if '-v' in flags['cxx_flags']:
theotherjimmy 40:7d3fa6b99b2b 655 opts['cpp']['verbose'] = True
theotherjimmy 40:7d3fa6b99b2b 656 self.remove_option(flags['cxx_flags'], '-v')
theotherjimmy 40:7d3fa6b99b2b 657
theotherjimmy 40:7d3fa6b99b2b 658 # Linker options.
theotherjimmy 40:7d3fa6b99b2b 659 linker_options = {
theotherjimmy 40:7d3fa6b99b2b 660 '-nostartfiles': 'nostart',
theotherjimmy 40:7d3fa6b99b2b 661 '-nodefaultlibs': 'nodeflibs',
theotherjimmy 40:7d3fa6b99b2b 662 '-nostdlib': 'nostdlibs',
theotherjimmy 40:7d3fa6b99b2b 663 }
theotherjimmy 40:7d3fa6b99b2b 664
theotherjimmy 40:7d3fa6b99b2b 665 for option in linker_options:
theotherjimmy 40:7d3fa6b99b2b 666 opts['ld'][linker_options[option]] = False
theotherjimmy 40:7d3fa6b99b2b 667 if option in flags['ld_flags']:
theotherjimmy 40:7d3fa6b99b2b 668 opts['ld'][linker_options[option]] = True
theotherjimmy 40:7d3fa6b99b2b 669 self.remove_option(flags['ld_flags'], option)
theotherjimmy 40:7d3fa6b99b2b 670
theotherjimmy 40:7d3fa6b99b2b 671 opts['ld']['gcsections'] = False
theotherjimmy 40:7d3fa6b99b2b 672 if '-Wl,--gc-sections' in flags['ld_flags']:
theotherjimmy 40:7d3fa6b99b2b 673 opts['ld']['gcsections'] = True
theotherjimmy 40:7d3fa6b99b2b 674 self.remove_option(flags['ld_flags'], '-Wl,--gc-sections')
theotherjimmy 40:7d3fa6b99b2b 675
theotherjimmy 40:7d3fa6b99b2b 676 opts['ld']['flags'] = []
theotherjimmy 40:7d3fa6b99b2b 677 to_remove = []
theotherjimmy 40:7d3fa6b99b2b 678 for opt in flags['ld_flags']:
theotherjimmy 40:7d3fa6b99b2b 679 if opt.startswith('-Wl,--wrap,'):
theotherjimmy 40:7d3fa6b99b2b 680 opts['ld']['flags'].append(
theotherjimmy 40:7d3fa6b99b2b 681 '--wrap=' + opt[len('-Wl,--wrap,'):])
theotherjimmy 40:7d3fa6b99b2b 682 to_remove.append(opt)
theotherjimmy 40:7d3fa6b99b2b 683 for opt in to_remove:
theotherjimmy 40:7d3fa6b99b2b 684 self.remove_option(flags['ld_flags'], opt)
theotherjimmy 40:7d3fa6b99b2b 685
theotherjimmy 40:7d3fa6b99b2b 686 # Other tool remaining options are separated by category.
theotherjimmy 40:7d3fa6b99b2b 687 opts['as']['otherwarnings'] = self.find_options(
theotherjimmy 40:7d3fa6b99b2b 688 flags['asm_flags'], '-W')
theotherjimmy 40:7d3fa6b99b2b 689
theotherjimmy 40:7d3fa6b99b2b 690 opts['c']['otherwarnings'] = self.find_options(
theotherjimmy 40:7d3fa6b99b2b 691 flags['c_flags'], '-W')
theotherjimmy 40:7d3fa6b99b2b 692 opts['c']['otheroptimizations'] = self.find_options(flags[
theotherjimmy 40:7d3fa6b99b2b 693 'c_flags'], '-f')
theotherjimmy 40:7d3fa6b99b2b 694
theotherjimmy 40:7d3fa6b99b2b 695 opts['cpp']['otherwarnings'] = self.find_options(
theotherjimmy 40:7d3fa6b99b2b 696 flags['cxx_flags'], '-W')
theotherjimmy 40:7d3fa6b99b2b 697 opts['cpp']['otheroptimizations'] = self.find_options(
theotherjimmy 40:7d3fa6b99b2b 698 flags['cxx_flags'], '-f')
theotherjimmy 40:7d3fa6b99b2b 699
theotherjimmy 40:7d3fa6b99b2b 700 # Other common remaining options are separated by category.
theotherjimmy 40:7d3fa6b99b2b 701 opts['common']['optimization.other'] = self.find_options(
theotherjimmy 40:7d3fa6b99b2b 702 flags['common_flags'], '-f')
theotherjimmy 40:7d3fa6b99b2b 703 opts['common']['warnings.other'] = self.find_options(
theotherjimmy 40:7d3fa6b99b2b 704 flags['common_flags'], '-W')
theotherjimmy 40:7d3fa6b99b2b 705
theotherjimmy 40:7d3fa6b99b2b 706 # Remaining common flags are added to each tool.
theotherjimmy 40:7d3fa6b99b2b 707 opts['as']['other'] += ' ' + \
theotherjimmy 40:7d3fa6b99b2b 708 ' '.join(flags['common_flags']) + ' ' + \
theotherjimmy 40:7d3fa6b99b2b 709 ' '.join(flags['asm_flags'])
theotherjimmy 40:7d3fa6b99b2b 710 opts['c']['other'] += ' ' + \
theotherjimmy 40:7d3fa6b99b2b 711 ' '.join(flags['common_flags']) + ' ' + ' '.join(flags['c_flags'])
theotherjimmy 40:7d3fa6b99b2b 712 opts['cpp']['other'] += ' ' + \
theotherjimmy 40:7d3fa6b99b2b 713 ' '.join(flags['common_flags']) + ' ' + \
theotherjimmy 40:7d3fa6b99b2b 714 ' '.join(flags['cxx_flags'])
theotherjimmy 40:7d3fa6b99b2b 715 opts['ld']['other'] += ' ' + \
theotherjimmy 40:7d3fa6b99b2b 716 ' '.join(flags['common_flags']) + ' ' + ' '.join(flags['ld_flags'])
theotherjimmy 40:7d3fa6b99b2b 717
theotherjimmy 40:7d3fa6b99b2b 718 if len(self.system_libraries) > 0:
theotherjimmy 40:7d3fa6b99b2b 719 opts['ld']['other'] += ' -Wl,--start-group '
theotherjimmy 40:7d3fa6b99b2b 720 opts['ld'][
theotherjimmy 40:7d3fa6b99b2b 721 'other'] += ' '.join('-l' + s for s in self.system_libraries) + ' '
theotherjimmy 40:7d3fa6b99b2b 722 opts['ld'][
theotherjimmy 40:7d3fa6b99b2b 723 'other'] += ' '.join('-l' + s for s in self.libraries)
theotherjimmy 40:7d3fa6b99b2b 724 opts['ld']['other'] += ' -Wl,--end-group '
theotherjimmy 40:7d3fa6b99b2b 725
theotherjimmy 40:7d3fa6b99b2b 726 # Strip all 'other' flags, since they might have leading spaces.
theotherjimmy 40:7d3fa6b99b2b 727 opts['as']['other'] = opts['as']['other'].strip()
theotherjimmy 40:7d3fa6b99b2b 728 opts['c']['other'] = opts['c']['other'].strip()
theotherjimmy 40:7d3fa6b99b2b 729 opts['cpp']['other'] = opts['cpp']['other'].strip()
theotherjimmy 40:7d3fa6b99b2b 730 opts['ld']['other'] = opts['ld']['other'].strip()
theotherjimmy 40:7d3fa6b99b2b 731
theotherjimmy 40:7d3fa6b99b2b 732 if False:
theotherjimmy 40:7d3fa6b99b2b 733 print
theotherjimmy 40:7d3fa6b99b2b 734 print opts
theotherjimmy 40:7d3fa6b99b2b 735
theotherjimmy 40:7d3fa6b99b2b 736 print
theotherjimmy 40:7d3fa6b99b2b 737 print 'common_flags', flags['common_flags']
theotherjimmy 40:7d3fa6b99b2b 738 print 'asm_flags', flags['asm_flags']
theotherjimmy 40:7d3fa6b99b2b 739 print 'c_flags', flags['c_flags']
theotherjimmy 40:7d3fa6b99b2b 740 print 'cxx_flags', flags['cxx_flags']
theotherjimmy 40:7d3fa6b99b2b 741 print 'ld_flags', flags['ld_flags']
theotherjimmy 40:7d3fa6b99b2b 742