mirror of https://github.com/ARMmbed/mbed-os.git
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
parent
5e6262a91a
commit
1bb844c842
|
@ -52,6 +52,8 @@ if __name__ == '__main__':
|
||||||
default=False, help="Verbose diagnostic output")
|
default=False, help="Verbose diagnostic output")
|
||||||
parser.add_option("-b", "--ublox", action="store_true", dest="ublox",
|
parser.add_option("-b", "--ublox", action="store_true", dest="ublox",
|
||||||
default=False, help="Compile the u-blox library")
|
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()
|
(options, args) = parser.parse_args()
|
||||||
|
|
||||||
# Get target list
|
# Get target list
|
||||||
|
@ -92,10 +94,12 @@ if __name__ == '__main__':
|
||||||
try:
|
try:
|
||||||
mcu = TARGET_MAP[target]
|
mcu = TARGET_MAP[target]
|
||||||
build_mbed_libs(mcu, toolchain, options=options.options,
|
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:
|
for lib_id in libraries:
|
||||||
build_lib(lib_id, mcu, toolchain, options=options.options,
|
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)
|
successes.append(id)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
if options.verbose:
|
if options.verbose:
|
||||||
|
|
|
@ -26,9 +26,9 @@ from workspace_tools.libraries import Library
|
||||||
|
|
||||||
def build_project(src_path, build_path, target, toolchain_name,
|
def build_project(src_path, build_path, target, toolchain_name,
|
||||||
libraries_paths=None, options=None, linker_script=None,
|
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 instance
|
||||||
toolchain = TOOLCHAIN_CLASSES[toolchain_name](target, options, notify)
|
toolchain = TOOLCHAIN_CLASSES[toolchain_name](target, options, notify, macros)
|
||||||
toolchain.VERBOSE = verbose
|
toolchain.VERBOSE = verbose
|
||||||
toolchain.build_all = clean
|
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
|
# Scan src_path and libraries_paths for resources
|
||||||
resources = toolchain.scan_resources(src_paths[0])
|
resources = toolchain.scan_resources(src_paths[0])
|
||||||
for path in src_paths[1:]:
|
for path in src_paths[1:]:
|
||||||
print "PATH:", path
|
|
||||||
resources.add(toolchain.scan_resources(path))
|
resources.add(toolchain.scan_resources(path))
|
||||||
if libraries_paths is not None:
|
if libraries_paths is not None:
|
||||||
src_paths.extend(libraries_paths)
|
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,
|
def build_library(src_paths, build_path, target, toolchain_name,
|
||||||
dependencies_paths=None, options=None, name=None, clean=False,
|
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]
|
if type(src_paths) != ListType: src_paths = [src_paths]
|
||||||
|
|
||||||
for src_path in 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)
|
raise Exception("The library source folder does not exist: %s", src_path)
|
||||||
|
|
||||||
# Toolchain instance
|
# Toolchain instance
|
||||||
toolchain = TOOLCHAIN_CLASSES[toolchain_name](target, options, notify)
|
toolchain = TOOLCHAIN_CLASSES[toolchain_name](target, options, notify, macros)
|
||||||
toolchain.VERBOSE = verbose
|
toolchain.VERBOSE = verbose
|
||||||
toolchain.build_all = clean
|
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
|
# 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
|
# Check toolchain support
|
||||||
if toolchain_name not in target.supported_toolchains:
|
if toolchain_name not in target.supported_toolchains:
|
||||||
print '\n%s target is not yet supported by toolchain %s' % (target.name, toolchain_name)
|
print '\n%s target is not yet supported by toolchain %s' % (target.name, toolchain_name)
|
||||||
return
|
return
|
||||||
|
|
||||||
# Toolchain
|
# Toolchain
|
||||||
toolchain = TOOLCHAIN_CLASSES[toolchain_name](target, options)
|
toolchain = TOOLCHAIN_CLASSES[toolchain_name](target, options, macros=macros)
|
||||||
toolchain.VERBOSE = verbose
|
toolchain.VERBOSE = verbose
|
||||||
toolchain.build_all = clean
|
toolchain.build_all = clean
|
||||||
|
|
||||||
|
@ -192,3 +191,4 @@ def build_mbed_libs(target, toolchain_name, options=None, verbose=False, clean=F
|
||||||
objects.remove(retargeting)
|
objects.remove(retargeting)
|
||||||
toolchain.build_library(objects, BUILD_TOOLCHAIN, "mbed")
|
toolchain.build_library(objects, BUILD_TOOLCHAIN, "mbed")
|
||||||
toolchain.copy_files(retargeting, BUILD_TOOLCHAIN)
|
toolchain.copy_files(retargeting, BUILD_TOOLCHAIN)
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,9 @@ if __name__ == '__main__':
|
||||||
help="The name of the desired test program")
|
help="The name of the desired test program")
|
||||||
parser.add_option("-v", "--verbose", action="store_true", dest="verbose",
|
parser.add_option("-v", "--verbose", action="store_true", dest="verbose",
|
||||||
default=False, help="Verbose diagnostic output")
|
default=False, help="Verbose diagnostic output")
|
||||||
|
parser.add_option("-D", "", action="append", dest="macros",
|
||||||
|
help="Add a macro definition")
|
||||||
|
|
||||||
# Local run
|
# Local run
|
||||||
parser.add_option("-d", "--disk", dest="disk",
|
parser.add_option("-d", "--disk", dest="disk",
|
||||||
default=None, help="The mbed disk")
|
default=None, help="The mbed disk")
|
||||||
|
@ -114,7 +116,8 @@ if __name__ == '__main__':
|
||||||
bin = build_project(test.source_dir, build_dir, target, toolchain,
|
bin = build_project(test.source_dir, build_dir, target, toolchain,
|
||||||
test.dependencies, options.options,
|
test.dependencies, options.options,
|
||||||
linker_script=options.linker_script,
|
linker_script=options.linker_script,
|
||||||
clean=options.clean, verbose=options.verbose)
|
clean=options.clean, verbose=options.verbose,
|
||||||
|
macros=options.macros)
|
||||||
print 'Image: %s' % bin
|
print 'Image: %s' % bin
|
||||||
|
|
||||||
if options.disk:
|
if options.disk:
|
||||||
|
|
|
@ -146,7 +146,7 @@ class mbedToolchain:
|
||||||
GOANNA_FORMAT = "[Goanna] warning [%FILENAME%:%LINENO%] - [%CHECKNAME%(%SEVERITY%)] %MESSAGE%"
|
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>.*)"')
|
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.target = target
|
||||||
self.name = self.__class__.__name__
|
self.name = self.__class__.__name__
|
||||||
self.hook = hooks.Hook(target, self)
|
self.hook = hooks.Hook(target, self)
|
||||||
|
@ -162,6 +162,7 @@ class mbedToolchain:
|
||||||
self.options = []
|
self.options = []
|
||||||
else:
|
else:
|
||||||
self.options = options
|
self.options = options
|
||||||
|
self.macros = macros or []
|
||||||
self.options.extend(BUILD_OPTIONS)
|
self.options.extend(BUILD_OPTIONS)
|
||||||
if self.options:
|
if self.options:
|
||||||
self.info("Build Options: %s" % (', '.join(self.options)))
|
self.info("Build Options: %s" % (', '.join(self.options)))
|
||||||
|
@ -347,7 +348,7 @@ class mbedToolchain:
|
||||||
self.progress("compile", source, build_update=True)
|
self.progress("compile", source, build_update=True)
|
||||||
|
|
||||||
# Compile
|
# 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"):
|
if hasattr(self, "get_dep_opt"):
|
||||||
command.extend(self.get_dep_opt(dep_path))
|
command.extend(self.get_dep_opt(dep_path))
|
||||||
|
|
||||||
|
|
|
@ -30,8 +30,8 @@ class ARM(mbedToolchain):
|
||||||
DIAGNOSTIC_PATTERN = re.compile('"(?P<file>[^"]+)", line (?P<line>\d+): (?P<severity>Warning|Error): (?P<message>.+)')
|
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')
|
DEP_PATTERN = re.compile('\S+:\s(?P<file>.+)\n')
|
||||||
|
|
||||||
def __init__(self, target, options=None, notify=None):
|
def __init__(self, target, options=None, notify=None, macros=None):
|
||||||
mbedToolchain.__init__(self, target, options, notify)
|
mbedToolchain.__init__(self, target, options, notify, macros)
|
||||||
|
|
||||||
if target.core == "Cortex-M0+":
|
if target.core == "Cortex-M0+":
|
||||||
cpu = "Cortex-M0"
|
cpu = "Cortex-M0"
|
||||||
|
@ -123,16 +123,16 @@ class ARM(mbedToolchain):
|
||||||
|
|
||||||
|
|
||||||
class ARM_STD(ARM):
|
class ARM_STD(ARM):
|
||||||
def __init__(self, target, options=None, notify=None):
|
def __init__(self, target, options=None, notify=None, macros=None):
|
||||||
ARM.__init__(self, target, options, notify)
|
ARM.__init__(self, target, options, notify, macros)
|
||||||
self.ld.append("--libpath=%s" % ARM_LIB)
|
self.ld.append("--libpath=%s" % ARM_LIB)
|
||||||
|
|
||||||
|
|
||||||
class ARM_MICRO(ARM):
|
class ARM_MICRO(ARM):
|
||||||
PATCHED_LIBRARY = False
|
PATCHED_LIBRARY = False
|
||||||
|
|
||||||
def __init__(self, target, options=None, notify=None):
|
def __init__(self, target, options=None, notify=None, macros=None):
|
||||||
ARM.__init__(self, target, notify)
|
ARM.__init__(self, target, options, notify, macros)
|
||||||
|
|
||||||
# Compiler
|
# Compiler
|
||||||
self.asm += ["-D__MICROLIB"]
|
self.asm += ["-D__MICROLIB"]
|
||||||
|
|
|
@ -29,8 +29,8 @@ class GCC(mbedToolchain):
|
||||||
CIRCULAR_DEPENDENCIES = True
|
CIRCULAR_DEPENDENCIES = True
|
||||||
DIAGNOSTIC_PATTERN = re.compile('((?P<line>\d+):)(\d+:)? (?P<severity>warning|error): (?P<message>.+)')
|
DIAGNOSTIC_PATTERN = re.compile('((?P<line>\d+):)(\d+:)? (?P<severity>warning|error): (?P<message>.+)')
|
||||||
|
|
||||||
def __init__(self, target, options=None, notify=None, tool_path=""):
|
def __init__(self, target, options=None, notify=None, macros=None, tool_path=""):
|
||||||
mbedToolchain.__init__(self, target, options, notify)
|
mbedToolchain.__init__(self, target, options, notify, macros)
|
||||||
|
|
||||||
if target.core == "Cortex-M0+":
|
if target.core == "Cortex-M0+":
|
||||||
cpu = "cortex-m0"
|
cpu = "cortex-m0"
|
||||||
|
@ -162,8 +162,8 @@ class GCC(mbedToolchain):
|
||||||
|
|
||||||
|
|
||||||
class GCC_ARM(GCC):
|
class GCC_ARM(GCC):
|
||||||
def __init__(self, target, options=None, notify=None):
|
def __init__(self, target, options=None, notify=None, macros=None):
|
||||||
GCC.__init__(self, target, options, notify, GCC_ARM_PATH)
|
GCC.__init__(self, target, options, notify, macros, GCC_ARM_PATH)
|
||||||
|
|
||||||
# Use latest gcc nanolib
|
# Use latest gcc nanolib
|
||||||
self.ld.append("--specs=nano.specs")
|
self.ld.append("--specs=nano.specs")
|
||||||
|
@ -174,8 +174,8 @@ class GCC_ARM(GCC):
|
||||||
|
|
||||||
|
|
||||||
class GCC_CR(GCC):
|
class GCC_CR(GCC):
|
||||||
def __init__(self, target, options=None, notify=None):
|
def __init__(self, target, options=None, notify=None, macros=None):
|
||||||
GCC.__init__(self, target, options, notify, GCC_CR_PATH)
|
GCC.__init__(self, target, options, notify, macros, GCC_CR_PATH)
|
||||||
|
|
||||||
additional_compiler_flags = [
|
additional_compiler_flags = [
|
||||||
"-D__NEWLIB__", "-D__CODE_RED", "-D__USE_CMSIS", "-DCPP_USE_HEAP",
|
"-D__NEWLIB__", "-D__CODE_RED", "-D__USE_CMSIS", "-DCPP_USE_HEAP",
|
||||||
|
@ -187,8 +187,8 @@ class GCC_CR(GCC):
|
||||||
|
|
||||||
|
|
||||||
class GCC_CS(GCC):
|
class GCC_CS(GCC):
|
||||||
def __init__(self, target, options=None, notify=None):
|
def __init__(self, target, options=None, notify=None, macros=None):
|
||||||
GCC.__init__(self, target, options, notify, GCC_CS_PATH)
|
GCC.__init__(self, target, options, notify, macros, GCC_CS_PATH)
|
||||||
|
|
||||||
|
|
||||||
class GCC_CW(GCC):
|
class GCC_CW(GCC):
|
||||||
|
@ -196,13 +196,13 @@ class GCC_CW(GCC):
|
||||||
"Cortex-M0+": "armv6-m",
|
"Cortex-M0+": "armv6-m",
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, target, options=None, notify=None):
|
def __init__(self, target, options=None, notify=None, macros=None):
|
||||||
GCC.__init__(self, target, options, notify, CW_GCC_PATH)
|
GCC.__init__(self, target, options, notify, macros, CW_GCC_PATH)
|
||||||
|
|
||||||
|
|
||||||
class GCC_CW_EWL(GCC_CW):
|
class GCC_CW_EWL(GCC_CW):
|
||||||
def __init__(self, target, options=None, notify=None):
|
def __init__(self, target, options=None, notify=None, macros=None):
|
||||||
GCC_CW.__init__(self, target, options, notify)
|
GCC_CW.__init__(self, target, options, notify, macros)
|
||||||
|
|
||||||
# Compiler
|
# Compiler
|
||||||
common = [
|
common = [
|
||||||
|
@ -230,5 +230,5 @@ class GCC_CW_EWL(GCC_CW):
|
||||||
|
|
||||||
|
|
||||||
class GCC_CW_NEWLIB(GCC_CW):
|
class GCC_CW_NEWLIB(GCC_CW):
|
||||||
def __init__(self, target, options=None, notify=None):
|
def __init__(self, target, options=None, notify=None, macros=None):
|
||||||
GCC_CW.__init__(self, target, options, notify)
|
GCC_CW.__init__(self, target, options, notify, macros)
|
||||||
|
|
|
@ -29,8 +29,8 @@ class IAR(mbedToolchain):
|
||||||
|
|
||||||
DIAGNOSTIC_PATTERN = re.compile('"(?P<file>[^"]+)",(?P<line>[\d]+)\s+(?P<severity>Warning|Error)(?P<message>.+)')
|
DIAGNOSTIC_PATTERN = re.compile('"(?P<file>[^"]+)",(?P<line>[\d]+)\s+(?P<severity>Warning|Error)(?P<message>.+)')
|
||||||
|
|
||||||
def __init__(self, target, options=None, notify=None):
|
def __init__(self, target, options=None, notify=None, macros=None):
|
||||||
mbedToolchain.__init__(self, target, options, notify)
|
mbedToolchain.__init__(self, target, options, notify, macros)
|
||||||
|
|
||||||
c_flags = [
|
c_flags = [
|
||||||
"-Oh",
|
"-Oh",
|
||||||
|
|
Loading…
Reference in New Issue