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