diff --git a/tools/build_api.py b/tools/build_api.py index f125edb53f..cc2c2bb68c 100644 --- a/tools/build_api.py +++ b/tools/build_api.py @@ -232,8 +232,8 @@ def build_project(src_path, build_path, target, toolchain_name, prev_features = features config.validate_config() - # And add the configuration macros to the toolchain - toolchain.add_macros(config.get_config_data_macros()) + # Set the toolchain's prefix header with the config data + toolchain.set_prefix_header_content(config.get_config_data_header()) # Compile Sources for path in src_paths: @@ -403,8 +403,8 @@ def build_library(src_paths, build_path, target, toolchain_name, prev_features = features config.validate_config() - # And add the configuration macros to the toolchain - toolchain.add_macros(config.get_config_data_macros()) + # Set the toolchain's prefix header with the config data + toolchain.set_prefix_header_content(config.get_config_data_header()) # Compile Sources for path in src_paths: diff --git a/tools/toolchains/__init__.py b/tools/toolchains/__init__.py index 043acaa279..a4f0a7d36b 100644 --- a/tools/toolchains/__init__.py +++ b/tools/toolchains/__init__.py @@ -265,6 +265,9 @@ class mbedToolchain: self.flags = deepcopy(self.DEFAULT_FLAGS) + # prefix_header_content will hold the content of the prefix header (if used) + self.prefix_header_content = None + def get_output(self): return self.output @@ -867,6 +870,26 @@ class mbedToolchain: map_csv = splitext(map)[0] + "_map.csv" memap.generate_output('csv-ci', map_csv) + # "Prefix headers" are automatically included by the compiler at the beginning of + # each source file. + # header_content - the content of the prefix header file. + def set_prefix_header_content(self, header_content): + self.prefix_header_content = header_content + + # Return the location of the prefix header. This function will create the prefix + # header first if needed. The header will be written in a file called "mbed_prefix.h" + # located in the project's build directory. + # If prefix headers are not used (self.prefix_header_content is None), the function + # returns None + def get_prefix_header(self): + if self.prefix_header_content is None: + return None + prefix_file = join(self.build_dir, "mbed_prefix.h") + if not exists(prefix_file): + with open(prefix_file, "wt") as f: + f.write(self.prefix_header_content) + return prefix_file + from tools.settings import ARM_BIN from tools.settings import GCC_ARM_PATH, GCC_CR_PATH diff --git a/tools/toolchains/arm.py b/tools/toolchains/arm.py index f58a20b017..6884b263be 100644 --- a/tools/toolchains/arm.py +++ b/tools/toolchains/arm.py @@ -115,7 +115,11 @@ class ARM(mbedToolchain): return ["--depend", dep_path] def get_compile_options(self, defines, includes): - return ['-D%s' % d for d in defines] + ['--via', self.get_inc_file(includes)] + opts = ['-D%s' % d for d in defines] + ['--via', self.get_inc_file(includes)] + prefix_header = self.get_prefix_header() + if prefix_header is not None: + opts = opts + ['--preinclude', prefix_header] + return opts @hook_tool def assemble(self, source, object, includes): diff --git a/tools/toolchains/gcc.py b/tools/toolchains/gcc.py index 3d0f9b5095..f2dc9f78b2 100644 --- a/tools/toolchains/gcc.py +++ b/tools/toolchains/gcc.py @@ -166,7 +166,11 @@ class GCC(mbedToolchain): return ["-MD", "-MF", dep_path] def get_compile_options(self, defines, includes): - return ['-D%s' % d for d in defines] + ['@%s' % self.get_inc_file(includes)] + opts = ['-D%s' % d for d in defines] + ['@%s' % self.get_inc_file(includes)] + prefix_header = self.get_prefix_header() + if prefix_header is not None: + opts = opts + ['-include', prefix_header] + return opts @hook_tool def assemble(self, source, object, includes): diff --git a/tools/toolchains/iar.py b/tools/toolchains/iar.py index aac31bc49d..256877451a 100644 --- a/tools/toolchains/iar.py +++ b/tools/toolchains/iar.py @@ -119,7 +119,11 @@ class IAR(mbedToolchain): return ["-l", base + '.s.txt'] def get_compile_options(self, defines, includes): - return ['-D%s' % d for d in defines] + ['-f', self.get_inc_file(includes)] + opts = ['-D%s' % d for d in defines] + ['-f', self.get_inc_file(includes)] + prefix_header = self.get_prefix_header() + if prefix_header is not None: + opts = opts + ['--preinclude', prefix_header] + return opts @hook_tool def assemble(self, source, object, includes):