|
15 | 15 | limitations under the License.
|
16 | 16 | """
|
17 | 17 | import re
|
18 |
| -from os.path import join, basename, splitext |
| 18 | +from os.path import join, basename, splitext, dirname |
19 | 19 |
|
20 | 20 | from tools.toolchains import mbedToolchain, TOOLCHAIN_PATHS
|
21 | 21 | from tools.hooks import hook_tool
|
@@ -93,6 +93,7 @@ def __init__(self, target, notify=None, macros=None,
|
93 | 93 | self.flags['ld'] += self.cpu
|
94 | 94 | self.ld = [join(tool_path, "arm-none-eabi-gcc")] + self.flags['ld']
|
95 | 95 | self.sys_libs = ["stdc++", "supc++", "m", "c", "gcc"]
|
| 96 | + self.preproc = [join(tool_path, "arm-none-eabi-cpp"), "-E", "-P"] |
96 | 97 |
|
97 | 98 | self.ar = join(tool_path, "arm-none-eabi-ar")
|
98 | 99 | self.elf2bin = join(tool_path, "arm-none-eabi-objcopy")
|
@@ -213,6 +214,15 @@ def link(self, output, objects, libraries, lib_dirs, mem_map):
|
213 | 214 | libs.append("-l%s" % name[3:])
|
214 | 215 | libs.extend(["-l%s" % l for l in self.sys_libs])
|
215 | 216 |
|
| 217 | + # Preprocess |
| 218 | + if mem_map: |
| 219 | + preproc_output = join(dirname(output), ".link_script.ld") |
| 220 | + cmd = (self.preproc + [mem_map] + self.ld[1:] + |
| 221 | + [ "-o", preproc_output]) |
| 222 | + self.cc_verbose("Preproc: %s" % ' '.join(cmd)) |
| 223 | + self.default_cmd(cmd) |
| 224 | + mem_map = preproc_output |
| 225 | + |
216 | 226 | # Build linker command
|
217 | 227 | map_file = splitext(output)[0] + ".map"
|
218 | 228 | cmd = self.ld + ["-o", output, "-Wl,-Map=%s" % map_file] + objects + ["-Wl,--start-group"] + libs + ["-Wl,--end-group"]
|
|
0 commit comments