Clone of official tools
export/gnuarmeclipse/__init__.py@41:2a77626a4c21, 2017-10-25 (annotated)
- Committer:
- theotherjimmy
- Date:
- Wed Oct 25 14:46:50 2017 -0500
- Revision:
- 41:2a77626a4c21
- Parent:
- 40:7d3fa6b99b2b
- Child:
- 43:2a7da56ebd24
Update to track Mbed OS 5.6.3
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
The Other Jimmy |
36:96847d42f010 | 1 | """ |
The Other Jimmy |
36:96847d42f010 | 2 | mbed SDK |
The Other Jimmy |
36:96847d42f010 | 3 | Copyright (c) 2011-2017 ARM Limited |
The Other Jimmy |
36:96847d42f010 | 4 | |
The Other Jimmy |
36:96847d42f010 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); |
The Other Jimmy |
36:96847d42f010 | 6 | you may not use this file except in compliance with the License. |
The Other Jimmy |
36:96847d42f010 | 7 | You may obtain a copy of the License at |
The Other Jimmy |
36:96847d42f010 | 8 | |
The Other Jimmy |
36:96847d42f010 | 9 | http://www.apache.org/licenses/LICENSE-2.0 |
The Other Jimmy |
36:96847d42f010 | 10 | |
The Other Jimmy |
36:96847d42f010 | 11 | Unless required by applicable law or agreed to in writing, software |
The Other Jimmy |
36:96847d42f010 | 12 | distributed under the License is distributed on an "AS IS" BASIS, |
The Other Jimmy |
36:96847d42f010 | 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
The Other Jimmy |
36:96847d42f010 | 14 | See the License for the specific language governing permissions and |
The Other Jimmy |
36:96847d42f010 | 15 | limitations under the License. |
The Other Jimmy |
36:96847d42f010 | 16 | |
The Other Jimmy |
36:96847d42f010 | 17 | Title: GNU ARM Eclipse (http://gnuarmeclipse.github.io) exporter. |
The Other Jimmy |
36:96847d42f010 | 18 | |
The Other Jimmy |
36:96847d42f010 | 19 | Description: Creates a managed build project that can be imported by |
The Other Jimmy |
36:96847d42f010 | 20 | the GNU ARM Eclipse plug-ins. |
The Other Jimmy |
36:96847d42f010 | 21 | |
The Other Jimmy |
36:96847d42f010 | 22 | Author: Liviu Ionescu <ilg@livius.net> |
The Other Jimmy |
36:96847d42f010 | 23 | """ |
The Other Jimmy |
36:96847d42f010 | 24 | |
The Other Jimmy |
36:96847d42f010 | 25 | import os |
The Other Jimmy |
36:96847d42f010 | 26 | import copy |
The Other Jimmy |
36:96847d42f010 | 27 | import tempfile |
The Other Jimmy |
36:96847d42f010 | 28 | import shutil |
The Other Jimmy |
36:96847d42f010 | 29 | import copy |
The Other Jimmy |
36:96847d42f010 | 30 | |
The Other Jimmy |
36:96847d42f010 | 31 | from subprocess import call, Popen, PIPE |
The Other Jimmy |
36:96847d42f010 | 32 | from os.path import splitext, basename, relpath, dirname, exists, join, dirname |
The Other Jimmy |
36:96847d42f010 | 33 | from random import randint |
The Other Jimmy |
36:96847d42f010 | 34 | from json import load |
The Other Jimmy |
36:96847d42f010 | 35 | |
theotherjimmy |
40:7d3fa6b99b2b | 36 | from tools.export.exporters import Exporter, apply_supported_whitelist |
The Other Jimmy |
36:96847d42f010 | 37 | from tools.options import list_profiles |
The Other Jimmy |
36:96847d42f010 | 38 | from tools.targets import TARGET_MAP |
The Other Jimmy |
36:96847d42f010 | 39 | from tools.utils import NotSupportedException |
The Other Jimmy |
36:96847d42f010 | 40 | from tools.build_api import prepare_toolchain |
The Other Jimmy |
36:96847d42f010 | 41 | |
The Other Jimmy |
36:96847d42f010 | 42 | # ============================================================================= |
The Other Jimmy |
36:96847d42f010 | 43 | |
The Other Jimmy |
36:96847d42f010 | 44 | |
The Other Jimmy |
36:96847d42f010 | 45 | class UID: |
The Other Jimmy |
36:96847d42f010 | 46 | """ |
The Other Jimmy |
36:96847d42f010 | 47 | Helper class, used to generate unique ids required by .cproject symbols. |
The Other Jimmy |
36:96847d42f010 | 48 | """ |
The Other Jimmy |
36:96847d42f010 | 49 | @property |
The Other Jimmy |
36:96847d42f010 | 50 | def id(self): |
The Other Jimmy |
36:96847d42f010 | 51 | return "%0.9u" % randint(0, 999999999) |
The Other Jimmy |
36:96847d42f010 | 52 | |
The Other Jimmy |
36:96847d42f010 | 53 | # Global UID generator instance. |
The Other Jimmy |
36:96847d42f010 | 54 | # Passed to the template engine, and referred as {{u.id}}. |
The Other Jimmy |
36:96847d42f010 | 55 | # Each invocation generates a new number. |
The Other Jimmy |
36:96847d42f010 | 56 | u = UID() |
The Other Jimmy |
36:96847d42f010 | 57 | |
The Other Jimmy |
36:96847d42f010 | 58 | # ============================================================================= |
The Other Jimmy |
36:96847d42f010 | 59 | |
The Other Jimmy |
36:96847d42f010 | 60 | |
The Other Jimmy |
36:96847d42f010 | 61 | POST_BINARY_WHITELIST = set([ |
The Other Jimmy |
36:96847d42f010 | 62 | "TEENSY3_1Code.binary_hook", |
The Other Jimmy |
36:96847d42f010 | 63 | "MCU_NRF51Code.binary_hook", |
The Other Jimmy |
36:96847d42f010 | 64 | "LPCTargetCode.lpc_patch", |
The Other Jimmy |
36:96847d42f010 | 65 | "LPC4088Code.binary_hook" |
The Other Jimmy |
36:96847d42f010 | 66 | ]) |
The Other Jimmy |
36:96847d42f010 | 67 | |
The Other Jimmy |
36:96847d42f010 | 68 | class GNUARMEclipse(Exporter): |
The Other Jimmy |
36:96847d42f010 | 69 | NAME = 'GNU ARM Eclipse' |
The Other Jimmy |
36:96847d42f010 | 70 | TOOLCHAIN = 'GCC_ARM' |
The Other Jimmy |
36:96847d42f010 | 71 | |
theotherjimmy |
40:7d3fa6b99b2b | 72 | @classmethod |
theotherjimmy |
40:7d3fa6b99b2b | 73 | def is_target_supported(cls, target_name): |
theotherjimmy |
40:7d3fa6b99b2b | 74 | target = TARGET_MAP[target_name] |
theotherjimmy |
40:7d3fa6b99b2b | 75 | return apply_supported_whitelist( |
theotherjimmy |
40:7d3fa6b99b2b | 76 | cls.TOOLCHAIN, POST_BINARY_WHITELIST, target) |
The Other Jimmy |
36:96847d42f010 | 77 | |
The Other Jimmy |
36:96847d42f010 | 78 | # override |
The Other Jimmy |
36:96847d42f010 | 79 | @property |
The Other Jimmy |
36:96847d42f010 | 80 | def flags(self): |
The Other Jimmy |
36:96847d42f010 | 81 | """Returns a dictionary of toolchain flags. |
The Other Jimmy |
36:96847d42f010 | 82 | Keys of the dictionary are: |
The Other Jimmy |
36:96847d42f010 | 83 | cxx_flags - c++ flags |
The Other Jimmy |
36:96847d42f010 | 84 | c_flags - c flags |
The Other Jimmy |
36:96847d42f010 | 85 | ld_flags - linker flags |
The Other Jimmy |
36:96847d42f010 | 86 | asm_flags - assembler flags |
The Other Jimmy |
36:96847d42f010 | 87 | common_flags - common options |
The Other Jimmy |
36:96847d42f010 | 88 | |
The Other Jimmy |
36:96847d42f010 | 89 | The difference from the parent function is that it does not |
The Other Jimmy |
36:96847d42f010 | 90 | add macro definitions, since they are passed separately. |
The Other Jimmy |
36:96847d42f010 | 91 | """ |
The Other Jimmy |
36:96847d42f010 | 92 | |
The Other Jimmy |
36:96847d42f010 | 93 | config_header = self.toolchain.get_config_header() |
The Other Jimmy |
36:96847d42f010 | 94 | flags = {key + "_flags": copy.deepcopy(value) for key, value |
The Other Jimmy |
36:96847d42f010 | 95 | in self.toolchain.flags.iteritems()} |
The Other Jimmy |
36:96847d42f010 | 96 | if config_header: |
The Other Jimmy |
36:96847d42f010 | 97 | config_header = relpath(config_header, |
The Other Jimmy |
36:96847d42f010 | 98 | self.resources.file_basepath[config_header]) |
The Other Jimmy |
36:96847d42f010 | 99 | flags['c_flags'] += self.toolchain.get_config_option(config_header) |
The Other Jimmy |
36:96847d42f010 | 100 | flags['cxx_flags'] += self.toolchain.get_config_option( |
The Other Jimmy |
36:96847d42f010 | 101 | config_header) |
The Other Jimmy |
36:96847d42f010 | 102 | return flags |
The Other Jimmy |
36:96847d42f010 | 103 | |
The Other Jimmy |
36:96847d42f010 | 104 | def toolchain_flags(self, toolchain): |
The Other Jimmy |
36:96847d42f010 | 105 | """Returns a dictionary of toolchain flags. |
The Other Jimmy |
36:96847d42f010 | 106 | Keys of the dictionary are: |
The Other Jimmy |
36:96847d42f010 | 107 | cxx_flags - c++ flags |
The Other Jimmy |
36:96847d42f010 | 108 | c_flags - c flags |
The Other Jimmy |
36:96847d42f010 | 109 | ld_flags - linker flags |
The Other Jimmy |
36:96847d42f010 | 110 | asm_flags - assembler flags |
The Other Jimmy |
36:96847d42f010 | 111 | common_flags - common options |
The Other Jimmy |
36:96847d42f010 | 112 | |
The Other Jimmy |
36:96847d42f010 | 113 | The difference from the above is that it takes a parameter. |
The Other Jimmy |
36:96847d42f010 | 114 | """ |
The Other Jimmy |
36:96847d42f010 | 115 | |
The Other Jimmy |
36:96847d42f010 | 116 | # Note: use the config options from the currently selected toolchain. |
The Other Jimmy |
36:96847d42f010 | 117 | config_header = self.toolchain.get_config_header() |
The Other Jimmy |
36:96847d42f010 | 118 | |
The Other Jimmy |
36:96847d42f010 | 119 | flags = {key + "_flags": copy.deepcopy(value) for key, value |
The Other Jimmy |
36:96847d42f010 | 120 | in toolchain.flags.iteritems()} |
The Other Jimmy |
36:96847d42f010 | 121 | if config_header: |
The Other Jimmy |
36:96847d42f010 | 122 | config_header = relpath(config_header, |
The Other Jimmy |
36:96847d42f010 | 123 | self.resources.file_basepath[config_header]) |
The Other Jimmy |
36:96847d42f010 | 124 | header_options = self.toolchain.get_config_option(config_header) |
The Other Jimmy |
36:96847d42f010 | 125 | flags['c_flags'] += header_options |
The Other Jimmy |
36:96847d42f010 | 126 | flags['cxx_flags'] += header_options |
The Other Jimmy |
36:96847d42f010 | 127 | return flags |
The Other Jimmy |
36:96847d42f010 | 128 | |
theotherjimmy |
41:2a77626a4c21 | 129 | def validate_resources(self): |
The Other Jimmy |
36:96847d42f010 | 130 | if not self.resources.linker_script: |
The Other Jimmy |
36:96847d42f010 | 131 | raise NotSupportedException("No linker script found.") |
The Other Jimmy |
36:96847d42f010 | 132 | |
theotherjimmy |
41:2a77626a4c21 | 133 | def create_jinja_ctx(self): |
theotherjimmy |
41:2a77626a4c21 | 134 | |
theotherjimmy |
41:2a77626a4c21 | 135 | self.validate_resources() |
The Other Jimmy |
36:96847d42f010 | 136 | |
The Other Jimmy |
36:96847d42f010 | 137 | self.resources.win_to_unix() |
The Other Jimmy |
36:96847d42f010 | 138 | |
The Other Jimmy |
36:96847d42f010 | 139 | # TODO: use some logger to display additional info if verbose |
The Other Jimmy |
36:96847d42f010 | 140 | |
The Other Jimmy |
36:96847d42f010 | 141 | libraries = [] |
The Other Jimmy |
36:96847d42f010 | 142 | # print 'libraries' |
The Other Jimmy |
36:96847d42f010 | 143 | # print self.resources.libraries |
The Other Jimmy |
36:96847d42f010 | 144 | for lib in self.resources.libraries: |
The Other Jimmy |
36:96847d42f010 | 145 | l, _ = splitext(basename(lib)) |
The Other Jimmy |
36:96847d42f010 | 146 | libraries.append(l[3:]) |
The Other Jimmy |
36:96847d42f010 | 147 | |
The Other Jimmy |
36:96847d42f010 | 148 | self.system_libraries = [ |
The Other Jimmy |
36:96847d42f010 | 149 | 'stdc++', 'supc++', 'm', 'c', 'gcc', 'nosys' |
The Other Jimmy |
36:96847d42f010 | 150 | ] |
The Other Jimmy |
36:96847d42f010 | 151 | |
The Other Jimmy |
36:96847d42f010 | 152 | # Read in all profiles, we'll extract compiler options. |
The Other Jimmy |
36:96847d42f010 | 153 | profiles = self.get_all_profiles() |
The Other Jimmy |
36:96847d42f010 | 154 | |
The Other Jimmy |
36:96847d42f010 | 155 | profile_ids = [s.lower() for s in profiles] |
The Other Jimmy |
36:96847d42f010 | 156 | profile_ids.sort() |
The Other Jimmy |
36:96847d42f010 | 157 | |
The Other Jimmy |
36:96847d42f010 | 158 | # TODO: get the list from existing .cproject |
The Other Jimmy |
36:96847d42f010 | 159 | build_folders = [s.capitalize() for s in profile_ids] |
The Other Jimmy |
36:96847d42f010 | 160 | build_folders.append('BUILD') |
The Other Jimmy |
36:96847d42f010 | 161 | # print build_folders |
The Other Jimmy |
36:96847d42f010 | 162 | |
The Other Jimmy |
36:96847d42f010 | 163 | objects = [self.filter_dot(s) for s in self.resources.objects] |
The Other Jimmy |
36:96847d42f010 | 164 | for bf in build_folders: |
The Other Jimmy |
36:96847d42f010 | 165 | objects = [o for o in objects if not o.startswith(bf + '/')] |
The Other Jimmy |
36:96847d42f010 | 166 | # print 'objects' |
The Other Jimmy |
36:96847d42f010 | 167 | # print objects |
The Other Jimmy |
36:96847d42f010 | 168 | |
The Other Jimmy |
36:96847d42f010 | 169 | self.compute_exclusions() |
The Other Jimmy |
36:96847d42f010 | 170 | |
The Other Jimmy |
36:96847d42f010 | 171 | self.include_path = [ |
The Other Jimmy |
36:96847d42f010 | 172 | self.filter_dot(s) for s in self.resources.inc_dirs] |
The Other Jimmy |
36:96847d42f010 | 173 | print 'Include folders: {0}'.format(len(self.include_path)) |
The Other Jimmy |
36:96847d42f010 | 174 | |
The Other Jimmy |
36:96847d42f010 | 175 | self.as_defines = self.toolchain.get_symbols(True) |
The Other Jimmy |
36:96847d42f010 | 176 | self.c_defines = self.toolchain.get_symbols() |
The Other Jimmy |
36:96847d42f010 | 177 | self.cpp_defines = self.c_defines |
The Other Jimmy |
36:96847d42f010 | 178 | print 'Symbols: {0}'.format(len(self.c_defines)) |
The Other Jimmy |
36:96847d42f010 | 179 | |
The Other Jimmy |
36:96847d42f010 | 180 | self.ld_script = self.filter_dot( |
The Other Jimmy |
36:96847d42f010 | 181 | self.resources.linker_script) |
The Other Jimmy |
36:96847d42f010 | 182 | print 'Linker script: {0}'.format(self.ld_script) |
The Other Jimmy |
36:96847d42f010 | 183 | |
The Other Jimmy |
36:96847d42f010 | 184 | self.options = {} |
The Other Jimmy |
36:96847d42f010 | 185 | for id in profile_ids: |
The Other Jimmy |
36:96847d42f010 | 186 | |
The Other Jimmy |
36:96847d42f010 | 187 | # There are 4 categories of options, a category common too |
The Other Jimmy |
36:96847d42f010 | 188 | # all tools and a specific category for each of the tools. |
The Other Jimmy |
36:96847d42f010 | 189 | opts = {} |
The Other Jimmy |
36:96847d42f010 | 190 | opts['common'] = {} |
The Other Jimmy |
36:96847d42f010 | 191 | opts['as'] = {} |
The Other Jimmy |
36:96847d42f010 | 192 | opts['c'] = {} |
The Other Jimmy |
36:96847d42f010 | 193 | opts['cpp'] = {} |
The Other Jimmy |
36:96847d42f010 | 194 | opts['ld'] = {} |
The Other Jimmy |
36:96847d42f010 | 195 | |
The Other Jimmy |
36:96847d42f010 | 196 | opts['id'] = id |
The Other Jimmy |
36:96847d42f010 | 197 | opts['name'] = opts['id'].capitalize() |
The Other Jimmy |
36:96847d42f010 | 198 | |
The Other Jimmy |
36:96847d42f010 | 199 | |
The Other Jimmy |
36:96847d42f010 | 200 | print 'Build configuration: {0}'.format(opts['name']) |
The Other Jimmy |
36:96847d42f010 | 201 | |
The Other Jimmy |
36:96847d42f010 | 202 | profile = profiles[id] |
The Other Jimmy |
36:96847d42f010 | 203 | |
The Other Jimmy |
36:96847d42f010 | 204 | # A small hack, do not bother with src_path again, |
The Other Jimmy |
36:96847d42f010 | 205 | # pass an empty string to avoid crashing. |
The Other Jimmy |
36:96847d42f010 | 206 | src_paths = [''] |
The Other Jimmy |
36:96847d42f010 | 207 | target_name = self.toolchain.target.name |
The Other Jimmy |
36:96847d42f010 | 208 | toolchain = prepare_toolchain( |
The Other Jimmy |
36:96847d42f010 | 209 | src_paths, "", target_name, self.TOOLCHAIN, build_profile=[profile]) |
The Other Jimmy |
36:96847d42f010 | 210 | |
The Other Jimmy |
36:96847d42f010 | 211 | # Hack to fill in build_dir |
The Other Jimmy |
36:96847d42f010 | 212 | toolchain.build_dir = self.toolchain.build_dir |
The Other Jimmy |
36:96847d42f010 | 213 | |
The Other Jimmy |
36:96847d42f010 | 214 | flags = self.toolchain_flags(toolchain) |
The Other Jimmy |
36:96847d42f010 | 215 | |
The Other Jimmy |
36:96847d42f010 | 216 | print 'Common flags:', ' '.join(flags['common_flags']) |
The Other Jimmy |
36:96847d42f010 | 217 | print 'C++ flags:', ' '.join(flags['cxx_flags']) |
The Other Jimmy |
36:96847d42f010 | 218 | print 'C flags:', ' '.join(flags['c_flags']) |
The Other Jimmy |
36:96847d42f010 | 219 | print 'ASM flags:', ' '.join(flags['asm_flags']) |
The Other Jimmy |
36:96847d42f010 | 220 | print 'Linker flags:', ' '.join(flags['ld_flags']) |
The Other Jimmy |
36:96847d42f010 | 221 | |
The Other Jimmy |
36:96847d42f010 | 222 | # Most GNU ARM Eclipse options have a parent, |
The Other Jimmy |
36:96847d42f010 | 223 | # either debug or release. |
The Other Jimmy |
36:96847d42f010 | 224 | if '-O0' in flags['common_flags'] or '-Og' in flags['common_flags']: |
The Other Jimmy |
36:96847d42f010 | 225 | opts['parent_id'] = 'debug' |
The Other Jimmy |
36:96847d42f010 | 226 | else: |
The Other Jimmy |
36:96847d42f010 | 227 | opts['parent_id'] = 'release' |
The Other Jimmy |
36:96847d42f010 | 228 | |
The Other Jimmy |
36:96847d42f010 | 229 | self.process_options(opts, flags) |
The Other Jimmy |
36:96847d42f010 | 230 | |
The Other Jimmy |
36:96847d42f010 | 231 | opts['as']['defines'] = self.as_defines |
The Other Jimmy |
36:96847d42f010 | 232 | opts['c']['defines'] = self.c_defines |
The Other Jimmy |
36:96847d42f010 | 233 | opts['cpp']['defines'] = self.cpp_defines |
The Other Jimmy |
36:96847d42f010 | 234 | |
The Other Jimmy |
36:96847d42f010 | 235 | opts['common']['include_paths'] = self.include_path |
The Other Jimmy |
36:96847d42f010 | 236 | opts['common']['excluded_folders'] = '|'.join( |
The Other Jimmy |
36:96847d42f010 | 237 | self.excluded_folders) |
The Other Jimmy |
36:96847d42f010 | 238 | |
The Other Jimmy |
36:96847d42f010 | 239 | opts['ld']['library_paths'] = [ |
The Other Jimmy |
36:96847d42f010 | 240 | self.filter_dot(s) for s in self.resources.lib_dirs] |
The Other Jimmy |
36:96847d42f010 | 241 | |
The Other Jimmy |
36:96847d42f010 | 242 | opts['ld']['object_files'] = objects |
The Other Jimmy |
36:96847d42f010 | 243 | opts['ld']['user_libraries'] = libraries |
The Other Jimmy |
36:96847d42f010 | 244 | opts['ld']['system_libraries'] = self.system_libraries |
The Other Jimmy |
36:96847d42f010 | 245 | opts['ld']['script'] = join(id.capitalize(), |
The Other Jimmy |
36:96847d42f010 | 246 | "linker-script-%s.ld" % id) |
theotherjimmy |
41:2a77626a4c21 | 247 | opts['cpp_cmd'] = '"{}"'.format(toolchain.preproc[0]) + " " + " ".join(toolchain.preproc[1:]) |
The Other Jimmy |
36:96847d42f010 | 248 | |
The Other Jimmy |
36:96847d42f010 | 249 | # Unique IDs used in multiple places. |
The Other Jimmy |
36:96847d42f010 | 250 | # Those used only once are implemented with {{u.id}}. |
The Other Jimmy |
36:96847d42f010 | 251 | uid = {} |
The Other Jimmy |
36:96847d42f010 | 252 | uid['config'] = u.id |
The Other Jimmy |
36:96847d42f010 | 253 | uid['tool_c_compiler'] = u.id |
The Other Jimmy |
36:96847d42f010 | 254 | uid['tool_c_compiler_input'] = u.id |
The Other Jimmy |
36:96847d42f010 | 255 | uid['tool_cpp_compiler'] = u.id |
The Other Jimmy |
36:96847d42f010 | 256 | uid['tool_cpp_compiler_input'] = u.id |
The Other Jimmy |
36:96847d42f010 | 257 | |
The Other Jimmy |
36:96847d42f010 | 258 | opts['uid'] = uid |
The Other Jimmy |
36:96847d42f010 | 259 | |
The Other Jimmy |
36:96847d42f010 | 260 | self.options[id] = opts |
The Other Jimmy |
36:96847d42f010 | 261 | |
The Other Jimmy |
36:96847d42f010 | 262 | jinja_ctx = { |
The Other Jimmy |
36:96847d42f010 | 263 | 'name': self.project_name, |
The Other Jimmy |
36:96847d42f010 | 264 | 'ld_script': self.ld_script, |
The Other Jimmy |
36:96847d42f010 | 265 | |
The Other Jimmy |
36:96847d42f010 | 266 | # Compiler & linker command line options |
The Other Jimmy |
36:96847d42f010 | 267 | 'options': self.options, |
The Other Jimmy |
36:96847d42f010 | 268 | |
The Other Jimmy |
36:96847d42f010 | 269 | # Must be an object with an `id` property, which |
The Other Jimmy |
36:96847d42f010 | 270 | # will be called repeatedly, to generate multiple UIDs. |
The Other Jimmy |
36:96847d42f010 | 271 | 'u': u, |
The Other Jimmy |
36:96847d42f010 | 272 | } |
theotherjimmy |
41:2a77626a4c21 | 273 | return jinja_ctx |
theotherjimmy |
41:2a77626a4c21 | 274 | |
theotherjimmy |
41:2a77626a4c21 | 275 | # override |
theotherjimmy |
41:2a77626a4c21 | 276 | def generate(self): |
theotherjimmy |
41:2a77626a4c21 | 277 | """ |
theotherjimmy |
41:2a77626a4c21 | 278 | Generate the .project and .cproject files. |
theotherjimmy |
41:2a77626a4c21 | 279 | """ |
theotherjimmy |
41:2a77626a4c21 | 280 | jinja_ctx = self.create_jinja_ctx() |
theotherjimmy |
41:2a77626a4c21 | 281 | |
theotherjimmy |
41:2a77626a4c21 | 282 | |
theotherjimmy |
41:2a77626a4c21 | 283 | print 'Create a GNU ARM Eclipse C++ managed project' |
theotherjimmy |
41:2a77626a4c21 | 284 | print 'Project name: {0}'.format(self.project_name) |
theotherjimmy |
41:2a77626a4c21 | 285 | print 'Target: {0}'.format(self.toolchain.target.name) |
theotherjimmy |
41:2a77626a4c21 | 286 | print 'Toolchain: {0}'.format(self.TOOLCHAIN) |
The Other Jimmy |
36:96847d42f010 | 287 | |
The Other Jimmy |
36:96847d42f010 | 288 | self.gen_file('gnuarmeclipse/.project.tmpl', jinja_ctx, |
The Other Jimmy |
36:96847d42f010 | 289 | '.project', trim_blocks=True, lstrip_blocks=True) |
The Other Jimmy |
36:96847d42f010 | 290 | self.gen_file('gnuarmeclipse/.cproject.tmpl', jinja_ctx, |
The Other Jimmy |
36:96847d42f010 | 291 | '.cproject', trim_blocks=True, lstrip_blocks=True) |
The Other Jimmy |
36:96847d42f010 | 292 | self.gen_file('gnuarmeclipse/makefile.targets.tmpl', jinja_ctx, |
The Other Jimmy |
36:96847d42f010 | 293 | 'makefile.targets', trim_blocks=True, lstrip_blocks=True) |
The Other Jimmy |
36:96847d42f010 | 294 | self.gen_file('gnuarmeclipse/mbedignore.tmpl', jinja_ctx, '.mbedignore') |
The Other Jimmy |
36:96847d42f010 | 295 | |
The Other Jimmy |
36:96847d42f010 | 296 | |
The Other Jimmy |
36:96847d42f010 | 297 | print 'Done. Import the \'{0}\' project in Eclipse.'.format(self.project_name) |
The Other Jimmy |
36:96847d42f010 | 298 | |
The Other Jimmy |
36:96847d42f010 | 299 | # override |
The Other Jimmy |
36:96847d42f010 | 300 | @staticmethod |
The Other Jimmy |
36:96847d42f010 | 301 | def build(project_name, log_name="build_log.txt", cleanup=True): |
The Other Jimmy |
36:96847d42f010 | 302 | """ |
The Other Jimmy |
36:96847d42f010 | 303 | Headless build an Eclipse project. |
The Other Jimmy |
36:96847d42f010 | 304 | |
The Other Jimmy |
36:96847d42f010 | 305 | The following steps are performed: |
The Other Jimmy |
36:96847d42f010 | 306 | - a temporary workspace is created, |
The Other Jimmy |
36:96847d42f010 | 307 | - the project is imported, |
The Other Jimmy |
36:96847d42f010 | 308 | - a clean build of all configurations is performed and |
The Other Jimmy |
36:96847d42f010 | 309 | - the temporary workspace is removed. |
The Other Jimmy |
36:96847d42f010 | 310 | |
The Other Jimmy |
36:96847d42f010 | 311 | The build results are in the Debug & Release folders. |
The Other Jimmy |
36:96847d42f010 | 312 | |
The Other Jimmy |
36:96847d42f010 | 313 | All executables (eclipse & toolchain) must be in the PATH. |
The Other Jimmy |
36:96847d42f010 | 314 | |
The Other Jimmy |
36:96847d42f010 | 315 | The general method to start a headless Eclipse build is: |
The Other Jimmy |
36:96847d42f010 | 316 | |
The Other Jimmy |
36:96847d42f010 | 317 | $ eclipse \ |
The Other Jimmy |
36:96847d42f010 | 318 | --launcher.suppressErrors \ |
The Other Jimmy |
36:96847d42f010 | 319 | -nosplash \ |
The Other Jimmy |
36:96847d42f010 | 320 | -application org.eclipse.cdt.managedbuilder.core.headlessbuild \ |
The Other Jimmy |
36:96847d42f010 | 321 | -data /path/to/workspace \ |
The Other Jimmy |
36:96847d42f010 | 322 | -import /path/to/project \ |
The Other Jimmy |
36:96847d42f010 | 323 | -cleanBuild "project[/configuration] | all" |
The Other Jimmy |
36:96847d42f010 | 324 | """ |
The Other Jimmy |
36:96847d42f010 | 325 | |
The Other Jimmy |
36:96847d42f010 | 326 | # TODO: possibly use the log file. |
The Other Jimmy |
36:96847d42f010 | 327 | |
The Other Jimmy |
36:96847d42f010 | 328 | # Create a temporary folder for the workspace. |
The Other Jimmy |
36:96847d42f010 | 329 | tmp_folder = tempfile.mkdtemp() |
The Other Jimmy |
36:96847d42f010 | 330 | |
The Other Jimmy |
36:96847d42f010 | 331 | cmd = [ |
The Other Jimmy |
36:96847d42f010 | 332 | 'eclipse', |
The Other Jimmy |
36:96847d42f010 | 333 | '--launcher.suppressErrors', |
The Other Jimmy |
36:96847d42f010 | 334 | '-nosplash', |
The Other Jimmy |
36:96847d42f010 | 335 | '-application org.eclipse.cdt.managedbuilder.core.headlessbuild', |
The Other Jimmy |
36:96847d42f010 | 336 | '-data', tmp_folder, |
The Other Jimmy |
36:96847d42f010 | 337 | '-import', os.getcwd(), |
The Other Jimmy |
36:96847d42f010 | 338 | '-cleanBuild', project_name |
The Other Jimmy |
36:96847d42f010 | 339 | ] |
The Other Jimmy |
36:96847d42f010 | 340 | |
The Other Jimmy |
36:96847d42f010 | 341 | p = Popen(' '.join(cmd), shell=True, stdout=PIPE, stderr=PIPE) |
The Other Jimmy |
36:96847d42f010 | 342 | out, err = p.communicate() |
The Other Jimmy |
36:96847d42f010 | 343 | ret_code = p.returncode |
The Other Jimmy |
36:96847d42f010 | 344 | stdout_string = "=" * 10 + "STDOUT" + "=" * 10 + "\n" |
The Other Jimmy |
36:96847d42f010 | 345 | err_string = "=" * 10 + "STDERR" + "=" * 10 + "\n" |
The Other Jimmy |
36:96847d42f010 | 346 | err_string += err |
The Other Jimmy |
36:96847d42f010 | 347 | |
The Other Jimmy |
36:96847d42f010 | 348 | ret_string = "SUCCESS\n" |
The Other Jimmy |
36:96847d42f010 | 349 | if ret_code != 0: |
The Other Jimmy |
36:96847d42f010 | 350 | ret_string += "FAILURE\n" |
The Other Jimmy |
36:96847d42f010 | 351 | |
The Other Jimmy |
36:96847d42f010 | 352 | print "%s\n%s\n%s\n%s" % (stdout_string, out, err_string, ret_string) |
The Other Jimmy |
36:96847d42f010 | 353 | |
The Other Jimmy |
36:96847d42f010 | 354 | if log_name: |
The Other Jimmy |
36:96847d42f010 | 355 | # Write the output to the log file |
The Other Jimmy |
36:96847d42f010 | 356 | with open(log_name, 'w+') as f: |
The Other Jimmy |
36:96847d42f010 | 357 | f.write(stdout_string) |
The Other Jimmy |
36:96847d42f010 | 358 | f.write(out) |
The Other Jimmy |
36:96847d42f010 | 359 | f.write(err_string) |
The Other Jimmy |
36:96847d42f010 | 360 | f.write(ret_string) |
The Other Jimmy |
36:96847d42f010 | 361 | |
The Other Jimmy |
36:96847d42f010 | 362 | # Cleanup the exported and built files |
The Other Jimmy |
36:96847d42f010 | 363 | if cleanup: |
The Other Jimmy |
36:96847d42f010 | 364 | if exists(log_name): |
The Other Jimmy |
36:96847d42f010 | 365 | os.remove(log_name) |
The Other Jimmy |
36:96847d42f010 | 366 | os.remove('.project') |
The Other Jimmy |
36:96847d42f010 | 367 | os.remove('.cproject') |
The Other Jimmy |
36:96847d42f010 | 368 | if exists('Debug'): |
The Other Jimmy |
36:96847d42f010 | 369 | shutil.rmtree('Debug') |
The Other Jimmy |
36:96847d42f010 | 370 | if exists('Release'): |
The Other Jimmy |
36:96847d42f010 | 371 | shutil.rmtree('Release') |
The Other Jimmy |
36:96847d42f010 | 372 | if exists('makefile.targets'): |
The Other Jimmy |
36:96847d42f010 | 373 | os.remove('makefile.targets') |
The Other Jimmy |
36:96847d42f010 | 374 | |
The Other Jimmy |
36:96847d42f010 | 375 | # Always remove the temporary folder. |
The Other Jimmy |
36:96847d42f010 | 376 | if exists(tmp_folder): |
The Other Jimmy |
36:96847d42f010 | 377 | shutil.rmtree(tmp_folder) |
The Other Jimmy |
36:96847d42f010 | 378 | |
The Other Jimmy |
36:96847d42f010 | 379 | if ret_code == 0: |
The Other Jimmy |
36:96847d42f010 | 380 | # Return Success |
The Other Jimmy |
36:96847d42f010 | 381 | return 0 |
The Other Jimmy |
36:96847d42f010 | 382 | |
The Other Jimmy |
36:96847d42f010 | 383 | # Seems like something went wrong. |
The Other Jimmy |
36:96847d42f010 | 384 | return -1 |
The Other Jimmy |
36:96847d42f010 | 385 | |
The Other Jimmy |
36:96847d42f010 | 386 | # ------------------------------------------------------------------------- |
The Other Jimmy |
36:96847d42f010 | 387 | |
The Other Jimmy |
36:96847d42f010 | 388 | @staticmethod |
The Other Jimmy |
36:96847d42f010 | 389 | def get_all_profiles(): |
The Other Jimmy |
36:96847d42f010 | 390 | tools_path = dirname(dirname(dirname(__file__))) |
The Other Jimmy |
36:96847d42f010 | 391 | file_names = [join(tools_path, "profiles", fn) for fn in os.listdir( |
The Other Jimmy |
36:96847d42f010 | 392 | join(tools_path, "profiles")) if fn.endswith(".json")] |
The Other Jimmy |
36:96847d42f010 | 393 | |
The Other Jimmy |
36:96847d42f010 | 394 | # print file_names |
The Other Jimmy |
36:96847d42f010 | 395 | |
The Other Jimmy |
36:96847d42f010 | 396 | profile_names = [basename(fn).replace(".json", "") |
The Other Jimmy |
36:96847d42f010 | 397 | for fn in file_names] |
The Other Jimmy |
36:96847d42f010 | 398 | # print profile_names |
The Other Jimmy |
36:96847d42f010 | 399 | |
The Other Jimmy |
36:96847d42f010 | 400 | profiles = {} |
The Other Jimmy |
36:96847d42f010 | 401 | |
The Other Jimmy |
36:96847d42f010 | 402 | for fn in file_names: |
The Other Jimmy |
36:96847d42f010 | 403 | content = load(open(fn)) |
The Other Jimmy |
36:96847d42f010 | 404 | profile_name = basename(fn).replace(".json", "") |
The Other Jimmy |
36:96847d42f010 | 405 | profiles[profile_name] = content |
The Other Jimmy |
36:96847d42f010 | 406 | |
The Other Jimmy |
36:96847d42f010 | 407 | return profiles |
The Other Jimmy |
36:96847d42f010 | 408 | |
The Other Jimmy |
36:96847d42f010 | 409 | # ------------------------------------------------------------------------- |
The Other Jimmy |
36:96847d42f010 | 410 | # Process source files/folders exclusions. |
The Other Jimmy |
36:96847d42f010 | 411 | |
The Other Jimmy |
36:96847d42f010 | 412 | def compute_exclusions(self): |
The Other Jimmy |
36:96847d42f010 | 413 | """ |
The Other Jimmy |
36:96847d42f010 | 414 | With the project root as the only source folder known to CDT, |
The Other Jimmy |
36:96847d42f010 | 415 | based on the list of source files, compute the folders to not |
The Other Jimmy |
36:96847d42f010 | 416 | be included in the build. |
The Other Jimmy |
36:96847d42f010 | 417 | |
The Other Jimmy |
36:96847d42f010 | 418 | The steps are: |
The Other Jimmy |
36:96847d42f010 | 419 | - get the list of source folders, as dirname(source_file) |
The Other Jimmy |
36:96847d42f010 | 420 | - compute the top folders (subfolders of the project folder) |
The Other Jimmy |
36:96847d42f010 | 421 | - iterate all subfolders and add them to a tree, with all |
The Other Jimmy |
36:96847d42f010 | 422 | nodes markes as 'not used' |
The Other Jimmy |
36:96847d42f010 | 423 | - iterate the source folders and mark them as 'used' in the |
The Other Jimmy |
36:96847d42f010 | 424 | tree, including all intermediate nodes |
The Other Jimmy |
36:96847d42f010 | 425 | - recurse the tree and collect all unused folders; descend |
The Other Jimmy |
36:96847d42f010 | 426 | the hierarchy only for used nodes |
The Other Jimmy |
36:96847d42f010 | 427 | """ |
The Other Jimmy |
36:96847d42f010 | 428 | source_folders = [self.filter_dot(s) for s in set(dirname( |
The Other Jimmy |
36:96847d42f010 | 429 | src) for src in self.resources.c_sources + self.resources.cpp_sources + self.resources.s_sources)] |
The Other Jimmy |
36:96847d42f010 | 430 | |
theotherjimmy |
40:7d3fa6b99b2b | 431 | self.excluded_folders = set(self.resources.ignored_dirs) - set(self.resources.inc_dirs) |
The Other Jimmy |
36:96847d42f010 | 432 | print 'Source folders: {0}, with {1} exclusions'.format(len(source_folders), len(self.excluded_folders)) |
The Other Jimmy |
36:96847d42f010 | 433 | |
The Other Jimmy |
36:96847d42f010 | 434 | |
The Other Jimmy |
36:96847d42f010 | 435 | # ------------------------------------------------------------------------- |
The Other Jimmy |
36:96847d42f010 | 436 | |
The Other Jimmy |
36:96847d42f010 | 437 | @staticmethod |
The Other Jimmy |
36:96847d42f010 | 438 | def filter_dot(str): |
The Other Jimmy |
36:96847d42f010 | 439 | """ |
The Other Jimmy |
36:96847d42f010 | 440 | Remove the './' prefix, if present. |
The Other Jimmy |
36:96847d42f010 | 441 | This function assumes that resources.win_to_unix() |
The Other Jimmy |
36:96847d42f010 | 442 | replaced all windows backslashes with slashes. |
The Other Jimmy |
36:96847d42f010 | 443 | """ |
The Other Jimmy |
36:96847d42f010 | 444 | if str == None: |
The Other Jimmy |
36:96847d42f010 | 445 | return None |
The Other Jimmy |
36:96847d42f010 | 446 | if str[:2] == './': |
The Other Jimmy |
36:96847d42f010 | 447 | return str[2:] |
The Other Jimmy |
36:96847d42f010 | 448 | return str |
The Other Jimmy |
36:96847d42f010 | 449 | |
The Other Jimmy |
36:96847d42f010 | 450 | # ------------------------------------------------------------------------- |
The Other Jimmy |
36:96847d42f010 | 451 | |
The Other Jimmy |
36:96847d42f010 | 452 | def dump_tree(self, nodes, depth=0): |
The Other Jimmy |
36:96847d42f010 | 453 | for k in nodes.keys(): |
The Other Jimmy |
36:96847d42f010 | 454 | node = nodes[k] |
The Other Jimmy |
36:96847d42f010 | 455 | parent_name = node['parent'][ |
The Other Jimmy |
36:96847d42f010 | 456 | 'name'] if 'parent' in node.keys() else '' |
The Other Jimmy |
36:96847d42f010 | 457 | print ' ' * depth, node['name'], node['is_used'], parent_name |
The Other Jimmy |
36:96847d42f010 | 458 | if len(node['children'].keys()) != 0: |
The Other Jimmy |
36:96847d42f010 | 459 | self.dump_tree(node['children'], depth + 1) |
The Other Jimmy |
36:96847d42f010 | 460 | |
The Other Jimmy |
36:96847d42f010 | 461 | def dump_paths(self, nodes, depth=0): |
The Other Jimmy |
36:96847d42f010 | 462 | for k in nodes.keys(): |
The Other Jimmy |
36:96847d42f010 | 463 | node = nodes[k] |
The Other Jimmy |
36:96847d42f010 | 464 | parts = [] |
The Other Jimmy |
36:96847d42f010 | 465 | while True: |
The Other Jimmy |
36:96847d42f010 | 466 | parts.insert(0, node['name']) |
The Other Jimmy |
36:96847d42f010 | 467 | if 'parent' not in node: |
The Other Jimmy |
36:96847d42f010 | 468 | break |
The Other Jimmy |
36:96847d42f010 | 469 | node = node['parent'] |
The Other Jimmy |
36:96847d42f010 | 470 | path = '/'.join(parts) |
The Other Jimmy |
36:96847d42f010 | 471 | print path, nodes[k]['is_used'] |
The Other Jimmy |
36:96847d42f010 | 472 | self.dump_paths(nodes[k]['children'], depth + 1) |
The Other Jimmy |
36:96847d42f010 | 473 | |
The Other Jimmy |
36:96847d42f010 | 474 | # ------------------------------------------------------------------------- |
The Other Jimmy |
36:96847d42f010 | 475 | |
The Other Jimmy |
36:96847d42f010 | 476 | def process_options(self, opts, flags_in): |
The Other Jimmy |
36:96847d42f010 | 477 | """ |
The Other Jimmy |
36:96847d42f010 | 478 | CDT managed projects store lots of build options in separate |
The Other Jimmy |
36:96847d42f010 | 479 | variables, with separate IDs in the .cproject file. |
The Other Jimmy |
36:96847d42f010 | 480 | When the CDT build is started, all these options are brought |
The Other Jimmy |
36:96847d42f010 | 481 | together to compose the compiler and linker command lines. |
The Other Jimmy |
36:96847d42f010 | 482 | |
The Other Jimmy |
36:96847d42f010 | 483 | Here the process is reversed, from the compiler and linker |
The Other Jimmy |
36:96847d42f010 | 484 | command lines, the options are identified and various flags are |
The Other Jimmy |
36:96847d42f010 | 485 | set to control the template generation process. |
The Other Jimmy |
36:96847d42f010 | 486 | |
The Other Jimmy |
36:96847d42f010 | 487 | Once identified, the options are removed from the command lines. |
The Other Jimmy |
36:96847d42f010 | 488 | |
The Other Jimmy |
36:96847d42f010 | 489 | The options that were not identified are options that do not |
The Other Jimmy |
36:96847d42f010 | 490 | have CDT equivalents and will be passed in the 'Other options' |
The Other Jimmy |
36:96847d42f010 | 491 | categories. |
The Other Jimmy |
36:96847d42f010 | 492 | |
The Other Jimmy |
36:96847d42f010 | 493 | Although this process does not have a very complicated logic, |
The Other Jimmy |
36:96847d42f010 | 494 | given the large number of explicit configuration options |
The Other Jimmy |
36:96847d42f010 | 495 | used by the GNU ARM Eclipse managed build plug-in, it is tedious... |
The Other Jimmy |
36:96847d42f010 | 496 | """ |
The Other Jimmy |
36:96847d42f010 | 497 | |
The Other Jimmy |
36:96847d42f010 | 498 | # Make a copy of the flags, to be one by one removed after processing. |
The Other Jimmy |
36:96847d42f010 | 499 | flags = copy.deepcopy(flags_in) |
The Other Jimmy |
36:96847d42f010 | 500 | |
The Other Jimmy |
36:96847d42f010 | 501 | if False: |
The Other Jimmy |
36:96847d42f010 | 502 | |
The Other Jimmy |
36:96847d42f010 | 503 | print 'common_flags', flags['common_flags'] |
The Other Jimmy |
36:96847d42f010 | 504 | print 'asm_flags', flags['asm_flags'] |
The Other Jimmy |
36:96847d42f010 | 505 | print 'c_flags', flags['c_flags'] |
The Other Jimmy |
36:96847d42f010 | 506 | print 'cxx_flags', flags['cxx_flags'] |
The Other Jimmy |
36:96847d42f010 | 507 | print 'ld_flags', flags['ld_flags'] |
The Other Jimmy |
36:96847d42f010 | 508 | |
The Other Jimmy |
36:96847d42f010 | 509 | # Initialise the 'last resort' options where all unrecognised |
The Other Jimmy |
36:96847d42f010 | 510 | # options will be collected. |
The Other Jimmy |
36:96847d42f010 | 511 | opts['as']['other'] = '' |
The Other Jimmy |
36:96847d42f010 | 512 | opts['c']['other'] = '' |
The Other Jimmy |
36:96847d42f010 | 513 | opts['cpp']['other'] = '' |
The Other Jimmy |
36:96847d42f010 | 514 | opts['ld']['other'] = '' |
The Other Jimmy |
36:96847d42f010 | 515 | |
The Other Jimmy |
36:96847d42f010 | 516 | MCPUS = { |
The Other Jimmy |
36:96847d42f010 | 517 | 'Cortex-M0': {'mcpu': 'cortex-m0', 'fpu_unit': None}, |
The Other Jimmy |
36:96847d42f010 | 518 | 'Cortex-M0+': {'mcpu': 'cortex-m0plus', 'fpu_unit': None}, |
The Other Jimmy |
36:96847d42f010 | 519 | 'Cortex-M1': {'mcpu': 'cortex-m1', 'fpu_unit': None}, |
The Other Jimmy |
36:96847d42f010 | 520 | 'Cortex-M3': {'mcpu': 'cortex-m3', 'fpu_unit': None}, |
The Other Jimmy |
36:96847d42f010 | 521 | 'Cortex-M4': {'mcpu': 'cortex-m4', 'fpu_unit': None}, |
The Other Jimmy |
36:96847d42f010 | 522 | 'Cortex-M4F': {'mcpu': 'cortex-m4', 'fpu_unit': 'fpv4spd16'}, |
The Other Jimmy |
36:96847d42f010 | 523 | 'Cortex-M7': {'mcpu': 'cortex-m7', 'fpu_unit': None}, |
The Other Jimmy |
36:96847d42f010 | 524 | 'Cortex-M7F': {'mcpu': 'cortex-m7', 'fpu_unit': 'fpv4spd16'}, |
The Other Jimmy |
36:96847d42f010 | 525 | 'Cortex-M7FD': {'mcpu': 'cortex-m7', 'fpu_unit': 'fpv5d16'}, |
The Other Jimmy |
36:96847d42f010 | 526 | 'Cortex-A9': {'mcpu': 'cortex-a9', 'fpu_unit': 'vfpv3'} |
The Other Jimmy |
36:96847d42f010 | 527 | } |
The Other Jimmy |
36:96847d42f010 | 528 | |
The Other Jimmy |
36:96847d42f010 | 529 | # Remove options that are supplied by CDT |
The Other Jimmy |
36:96847d42f010 | 530 | self.remove_option(flags['common_flags'], '-c') |
The Other Jimmy |
36:96847d42f010 | 531 | self.remove_option(flags['common_flags'], '-MMD') |
The Other Jimmy |
36:96847d42f010 | 532 | |
The Other Jimmy |
36:96847d42f010 | 533 | # As 'plan B', get the CPU from the target definition. |
The Other Jimmy |
36:96847d42f010 | 534 | core = self.toolchain.target.core |
The Other Jimmy |
36:96847d42f010 | 535 | |
The Other Jimmy |
36:96847d42f010 | 536 | opts['common']['arm.target.family'] = None |
The Other Jimmy |
36:96847d42f010 | 537 | |
The Other Jimmy |
36:96847d42f010 | 538 | # cortex-m0, cortex-m0-small-multiply, cortex-m0plus, |
The Other Jimmy |
36:96847d42f010 | 539 | # cortex-m0plus-small-multiply, cortex-m1, cortex-m1-small-multiply, |
The Other Jimmy |
36:96847d42f010 | 540 | # cortex-m3, cortex-m4, cortex-m7. |
The Other Jimmy |
36:96847d42f010 | 541 | str = self.find_options(flags['common_flags'], '-mcpu=') |
The Other Jimmy |
36:96847d42f010 | 542 | if str != None: |
The Other Jimmy |
36:96847d42f010 | 543 | opts['common']['arm.target.family'] = str[len('-mcpu='):] |
The Other Jimmy |
36:96847d42f010 | 544 | self.remove_option(flags['common_flags'], str) |
The Other Jimmy |
36:96847d42f010 | 545 | self.remove_option(flags['ld_flags'], str) |
The Other Jimmy |
36:96847d42f010 | 546 | else: |
The Other Jimmy |
36:96847d42f010 | 547 | if core not in MCPUS: |
The Other Jimmy |
36:96847d42f010 | 548 | raise NotSupportedException( |
The Other Jimmy |
36:96847d42f010 | 549 | 'Target core {0} not supported.'.format(core)) |
The Other Jimmy |
36:96847d42f010 | 550 | opts['common']['arm.target.family'] = MCPUS[core]['mcpu'] |
The Other Jimmy |
36:96847d42f010 | 551 | |
The Other Jimmy |
36:96847d42f010 | 552 | opts['common']['arm.target.arch'] = 'none' |
The Other Jimmy |
36:96847d42f010 | 553 | str = self.find_options(flags['common_flags'], '-march=') |
The Other Jimmy |
36:96847d42f010 | 554 | arch = str[len('-march='):] |
The Other Jimmy |
36:96847d42f010 | 555 | archs = {'armv6-m': 'armv6-m', 'armv7-m': 'armv7-m', 'armv7-a': 'armv7-a'} |
The Other Jimmy |
36:96847d42f010 | 556 | if arch in archs: |
The Other Jimmy |
36:96847d42f010 | 557 | opts['common']['arm.target.arch'] = archs[arch] |
The Other Jimmy |
36:96847d42f010 | 558 | self.remove_option(flags['common_flags'], str) |
The Other Jimmy |
36:96847d42f010 | 559 | |
The Other Jimmy |
36:96847d42f010 | 560 | opts['common']['arm.target.instructionset'] = 'thumb' |
The Other Jimmy |
36:96847d42f010 | 561 | if '-mthumb' in flags['common_flags']: |
The Other Jimmy |
36:96847d42f010 | 562 | self.remove_option(flags['common_flags'], '-mthumb') |
The Other Jimmy |
36:96847d42f010 | 563 | self.remove_option(flags['ld_flags'], '-mthumb') |
The Other Jimmy |
36:96847d42f010 | 564 | elif '-marm' in flags['common_flags']: |
The Other Jimmy |
36:96847d42f010 | 565 | opts['common']['arm.target.instructionset'] = 'arm' |
The Other Jimmy |
36:96847d42f010 | 566 | self.remove_option(flags['common_flags'], '-marm') |
The Other Jimmy |
36:96847d42f010 | 567 | self.remove_option(flags['ld_flags'], '-marm') |
The Other Jimmy |
36:96847d42f010 | 568 | |
The Other Jimmy |
36:96847d42f010 | 569 | opts['common']['arm.target.thumbinterwork'] = False |
The Other Jimmy |
36:96847d42f010 | 570 | if '-mthumb-interwork' in flags['common_flags']: |
The Other Jimmy |
36:96847d42f010 | 571 | opts['common']['arm.target.thumbinterwork'] = True |
The Other Jimmy |
36:96847d42f010 | 572 | self.remove_option(flags['common_flags'], '-mthumb-interwork') |
The Other Jimmy |
36:96847d42f010 | 573 | |
The Other Jimmy |
36:96847d42f010 | 574 | opts['common']['arm.target.endianness'] = None |
The Other Jimmy |
36:96847d42f010 | 575 | if '-mlittle-endian' in flags['common_flags']: |
The Other Jimmy |
36:96847d42f010 | 576 | opts['common']['arm.target.endianness'] = 'little' |
The Other Jimmy |
36:96847d42f010 | 577 | self.remove_option(flags['common_flags'], '-mlittle-endian') |
The Other Jimmy |
36:96847d42f010 | 578 | elif '-mbig-endian' in flags['common_flags']: |
The Other Jimmy |
36:96847d42f010 | 579 | opts['common']['arm.target.endianness'] = 'big' |
The Other Jimmy |
36:96847d42f010 | 580 | self.remove_option(flags['common_flags'], '-mbig-endian') |
The Other Jimmy |
36:96847d42f010 | 581 | |
The Other Jimmy |
36:96847d42f010 | 582 | opts['common']['arm.target.fpu.unit'] = None |
The Other Jimmy |
36:96847d42f010 | 583 | # default, fpv4spd16, fpv5d16, fpv5spd16 |
The Other Jimmy |
36:96847d42f010 | 584 | str = self.find_options(flags['common_flags'], '-mfpu=') |
The Other Jimmy |
36:96847d42f010 | 585 | if str != None: |
The Other Jimmy |
36:96847d42f010 | 586 | fpu = str[len('-mfpu='):] |
The Other Jimmy |
36:96847d42f010 | 587 | fpus = { |
The Other Jimmy |
36:96847d42f010 | 588 | 'fpv4-sp-d16': 'fpv4spd16', |
The Other Jimmy |
36:96847d42f010 | 589 | 'fpv5-d16': 'fpv5d16', |
The Other Jimmy |
36:96847d42f010 | 590 | 'fpv5-sp-d16': 'fpv5spd16' |
The Other Jimmy |
36:96847d42f010 | 591 | } |
The Other Jimmy |
36:96847d42f010 | 592 | if fpu in fpus: |
The Other Jimmy |
36:96847d42f010 | 593 | opts['common']['arm.target.fpu.unit'] = fpus[fpu] |
The Other Jimmy |
36:96847d42f010 | 594 | |
The Other Jimmy |
36:96847d42f010 | 595 | self.remove_option(flags['common_flags'], str) |
The Other Jimmy |
36:96847d42f010 | 596 | self.remove_option(flags['ld_flags'], str) |
The Other Jimmy |
36:96847d42f010 | 597 | if opts['common']['arm.target.fpu.unit'] == None: |
The Other Jimmy |
36:96847d42f010 | 598 | if core not in MCPUS: |
The Other Jimmy |
36:96847d42f010 | 599 | raise NotSupportedException( |
The Other Jimmy |
36:96847d42f010 | 600 | 'Target core {0} not supported.'.format(core)) |
The Other Jimmy |
36:96847d42f010 | 601 | if MCPUS[core]['fpu_unit']: |
The Other Jimmy |
36:96847d42f010 | 602 | opts['common'][ |
The Other Jimmy |
36:96847d42f010 | 603 | 'arm.target.fpu.unit'] = MCPUS[core]['fpu_unit'] |
The Other Jimmy |
36:96847d42f010 | 604 | |
The Other Jimmy |
36:96847d42f010 | 605 | # soft, softfp, hard. |
The Other Jimmy |
36:96847d42f010 | 606 | str = self.find_options(flags['common_flags'], '-mfloat-abi=') |
The Other Jimmy |
36:96847d42f010 | 607 | if str != None: |
The Other Jimmy |
36:96847d42f010 | 608 | opts['common']['arm.target.fpu.abi'] = str[ |
The Other Jimmy |
36:96847d42f010 | 609 | len('-mfloat-abi='):] |
The Other Jimmy |
36:96847d42f010 | 610 | self.remove_option(flags['common_flags'], str) |
The Other Jimmy |
36:96847d42f010 | 611 | self.remove_option(flags['ld_flags'], str) |
The Other Jimmy |
36:96847d42f010 | 612 | |
The Other Jimmy |
36:96847d42f010 | 613 | opts['common']['arm.target.unalignedaccess'] = None |
The Other Jimmy |
36:96847d42f010 | 614 | if '-munaligned-access' in flags['common_flags']: |
The Other Jimmy |
36:96847d42f010 | 615 | opts['common']['arm.target.unalignedaccess'] = 'enabled' |
The Other Jimmy |
36:96847d42f010 | 616 | self.remove_option(flags['common_flags'], '-munaligned-access') |
The Other Jimmy |
36:96847d42f010 | 617 | elif '-mno-unaligned-access' in flags['common_flags']: |
The Other Jimmy |
36:96847d42f010 | 618 | opts['common']['arm.target.unalignedaccess'] = 'disabled' |
The Other Jimmy |
36:96847d42f010 | 619 | self.remove_option(flags['common_flags'], '-mno-unaligned-access') |
The Other Jimmy |
36:96847d42f010 | 620 | |
The Other Jimmy |
36:96847d42f010 | 621 | # Default optimisation level for Release. |
The Other Jimmy |
36:96847d42f010 | 622 | opts['common']['optimization.level'] = '-Os' |
The Other Jimmy |
36:96847d42f010 | 623 | |
The Other Jimmy |
36:96847d42f010 | 624 | # If the project defines an optimisation level, it is used |
The Other Jimmy |
36:96847d42f010 | 625 | # only for the Release configuration, the Debug one used '-Og'. |
The Other Jimmy |
36:96847d42f010 | 626 | str = self.find_options(flags['common_flags'], '-O') |
The Other Jimmy |
36:96847d42f010 | 627 | if str != None: |
The Other Jimmy |
36:96847d42f010 | 628 | levels = { |
The Other Jimmy |
36:96847d42f010 | 629 | '-O0': 'none', '-O1': 'optimize', '-O2': 'more', |
The Other Jimmy |
36:96847d42f010 | 630 | '-O3': 'most', '-Os': 'size', '-Og': 'debug' |
The Other Jimmy |
36:96847d42f010 | 631 | } |
The Other Jimmy |
36:96847d42f010 | 632 | if str in levels: |
The Other Jimmy |
36:96847d42f010 | 633 | opts['common']['optimization.level'] = levels[str] |
The Other Jimmy |
36:96847d42f010 | 634 | self.remove_option(flags['common_flags'], str) |
The Other Jimmy |
36:96847d42f010 | 635 | |
The Other Jimmy |
36:96847d42f010 | 636 | include_files = [] |
The Other Jimmy |
36:96847d42f010 | 637 | for all_flags in [flags['common_flags'], flags['c_flags'], flags['cxx_flags']]: |
The Other Jimmy |
36:96847d42f010 | 638 | while '-include' in all_flags: |
The Other Jimmy |
36:96847d42f010 | 639 | ix = all_flags.index('-include') |
The Other Jimmy |
36:96847d42f010 | 640 | str = all_flags[ix + 1] |
The Other Jimmy |
36:96847d42f010 | 641 | if str not in include_files: |
The Other Jimmy |
36:96847d42f010 | 642 | include_files.append(str) |
The Other Jimmy |
36:96847d42f010 | 643 | self.remove_option(all_flags, '-include') |
The Other Jimmy |
36:96847d42f010 | 644 | self.remove_option(all_flags, str) |
The Other Jimmy |
36:96847d42f010 | 645 | |
The Other Jimmy |
36:96847d42f010 | 646 | opts['common']['include_files'] = include_files |
The Other Jimmy |
36:96847d42f010 | 647 | |
The Other Jimmy |
36:96847d42f010 | 648 | if '-ansi' in flags['c_flags']: |
The Other Jimmy |
36:96847d42f010 | 649 | opts['c']['compiler.std'] = '-ansi' |
The Other Jimmy |
36:96847d42f010 | 650 | self.remove_option(flags['c_flags'], str) |
The Other Jimmy |
36:96847d42f010 | 651 | else: |
The Other Jimmy |
36:96847d42f010 | 652 | str = self.find_options(flags['c_flags'], '-std') |
The Other Jimmy |
36:96847d42f010 | 653 | std = str[len('-std='):] |
The Other Jimmy |
36:96847d42f010 | 654 | c_std = { |
The Other Jimmy |
36:96847d42f010 | 655 | 'c90': 'c90', 'c89': 'c90', 'gnu90': 'gnu90', 'gnu89': 'gnu90', |
The Other Jimmy |
36:96847d42f010 | 656 | 'c99': 'c99', 'c9x': 'c99', 'gnu99': 'gnu99', 'gnu9x': 'gnu98', |
The Other Jimmy |
36:96847d42f010 | 657 | 'c11': 'c11', 'c1x': 'c11', 'gnu11': 'gnu11', 'gnu1x': 'gnu11' |
The Other Jimmy |
36:96847d42f010 | 658 | } |
The Other Jimmy |
36:96847d42f010 | 659 | if std in c_std: |
The Other Jimmy |
36:96847d42f010 | 660 | opts['c']['compiler.std'] = c_std[std] |
The Other Jimmy |
36:96847d42f010 | 661 | self.remove_option(flags['c_flags'], str) |
The Other Jimmy |
36:96847d42f010 | 662 | |
The Other Jimmy |
36:96847d42f010 | 663 | if '-ansi' in flags['cxx_flags']: |
The Other Jimmy |
36:96847d42f010 | 664 | opts['cpp']['compiler.std'] = '-ansi' |
The Other Jimmy |
36:96847d42f010 | 665 | self.remove_option(flags['cxx_flags'], str) |
The Other Jimmy |
36:96847d42f010 | 666 | else: |
The Other Jimmy |
36:96847d42f010 | 667 | str = self.find_options(flags['cxx_flags'], '-std') |
The Other Jimmy |
36:96847d42f010 | 668 | std = str[len('-std='):] |
The Other Jimmy |
36:96847d42f010 | 669 | cpp_std = { |
The Other Jimmy |
36:96847d42f010 | 670 | 'c++98': 'cpp98', 'c++03': 'cpp98', |
The Other Jimmy |
36:96847d42f010 | 671 | 'gnu++98': 'gnucpp98', 'gnu++03': 'gnucpp98', |
The Other Jimmy |
36:96847d42f010 | 672 | 'c++0x': 'cpp0x', 'gnu++0x': 'gnucpp0x', |
The Other Jimmy |
36:96847d42f010 | 673 | 'c++11': 'cpp11', 'gnu++11': 'gnucpp11', |
The Other Jimmy |
36:96847d42f010 | 674 | 'c++1y': 'cpp1y', 'gnu++1y': 'gnucpp1y', |
The Other Jimmy |
36:96847d42f010 | 675 | 'c++14': 'cpp14', 'gnu++14': 'gnucpp14', |
The Other Jimmy |
36:96847d42f010 | 676 | 'c++1z': 'cpp1z', 'gnu++1z': 'gnucpp1z', |
The Other Jimmy |
36:96847d42f010 | 677 | } |
The Other Jimmy |
36:96847d42f010 | 678 | if std in cpp_std: |
The Other Jimmy |
36:96847d42f010 | 679 | opts['cpp']['compiler.std'] = cpp_std[std] |
The Other Jimmy |
36:96847d42f010 | 680 | self.remove_option(flags['cxx_flags'], str) |
The Other Jimmy |
36:96847d42f010 | 681 | |
The Other Jimmy |
36:96847d42f010 | 682 | # Common optimisation options. |
The Other Jimmy |
36:96847d42f010 | 683 | optimization_options = { |
The Other Jimmy |
36:96847d42f010 | 684 | '-fmessage-length=0': 'optimization.messagelength', |
The Other Jimmy |
36:96847d42f010 | 685 | '-fsigned-char': 'optimization.signedchar', |
The Other Jimmy |
36:96847d42f010 | 686 | '-ffunction-sections': 'optimization.functionsections', |
The Other Jimmy |
36:96847d42f010 | 687 | '-fdata-sections': 'optimization.datasections', |
The Other Jimmy |
36:96847d42f010 | 688 | '-fno-common': 'optimization.nocommon', |
The Other Jimmy |
36:96847d42f010 | 689 | '-fno-inline-functions': 'optimization.noinlinefunctions', |
The Other Jimmy |
36:96847d42f010 | 690 | '-ffreestanding': 'optimization.freestanding', |
The Other Jimmy |
36:96847d42f010 | 691 | '-fno-builtin': 'optimization.nobuiltin', |
The Other Jimmy |
36:96847d42f010 | 692 | '-fsingle-precision-constant': 'optimization.spconstant', |
The Other Jimmy |
36:96847d42f010 | 693 | '-fPIC': 'optimization.PIC', |
The Other Jimmy |
36:96847d42f010 | 694 | '-fno-move-loop-invariants': 'optimization.nomoveloopinvariants', |
The Other Jimmy |
36:96847d42f010 | 695 | } |
The Other Jimmy |
36:96847d42f010 | 696 | |
The Other Jimmy |
36:96847d42f010 | 697 | for option in optimization_options: |
The Other Jimmy |
36:96847d42f010 | 698 | opts['common'][optimization_options[option]] = False |
The Other Jimmy |
36:96847d42f010 | 699 | if option in flags['common_flags']: |
The Other Jimmy |
36:96847d42f010 | 700 | opts['common'][optimization_options[option]] = True |
The Other Jimmy |
36:96847d42f010 | 701 | self.remove_option(flags['common_flags'], option) |
The Other Jimmy |
36:96847d42f010 | 702 | |
The Other Jimmy |
36:96847d42f010 | 703 | # Common warning options. |
The Other Jimmy |
36:96847d42f010 | 704 | warning_options = { |
The Other Jimmy |
36:96847d42f010 | 705 | '-fsyntax-only': 'warnings.syntaxonly', |
The Other Jimmy |
36:96847d42f010 | 706 | '-pedantic': 'warnings.pedantic', |
The Other Jimmy |
36:96847d42f010 | 707 | '-pedantic-errors': 'warnings.pedanticerrors', |
The Other Jimmy |
36:96847d42f010 | 708 | '-w': 'warnings.nowarn', |
The Other Jimmy |
36:96847d42f010 | 709 | '-Wunused': 'warnings.unused', |
The Other Jimmy |
36:96847d42f010 | 710 | '-Wuninitialized': 'warnings.uninitialized', |
The Other Jimmy |
36:96847d42f010 | 711 | '-Wall': 'warnings.allwarn', |
The Other Jimmy |
36:96847d42f010 | 712 | '-Wextra': 'warnings.extrawarn', |
The Other Jimmy |
36:96847d42f010 | 713 | '-Wmissing-declarations': 'warnings.missingdeclaration', |
The Other Jimmy |
36:96847d42f010 | 714 | '-Wconversion': 'warnings.conversion', |
The Other Jimmy |
36:96847d42f010 | 715 | '-Wpointer-arith': 'warnings.pointerarith', |
The Other Jimmy |
36:96847d42f010 | 716 | '-Wpadded': 'warnings.padded', |
The Other Jimmy |
36:96847d42f010 | 717 | '-Wshadow': 'warnings.shadow', |
The Other Jimmy |
36:96847d42f010 | 718 | '-Wlogical-op': 'warnings.logicalop', |
The Other Jimmy |
36:96847d42f010 | 719 | '-Waggregate-return': 'warnings.agreggatereturn', |
The Other Jimmy |
36:96847d42f010 | 720 | '-Wfloat-equal': 'warnings.floatequal', |
The Other Jimmy |
36:96847d42f010 | 721 | '-Werror': 'warnings.toerrors', |
The Other Jimmy |
36:96847d42f010 | 722 | } |
The Other Jimmy |
36:96847d42f010 | 723 | |
The Other Jimmy |
36:96847d42f010 | 724 | for option in warning_options: |
The Other Jimmy |
36:96847d42f010 | 725 | opts['common'][warning_options[option]] = False |
The Other Jimmy |
36:96847d42f010 | 726 | if option in flags['common_flags']: |
The Other Jimmy |
36:96847d42f010 | 727 | opts['common'][warning_options[option]] = True |
The Other Jimmy |
36:96847d42f010 | 728 | self.remove_option(flags['common_flags'], option) |
The Other Jimmy |
36:96847d42f010 | 729 | |
The Other Jimmy |
36:96847d42f010 | 730 | # Common debug options. |
The Other Jimmy |
36:96847d42f010 | 731 | debug_levels = { |
The Other Jimmy |
36:96847d42f010 | 732 | '-g': 'default', |
The Other Jimmy |
36:96847d42f010 | 733 | '-g1': 'minimal', |
The Other Jimmy |
36:96847d42f010 | 734 | '-g3': 'max', |
The Other Jimmy |
36:96847d42f010 | 735 | } |
The Other Jimmy |
36:96847d42f010 | 736 | opts['common']['debugging.level'] = 'none' |
The Other Jimmy |
36:96847d42f010 | 737 | for option in debug_levels: |
The Other Jimmy |
36:96847d42f010 | 738 | if option in flags['common_flags']: |
The Other Jimmy |
36:96847d42f010 | 739 | opts['common'][ |
The Other Jimmy |
36:96847d42f010 | 740 | 'debugging.level'] = debug_levels[option] |
The Other Jimmy |
36:96847d42f010 | 741 | self.remove_option(flags['common_flags'], option) |
The Other Jimmy |
36:96847d42f010 | 742 | |
The Other Jimmy |
36:96847d42f010 | 743 | debug_formats = { |
The Other Jimmy |
36:96847d42f010 | 744 | '-ggdb': 'gdb', |
The Other Jimmy |
36:96847d42f010 | 745 | '-gstabs': 'stabs', |
The Other Jimmy |
36:96847d42f010 | 746 | '-gstabs+': 'stabsplus', |
The Other Jimmy |
36:96847d42f010 | 747 | '-gdwarf-2': 'dwarf2', |
The Other Jimmy |
36:96847d42f010 | 748 | '-gdwarf-3': 'dwarf3', |
The Other Jimmy |
36:96847d42f010 | 749 | '-gdwarf-4': 'dwarf4', |
The Other Jimmy |
36:96847d42f010 | 750 | '-gdwarf-5': 'dwarf5', |
The Other Jimmy |
36:96847d42f010 | 751 | } |
The Other Jimmy |
36:96847d42f010 | 752 | |
The Other Jimmy |
36:96847d42f010 | 753 | opts['common']['debugging.format'] = '' |
The Other Jimmy |
36:96847d42f010 | 754 | for option in debug_levels: |
The Other Jimmy |
36:96847d42f010 | 755 | if option in flags['common_flags']: |
The Other Jimmy |
36:96847d42f010 | 756 | opts['common'][ |
The Other Jimmy |
36:96847d42f010 | 757 | 'debugging.format'] = debug_formats[option] |
The Other Jimmy |
36:96847d42f010 | 758 | self.remove_option(flags['common_flags'], option) |
The Other Jimmy |
36:96847d42f010 | 759 | |
The Other Jimmy |
36:96847d42f010 | 760 | opts['common']['debugging.prof'] = False |
The Other Jimmy |
36:96847d42f010 | 761 | if '-p' in flags['common_flags']: |
The Other Jimmy |
36:96847d42f010 | 762 | opts['common']['debugging.prof'] = True |
The Other Jimmy |
36:96847d42f010 | 763 | self.remove_option(flags['common_flags'], '-p') |
The Other Jimmy |
36:96847d42f010 | 764 | |
The Other Jimmy |
36:96847d42f010 | 765 | opts['common']['debugging.gprof'] = False |
The Other Jimmy |
36:96847d42f010 | 766 | if '-pg' in flags['common_flags']: |
The Other Jimmy |
36:96847d42f010 | 767 | opts['common']['debugging.gprof'] = True |
The Other Jimmy |
36:96847d42f010 | 768 | self.remove_option(flags['common_flags'], '-gp') |
The Other Jimmy |
36:96847d42f010 | 769 | |
The Other Jimmy |
36:96847d42f010 | 770 | # Assembler options. |
The Other Jimmy |
36:96847d42f010 | 771 | opts['as']['usepreprocessor'] = False |
The Other Jimmy |
36:96847d42f010 | 772 | while '-x' in flags['asm_flags']: |
The Other Jimmy |
36:96847d42f010 | 773 | ix = flags['asm_flags'].index('-x') |
The Other Jimmy |
36:96847d42f010 | 774 | str = flags['asm_flags'][ix + 1] |
The Other Jimmy |
36:96847d42f010 | 775 | |
The Other Jimmy |
36:96847d42f010 | 776 | if str == 'assembler-with-cpp': |
The Other Jimmy |
36:96847d42f010 | 777 | opts['as']['usepreprocessor'] = True |
The Other Jimmy |
36:96847d42f010 | 778 | else: |
The Other Jimmy |
36:96847d42f010 | 779 | # Collect all other assembler options. |
The Other Jimmy |
36:96847d42f010 | 780 | opts['as']['other'] += ' -x ' + str |
The Other Jimmy |
36:96847d42f010 | 781 | |
The Other Jimmy |
36:96847d42f010 | 782 | self.remove_option(flags['asm_flags'], '-x') |
The Other Jimmy |
36:96847d42f010 | 783 | self.remove_option(flags['asm_flags'], 'assembler-with-cpp') |
The Other Jimmy |
36:96847d42f010 | 784 | |
The Other Jimmy |
36:96847d42f010 | 785 | opts['as']['nostdinc'] = False |
The Other Jimmy |
36:96847d42f010 | 786 | if '-nostdinc' in flags['asm_flags']: |
The Other Jimmy |
36:96847d42f010 | 787 | opts['as']['nostdinc'] = True |
The Other Jimmy |
36:96847d42f010 | 788 | self.remove_option(flags['asm_flags'], '-nostdinc') |
The Other Jimmy |
36:96847d42f010 | 789 | |
The Other Jimmy |
36:96847d42f010 | 790 | opts['as']['verbose'] = False |
The Other Jimmy |
36:96847d42f010 | 791 | if '-v' in flags['asm_flags']: |
The Other Jimmy |
36:96847d42f010 | 792 | opts['as']['verbose'] = True |
The Other Jimmy |
36:96847d42f010 | 793 | self.remove_option(flags['asm_flags'], '-v') |
The Other Jimmy |
36:96847d42f010 | 794 | |
The Other Jimmy |
36:96847d42f010 | 795 | # C options. |
The Other Jimmy |
36:96847d42f010 | 796 | opts['c']['nostdinc'] = False |
The Other Jimmy |
36:96847d42f010 | 797 | if '-nostdinc' in flags['c_flags']: |
The Other Jimmy |
36:96847d42f010 | 798 | opts['c']['nostdinc'] = True |
The Other Jimmy |
36:96847d42f010 | 799 | self.remove_option(flags['c_flags'], '-nostdinc') |
The Other Jimmy |
36:96847d42f010 | 800 | |
The Other Jimmy |
36:96847d42f010 | 801 | opts['c']['verbose'] = False |
The Other Jimmy |
36:96847d42f010 | 802 | if '-v' in flags['c_flags']: |
The Other Jimmy |
36:96847d42f010 | 803 | opts['c']['verbose'] = True |
The Other Jimmy |
36:96847d42f010 | 804 | self.remove_option(flags['c_flags'], '-v') |
The Other Jimmy |
36:96847d42f010 | 805 | |
The Other Jimmy |
36:96847d42f010 | 806 | warning_options = { |
The Other Jimmy |
36:96847d42f010 | 807 | '-Wmissing-prototypes': 'warnings.missingprototypes', |
The Other Jimmy |
36:96847d42f010 | 808 | '-Wstrict-prototypes': 'warnings.strictprototypes', |
The Other Jimmy |
36:96847d42f010 | 809 | '-Wbad-function-cast': 'warnings.badfunctioncast', |
The Other Jimmy |
36:96847d42f010 | 810 | } |
The Other Jimmy |
36:96847d42f010 | 811 | |
The Other Jimmy |
36:96847d42f010 | 812 | for option in warning_options: |
The Other Jimmy |
36:96847d42f010 | 813 | opts['c'][warning_options[option]] = False |
The Other Jimmy |
36:96847d42f010 | 814 | if option in flags['common_flags']: |
The Other Jimmy |
36:96847d42f010 | 815 | opts['c'][warning_options[option]] = True |
The Other Jimmy |
36:96847d42f010 | 816 | self.remove_option(flags['common_flags'], option) |
The Other Jimmy |
36:96847d42f010 | 817 | |
The Other Jimmy |
36:96847d42f010 | 818 | # C++ options. |
The Other Jimmy |
36:96847d42f010 | 819 | opts['cpp']['nostdinc'] = False |
The Other Jimmy |
36:96847d42f010 | 820 | if '-nostdinc' in flags['cxx_flags']: |
The Other Jimmy |
36:96847d42f010 | 821 | opts['cpp']['nostdinc'] = True |
The Other Jimmy |
36:96847d42f010 | 822 | self.remove_option(flags['cxx_flags'], '-nostdinc') |
The Other Jimmy |
36:96847d42f010 | 823 | |
The Other Jimmy |
36:96847d42f010 | 824 | opts['cpp']['nostdincpp'] = False |
The Other Jimmy |
36:96847d42f010 | 825 | if '-nostdinc++' in flags['cxx_flags']: |
The Other Jimmy |
36:96847d42f010 | 826 | opts['cpp']['nostdincpp'] = True |
The Other Jimmy |
36:96847d42f010 | 827 | self.remove_option(flags['cxx_flags'], '-nostdinc++') |
The Other Jimmy |
36:96847d42f010 | 828 | |
The Other Jimmy |
36:96847d42f010 | 829 | optimization_options = { |
The Other Jimmy |
36:96847d42f010 | 830 | '-fno-exceptions': 'optimization.noexceptions', |
The Other Jimmy |
36:96847d42f010 | 831 | '-fno-rtti': 'optimization.nortti', |
The Other Jimmy |
36:96847d42f010 | 832 | '-fno-use-cxa-atexit': 'optimization.nousecxaatexit', |
The Other Jimmy |
36:96847d42f010 | 833 | '-fno-threadsafe-statics': 'optimization.nothreadsafestatics', |
The Other Jimmy |
36:96847d42f010 | 834 | } |
The Other Jimmy |
36:96847d42f010 | 835 | |
The Other Jimmy |
36:96847d42f010 | 836 | for option in optimization_options: |
The Other Jimmy |
36:96847d42f010 | 837 | opts['cpp'][optimization_options[option]] = False |
The Other Jimmy |
36:96847d42f010 | 838 | if option in flags['cxx_flags']: |
The Other Jimmy |
36:96847d42f010 | 839 | opts['cpp'][optimization_options[option]] = True |
The Other Jimmy |
36:96847d42f010 | 840 | self.remove_option(flags['cxx_flags'], option) |
The Other Jimmy |
36:96847d42f010 | 841 | if option in flags['common_flags']: |
The Other Jimmy |
36:96847d42f010 | 842 | opts['cpp'][optimization_options[option]] = True |
The Other Jimmy |
36:96847d42f010 | 843 | self.remove_option(flags['common_flags'], option) |
The Other Jimmy |
36:96847d42f010 | 844 | |
The Other Jimmy |
36:96847d42f010 | 845 | warning_options = { |
The Other Jimmy |
36:96847d42f010 | 846 | '-Wabi': 'warnabi', |
The Other Jimmy |
36:96847d42f010 | 847 | '-Wctor-dtor-privacy': 'warnings.ctordtorprivacy', |
The Other Jimmy |
36:96847d42f010 | 848 | '-Wnoexcept': 'warnings.noexcept', |
The Other Jimmy |
36:96847d42f010 | 849 | '-Wnon-virtual-dtor': 'warnings.nonvirtualdtor', |
The Other Jimmy |
36:96847d42f010 | 850 | '-Wstrict-null-sentinel': 'warnings.strictnullsentinel', |
The Other Jimmy |
36:96847d42f010 | 851 | '-Wsign-promo': 'warnings.signpromo', |
The Other Jimmy |
36:96847d42f010 | 852 | '-Weffc++': 'warneffc', |
The Other Jimmy |
36:96847d42f010 | 853 | } |
The Other Jimmy |
36:96847d42f010 | 854 | |
The Other Jimmy |
36:96847d42f010 | 855 | for option in warning_options: |
The Other Jimmy |
36:96847d42f010 | 856 | opts['cpp'][warning_options[option]] = False |
The Other Jimmy |
36:96847d42f010 | 857 | if option in flags['cxx_flags']: |
The Other Jimmy |
36:96847d42f010 | 858 | opts['cpp'][warning_options[option]] = True |
The Other Jimmy |
36:96847d42f010 | 859 | self.remove_option(flags['cxx_flags'], option) |
The Other Jimmy |
36:96847d42f010 | 860 | if option in flags['common_flags']: |
The Other Jimmy |
36:96847d42f010 | 861 | opts['cpp'][warning_options[option]] = True |
The Other Jimmy |
36:96847d42f010 | 862 | self.remove_option(flags['common_flags'], option) |
The Other Jimmy |
36:96847d42f010 | 863 | |
The Other Jimmy |
36:96847d42f010 | 864 | opts['cpp']['verbose'] = False |
The Other Jimmy |
36:96847d42f010 | 865 | if '-v' in flags['cxx_flags']: |
The Other Jimmy |
36:96847d42f010 | 866 | opts['cpp']['verbose'] = True |
The Other Jimmy |
36:96847d42f010 | 867 | self.remove_option(flags['cxx_flags'], '-v') |
The Other Jimmy |
36:96847d42f010 | 868 | |
The Other Jimmy |
36:96847d42f010 | 869 | # Linker options. |
The Other Jimmy |
36:96847d42f010 | 870 | linker_options = { |
The Other Jimmy |
36:96847d42f010 | 871 | '-nostartfiles': 'nostart', |
The Other Jimmy |
36:96847d42f010 | 872 | '-nodefaultlibs': 'nodeflibs', |
The Other Jimmy |
36:96847d42f010 | 873 | '-nostdlib': 'nostdlibs', |
The Other Jimmy |
36:96847d42f010 | 874 | } |
The Other Jimmy |
36:96847d42f010 | 875 | |
The Other Jimmy |
36:96847d42f010 | 876 | for option in linker_options: |
The Other Jimmy |
36:96847d42f010 | 877 | opts['ld'][linker_options[option]] = False |
The Other Jimmy |
36:96847d42f010 | 878 | if option in flags['ld_flags']: |
The Other Jimmy |
36:96847d42f010 | 879 | opts['ld'][linker_options[option]] = True |
The Other Jimmy |
36:96847d42f010 | 880 | self.remove_option(flags['ld_flags'], option) |
The Other Jimmy |
36:96847d42f010 | 881 | |
The Other Jimmy |
36:96847d42f010 | 882 | opts['ld']['gcsections'] = False |
The Other Jimmy |
36:96847d42f010 | 883 | if '-Wl,--gc-sections' in flags['ld_flags']: |
The Other Jimmy |
36:96847d42f010 | 884 | opts['ld']['gcsections'] = True |
The Other Jimmy |
36:96847d42f010 | 885 | self.remove_option(flags['ld_flags'], '-Wl,--gc-sections') |
The Other Jimmy |
36:96847d42f010 | 886 | |
The Other Jimmy |
36:96847d42f010 | 887 | opts['ld']['flags'] = [] |
The Other Jimmy |
36:96847d42f010 | 888 | to_remove = [] |
The Other Jimmy |
36:96847d42f010 | 889 | for opt in flags['ld_flags']: |
The Other Jimmy |
36:96847d42f010 | 890 | if opt.startswith('-Wl,--wrap,'): |
The Other Jimmy |
36:96847d42f010 | 891 | opts['ld']['flags'].append( |
The Other Jimmy |
36:96847d42f010 | 892 | '--wrap=' + opt[len('-Wl,--wrap,'):]) |
The Other Jimmy |
36:96847d42f010 | 893 | to_remove.append(opt) |
The Other Jimmy |
36:96847d42f010 | 894 | for opt in to_remove: |
The Other Jimmy |
36:96847d42f010 | 895 | self.remove_option(flags['ld_flags'], opt) |
The Other Jimmy |
36:96847d42f010 | 896 | |
The Other Jimmy |
36:96847d42f010 | 897 | # Other tool remaining options are separated by category. |
The Other Jimmy |
36:96847d42f010 | 898 | opts['as']['otherwarnings'] = self.find_options( |
The Other Jimmy |
36:96847d42f010 | 899 | flags['asm_flags'], '-W') |
The Other Jimmy |
36:96847d42f010 | 900 | |
The Other Jimmy |
36:96847d42f010 | 901 | opts['c']['otherwarnings'] = self.find_options( |
The Other Jimmy |
36:96847d42f010 | 902 | flags['c_flags'], '-W') |
The Other Jimmy |
36:96847d42f010 | 903 | opts['c']['otheroptimizations'] = self.find_options(flags[ |
The Other Jimmy |
36:96847d42f010 | 904 | 'c_flags'], '-f') |
The Other Jimmy |
36:96847d42f010 | 905 | |
The Other Jimmy |
36:96847d42f010 | 906 | opts['cpp']['otherwarnings'] = self.find_options( |
The Other Jimmy |
36:96847d42f010 | 907 | flags['cxx_flags'], '-W') |
The Other Jimmy |
36:96847d42f010 | 908 | opts['cpp']['otheroptimizations'] = self.find_options( |
The Other Jimmy |
36:96847d42f010 | 909 | flags['cxx_flags'], '-f') |
The Other Jimmy |
36:96847d42f010 | 910 | |
The Other Jimmy |
36:96847d42f010 | 911 | # Other common remaining options are separated by category. |
The Other Jimmy |
36:96847d42f010 | 912 | opts['common']['optimization.other'] = self.find_options( |
The Other Jimmy |
36:96847d42f010 | 913 | flags['common_flags'], '-f') |
The Other Jimmy |
36:96847d42f010 | 914 | opts['common']['warnings.other'] = self.find_options( |
The Other Jimmy |
36:96847d42f010 | 915 | flags['common_flags'], '-W') |
The Other Jimmy |
36:96847d42f010 | 916 | |
The Other Jimmy |
36:96847d42f010 | 917 | # Remaining common flags are added to each tool. |
The Other Jimmy |
36:96847d42f010 | 918 | opts['as']['other'] += ' ' + \ |
The Other Jimmy |
36:96847d42f010 | 919 | ' '.join(flags['common_flags']) + ' ' + \ |
The Other Jimmy |
36:96847d42f010 | 920 | ' '.join(flags['asm_flags']) |
The Other Jimmy |
36:96847d42f010 | 921 | opts['c']['other'] += ' ' + \ |
The Other Jimmy |
36:96847d42f010 | 922 | ' '.join(flags['common_flags']) + ' ' + ' '.join(flags['c_flags']) |
The Other Jimmy |
36:96847d42f010 | 923 | opts['cpp']['other'] += ' ' + \ |
The Other Jimmy |
36:96847d42f010 | 924 | ' '.join(flags['common_flags']) + ' ' + \ |
The Other Jimmy |
36:96847d42f010 | 925 | ' '.join(flags['cxx_flags']) |
The Other Jimmy |
36:96847d42f010 | 926 | opts['ld']['other'] += ' ' + \ |
The Other Jimmy |
36:96847d42f010 | 927 | ' '.join(flags['common_flags']) + ' ' + ' '.join(flags['ld_flags']) |
The Other Jimmy |
36:96847d42f010 | 928 | |
The Other Jimmy |
36:96847d42f010 | 929 | if len(self.system_libraries) > 0: |
The Other Jimmy |
36:96847d42f010 | 930 | opts['ld']['other'] += ' -Wl,--start-group ' |
The Other Jimmy |
36:96847d42f010 | 931 | opts['ld'][ |
The Other Jimmy |
36:96847d42f010 | 932 | 'other'] += ' '.join('-l' + s for s in self.system_libraries) |
The Other Jimmy |
36:96847d42f010 | 933 | opts['ld']['other'] += ' -Wl,--end-group ' |
The Other Jimmy |
36:96847d42f010 | 934 | |
The Other Jimmy |
36:96847d42f010 | 935 | # Strip all 'other' flags, since they might have leading spaces. |
The Other Jimmy |
36:96847d42f010 | 936 | opts['as']['other'] = opts['as']['other'].strip() |
The Other Jimmy |
36:96847d42f010 | 937 | opts['c']['other'] = opts['c']['other'].strip() |
The Other Jimmy |
36:96847d42f010 | 938 | opts['cpp']['other'] = opts['cpp']['other'].strip() |
The Other Jimmy |
36:96847d42f010 | 939 | opts['ld']['other'] = opts['ld']['other'].strip() |
The Other Jimmy |
36:96847d42f010 | 940 | |
The Other Jimmy |
36:96847d42f010 | 941 | if False: |
The Other Jimmy |
36:96847d42f010 | 942 | |
The Other Jimmy |
36:96847d42f010 | 943 | print opts |
The Other Jimmy |
36:96847d42f010 | 944 | |
The Other Jimmy |
36:96847d42f010 | 945 | |
The Other Jimmy |
36:96847d42f010 | 946 | print 'common_flags', flags['common_flags'] |
The Other Jimmy |
36:96847d42f010 | 947 | print 'asm_flags', flags['asm_flags'] |
The Other Jimmy |
36:96847d42f010 | 948 | print 'c_flags', flags['c_flags'] |
The Other Jimmy |
36:96847d42f010 | 949 | print 'cxx_flags', flags['cxx_flags'] |
The Other Jimmy |
36:96847d42f010 | 950 | print 'ld_flags', flags['ld_flags'] |
The Other Jimmy |
36:96847d42f010 | 951 | |
The Other Jimmy |
36:96847d42f010 | 952 | @staticmethod |
The Other Jimmy |
36:96847d42f010 | 953 | def find_options(lst, option): |
The Other Jimmy |
36:96847d42f010 | 954 | tmp = [str for str in lst if str.startswith(option)] |
The Other Jimmy |
36:96847d42f010 | 955 | if len(tmp) > 0: |
The Other Jimmy |
36:96847d42f010 | 956 | return tmp[0] |
The Other Jimmy |
36:96847d42f010 | 957 | else: |
The Other Jimmy |
36:96847d42f010 | 958 | return None |
The Other Jimmy |
36:96847d42f010 | 959 | |
The Other Jimmy |
36:96847d42f010 | 960 | @staticmethod |
The Other Jimmy |
36:96847d42f010 | 961 | def find_options(lst, prefix): |
The Other Jimmy |
36:96847d42f010 | 962 | other = '' |
The Other Jimmy |
36:96847d42f010 | 963 | opts = [str for str in lst if str.startswith(prefix)] |
The Other Jimmy |
36:96847d42f010 | 964 | if len(opts) > 0: |
The Other Jimmy |
36:96847d42f010 | 965 | for opt in opts: |
The Other Jimmy |
36:96847d42f010 | 966 | other += ' ' + opt |
The Other Jimmy |
36:96847d42f010 | 967 | GNUARMEclipse.remove_option(lst, opt) |
The Other Jimmy |
36:96847d42f010 | 968 | return other.strip() |
The Other Jimmy |
36:96847d42f010 | 969 | |
The Other Jimmy |
36:96847d42f010 | 970 | @staticmethod |
The Other Jimmy |
36:96847d42f010 | 971 | def remove_option(lst, option): |
The Other Jimmy |
36:96847d42f010 | 972 | if option in lst: |
The Other Jimmy |
36:96847d42f010 | 973 | lst.remove(option) |
The Other Jimmy |
36:96847d42f010 | 974 | |
The Other Jimmy |
36:96847d42f010 | 975 | # ============================================================================= |