Added macro definition from command line

build_api.py now support macros defined at compile time, so build.py and
make.py can be used like this:

$ make.py/build.py <options> -DMACRO1 -DMACRO2=VALUE2 ...
pull/88/head^2
Bogdan Marinescu 2013-10-21 11:11:06 +03:00
parent 5e6262a91a
commit 1bb844c842
7 changed files with 43 additions and 35 deletions

View File

@ -52,6 +52,8 @@ if __name__ == '__main__':
default=False, help="Verbose diagnostic output")
parser.add_option("-b", "--ublox", action="store_true", dest="ublox",
default=False, help="Compile the u-blox library")
parser.add_option("-D", "", action="append", dest="macros",
help="Add a macro definition")
(options, args) = parser.parse_args()
# Get target list
@ -92,10 +94,12 @@ if __name__ == '__main__':
try:
mcu = TARGET_MAP[target]
build_mbed_libs(mcu, toolchain, options=options.options,
verbose=options.verbose, clean=options.clean)
verbose=options.verbose, clean=options.clean,
macros=options.macros)
for lib_id in libraries:
build_lib(lib_id, mcu, toolchain, options=options.options,
verbose=options.verbose, clean=options.clean)
verbose=options.verbose, clean=options.clean,
macros=options.macros)
successes.append(id)
except Exception, e:
if options.verbose:

View File

@ -26,9 +26,9 @@ from workspace_tools.libraries import Library
def build_project(src_path, build_path, target, toolchain_name,
libraries_paths=None, options=None, linker_script=None,
clean=False, notify=None, verbose=False, name=None):
clean=False, notify=None, verbose=False, name=None, macros=None):
# Toolchain instance
toolchain = TOOLCHAIN_CLASSES[toolchain_name](target, options, notify)
toolchain = TOOLCHAIN_CLASSES[toolchain_name](target, options, notify, macros)
toolchain.VERBOSE = verbose
toolchain.build_all = clean
@ -40,7 +40,6 @@ def build_project(src_path, build_path, target, toolchain_name,
# Scan src_path and libraries_paths for resources
resources = toolchain.scan_resources(src_paths[0])
for path in src_paths[1:]:
print "PATH:", path
resources.add(toolchain.scan_resources(path))
if libraries_paths is not None:
src_paths.extend(libraries_paths)
@ -78,7 +77,7 @@ verbose: Write the actual tools command lines if True
"""
def build_library(src_paths, build_path, target, toolchain_name,
dependencies_paths=None, options=None, name=None, clean=False,
notify=None, verbose=False):
notify=None, verbose=False, macros=None):
if type(src_paths) != ListType: src_paths = [src_paths]
for src_path in src_paths:
@ -86,7 +85,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, options, notify)
toolchain = TOOLCHAIN_CLASSES[toolchain_name](target, options, notify, macros)
toolchain.VERBOSE = verbose
toolchain.build_all = clean
@ -136,14 +135,14 @@ def build_lib(lib_id, target, toolchain, options=None, verbose=False, clean=Fals
# We do have unique legacy conventions about how we build and package the mbed library
def build_mbed_libs(target, toolchain_name, options=None, verbose=False, clean=False):
def build_mbed_libs(target, toolchain_name, options=None, verbose=False, clean=False, macros=None):
# 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, options)
toolchain = TOOLCHAIN_CLASSES[toolchain_name](target, options, macros=macros)
toolchain.VERBOSE = verbose
toolchain.build_all = clean
@ -192,3 +191,4 @@ def build_mbed_libs(target, toolchain_name, options=None, verbose=False, clean=F
objects.remove(retargeting)
toolchain.build_library(objects, BUILD_TOOLCHAIN, "mbed")
toolchain.copy_files(retargeting, BUILD_TOOLCHAIN)

View File

@ -48,6 +48,8 @@ if __name__ == '__main__':
help="The name of the desired test program")
parser.add_option("-v", "--verbose", action="store_true", dest="verbose",
default=False, help="Verbose diagnostic output")
parser.add_option("-D", "", action="append", dest="macros",
help="Add a macro definition")
# Local run
parser.add_option("-d", "--disk", dest="disk",
@ -114,7 +116,8 @@ if __name__ == '__main__':
bin = build_project(test.source_dir, build_dir, target, toolchain,
test.dependencies, options.options,
linker_script=options.linker_script,
clean=options.clean, verbose=options.verbose)
clean=options.clean, verbose=options.verbose,
macros=options.macros)
print 'Image: %s' % bin
if options.disk:

View File

@ -146,7 +146,7 @@ class mbedToolchain:
GOANNA_FORMAT = "[Goanna] warning [%FILENAME%:%LINENO%] - [%CHECKNAME%(%SEVERITY%)] %MESSAGE%"
GOANNA_DIAGNOSTIC_PATTERN = re.compile(r'"\[Goanna\] (?P<severity>warning) \[(?P<file>[^:]+):(?P<line>\d+)\] \- (?P<message>.*)"')
def __init__(self, target, options=None, notify=None):
def __init__(self, target, options=None, notify=None, macros=None):
self.target = target
self.name = self.__class__.__name__
self.hook = hooks.Hook(target, self)
@ -162,6 +162,7 @@ class mbedToolchain:
self.options = []
else:
self.options = options
self.macros = macros or []
self.options.extend(BUILD_OPTIONS)
if self.options:
self.info("Build Options: %s" % (', '.join(self.options)))
@ -347,7 +348,7 @@ class mbedToolchain:
self.progress("compile", source, build_update=True)
# Compile
command = cc + ['-D%s' % s for s in self.get_symbols()] + ["-I%s" % i for i in includes] + ["-o", object, source]
command = cc + ['-D%s' % s for s in self.get_symbols() + self.macros] + ["-I%s" % i for i in includes] + ["-o", object, source]
if hasattr(self, "get_dep_opt"):
command.extend(self.get_dep_opt(dep_path))

View File

@ -30,8 +30,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, options=None, notify=None):
mbedToolchain.__init__(self, target, options, notify)
def __init__(self, target, options=None, notify=None, macros=None):
mbedToolchain.__init__(self, target, options, notify, macros)
if target.core == "Cortex-M0+":
cpu = "Cortex-M0"
@ -123,16 +123,16 @@ class ARM(mbedToolchain):
class ARM_STD(ARM):
def __init__(self, target, options=None, notify=None):
ARM.__init__(self, target, options, notify)
def __init__(self, target, options=None, notify=None, macros=None):
ARM.__init__(self, target, options, notify, macros)
self.ld.append("--libpath=%s" % ARM_LIB)
class ARM_MICRO(ARM):
PATCHED_LIBRARY = False
def __init__(self, target, options=None, notify=None):
ARM.__init__(self, target, notify)
def __init__(self, target, options=None, notify=None, macros=None):
ARM.__init__(self, target, options, notify, macros)
# Compiler
self.asm += ["-D__MICROLIB"]

View File

@ -29,8 +29,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, options=None, notify=None, tool_path=""):
mbedToolchain.__init__(self, target, options, notify)
def __init__(self, target, options=None, notify=None, macros=None, tool_path=""):
mbedToolchain.__init__(self, target, options, notify, macros)
if target.core == "Cortex-M0+":
cpu = "cortex-m0"
@ -162,8 +162,8 @@ class GCC(mbedToolchain):
class GCC_ARM(GCC):
def __init__(self, target, options=None, notify=None):
GCC.__init__(self, target, options, notify, GCC_ARM_PATH)
def __init__(self, target, options=None, notify=None, macros=None):
GCC.__init__(self, target, options, notify, macros, GCC_ARM_PATH)
# Use latest gcc nanolib
self.ld.append("--specs=nano.specs")
@ -174,8 +174,8 @@ class GCC_ARM(GCC):
class GCC_CR(GCC):
def __init__(self, target, options=None, notify=None):
GCC.__init__(self, target, options, notify, GCC_CR_PATH)
def __init__(self, target, options=None, notify=None, macros=None):
GCC.__init__(self, target, options, notify, macros, GCC_CR_PATH)
additional_compiler_flags = [
"-D__NEWLIB__", "-D__CODE_RED", "-D__USE_CMSIS", "-DCPP_USE_HEAP",
@ -187,8 +187,8 @@ class GCC_CR(GCC):
class GCC_CS(GCC):
def __init__(self, target, options=None, notify=None):
GCC.__init__(self, target, options, notify, GCC_CS_PATH)
def __init__(self, target, options=None, notify=None, macros=None):
GCC.__init__(self, target, options, notify, macros, GCC_CS_PATH)
class GCC_CW(GCC):
@ -196,13 +196,13 @@ class GCC_CW(GCC):
"Cortex-M0+": "armv6-m",
}
def __init__(self, target, options=None, notify=None):
GCC.__init__(self, target, options, notify, CW_GCC_PATH)
def __init__(self, target, options=None, notify=None, macros=None):
GCC.__init__(self, target, options, notify, macros, CW_GCC_PATH)
class GCC_CW_EWL(GCC_CW):
def __init__(self, target, options=None, notify=None):
GCC_CW.__init__(self, target, options, notify)
def __init__(self, target, options=None, notify=None, macros=None):
GCC_CW.__init__(self, target, options, notify, macros)
# Compiler
common = [
@ -230,5 +230,5 @@ class GCC_CW_EWL(GCC_CW):
class GCC_CW_NEWLIB(GCC_CW):
def __init__(self, target, options=None, notify=None):
GCC_CW.__init__(self, target, options, notify)
def __init__(self, target, options=None, notify=None, macros=None):
GCC_CW.__init__(self, target, options, notify, macros)

View File

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