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
@@ -82,14 +82,6 @@ def remove_option(self, option):
82
82
if option in tool :
83
83
tool .remove (option )
84
84
85
- def assemble (self , source , object , includes ):
86
- # Preprocess first, then assemble
87
- tempfile = object + '.E.s'
88
- return [
89
- self .asm + ['-D%s' % s for s in self .get_symbols () + self .macros ] + ["-I%s" % i for i in includes ] + ["-E" , "-o" , tempfile , source ],
90
- self .hook .get_cmdline_assembler (self .asm + ["-o" , object , tempfile ])
91
- ]
92
-
93
85
def parse_dependencies (self , dep_path ):
94
86
dependencies = []
95
87
for line in open (dep_path ).readlines ():
@@ -125,6 +117,26 @@ def get_dep_opt(self, dep_path):
125
117
def archive (self , objects , lib_path ):
126
118
self .default_cmd ([self .ar , '-r' , lib_path ] + objects )
127
119
120
+ @hook_tool
121
+ def assemble (self , source , object , includes ):
122
+ # Preprocess first, then assemble
123
+ tempfile = object + '.E.s'
124
+
125
+ # Build preprocess assemble command
126
+ 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 ]
127
+
128
+ # Build main assemble command
129
+ cmd = self .asm + ["-o" , object , tempfile ]
130
+
131
+ # Call cmdline hook
132
+ cmd_pre = self .hook .get_cmdline_assembler (cmd_pre )
133
+ cmd = self .hook .get_cmdline_assembler (cmd )
134
+
135
+ # Return command array, don't execute
136
+ return [cmd_pre , cmd ]
137
+
138
+
139
+ @hook_tool
128
140
def link (self , output , objects , libraries , lib_dirs , mem_map ):
129
141
if len (lib_dirs ):
130
142
args = ["-o" , output , "--userlibpath" , "," .join (lib_dirs ), "--info=totals" , "--list=.link_totals.txt" ]
@@ -134,26 +146,44 @@ def link(self, output, objects, libraries, lib_dirs, mem_map):
134
146
if mem_map :
135
147
args .extend (["--scatter" , mem_map ])
136
148
137
- if hasattr (self .target , "link_cmdline_hook" ):
138
- args = self .target .link_cmdline_hook (self .__class__ .__name__ , args )
149
+ # Build linker command
150
+ cmd = self .ld + args + objects + libraries + self .sys_libs
151
+ print self .ld
152
+
153
+ # Call cmdline hook
154
+ cmd = self .hook .get_cmdline_linker (cmd )
139
155
140
- 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 ])
141
168
142
169
@hook_tool
143
170
def binary (self , resources , elf , bin ):
144
- 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 )
145
176
146
- if hasattr ( self . target , "binary_cmdline_hook" ):
147
- args = self .target . binary_cmdline_hook ( self . __class__ . __name__ , args )
177
+ # Exec command
178
+ self .default_cmd ( cmd )
148
179
149
- self .default_cmd (args )
150
180
151
181
class ARM_STD (ARM ):
152
182
def __init__ (self , target , options = None , notify = None , macros = None , silent = False , extra_verbose = False ):
153
183
ARM .__init__ (self , target , options , notify , macros , silent , extra_verbose = extra_verbose )
154
184
self .cc += ["-D__ASSERT_MSG" ]
155
185
self .cppc += ["-D__ASSERT_MSG" ]
156
- self .ld .append ( "--libpath=%s" % ARM_LIB )
186
+ self .ld .extend ([ "--libpath" , ARM_LIB ] )
157
187
158
188
159
189
class ARM_MICRO (ARM ):
@@ -184,4 +214,4 @@ def __init__(self, target, options=None, notify=None, macros=None, silent=False,
184
214
elif target .core in ["Cortex-M0" , "Cortex-M0+" ]:
185
215
self .sys_libs .extend ([join (ARM_CPPLIB , lib + ".l" ) for lib in ["cpp_ps" , "cpprt_p" ]])
186
216
else :
187
- self .ld .append ( "--libpath=%s" % ARM_LIB )
217
+ self .ld .extend ([ "--libpath" , ARM_LIB ] )
0 commit comments