Clone of official tools

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?

UserRevisionLine numberNew contents of line
theotherjimmy 43:2a7da56ebd24 1 """
theotherjimmy 43:2a7da56ebd24 2 mbed SDK
theotherjimmy 43:2a7da56ebd24 3 Copyright (c) 2014-2017 ARM Limited
theotherjimmy 43:2a7da56ebd24 4 Copyright (c) 2018 ON Semiconductor
theotherjimmy 43:2a7da56ebd24 5
theotherjimmy 43:2a7da56ebd24 6 Licensed under the Apache License, Version 2.0 (the "License");
theotherjimmy 43:2a7da56ebd24 7 you may not use this file except in compliance with the License.
theotherjimmy 43:2a7da56ebd24 8 You may obtain a copy of the License at
theotherjimmy 43:2a7da56ebd24 9
theotherjimmy 43:2a7da56ebd24 10 http://www.apache.org/licenses/LICENSE-2.0
theotherjimmy 43:2a7da56ebd24 11
theotherjimmy 43:2a7da56ebd24 12 Unless required by applicable law or agreed to in writing, software
theotherjimmy 43:2a7da56ebd24 13 distributed under the License is distributed on an "AS IS" BASIS,
theotherjimmy 43:2a7da56ebd24 14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
theotherjimmy 43:2a7da56ebd24 15 See the License for the specific language governing permissions and
theotherjimmy 43:2a7da56ebd24 16 limitations under the License.
theotherjimmy 43:2a7da56ebd24 17 """
theotherjimmy 43:2a7da56ebd24 18 import copy
theotherjimmy 43:2a7da56ebd24 19 import stat
theotherjimmy 43:2a7da56ebd24 20 import os
theotherjimmy 43:2a7da56ebd24 21 from os.path import splitext, basename, dirname, abspath, isdir
theotherjimmy 43:2a7da56ebd24 22 from os import remove, mkdir
theotherjimmy 43:2a7da56ebd24 23 from shutil import rmtree, copyfile
theotherjimmy 43:2a7da56ebd24 24 from tools.targets import TARGET_MAP
theotherjimmy 43:2a7da56ebd24 25 from tools.export.exporters import Exporter
theotherjimmy 43:2a7da56ebd24 26 from tools.export.makefile import GccArm
theotherjimmy 43:2a7da56ebd24 27
theotherjimmy 43:2a7da56ebd24 28 class CodeBlocks(GccArm):
theotherjimmy 43:2a7da56ebd24 29 NAME = 'Code::Blocks'
theotherjimmy 43:2a7da56ebd24 30
theotherjimmy 43:2a7da56ebd24 31 DOT_IN_RELATIVE_PATH = True
theotherjimmy 43:2a7da56ebd24 32
theotherjimmy 43:2a7da56ebd24 33 MBED_CONFIG_HEADER_SUPPORTED = True
theotherjimmy 43:2a7da56ebd24 34
theotherjimmy 43:2a7da56ebd24 35 PREPROCESS_ASM = False
theotherjimmy 43:2a7da56ebd24 36
theotherjimmy 43:2a7da56ebd24 37 POST_BINARY_WHITELIST = set([
theotherjimmy 43:2a7da56ebd24 38 "NCS36510TargetCode.ncs36510_addfib"
theotherjimmy 43:2a7da56ebd24 39 ])
theotherjimmy 43:2a7da56ebd24 40
theotherjimmy 43:2a7da56ebd24 41 @staticmethod
theotherjimmy 43:2a7da56ebd24 42 def filter_dot(str_in):
theotherjimmy 43:2a7da56ebd24 43 """
theotherjimmy 43:2a7da56ebd24 44 Remove the './' prefix, if present.
theotherjimmy 43:2a7da56ebd24 45 This function assumes that resources.win_to_unix()
theotherjimmy 43:2a7da56ebd24 46 replaced all windows backslashes with slashes.
theotherjimmy 43:2a7da56ebd24 47 """
theotherjimmy 43:2a7da56ebd24 48 if str_in is None:
theotherjimmy 43:2a7da56ebd24 49 return None
theotherjimmy 43:2a7da56ebd24 50 if str_in[:2] == './':
theotherjimmy 43:2a7da56ebd24 51 return str_in[2:]
theotherjimmy 43:2a7da56ebd24 52 return str_in
theotherjimmy 43:2a7da56ebd24 53
theotherjimmy 43:2a7da56ebd24 54 @staticmethod
theotherjimmy 43:2a7da56ebd24 55 def prepare_lib(libname):
theotherjimmy 43:2a7da56ebd24 56 if "lib" == libname[:3]:
theotherjimmy 43:2a7da56ebd24 57 libname = libname[3:-2]
theotherjimmy 43:2a7da56ebd24 58 return "-l" + libname
theotherjimmy 43:2a7da56ebd24 59
theotherjimmy 43:2a7da56ebd24 60 @staticmethod
theotherjimmy 43:2a7da56ebd24 61 def prepare_sys_lib(libname):
theotherjimmy 43:2a7da56ebd24 62 return "-l" + libname
theotherjimmy 43:2a7da56ebd24 63
theotherjimmy 43:2a7da56ebd24 64 def generate(self):
theotherjimmy 43:2a7da56ebd24 65 self.resources.win_to_unix()
theotherjimmy 43:2a7da56ebd24 66
theotherjimmy 43:2a7da56ebd24 67 comp_flags = []
theotherjimmy 43:2a7da56ebd24 68 debug_flags = []
theotherjimmy 43:2a7da56ebd24 69 release_flags = [ '-Os', '-g1' ]
theotherjimmy 43:2a7da56ebd24 70 next_is_include = False
theotherjimmy 43:2a7da56ebd24 71 for f in self.flags['c_flags'] + self.flags['cxx_flags'] + self.flags['common_flags']:
theotherjimmy 43:2a7da56ebd24 72 f = f.strip()
theotherjimmy 43:2a7da56ebd24 73 if f == "-include":
theotherjimmy 43:2a7da56ebd24 74 next_is_include = True
theotherjimmy 43:2a7da56ebd24 75 continue
theotherjimmy 43:2a7da56ebd24 76 if f == '-c':
theotherjimmy 43:2a7da56ebd24 77 continue
theotherjimmy 43:2a7da56ebd24 78 if next_is_include:
theotherjimmy 43:2a7da56ebd24 79 f = '-include ' + f
theotherjimmy 43:2a7da56ebd24 80 next_is_include = False
theotherjimmy 43:2a7da56ebd24 81 if f.startswith('-O') or f.startswith('-g'):
theotherjimmy 43:2a7da56ebd24 82 debug_flags.append(f)
theotherjimmy 43:2a7da56ebd24 83 else:
theotherjimmy 43:2a7da56ebd24 84 comp_flags.append(f)
theotherjimmy 43:2a7da56ebd24 85 comp_flags = sorted(list(set(comp_flags)))
theotherjimmy 43:2a7da56ebd24 86 inc_dirs = [self.filter_dot(s) for s in self.resources.inc_dirs];
theotherjimmy 43:2a7da56ebd24 87 inc_dirs = [x for x in inc_dirs if (x is not None and
theotherjimmy 43:2a7da56ebd24 88 x != '' and x != '.' and
theotherjimmy 43:2a7da56ebd24 89 not x.startswith('bin') and
theotherjimmy 43:2a7da56ebd24 90 not x.startswith('obj'))];
theotherjimmy 43:2a7da56ebd24 91
theotherjimmy 43:2a7da56ebd24 92 c_sources = sorted([self.filter_dot(s) for s in self.resources.c_sources])
theotherjimmy 43:2a7da56ebd24 93 libraries = [self.prepare_lib(basename(lib)) for lib in self.libraries]
theotherjimmy 43:2a7da56ebd24 94 sys_libs = [self.prepare_sys_lib(lib) for lib
theotherjimmy 43:2a7da56ebd24 95 in self.toolchain.sys_libs]
theotherjimmy 43:2a7da56ebd24 96 ncs36510fib = (hasattr(self.toolchain.target, 'post_binary_hook') and
theotherjimmy 43:2a7da56ebd24 97 self.toolchain.target.post_binary_hook['function'] == 'NCS36510TargetCode.ncs36510_addfib')
theotherjimmy 43:2a7da56ebd24 98 if ncs36510fib:
theotherjimmy 43:2a7da56ebd24 99 c_sources.append('ncs36510fib.c')
theotherjimmy 43:2a7da56ebd24 100 c_sources.append('ncs36510trim.c')
theotherjimmy 43:2a7da56ebd24 101
theotherjimmy 43:2a7da56ebd24 102 ctx = {
theotherjimmy 43:2a7da56ebd24 103 'project_name': self.project_name,
theotherjimmy 43:2a7da56ebd24 104 'debug_flags': debug_flags,
theotherjimmy 43:2a7da56ebd24 105 'release_flags': release_flags,
theotherjimmy 43:2a7da56ebd24 106 'comp_flags': comp_flags,
theotherjimmy 43:2a7da56ebd24 107 'ld_flags': self.flags['ld_flags'],
theotherjimmy 43:2a7da56ebd24 108 'headers': sorted(list(set([self.filter_dot(s) for s in self.resources.headers]))),
theotherjimmy 43:2a7da56ebd24 109 'c_sources': c_sources,
theotherjimmy 43:2a7da56ebd24 110 's_sources': sorted([self.filter_dot(s) for s in self.resources.s_sources]),
theotherjimmy 43:2a7da56ebd24 111 'cpp_sources': sorted([self.filter_dot(s) for s in self.resources.cpp_sources]),
theotherjimmy 43:2a7da56ebd24 112 'include_paths': inc_dirs,
theotherjimmy 43:2a7da56ebd24 113 'linker_script': self.filter_dot(self.resources.linker_script),
theotherjimmy 43:2a7da56ebd24 114 'libraries': libraries,
theotherjimmy 43:2a7da56ebd24 115 'sys_libs': sys_libs,
theotherjimmy 43:2a7da56ebd24 116 'ncs36510addfib': ncs36510fib,
theotherjimmy 43:2a7da56ebd24 117 'openocdboard': ''
theotherjimmy 43:2a7da56ebd24 118 }
theotherjimmy 43:2a7da56ebd24 119
theotherjimmy 43:2a7da56ebd24 120 openocd_board = {
theotherjimmy 43:2a7da56ebd24 121 'NCS36510': 'board/ncs36510_axdbg.cfg',
theotherjimmy 43:2a7da56ebd24 122 'DISCO_F429ZI': 'board/stm32f429discovery.cfg',
theotherjimmy 43:2a7da56ebd24 123 'DISCO_F469NI': 'board/stm32f469discovery.cfg',
theotherjimmy 43:2a7da56ebd24 124 'DISCO_L053C8': 'board/stm32l0discovery.cfg',
theotherjimmy 43:2a7da56ebd24 125 'DISCO_L072CZ_LRWAN1': 'board/stm32l0discovery.cfg',
theotherjimmy 43:2a7da56ebd24 126 'DISCO_F769NI': 'board/stm32f7discovery.cfg',
theotherjimmy 43:2a7da56ebd24 127 'DISCO_L475VG_IOT01A': 'board/stm32l4discovery.cfg',
theotherjimmy 43:2a7da56ebd24 128 'DISCO_L476VG': 'board/stm32l4discovery.cfg',
theotherjimmy 43:2a7da56ebd24 129 'NRF51822': 'board/nordic_nrf51822_mkit.cfg',
theotherjimmy 43:2a7da56ebd24 130 'NRF51822_BOOT': 'board/nordic_nrf51822_mkit.cfg',
theotherjimmy 43:2a7da56ebd24 131 'NRF51822_OTA': 'board/nordic_nrf51822_mkit.cfg',
theotherjimmy 43:2a7da56ebd24 132 'NRF51_DK_LEGACY': 'board/nordic_nrf51_dk.cfg',
theotherjimmy 43:2a7da56ebd24 133 'NRF51_DK_BOOT': 'board/nordic_nrf51_dk.cfg',
theotherjimmy 43:2a7da56ebd24 134 'NRF51_DK_OTA': 'board/nordic_nrf51_dk.cfg',
theotherjimmy 43:2a7da56ebd24 135 'NRF51_DK': 'board/nordic_nrf51_dk.cfg'
theotherjimmy 43:2a7da56ebd24 136 }
theotherjimmy 43:2a7da56ebd24 137
theotherjimmy 43:2a7da56ebd24 138 if self.target in openocd_board:
theotherjimmy 43:2a7da56ebd24 139 ctx['openocdboard'] = openocd_board[self.target]
theotherjimmy 43:2a7da56ebd24 140
theotherjimmy 43:2a7da56ebd24 141 self.gen_file('codeblocks/cbp.tmpl', ctx, "%s.%s" % (self.project_name, 'cbp'))
theotherjimmy 43:2a7da56ebd24 142 for f in [ 'obj', 'bin' ]:
theotherjimmy 43:2a7da56ebd24 143 if not isdir(f):
theotherjimmy 43:2a7da56ebd24 144 mkdir(f)
theotherjimmy 43:2a7da56ebd24 145 self.gen_file_nonoverwrite('codeblocks/mbedignore.tmpl',
theotherjimmy 43:2a7da56ebd24 146 ctx, f + '/.mbedignore')
theotherjimmy 43:2a7da56ebd24 147
theotherjimmy 43:2a7da56ebd24 148 if ncs36510fib:
theotherjimmy 43:2a7da56ebd24 149 genaddfiles = [ 'ncs36510fib.c', 'ncs36510trim.c' ]
theotherjimmy 43:2a7da56ebd24 150 for f in genaddfiles:
theotherjimmy 43:2a7da56ebd24 151 copyfile(os.path.join(dirname(abspath(__file__)), f),
theotherjimmy 43:2a7da56ebd24 152 self.gen_file_dest(f))
theotherjimmy 43:2a7da56ebd24 153 ignorefiles = genaddfiles
theotherjimmy 43:2a7da56ebd24 154 try:
theotherjimmy 43:2a7da56ebd24 155 with open(self.gen_file_dest('.mbedignore'), 'r') as f:
theotherjimmy 43:2a7da56ebd24 156 l = set(map(lambda x: x.strip(), f.readlines()))
theotherjimmy 43:2a7da56ebd24 157 ignorefiles = [x for x in genaddfiles if x not in l]
theotherjimmy 43:2a7da56ebd24 158 except IOError as e:
theotherjimmy 43:2a7da56ebd24 159 pass
theotherjimmy 43:2a7da56ebd24 160 except:
theotherjimmy 43:2a7da56ebd24 161 raise
theotherjimmy 43:2a7da56ebd24 162 if ignorefiles:
theotherjimmy 43:2a7da56ebd24 163 with open(self.gen_file_dest('.mbedignore'), 'a') as f:
theotherjimmy 43:2a7da56ebd24 164 for fi in ignorefiles:
theotherjimmy 43:2a7da56ebd24 165 f.write("%s\n" % fi)
theotherjimmy 43:2a7da56ebd24 166
theotherjimmy 43:2a7da56ebd24 167 # finally, generate the project file
theotherjimmy 43:2a7da56ebd24 168 super(CodeBlocks, self).generate()
theotherjimmy 43:2a7da56ebd24 169
theotherjimmy 43:2a7da56ebd24 170 @staticmethod
theotherjimmy 43:2a7da56ebd24 171 def clean(project_name):
theotherjimmy 43:2a7da56ebd24 172 for ext in ['cbp', 'depend', 'layout']:
theotherjimmy 43:2a7da56ebd24 173 remove("%s.%s" % (project_name, ext))
theotherjimmy 43:2a7da56ebd24 174 for f in ['openocd.log', 'ncs36510fib.c', 'ncs36510trim.c']:
theotherjimmy 43:2a7da56ebd24 175 remove(f)
theotherjimmy 43:2a7da56ebd24 176 for d in ['bin', 'obj']:
theotherjimmy 43:2a7da56ebd24 177 rmtree(d, ignore_errors=True)