BA / Mbed OS BaBoRo_test2
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers __init__.py Source File

__init__.py

00001 """
00002 mbed SDK
00003 Copyright (c) 2014-2017 ARM Limited
00004 Copyright (c) 2018 ON Semiconductor
00005 
00006 Licensed under the Apache License, Version 2.0 (the "License");
00007 you may not use this file except in compliance with the License.
00008 You may obtain a copy of the License at
00009 
00010     http://www.apache.org/licenses/LICENSE-2.0
00011 
00012 Unless required by applicable law or agreed to in writing, software
00013 distributed under the License is distributed on an "AS IS" BASIS,
00014 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00015 See the License for the specific language governing permissions and
00016 limitations under the License.
00017 """
00018 import copy
00019 import stat
00020 import os
00021 from os.path import splitext, basename, dirname, abspath, isdir
00022 from os import remove, mkdir
00023 from shutil import rmtree, copyfile
00024 from tools.targets import TARGET_MAP
00025 from tools.export.exporters import Exporter
00026 from tools.export.makefile import GccArm
00027 
00028 class CodeBlocks(GccArm ):
00029     NAME = 'Code::Blocks'
00030 
00031     DOT_IN_RELATIVE_PATH = True
00032 
00033     MBED_CONFIG_HEADER_SUPPORTED = True
00034 
00035     PREPROCESS_ASM = False
00036 
00037     POST_BINARY_WHITELIST = set([
00038         "NCS36510TargetCode.ncs36510_addfib"
00039     ])
00040 
00041     @staticmethod
00042     def filter_dot(str_in):
00043         """
00044         Remove the './' prefix, if present.
00045         This function assumes that resources.win_to_unix()
00046         replaced all windows backslashes with slashes.
00047         """
00048         if str_in is None:
00049             return None
00050         if str_in[:2] == './':
00051             return str_in[2:]
00052         return str_in
00053 
00054     @staticmethod
00055     def prepare_lib(libname):
00056         if "lib" == libname[:3]:
00057             libname = libname[3:-2]
00058         return "-l" + libname
00059 
00060     @staticmethod
00061     def prepare_sys_lib(libname):
00062         return "-l" + libname
00063 
00064     def generate(self):
00065         self.resources.win_to_unix()
00066 
00067         comp_flags = []
00068         debug_flags = []
00069         release_flags = [ '-Os', '-g1' ]
00070         next_is_include = False
00071         for f in self.flags['c_flags'] + self.flags['cxx_flags'] + self.flags['common_flags']:
00072             f = f.strip()
00073             if f == "-include":
00074                 next_is_include = True
00075                 continue
00076             if f == '-c':
00077                 continue
00078             if next_is_include:
00079                 f = '-include ' + f
00080             next_is_include = False
00081             if f.startswith('-O') or f.startswith('-g'):
00082                 debug_flags.append(f)
00083             else:
00084                 comp_flags.append(f)
00085         comp_flags = sorted(list(set(comp_flags)))
00086         inc_dirs = [self.filter_dot(s) for s in self.resources.inc_dirs];
00087         inc_dirs = [x for x in inc_dirs if (x is not None and
00088                                             x != '' and x != '.' and
00089                                             not x.startswith('bin') and
00090                                             not x.startswith('obj'))];
00091 
00092         c_sources = sorted([self.filter_dot(s) for s in self.resources.c_sources])
00093         libraries = [self.prepare_lib(basename(lib)) for lib
00094                      in self.resources.libraries]
00095         sys_libs = [self.prepare_sys_lib(lib) for lib
00096                     in self.toolchain.sys_libs]
00097 
00098         ctx = {
00099             'project_name': self.project_name,
00100             'debug_flags': debug_flags,
00101             'release_flags': release_flags,
00102             'comp_flags': comp_flags,
00103             'ld_flags': self.flags['ld_flags'],
00104             'headers': sorted(list(set([self.filter_dot(s) for s in self.resources.headers]))),
00105             'c_sources': c_sources,
00106             's_sources': sorted([self.filter_dot(s) for s in self.resources.s_sources]),
00107             'cpp_sources': sorted([self.filter_dot(s) for s in self.resources.cpp_sources]),
00108             'include_paths': inc_dirs,
00109             'linker_script': self.filter_dot(self.resources.linker_script),
00110             'libraries': libraries,
00111             'sys_libs': sys_libs,
00112             'openocdboard': ''
00113             }
00114 
00115         openocd_board = {
00116             'NCS36510': 'board/ncs36510_axdbg.cfg',
00117             'DISCO_F429ZI': 'board/stm32f429discovery.cfg',
00118             'DISCO_F469NI': 'board/stm32f469discovery.cfg',
00119             'DISCO_L053C8': 'board/stm32l0discovery.cfg',
00120             'DISCO_L072CZ_LRWAN1': 'board/stm32l0discovery.cfg',
00121             'DISCO_F769NI': 'board/stm32f7discovery.cfg',
00122             'DISCO_L475VG_IOT01A': 'board/stm32l4discovery.cfg',
00123             'DISCO_L476VG': 'board/stm32l4discovery.cfg',
00124             'NRF51822': 'board/nordic_nrf51822_mkit.cfg',
00125             'NRF51822_BOOT': 'board/nordic_nrf51822_mkit.cfg',
00126             'NRF51822_OTA': 'board/nordic_nrf51822_mkit.cfg',
00127             'NRF51_DK_LEGACY': 'board/nordic_nrf51_dk.cfg',
00128             'NRF51_DK_BOOT': 'board/nordic_nrf51_dk.cfg',
00129             'NRF51_DK_OTA': 'board/nordic_nrf51_dk.cfg',
00130             'NRF51_DK': 'board/nordic_nrf51_dk.cfg'
00131             }
00132 
00133         if self.target in openocd_board:
00134             ctx['openocdboard'] = openocd_board[self.target]
00135 
00136         self.gen_file('codeblocks/cbp.tmpl', ctx, "%s.%s" % (self.project_name, 'cbp'))
00137         for f in [ 'obj', 'bin' ]:
00138             if not isdir(f):
00139                 mkdir(f)
00140             self.gen_file_nonoverwrite('codeblocks/mbedignore.tmpl',
00141                                        ctx, f + '/.mbedignore')
00142 
00143         # finally, generate the project file
00144         super(CodeBlocks, self).generate()
00145 
00146     @staticmethod
00147     def clean(project_name):
00148         for ext in ['cbp', 'depend', 'layout']:
00149             remove("%s.%s" % (project_name, ext))
00150         for f in ['openocd.log']:
00151             remove(f)
00152         for d in ['bin', 'obj']:
00153             rmtree(d, ignore_errors=True)