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