Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
__init__.py
00001 """ 00002 mbed SDK 00003 Copyright (c) 2011-2016 ARM Limited 00004 00005 Licensed under the Apache License, Version 2.0 (the "License"); 00006 you may not use this file except in compliance with the License. 00007 You may obtain a copy of the License at 00008 00009 http://www.apache.org/licenses/LICENSE-2.0 00010 00011 Unless required by applicable law or agreed to in writing, software 00012 distributed under the License is distributed on an "AS IS" BASIS, 00013 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 See the License for the specific language governing permissions and 00015 limitations under the License. 00016 """ 00017 from os.path import splitext, basename, relpath, join, abspath, dirname,\ 00018 exists 00019 from os import curdir, getcwd 00020 from jinja2.exceptions import TemplateNotFound 00021 from tools.export.exporters import Exporter 00022 from tools.utils import NotSupportedException 00023 from tools.targets import TARGET_MAP 00024 00025 00026 class Makefile (Exporter ): 00027 """Generic Makefile template that mimics the behavior of the python build 00028 system 00029 """ 00030 00031 DOT_IN_RELATIVE_PATH = True 00032 00033 MBED_CONFIG_HEADER_SUPPORTED = True 00034 00035 def generate (self): 00036 """Generate the makefile 00037 00038 Note: subclasses should not need to override this method 00039 """ 00040 self.resources.win_to_unix() 00041 00042 to_be_compiled = [splitext(src)[0] + ".o" for src in 00043 self.resources.s_sources + 00044 self.resources.c_sources + 00045 self.resources.cpp_sources] 00046 00047 libraries = [self.prepare_lib(basename(lib)) for lib 00048 in self.resources.libraries] 00049 00050 ctx = { 00051 'name': self.project_name, 00052 'to_be_compiled': to_be_compiled, 00053 'object_files': self.resources.objects, 00054 'include_paths': list(set(self.resources.inc_dirs)), 00055 'library_paths': self.resources.lib_dirs, 00056 'linker_script': self.resources.linker_script, 00057 'libraries': libraries, 00058 'hex_files': self.resources.hex_files, 00059 'vpath': (["../../.."] 00060 if (basename(dirname(dirname(self.export_dir))) 00061 == "projectfiles") 00062 else [".."]), 00063 'cc_cmd': " ".join(["\'" + part + "\'" for part 00064 in self.toolchain.cc]), 00065 'cppc_cmd': " ".join(["\'" + part + "\'" for part 00066 in self.toolchain.cppc]), 00067 'asm_cmd': " ".join(["\'" + part + "\'" for part 00068 in self.toolchain.asm]), 00069 'ld_cmd': " ".join(["\'" + part + "\'" for part 00070 in self.toolchain.ld]), 00071 'elf2bin_cmd': "\'" + self.toolchain.elf2bin + "\'", 00072 'link_script_ext': self.toolchain.LINKER_EXT, 00073 'link_script_option': self.LINK_SCRIPT_OPTION, 00074 'user_library_flag': self.USER_LIBRARY_FLAG, 00075 } 00076 00077 for key in ['include_paths', 'library_paths', 'linker_script', 00078 'hex_files']: 00079 if isinstance(ctx[key], list): 00080 ctx[key] = [ctx['vpath'][0] + "/" + t for t in ctx[key]] 00081 else: 00082 ctx[key] = ctx['vpath'][0] + "/" + ctx[key] 00083 if "../." not in ctx["include_paths"]: 00084 ctx["include_paths"] += ['../.'] 00085 for key in ['include_paths', 'library_paths', 'hex_files', 00086 'to_be_compiled']: 00087 ctx[key] = sorted(ctx[key]) 00088 ctx.update(self.flags) 00089 00090 for templatefile in \ 00091 ['makefile/%s_%s.tmpl' % (self.NAME.lower(), 00092 self.target.lower())] + \ 00093 ['makefile/%s_%s.tmpl' % (self.NAME.lower(), 00094 label.lower()) for label 00095 in self.toolchain.target.extra_labels] +\ 00096 ['makefile/%s.tmpl' % self.NAME.lower()]: 00097 try: 00098 self.gen_file(templatefile, ctx, 'Makefile') 00099 break 00100 except TemplateNotFound: 00101 pass 00102 else: 00103 raise NotSupportedException("This make tool is in development") 00104 00105 00106 class GccArm (Makefile ): 00107 """GCC ARM specific makefile target""" 00108 TARGETS = [target for target, obj in TARGET_MAP.iteritems() 00109 if "GCC_ARM" in obj.supported_toolchains] 00110 NAME = 'Make-GCC-ARM' 00111 TOOLCHAIN = "GCC_ARM" 00112 LINK_SCRIPT_OPTION = "-T" 00113 USER_LIBRARY_FLAG = "-L" 00114 00115 @staticmethod 00116 def prepare_lib(libname): 00117 return "-l:" + libname 00118 00119 00120 class Armc5 (Makefile ): 00121 """ARM Compiler 5 specific makefile target""" 00122 TARGETS = [target for target, obj in TARGET_MAP.iteritems() 00123 if "ARM" in obj.supported_toolchains] 00124 NAME = 'Make-ARMc5' 00125 TOOLCHAIN = "ARM" 00126 LINK_SCRIPT_OPTION = "--scatter" 00127 USER_LIBRARY_FLAG = "--userlibpath " 00128 00129 @staticmethod 00130 def prepare_lib(libname): 00131 return libname 00132 00133 00134 class IAR (Makefile ): 00135 """IAR specific makefile target""" 00136 TARGETS = [target for target, obj in TARGET_MAP.iteritems() 00137 if "IAR" in obj.supported_toolchains] 00138 NAME = 'Make-IAR' 00139 TOOLCHAIN = "IAR" 00140 LINK_SCRIPT_OPTION = "--config" 00141 USER_LIBRARY_FLAG = "-L" 00142 00143 @staticmethod 00144 def prepare_lib(libname): 00145 if "lib" == libname[:3]: 00146 libname = libname[3:] 00147 return "-l" + splitext(libname)[0]
Generated on Tue Jul 12 2022 17:34:33 by
