Merge pull request #43 from screamerbg/master

Add reponse files for GCC, ARMCC and IAR linking
Bogdan Marinescu 2016-04-12 14:17:30 +03:00
commit 7996649d96
3 changed files with 132 additions and 31 deletions

View File

@ -15,7 +15,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
""" """
import re import re
from os.path import join from os.path import join, dirname
from tools.toolchains import mbedToolchain from tools.toolchains import mbedToolchain
from tools.settings import ARM_BIN, ARM_INC, ARM_LIB, MY_ARM_CLIB, ARM_CPPLIB from tools.settings import ARM_BIN, ARM_INC, ARM_LIB, MY_ARM_CLIB, ARM_CPPLIB
@ -83,14 +83,6 @@ class ARM(mbedToolchain):
if option in tool: if option in tool:
tool.remove(option) tool.remove(option)
def assemble(self, source, object, includes):
# Preprocess first, then assemble
tempfile = object + '.E.s'
return [
self.asm + ['-D%s' % s for s in self.get_symbols() + self.macros] + ["-I%s" % i for i in includes] + ["-E", "-o", tempfile, source],
self.hook.get_cmdline_assembler(self.asm + ["-o", object, tempfile])
]
def parse_dependencies(self, dep_path): def parse_dependencies(self, dep_path):
dependencies = [] dependencies = []
for line in open(dep_path).readlines(): for line in open(dep_path).readlines():
@ -126,6 +118,26 @@ class ARM(mbedToolchain):
def archive(self, objects, lib_path): def archive(self, objects, lib_path):
self.default_cmd([self.ar, '-r', lib_path] + objects) self.default_cmd([self.ar, '-r', lib_path] + objects)
@hook_tool
def assemble(self, source, object, includes):
# Preprocess first, then assemble
tempfile = object + '.E.s'
# Build preprocess assemble command
cmd_pre = self.asm + ['-D%s' % s for s in self.get_symbols() + self.macros] + ["-I%s" % i for i in includes] + ["-E", "-o", tempfile, source]
# Build main assemble command
cmd = self.asm + ["-o", object, tempfile]
# Call cmdline hook
cmd_pre = self.hook.get_cmdline_assembler(cmd_pre)
cmd = self.hook.get_cmdline_assembler(cmd)
# Return command array, don't execute
return [cmd_pre, cmd]
@hook_tool
def link(self, output, objects, libraries, lib_dirs, mem_map): def link(self, output, objects, libraries, lib_dirs, mem_map):
if len(lib_dirs): if len(lib_dirs):
args = ["-o", output, "--userlibpath", ",".join(lib_dirs), "--info=totals", "--list=.link_totals.txt"] args = ["-o", output, "--userlibpath", ",".join(lib_dirs), "--info=totals", "--list=.link_totals.txt"]
@ -135,26 +147,43 @@ class ARM(mbedToolchain):
if mem_map: if mem_map:
args.extend(["--scatter", mem_map]) args.extend(["--scatter", mem_map])
if hasattr(self.target, "link_cmdline_hook"): # Build linker command
args = self.target.link_cmdline_hook(self.__class__.__name__, args) cmd = self.ld + args + objects + libraries + self.sys_libs
self.default_cmd(self.ld + args + objects + libraries + self.sys_libs) # Call cmdline hook
cmd = self.hook.get_cmdline_linker(cmd)
# Split link command to linker executable + response file
link_files = join(dirname(output), ".link_files.txt")
with open(link_files, "wb") as f:
cmd_linker = cmd[0]
cmd_list = []
for c in cmd[1:]:
cmd_list.append(('"%s"' % c) if not c.startswith('-') else c)
string = " ".join(cmd_list).replace("\\", "/")
f.write(string)
# Exec command
self.default_cmd([cmd_linker, '--via', link_files])
@hook_tool @hook_tool
def binary(self, resources, elf, bin): def binary(self, resources, elf, bin):
args = [self.elf2bin, '--bin', '-o', bin, elf] # Build binary command
cmd = [self.elf2bin, '--bin', '-o', bin, elf]
if hasattr(self.target, "binary_cmdline_hook"): # Call cmdline hook
args = self.target.binary_cmdline_hook(self.__class__.__name__, args) cmd = self.hook.get_cmdline_binary(cmd)
# Exec command
self.default_cmd(cmd)
self.default_cmd(args)
class ARM_STD(ARM): class ARM_STD(ARM):
def __init__(self, target, options=None, notify=None, macros=None, silent=False, extra_verbose=False): def __init__(self, target, options=None, notify=None, macros=None, silent=False, extra_verbose=False):
ARM.__init__(self, target, options, notify, macros, silent, extra_verbose=extra_verbose) ARM.__init__(self, target, options, notify, macros, silent, extra_verbose=extra_verbose)
self.cc += ["-D__ASSERT_MSG"] self.cc += ["-D__ASSERT_MSG"]
self.cppc += ["-D__ASSERT_MSG"] self.cppc += ["-D__ASSERT_MSG"]
self.ld.append("--libpath=%s" % ARM_LIB) self.ld.extend(["--libpath", ARM_LIB])
class ARM_MICRO(ARM): class ARM_MICRO(ARM):
@ -185,4 +214,4 @@ class ARM_MICRO(ARM):
elif target.core in ["Cortex-M0", "Cortex-M0+"]: elif target.core in ["Cortex-M0", "Cortex-M0+"]:
self.sys_libs.extend([join(ARM_CPPLIB, lib+".l") for lib in ["cpp_ps", "cpprt_p"]]) self.sys_libs.extend([join(ARM_CPPLIB, lib+".l") for lib in ["cpp_ps", "cpprt_p"]])
else: else:
self.ld.append("--libpath=%s" % ARM_LIB) self.ld.extend(["--libpath", ARM_LIB])

View File

@ -15,7 +15,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
""" """
import re import re
from os.path import join, basename, splitext from os.path import join, basename, splitext, dirname
from tools.toolchains import mbedToolchain from tools.toolchains import mbedToolchain
from tools.settings import GCC_ARM_PATH, GCC_CR_PATH from tools.settings import GCC_ARM_PATH, GCC_CR_PATH
@ -97,9 +97,6 @@ class GCC(mbedToolchain):
self.ar = join(tool_path, "arm-none-eabi-ar") self.ar = join(tool_path, "arm-none-eabi-ar")
self.elf2bin = join(tool_path, "arm-none-eabi-objcopy") self.elf2bin = join(tool_path, "arm-none-eabi-objcopy")
def assemble(self, source, object, includes):
return [self.hook.get_cmdline_assembler(self.asm + ['-D%s' % s for s in self.get_symbols() + self.macros] + ["-I%s" % i for i in includes] + ["-o", object, source])]
def parse_dependencies(self, dep_path): def parse_dependencies(self, dep_path):
dependencies = [] dependencies = []
buff = open(dep_path).readlines() buff = open(dep_path).readlines()
@ -165,8 +162,24 @@ class GCC(mbedToolchain):
) )
def archive(self, objects, lib_path): def archive(self, objects, lib_path):
self.default_cmd([self.ar, "rcs", lib_path] + objects) # Build archive command
cmd = [self.ar, "rcs", lib_path] + objects
# Exec cmd
self.default_cmd(cmd)
@hook_tool
def assemble(self, source, object, includes):
# Build assemble command
cmd = self.asm + ['-D%s' % s for s in self.get_symbols() + self.macros] + ["-I%s" % i for i in includes] + ["-o", object, source]
# Call cmdline hook
cmd = self.hook.get_cmdline_assembler(cmd)
# Return command array, don't execute
return [cmd]
@hook_tool
def link(self, output, objects, libraries, lib_dirs, mem_map): def link(self, output, objects, libraries, lib_dirs, mem_map):
libs = [] libs = []
for l in libraries: for l in libraries:
@ -180,13 +193,39 @@ class GCC(mbedToolchain):
# image is not correctly retargeted # image is not correctly retargeted
if self.CIRCULAR_DEPENDENCIES: if self.CIRCULAR_DEPENDENCIES:
libs.extend(libs) libs.extend(libs)
# Build linker command
cmd = self.ld + ["-T", mem_map, "-o", output] + objects
for L in lib_dirs:
cmd.extend(['-L', L])
cmd.extend(libs)
self.default_cmd(self.hook.get_cmdline_linker(self.ld + ["-T%s" % mem_map, "-o", output] + # Call cmdline hook
objects + ["-L%s" % L for L in lib_dirs] + libs)) cmd = self.hook.get_cmdline_linker(cmd)
# Split link command to linker executable + response file
link_files = join(dirname(output), ".link_files.txt")
with open(link_files, "wb") as f:
cmd_linker = cmd[0]
cmd_list = []
for c in cmd[1:]:
cmd_list.append(('"%s"' % c) if not c.startswith('-') else c)
string = " ".join(cmd_list).replace("\\", "/")
f.write(string)
# Exec command
self.default_cmd([cmd_linker, "@%s" % link_files])
@hook_tool @hook_tool
def binary(self, resources, elf, bin): def binary(self, resources, elf, bin):
self.default_cmd(self.hook.get_cmdline_binary([self.elf2bin, "-O", "binary", elf, bin])) # Build binary command
cmd = [self.elf2bin, "-O", "binary", elf, bin]
# Call cmdline hook
cmd = self.hook.get_cmdline_binary(cmd)
# Exec command
self.default_cmd(cmd)
class GCC_ARM(GCC): class GCC_ARM(GCC):

View File

@ -16,7 +16,7 @@ limitations under the License.
""" """
import re import re
from os import remove from os import remove
from os.path import join, exists from os.path import join, exists, dirname
from tools.toolchains import mbedToolchain from tools.toolchains import mbedToolchain
from tools.settings import IAR_PATH from tools.settings import IAR_PATH
@ -103,18 +103,51 @@ class IAR(mbedToolchain):
return [path.strip() for path in open(dep_path).readlines() return [path.strip() for path in open(dep_path).readlines()
if (path and not path.isspace())] if (path and not path.isspace())]
@hook_tool
def assemble(self, source, object, includes): def assemble(self, source, object, includes):
return [self.hook.get_cmdline_assembler(self.asm + ['-D%s' % s for s in self.get_symbols() + self.macros] + ["-I%s" % i for i in includes] + ["-o", object, source])] # Build assemble command
cmd = self.asm + ['-D%s' % s for s in self.get_symbols() + self.macros] + ["-I%s" % i for i in includes] + ["-o", object, source]
# Call cmdline hook
cmd = self.hook.get_cmdline_assembler(cmd)
# Return command array, don't execute
return [cmd]
@hook_tool
def archive(self, objects, lib_path): def archive(self, objects, lib_path):
if exists(lib_path): if exists(lib_path):
remove(lib_path) remove(lib_path)
self.default_cmd([self.ar, lib_path] + objects) self.default_cmd([self.ar, lib_path] + objects)
@hook_tool
def link(self, output, objects, libraries, lib_dirs, mem_map): def link(self, output, objects, libraries, lib_dirs, mem_map):
args = [self.ld, "-o", output, "--config", mem_map, "--skip_dynamic_initialization"] # Build linker command
self.default_cmd(self.hook.get_cmdline_linker(args + objects + libraries)) cmd = [self.ld, "-o", output, "--config", mem_map, "--skip_dynamic_initialization"] + objects + libraries
# Call cmdline hook
cmd = self.hook.get_cmdline_linker(cmd)
# Split link command to linker executable + response file
link_files = join(dirname(output), ".link_files.txt")
with open(link_files, "wb") as f:
cmd_linker = cmd[0]
cmd_list = []
for c in cmd[1:]:
cmd_list.append(('"%s"' % c) if not c.startswith('-') else c)
string = " ".join(cmd_list).replace("\\", "/")
f.write(string)
# Exec command
self.default_cmd([cmd_linker, '-f', link_files])
@hook_tool @hook_tool
def binary(self, resources, elf, bin): def binary(self, resources, elf, bin):
self.default_cmd(self.hook.get_cmdline_binary([self.elf2bin, '--bin', elf, bin])) # Build binary command
cmd = [self.elf2bin, "--bin", elf, bin]
# Call cmdline hook
cmd = self.hook.get_cmdline_binary(cmd)
# Exec command
self.default_cmd(cmd)