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