Clone of official tools
Diff: toolchains/gcc.py
- Revision:
- 36:96847d42f010
- Parent:
- 35:da9c89f8be7d
- Child:
- 40:7d3fa6b99b2b
--- a/toolchains/gcc.py Wed Feb 15 13:53:18 2017 -0600 +++ b/toolchains/gcc.py Thu Jun 22 11:12:28 2017 -0500 @@ -15,7 +15,8 @@ limitations under the License. """ import re -from os.path import join, basename, splitext +from os.path import join, basename, splitext, dirname, exists +from distutils.spawn import find_executable from tools.toolchains import mbedToolchain, TOOLCHAIN_PATHS from tools.hooks import hook_tool @@ -29,12 +30,13 @@ INDEX_PATTERN = re.compile('(?P<col>\s*)\^') def __init__(self, target, notify=None, macros=None, - silent=False, tool_path="", extra_verbose=False, - build_profile=None): + silent=False, extra_verbose=False, build_profile=None, + build_dir=None): mbedToolchain.__init__(self, target, notify, macros, silent, extra_verbose=extra_verbose, - build_profile=build_profile) + build_profile=build_profile, build_dir=build_dir) + tool_path=TOOLCHAIN_PATHS['GCC_ARM'] # Add flags for current size setting default_lib = "std" if hasattr(target, "default_lib"): @@ -58,7 +60,7 @@ cpu = target.core.lower() self.cpu = ["-mcpu=%s" % cpu] - if target.core.startswith("Cortex"): + if target.core.startswith("Cortex-M"): self.cpu.append("-mthumb") # FPU handling, M7 possibly to have double FPU @@ -92,7 +94,8 @@ self.flags['ld'] += self.cpu self.ld = [join(tool_path, "arm-none-eabi-gcc")] + self.flags['ld'] - self.sys_libs = ["stdc++", "supc++", "m", "c", "gcc"] + self.sys_libs = ["stdc++", "supc++", "m", "c", "gcc", "nosys"] + self.preproc = [join(tool_path, "arm-none-eabi-cpp"), "-E", "-P"] self.ar = join(tool_path, "arm-none-eabi-ar") self.elf2bin = join(tool_path, "arm-none-eabi-objcopy") @@ -125,7 +128,7 @@ # The warning/error notification is multiline msg = None for line in output.splitlines(): - match = GCC.DIAGNOSTIC_PATTERN.search(line) + match = self.DIAGNOSTIC_PATTERN.search(line) if match is not None: if msg is not None: self.cc_info(msg) @@ -142,7 +145,7 @@ } elif msg is not None: # Determine the warning/error column by calculating the ^ position - match = GCC.INDEX_PATTERN.match(line) + match = self.INDEX_PATTERN.match(line) if match is not None: msg['col'] = len(match.group('col')) self.cc_info(msg) @@ -213,6 +216,15 @@ libs.append("-l%s" % name[3:]) libs.extend(["-l%s" % l for l in self.sys_libs]) + # Preprocess + if mem_map: + preproc_output = join(dirname(output), ".link_script.ld") + cmd = (self.preproc + [mem_map] + self.ld[1:] + + [ "-o", preproc_output]) + self.cc_verbose("Preproc: %s" % ' '.join(cmd)) + self.default_cmd(cmd) + mem_map = preproc_output + # Build linker command map_file = splitext(output)[0] + ".map" cmd = self.ld + ["-o", output, "-Wl,-Map=%s" % map_file] + objects + ["-Wl,--start-group"] + libs + ["-Wl,--end-group"] @@ -249,7 +261,9 @@ @hook_tool def binary(self, resources, elf, bin): # Build binary command - cmd = [self.elf2bin, "-O", "binary", elf, bin] + _, fmt = splitext(bin) + bin_arg = {'.bin': 'binary', '.hex': 'ihex'}[fmt] + cmd = [self.elf2bin, "-O", bin_arg, elf, bin] # Call cmdline hook cmd = self.hook.get_cmdline_binary(cmd) @@ -258,46 +272,32 @@ self.cc_verbose("FromELF: %s" % ' '.join(cmd)) self.default_cmd(cmd) + @staticmethod + def name_mangle(name): + return "_Z%i%sv" % (len(name), name) -class GCC_ARM(GCC): + @staticmethod + def make_ld_define(name, value): + return "-D%s=0x%x" % (name, value) + + @staticmethod + def redirect_symbol(source, sync, build_dir): + return "-Wl,--defsym=%s=%s" % (source, sync) + @staticmethod def check_executable(): """Returns True if the executable (arm-none-eabi-gcc) location specified by the user exists OR the executable can be found on the PATH. Returns False otherwise.""" - return mbedToolchain.generic_check_executable("GCC_ARM", 'arm-none-eabi-gcc', 1) - - def __init__(self, target, notify=None, macros=None, - silent=False, extra_verbose=False, build_profile=None): - GCC.__init__(self, target, notify, macros, silent, - TOOLCHAIN_PATHS['GCC_ARM'], extra_verbose=extra_verbose, - build_profile=build_profile) - - self.sys_libs.append("nosys") - + if not TOOLCHAIN_PATHS['GCC_ARM'] or not exists(TOOLCHAIN_PATHS['GCC_ARM']): + if find_executable('arm-none-eabi-gcc'): + TOOLCHAIN_PATHS['GCC_ARM'] = '' + return True + else: + return False + else: + exec_name = join(TOOLCHAIN_PATHS['GCC_ARM'], 'arm-none-eabi-gcc') + return exists(exec_name) or exists(exec_name + '.exe') -class GCC_CR(GCC): - @staticmethod - def check_executable(): - """Returns True if the executable (arm-none-eabi-gcc) location - specified by the user exists OR the executable can be found on the PATH. - Returns False otherwise.""" - return mbedToolchain.generic_check_executable("GCC_CR", 'arm-none-eabi-gcc', 1) - - def __init__(self, target, notify=None, macros=None, - silent=False, extra_verbose=False, build_profile=None): - GCC.__init__(self, target, notify, macros, silent, - TOOLCHAIN_PATHS['GCC_CR'], extra_verbose=extra_verbose, - build_profile=build_profile) - - additional_compiler_flags = [ - "-D__NEWLIB__", "-D__CODE_RED", "-D__USE_CMSIS", "-DCPP_USE_HEAP", - ] - self.cc += additional_compiler_flags - self.cppc += additional_compiler_flags - - # Use latest gcc nanolib - self.ld.append("--specs=nano.specs") - if target.name in ["LPC1768", "LPC4088", "LPC4088_DM", "LPC4330", "UBLOX_C027", "LPC2368"]: - self.ld.extend(["-u _printf_float", "-u _scanf_float"]) - self.ld += ["-nostdlib"] +class GCC_ARM(GCC): + pass