Add build options

Implement "save-asm" option
pull/10/head
Emilio Monti 2013-07-02 16:43:29 +01:00
parent f4f34a025d
commit cd669a943f
9 changed files with 64 additions and 40 deletions

View File

@ -85,9 +85,11 @@ if __name__ == '__main__':
id = "%s::%s" % (toolchain, target)
try:
mcu = TARGET_MAP[target]
build_mbed_libs(mcu, toolchain, verbose=options.verbose)
build_mbed_libs(mcu, toolchain, options=options.options,
verbose=options.verbose)
for lib_id in libraries:
build_lib(lib_id, mcu, toolchain, verbose=options.verbose)
build_lib(lib_id, mcu, toolchain, options=options.options,
verbose=options.verbose)
successes.append(id)
except Exception, e:
if options.verbose:

View File

@ -9,10 +9,10 @@ from workspace_tools.libraries import Library
def build_project(src_path, build_path, target, toolchain_name,
libraries_paths=None, linker_script=None,
libraries_paths=None, options=None, linker_script=None,
clean=False, notify=None, verbose=False, name=None):
# Toolchain instance
toolchain = TOOLCHAIN_CLASSES[toolchain_name](target, notify)
toolchain = TOOLCHAIN_CLASSES[toolchain_name](target, options, notify)
toolchain.VERBOSE = verbose
toolchain.build_all = clean
@ -50,7 +50,8 @@ notify: Notify function for logs
verbose: Write the actual tools command lines if True
"""
def build_library(src_paths, build_path, target, toolchain_name,
dependencies_paths=None, name=None, clean=False, notify=None, verbose=False):
dependencies_paths=None, options=None, name=None, clean=False,
notify=None, verbose=False):
if type(src_paths) != ListType: src_paths = [src_paths]
for src_path in src_paths:
@ -58,7 +59,7 @@ def build_library(src_paths, build_path, target, toolchain_name,
raise Exception("The library source folder does not exist: %s", src_path)
# Toolchain instance
toolchain = TOOLCHAIN_CLASSES[toolchain_name](target, notify)
toolchain = TOOLCHAIN_CLASSES[toolchain_name](target, options, notify)
toolchain.VERBOSE = verbose
toolchain.build_all = clean
@ -95,23 +96,23 @@ def build_library(src_paths, build_path, target, toolchain_name,
toolchain.build_library(objects, bin_path, name)
def build_lib(lib_id, target, toolchain, verbose=False):
def build_lib(lib_id, target, toolchain, options=None, verbose=False):
lib = Library(lib_id)
if lib.is_supported(target, toolchain):
build_library(lib.source_dir, lib.build_dir, target, toolchain, lib.dependencies, verbose=verbose)
build_library(lib.source_dir, lib.build_dir, target, toolchain, lib.dependencies, options, verbose=verbose)
else:
print '\n\nLibrary "%s" is not yet supported on target %s with toolchain %s' % (lib_id, target.name, toolchain)
# We do have unique legacy conventions about how we build and package the mbed library
def build_mbed_libs(target, toolchain_name, verbose=False):
def build_mbed_libs(target, toolchain_name, options=None, verbose=False):
# Check toolchain support
if toolchain_name not in target.supported_toolchains:
print '\n%s target is not yet supported by toolchain %s' % (target.name, toolchain_name)
return
# Toolchain
toolchain = TOOLCHAIN_CLASSES[toolchain_name](target)
toolchain = TOOLCHAIN_CLASSES[toolchain_name](target, options)
toolchain.VERBOSE = verbose
# Source and Build Paths

View File

@ -91,7 +91,8 @@ if __name__ == '__main__':
target = TARGET_MAP[mcu]
try:
bin = build_project(test.source_dir, build_dir, target, toolchain,
test.dependencies, linker_script=options.linker_script,
test.dependencies, options.options,
linker_script=options.linker_script,
clean=options.clean, verbose=options.verbose)
print 'Image: %s' % bin

View File

@ -7,16 +7,18 @@ from workspace_tools.targets import TARGET_NAMES
def get_default_options_parser():
parser = OptionParser()
parser.add_option("-m", "--mcu", dest="mcu",
parser.add_option("-m", "--mcu",
help="build for the given MCU (%s)" % ', '.join(TARGET_NAMES),
metavar="MCU")
parser.add_option("-t", "--tool", dest="tool",
parser.add_option("-t", "--tool",
help="build using the given TOOLCHAIN (%s)" % ', '.join(TOOLCHAINS),
metavar="TOOLCHAIN")
parser.add_option("-c", "--clean",
action="store_true", dest="clean", default=False,
parser.add_option("-c", "--clean", action="store_true", default=False,
help="clean the build directory")
parser.add_option("-o", "--options", action="append",
help='Add a build option ("save-asm": save the asm generated by the compiler)')
return parser

View File

@ -71,6 +71,8 @@ IAR_PATH = "C:/Program Files (x86)/IAR Systems/Embedded Workbench 6.0/arm"
CW_GCC_PATH = "C:/Freescale/CW MCU v10.3/Cross_Tools/arm-none-eabi-gcc-4_6_2/bin"
CW_EWL_PATH = "C:/Freescale/CW MCU v10.3/MCU/ARM_GCC_Support/ewl/lib"
BUILD_OPTIONS = []
try:
# Allow to overwrite the default settings without the need to edit the
# settings file stored in the repository

View File

@ -7,6 +7,7 @@ from inspect import getmro
from workspace_tools.utils import run_cmd, mkdir, rel_path, ToolException, split_path
from workspace_tools.patch import patch
from workspace_tools.settings import BUILD_OPTIONS
def print_notify(event):
@ -110,7 +111,7 @@ class mbedToolchain:
"Cortex-M4" : ["__CORTEX_M4", "ARM_MATH_CM4", "__FPU_PRESENT=1"],
}
def __init__(self, target, notify=None):
def __init__(self, target, options=None, notify=None):
self.target = target
if notify is not None:
@ -118,6 +119,14 @@ class mbedToolchain:
else:
self.notify = print_notify
if options is None:
self.options = []
else:
self.options = options
self.options.extend(BUILD_OPTIONS)
if self.options:
self.info("Build Options: %s" % (', '.join(self.options)))
self.name = self.__class__.__name__
self.obj_path = join(target.name, self.name)

View File

@ -13,8 +13,8 @@ class ARM(mbedToolchain):
DIAGNOSTIC_PATTERN = re.compile('"(?P<file>[^"]+)", line (?P<line>\d+): (?P<severity>Warning|Error): (?P<message>.+)')
DEP_PATTERN = re.compile('\S+:\s(?P<file>.+)\n')
def __init__(self, target, notify):
mbedToolchain.__init__(self, target, notify)
def __init__(self, target, options=None, notify=None):
mbedToolchain.__init__(self, target, options, notify)
if target.core == "Cortex-M0+":
cpu = "Cortex-M0"
@ -27,7 +27,11 @@ class ARM(mbedToolchain):
"--cpu=%s" % cpu, "--gnu",
"-Ospace", "--split_sections", "--apcs=interwork",
"--brief_diagnostics", "--restrict"
] # "--asm" "--interleave"
]
if "save-asm" in self.options:
common.extend(["--asm", "--interleave"])
common_c = [
"--md", "--no_depend_system_headers",
'-I%s' % ARM_INC
@ -85,15 +89,15 @@ class ARM(mbedToolchain):
class ARM_STD(ARM):
def __init__(self, target, notify=None):
ARM.__init__(self, target, notify)
def __init__(self, target, options=None, notify=None):
ARM.__init__(self, target, options, notify)
self.ld.append("--libpath=%s" % ARM_LIB)
class ARM_MICRO(ARM):
PATCHED_LIBRARY = True
def __init__(self, target, notify=None):
def __init__(self, target, options=None, notify=None):
ARM.__init__(self, target, notify)
# Compiler

View File

@ -13,8 +13,8 @@ class GCC(mbedToolchain):
CIRCULAR_DEPENDENCIES = True
DIAGNOSTIC_PATTERN = re.compile('((?P<line>\d+):)(\d+:)? (?P<severity>warning|error): (?P<message>.+)')
def __init__(self, target, notify, tool_path):
mbedToolchain.__init__(self, target, notify)
def __init__(self, target, options=None, notify=None, tool_path=""):
mbedToolchain.__init__(self, target, options, notify)
if target.core == "Cortex-M0+":
cpu = "cortex-m0"
@ -34,9 +34,12 @@ class GCC(mbedToolchain):
common_flags = ["-c", "-O2", "-Wall",
"-fmessage-length=0", "-fno-exceptions", "-fno-builtin",
"-ffunction-sections", "-fdata-sections",
"-MMD", "-save-temps"
"-MMD"
] + self.cpu
if "save-asm" in self.options:
common_flags.extends("-save-temps")
self.asm = [join(tool_path, "arm-none-eabi-as")] + self.cpu
self.cc = [join(tool_path, "arm-none-eabi-gcc"), "-std=gnu99"] + common_flags
@ -112,8 +115,8 @@ class GCC(mbedToolchain):
class GCC_ARM(GCC):
def __init__(self, target, notify=None):
GCC.__init__(self, target, notify, GCC_ARM_PATH)
def __init__(self, target, options=None, notify=None):
GCC.__init__(self, target, options, notify, GCC_ARM_PATH)
# Use latest gcc nanolib
self.ld.append("--specs=nano.specs")
@ -124,8 +127,8 @@ class GCC_ARM(GCC):
class GCC_CR(GCC):
def __init__(self, target, notify=None):
GCC.__init__(self, target, notify, GCC_CR_PATH)
def __init__(self, target, options=None, notify=None):
GCC.__init__(self, target, options, notify, GCC_CR_PATH)
additional_compiler_flags = [
"-D__NEWLIB__", "-D__CODE_RED", "-D__USE_CMSIS", "-DCPP_USE_HEAP",
@ -137,8 +140,8 @@ class GCC_CR(GCC):
class GCC_CS(GCC):
def __init__(self, target, notify=None):
GCC.__init__(self, target, notify, GCC_CS_PATH)
def __init__(self, target, options=None, notify=None):
GCC.__init__(self, target, options, notify, GCC_CS_PATH)
class GCC_CW(GCC):
@ -146,13 +149,13 @@ class GCC_CW(GCC):
"Cortex-M0+": "armv6-m",
}
def __init__(self, target, notify=None):
GCC.__init__(self, target, notify, CW_GCC_PATH)
def __init__(self, target, options=None, notify=None):
GCC.__init__(self, target, options, notify, CW_GCC_PATH)
class GCC_CW_EWL(GCC_CW):
def __init__(self, target, notify=None):
GCC_CW.__init__(self, target, notify)
def __init__(self, target, options=None, notify=None):
GCC_CW.__init__(self, target, options, notify)
# Compiler
common = [
@ -170,7 +173,7 @@ class GCC_CW_EWL(GCC_CW):
# Linker
self.sys_libs = []
self.CIRCULAR_DEPENDENCIES = False
self.ld = [join(GCC_CW_PATH, "arm-none-eabi-g++"),
self.ld = [join(CW_GCC_PATH, "arm-none-eabi-g++"),
"-Xlinker", "--gc-sections",
"-L%s" % join(CW_EWL_PATH, "lib", GCC_CW.ARCH_LIB[target.core]),
"-n", "-specs=ewl_c++.specs", "-mfloat-abi=soft",
@ -180,5 +183,5 @@ class GCC_CW_EWL(GCC_CW):
class GCC_CW_NEWLIB(GCC_CW):
def __init__(self, target, notify=None):
GCC_CW.__init__(self, target, notify)
def __init__(self, target, options=None, notify=None):
GCC_CW.__init__(self, target, options, notify)

View File

@ -13,8 +13,8 @@ class IAR(mbedToolchain):
DIAGNOSTIC_PATTERN = re.compile('"(?P<file>[^"]+)",(?P<line>[\d]+)\s+(?P<severity>Warning|Error)(?P<message>.+)')
def __init__(self, target, notify=None):
mbedToolchain.__init__(self, target, notify)
def __init__(self, target, options=None, notify=None):
mbedToolchain.__init__(self, target, options, notify)
c_flags = [
"-Oh",