Skip to content

Commit cd669a9

Browse files
committed
Add build options
Implement "save-asm" option
1 parent f4f34a0 commit cd669a9

File tree

9 files changed

+64
-40
lines changed

9 files changed

+64
-40
lines changed

workspace_tools/build.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,11 @@
8585
id = "%s::%s" % (toolchain, target)
8686
try:
8787
mcu = TARGET_MAP[target]
88-
build_mbed_libs(mcu, toolchain, verbose=options.verbose)
88+
build_mbed_libs(mcu, toolchain, options=options.options,
89+
verbose=options.verbose)
8990
for lib_id in libraries:
90-
build_lib(lib_id, mcu, toolchain, verbose=options.verbose)
91+
build_lib(lib_id, mcu, toolchain, options=options.options,
92+
verbose=options.verbose)
9193
successes.append(id)
9294
except Exception, e:
9395
if options.verbose:

workspace_tools/build_api.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99

1010

1111
def build_project(src_path, build_path, target, toolchain_name,
12-
libraries_paths=None, linker_script=None,
12+
libraries_paths=None, options=None, linker_script=None,
1313
clean=False, notify=None, verbose=False, name=None):
1414
# Toolchain instance
15-
toolchain = TOOLCHAIN_CLASSES[toolchain_name](target, notify)
15+
toolchain = TOOLCHAIN_CLASSES[toolchain_name](target, options, notify)
1616
toolchain.VERBOSE = verbose
1717
toolchain.build_all = clean
1818

@@ -50,15 +50,16 @@ def build_project(src_path, build_path, target, toolchain_name,
5050
verbose: Write the actual tools command lines if True
5151
"""
5252
def build_library(src_paths, build_path, target, toolchain_name,
53-
dependencies_paths=None, name=None, clean=False, notify=None, verbose=False):
53+
dependencies_paths=None, options=None, name=None, clean=False,
54+
notify=None, verbose=False):
5455
if type(src_paths) != ListType: src_paths = [src_paths]
5556

5657
for src_path in src_paths:
5758
if not exists(src_path):
5859
raise Exception("The library source folder does not exist: %s", src_path)
5960

6061
# Toolchain instance
61-
toolchain = TOOLCHAIN_CLASSES[toolchain_name](target, notify)
62+
toolchain = TOOLCHAIN_CLASSES[toolchain_name](target, options, notify)
6263
toolchain.VERBOSE = verbose
6364
toolchain.build_all = clean
6465

@@ -95,23 +96,23 @@ def build_library(src_paths, build_path, target, toolchain_name,
9596
toolchain.build_library(objects, bin_path, name)
9697

9798

98-
def build_lib(lib_id, target, toolchain, verbose=False):
99+
def build_lib(lib_id, target, toolchain, options=None, verbose=False):
99100
lib = Library(lib_id)
100101
if lib.is_supported(target, toolchain):
101-
build_library(lib.source_dir, lib.build_dir, target, toolchain, lib.dependencies, verbose=verbose)
102+
build_library(lib.source_dir, lib.build_dir, target, toolchain, lib.dependencies, options, verbose=verbose)
102103
else:
103104
print '\n\nLibrary "%s" is not yet supported on target %s with toolchain %s' % (lib_id, target.name, toolchain)
104105

105106

106107
# We do have unique legacy conventions about how we build and package the mbed library
107-
def build_mbed_libs(target, toolchain_name, verbose=False):
108+
def build_mbed_libs(target, toolchain_name, options=None, verbose=False):
108109
# Check toolchain support
109110
if toolchain_name not in target.supported_toolchains:
110111
print '\n%s target is not yet supported by toolchain %s' % (target.name, toolchain_name)
111112
return
112113

113114
# Toolchain
114-
toolchain = TOOLCHAIN_CLASSES[toolchain_name](target)
115+
toolchain = TOOLCHAIN_CLASSES[toolchain_name](target, options)
115116
toolchain.VERBOSE = verbose
116117

117118
# Source and Build Paths

workspace_tools/make.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ def args_error(parser, message):
9191
target = TARGET_MAP[mcu]
9292
try:
9393
bin = build_project(test.source_dir, build_dir, target, toolchain,
94-
test.dependencies, linker_script=options.linker_script,
94+
test.dependencies, options.options,
95+
linker_script=options.linker_script,
9596
clean=options.clean, verbose=options.verbose)
9697
print 'Image: %s' % bin
9798

workspace_tools/options.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,18 @@
77
def get_default_options_parser():
88
parser = OptionParser()
99

10-
parser.add_option("-m", "--mcu", dest="mcu",
10+
parser.add_option("-m", "--mcu",
1111
help="build for the given MCU (%s)" % ', '.join(TARGET_NAMES),
1212
metavar="MCU")
1313

14-
parser.add_option("-t", "--tool", dest="tool",
14+
parser.add_option("-t", "--tool",
1515
help="build using the given TOOLCHAIN (%s)" % ', '.join(TOOLCHAINS),
1616
metavar="TOOLCHAIN")
1717

18-
parser.add_option("-c", "--clean",
19-
action="store_true", dest="clean", default=False,
18+
parser.add_option("-c", "--clean", action="store_true", default=False,
2019
help="clean the build directory")
2120

21+
parser.add_option("-o", "--options", action="append",
22+
help='Add a build option ("save-asm": save the asm generated by the compiler)')
23+
2224
return parser

workspace_tools/settings.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@
7171
CW_GCC_PATH = "C:/Freescale/CW MCU v10.3/Cross_Tools/arm-none-eabi-gcc-4_6_2/bin"
7272
CW_EWL_PATH = "C:/Freescale/CW MCU v10.3/MCU/ARM_GCC_Support/ewl/lib"
7373

74+
BUILD_OPTIONS = []
75+
7476
try:
7577
# Allow to overwrite the default settings without the need to edit the
7678
# settings file stored in the repository

workspace_tools/toolchains/__init__.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from workspace_tools.utils import run_cmd, mkdir, rel_path, ToolException, split_path
99
from workspace_tools.patch import patch
10+
from workspace_tools.settings import BUILD_OPTIONS
1011

1112

1213
def print_notify(event):
@@ -110,14 +111,22 @@ class mbedToolchain:
110111
"Cortex-M4" : ["__CORTEX_M4", "ARM_MATH_CM4", "__FPU_PRESENT=1"],
111112
}
112113

113-
def __init__(self, target, notify=None):
114+
def __init__(self, target, options=None, notify=None):
114115
self.target = target
115116

116117
if notify is not None:
117118
self.notify = notify
118119
else:
119120
self.notify = print_notify
120121

122+
if options is None:
123+
self.options = []
124+
else:
125+
self.options = options
126+
self.options.extend(BUILD_OPTIONS)
127+
if self.options:
128+
self.info("Build Options: %s" % (', '.join(self.options)))
129+
121130
self.name = self.__class__.__name__
122131
self.obj_path = join(target.name, self.name)
123132

workspace_tools/toolchains/arm.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ class ARM(mbedToolchain):
1313
DIAGNOSTIC_PATTERN = re.compile('"(?P<file>[^"]+)", line (?P<line>\d+): (?P<severity>Warning|Error): (?P<message>.+)')
1414
DEP_PATTERN = re.compile('\S+:\s(?P<file>.+)\n')
1515

16-
def __init__(self, target, notify):
17-
mbedToolchain.__init__(self, target, notify)
16+
def __init__(self, target, options=None, notify=None):
17+
mbedToolchain.__init__(self, target, options, notify)
1818

1919
if target.core == "Cortex-M0+":
2020
cpu = "Cortex-M0"
@@ -27,7 +27,11 @@ def __init__(self, target, notify):
2727
"--cpu=%s" % cpu, "--gnu",
2828
"-Ospace", "--split_sections", "--apcs=interwork",
2929
"--brief_diagnostics", "--restrict"
30-
] # "--asm" "--interleave"
30+
]
31+
32+
if "save-asm" in self.options:
33+
common.extend(["--asm", "--interleave"])
34+
3135
common_c = [
3236
"--md", "--no_depend_system_headers",
3337
'-I%s' % ARM_INC
@@ -85,15 +89,15 @@ def binary(self, elf, bin):
8589

8690

8791
class ARM_STD(ARM):
88-
def __init__(self, target, notify=None):
89-
ARM.__init__(self, target, notify)
92+
def __init__(self, target, options=None, notify=None):
93+
ARM.__init__(self, target, options, notify)
9094
self.ld.append("--libpath=%s" % ARM_LIB)
9195

9296

9397
class ARM_MICRO(ARM):
9498
PATCHED_LIBRARY = True
9599

96-
def __init__(self, target, notify=None):
100+
def __init__(self, target, options=None, notify=None):
97101
ARM.__init__(self, target, notify)
98102

99103
# Compiler

workspace_tools/toolchains/gcc.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ class GCC(mbedToolchain):
1313
CIRCULAR_DEPENDENCIES = True
1414
DIAGNOSTIC_PATTERN = re.compile('((?P<line>\d+):)(\d+:)? (?P<severity>warning|error): (?P<message>.+)')
1515

16-
def __init__(self, target, notify, tool_path):
17-
mbedToolchain.__init__(self, target, notify)
16+
def __init__(self, target, options=None, notify=None, tool_path=""):
17+
mbedToolchain.__init__(self, target, options, notify)
1818

1919
if target.core == "Cortex-M0+":
2020
cpu = "cortex-m0"
@@ -34,9 +34,12 @@ def __init__(self, target, notify, tool_path):
3434
common_flags = ["-c", "-O2", "-Wall",
3535
"-fmessage-length=0", "-fno-exceptions", "-fno-builtin",
3636
"-ffunction-sections", "-fdata-sections",
37-
"-MMD", "-save-temps"
37+
"-MMD"
3838
] + self.cpu
3939

40+
if "save-asm" in self.options:
41+
common_flags.extends("-save-temps")
42+
4043
self.asm = [join(tool_path, "arm-none-eabi-as")] + self.cpu
4144

4245
self.cc = [join(tool_path, "arm-none-eabi-gcc"), "-std=gnu99"] + common_flags
@@ -112,8 +115,8 @@ def binary(self, elf, bin):
112115

113116

114117
class GCC_ARM(GCC):
115-
def __init__(self, target, notify=None):
116-
GCC.__init__(self, target, notify, GCC_ARM_PATH)
118+
def __init__(self, target, options=None, notify=None):
119+
GCC.__init__(self, target, options, notify, GCC_ARM_PATH)
117120

118121
# Use latest gcc nanolib
119122
self.ld.append("--specs=nano.specs")
@@ -124,8 +127,8 @@ def __init__(self, target, notify=None):
124127

125128

126129
class GCC_CR(GCC):
127-
def __init__(self, target, notify=None):
128-
GCC.__init__(self, target, notify, GCC_CR_PATH)
130+
def __init__(self, target, options=None, notify=None):
131+
GCC.__init__(self, target, options, notify, GCC_CR_PATH)
129132

130133
additional_compiler_flags = [
131134
"-D__NEWLIB__", "-D__CODE_RED", "-D__USE_CMSIS", "-DCPP_USE_HEAP",
@@ -137,22 +140,22 @@ def __init__(self, target, notify=None):
137140

138141

139142
class GCC_CS(GCC):
140-
def __init__(self, target, notify=None):
141-
GCC.__init__(self, target, notify, GCC_CS_PATH)
143+
def __init__(self, target, options=None, notify=None):
144+
GCC.__init__(self, target, options, notify, GCC_CS_PATH)
142145

143146

144147
class GCC_CW(GCC):
145148
ARCH_LIB = {
146149
"Cortex-M0+": "armv6-m",
147150
}
148151

149-
def __init__(self, target, notify=None):
150-
GCC.__init__(self, target, notify, CW_GCC_PATH)
152+
def __init__(self, target, options=None, notify=None):
153+
GCC.__init__(self, target, options, notify, CW_GCC_PATH)
151154

152155

153156
class GCC_CW_EWL(GCC_CW):
154-
def __init__(self, target, notify=None):
155-
GCC_CW.__init__(self, target, notify)
157+
def __init__(self, target, options=None, notify=None):
158+
GCC_CW.__init__(self, target, options, notify)
156159

157160
# Compiler
158161
common = [
@@ -170,7 +173,7 @@ def __init__(self, target, notify=None):
170173
# Linker
171174
self.sys_libs = []
172175
self.CIRCULAR_DEPENDENCIES = False
173-
self.ld = [join(GCC_CW_PATH, "arm-none-eabi-g++"),
176+
self.ld = [join(CW_GCC_PATH, "arm-none-eabi-g++"),
174177
"-Xlinker", "--gc-sections",
175178
"-L%s" % join(CW_EWL_PATH, "lib", GCC_CW.ARCH_LIB[target.core]),
176179
"-n", "-specs=ewl_c++.specs", "-mfloat-abi=soft",
@@ -180,5 +183,5 @@ def __init__(self, target, notify=None):
180183

181184

182185
class GCC_CW_NEWLIB(GCC_CW):
183-
def __init__(self, target, notify=None):
184-
GCC_CW.__init__(self, target, notify)
186+
def __init__(self, target, options=None, notify=None):
187+
GCC_CW.__init__(self, target, options, notify)

workspace_tools/toolchains/iar.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ class IAR(mbedToolchain):
1313

1414
DIAGNOSTIC_PATTERN = re.compile('"(?P<file>[^"]+)",(?P<line>[\d]+)\s+(?P<severity>Warning|Error)(?P<message>.+)')
1515

16-
def __init__(self, target, notify=None):
17-
mbedToolchain.__init__(self, target, notify)
16+
def __init__(self, target, options=None, notify=None):
17+
mbedToolchain.__init__(self, target, options, notify)
1818

1919
c_flags = [
2020
"-Oh",

0 commit comments

Comments
 (0)