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