diff --git a/workspace_tools/build.py b/workspace_tools/build.py index 0f9593a3bf..1cf2eb4acb 100644 --- a/workspace_tools/build.py +++ b/workspace_tools/build.py @@ -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: diff --git a/workspace_tools/build_api.py b/workspace_tools/build_api.py index e965435d17..2c95d92366 100644 --- a/workspace_tools/build_api.py +++ b/workspace_tools/build_api.py @@ -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) + diff --git a/workspace_tools/make.py b/workspace_tools/make.py index 2abca9a22b..99d5d5272b 100644 --- a/workspace_tools/make.py +++ b/workspace_tools/make.py @@ -48,7 +48,9 @@ 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", default=None, help="The mbed 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: diff --git a/workspace_tools/toolchains/__init__.py b/workspace_tools/toolchains/__init__.py index 29fbf34f15..a5ee60d497 100644 --- a/workspace_tools/toolchains/__init__.py +++ b/workspace_tools/toolchains/__init__.py @@ -146,7 +146,7 @@ class mbedToolchain: GOANNA_FORMAT = "[Goanna] warning [%FILENAME%:%LINENO%] - [%CHECKNAME%(%SEVERITY%)] %MESSAGE%" GOANNA_DIAGNOSTIC_PATTERN = re.compile(r'"\[Goanna\] (?Pwarning) \[(?P[^:]+):(?P\d+)\] \- (?P.*)"') - 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)) diff --git a/workspace_tools/toolchains/arm.py b/workspace_tools/toolchains/arm.py index 902d84edef..5c96c9778b 100644 --- a/workspace_tools/toolchains/arm.py +++ b/workspace_tools/toolchains/arm.py @@ -30,8 +30,8 @@ class ARM(mbedToolchain): DIAGNOSTIC_PATTERN = re.compile('"(?P[^"]+)", line (?P\d+): (?PWarning|Error): (?P.+)') DEP_PATTERN = re.compile('\S+:\s(?P.+)\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"] diff --git a/workspace_tools/toolchains/gcc.py b/workspace_tools/toolchains/gcc.py index fef4c03fe7..b74c1bd638 100644 --- a/workspace_tools/toolchains/gcc.py +++ b/workspace_tools/toolchains/gcc.py @@ -29,8 +29,8 @@ class GCC(mbedToolchain): CIRCULAR_DEPENDENCIES = True DIAGNOSTIC_PATTERN = re.compile('((?P\d+):)(\d+:)? (?Pwarning|error): (?P.+)') - 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) diff --git a/workspace_tools/toolchains/iar.py b/workspace_tools/toolchains/iar.py index 8f935b6f3f..f6a6741d84 100644 --- a/workspace_tools/toolchains/iar.py +++ b/workspace_tools/toolchains/iar.py @@ -29,8 +29,8 @@ class IAR(mbedToolchain): DIAGNOSTIC_PATTERN = re.compile('"(?P[^"]+)",(?P[\d]+)\s+(?PWarning|Error)(?P.+)') - 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",