15
15
limitations under the License.
16
16
"""
17
17
import re
18
- from os .path import join
18
+ from os .path import join , dirname
19
19
20
20
from tools .toolchains import mbedToolchain
21
21
from tools .settings import ARM_BIN , ARM_INC , ARM_LIB , MY_ARM_CLIB , ARM_CPPLIB
@@ -83,14 +83,6 @@ def remove_option(self, option):
83
83
if option in tool :
84
84
tool .remove (option )
85
85
86
- def assemble (self , source , object , includes ):
87
- # Preprocess first, then assemble
88
- tempfile = object + '.E.s'
89
- return [
90
- self .asm + ['-D%s' % s for s in self .get_symbols () + self .macros ] + ["-I%s" % i for i in includes ] + ["-E" , "-o" , tempfile , source ],
91
- self .hook .get_cmdline_assembler (self .asm + ["-o" , object , tempfile ])
92
- ]
93
-
94
86
def parse_dependencies (self , dep_path ):
95
87
dependencies = []
96
88
for line in open (dep_path ).readlines ():
@@ -126,6 +118,26 @@ def get_dep_opt(self, dep_path):
126
118
def archive (self , objects , lib_path ):
127
119
self .default_cmd ([self .ar , '-r' , lib_path ] + objects )
128
120
121
+ @hook_tool
122
+ def assemble (self , source , object , includes ):
123
+ # Preprocess first, then assemble
124
+ tempfile = object + '.E.s'
125
+
126
+ # Build preprocess assemble command
127
+ cmd_pre = self .asm + ['-D%s' % s for s in self .get_symbols () + self .macros ] + ["-I%s" % i for i in includes ] + ["-E" , "-o" , tempfile , source ]
128
+
129
+ # Build main assemble command
130
+ cmd = self .asm + ["-o" , object , tempfile ]
131
+
132
+ # Call cmdline hook
133
+ cmd_pre = self .hook .get_cmdline_assembler (cmd_pre )
134
+ cmd = self .hook .get_cmdline_assembler (cmd )
135
+
136
+ # Return command array, don't execute
137
+ return [cmd_pre , cmd ]
138
+
139
+
140
+ @hook_tool
129
141
def link (self , output , objects , libraries , lib_dirs , mem_map ):
130
142
if len (lib_dirs ):
131
143
args = ["-o" , output , "--userlibpath" , "," .join (lib_dirs ), "--info=totals" , "--list=.link_totals.txt" ]
@@ -135,26 +147,43 @@ def link(self, output, objects, libraries, lib_dirs, mem_map):
135
147
if mem_map :
136
148
args .extend (["--scatter" , mem_map ])
137
149
138
- if hasattr (self .target , "link_cmdline_hook" ):
139
- args = self .target .link_cmdline_hook (self .__class__ .__name__ , args )
150
+ # Build linker command
151
+ cmd = self .ld + args + objects + libraries + self .sys_libs
152
+
153
+ # Call cmdline hook
154
+ cmd = self .hook .get_cmdline_linker (cmd )
140
155
141
- self .default_cmd (self .ld + args + objects + libraries + self .sys_libs )
156
+ # Split link command to linker executable + response file
157
+ link_files = join (dirname (output ), ".link_files.txt" )
158
+ with open (link_files , "wb" ) as f :
159
+ cmd_linker = cmd [0 ]
160
+ cmd_list = []
161
+ for c in cmd [1 :]:
162
+ cmd_list .append (('"%s"' % c ) if not c .startswith ('-' ) else c )
163
+ string = " " .join (cmd_list ).replace ("\\ " , "/" )
164
+ f .write (string )
165
+
166
+ # Exec command
167
+ self .default_cmd ([cmd_linker , '--via' , link_files ])
142
168
143
169
@hook_tool
144
170
def binary (self , resources , elf , bin ):
145
- args = [self .elf2bin , '--bin' , '-o' , bin , elf ]
171
+ # Build binary command
172
+ cmd = [self .elf2bin , '--bin' , '-o' , bin , elf ]
173
+
174
+ # Call cmdline hook
175
+ cmd = self .hook .get_cmdline_binary (cmd )
146
176
147
- if hasattr ( self . target , "binary_cmdline_hook" ):
148
- args = self .target . binary_cmdline_hook ( self . __class__ . __name__ , args )
177
+ # Exec command
178
+ self .default_cmd ( cmd )
149
179
150
- self .default_cmd (args )
151
180
152
181
class ARM_STD (ARM ):
153
182
def __init__ (self , target , options = None , notify = None , macros = None , silent = False , extra_verbose = False ):
154
183
ARM .__init__ (self , target , options , notify , macros , silent , extra_verbose = extra_verbose )
155
184
self .cc += ["-D__ASSERT_MSG" ]
156
185
self .cppc += ["-D__ASSERT_MSG" ]
157
- self .ld .append ( "--libpath=%s" % ARM_LIB )
186
+ self .ld .extend ([ "--libpath" , ARM_LIB ] )
158
187
159
188
160
189
class ARM_MICRO (ARM ):
@@ -185,4 +214,4 @@ def __init__(self, target, options=None, notify=None, macros=None, silent=False,
185
214
elif target .core in ["Cortex-M0" , "Cortex-M0+" ]:
186
215
self .sys_libs .extend ([join (ARM_CPPLIB , lib + ".l" ) for lib in ["cpp_ps" , "cpprt_p" ]])
187
216
else :
188
- self .ld .append ( "--libpath=%s" % ARM_LIB )
217
+ self .ld .extend ([ "--libpath" , ARM_LIB ] )
0 commit comments