16
16
"""
17
17
import re
18
18
from copy import copy
19
- from os .path import join , dirname , splitext , basename , exists
20
- from os import makedirs , write
19
+ from os .path import join , dirname , splitext , basename , exists , relpath
20
+ from os import makedirs , write , curdir
21
21
from tempfile import mkstemp
22
22
23
23
from tools .toolchains import mbedToolchain , TOOLCHAIN_PATHS
@@ -81,6 +81,8 @@ def __init__(self, target, notify=None, macros=None,
81
81
self .ar = join (ARM_BIN , "armar" )
82
82
self .elf2bin = join (ARM_BIN , "fromelf" )
83
83
84
+ self .SHEBANG += " --cpu=%s" % cpu
85
+
84
86
def parse_dependencies (self , dep_path ):
85
87
dependencies = []
86
88
for line in open (dep_path ).readlines ():
@@ -182,7 +184,7 @@ def compile_c(self, source, object, includes):
182
184
def compile_cpp (self , source , object , includes ):
183
185
return self .compile (self .cppc , source , object , includes )
184
186
185
- def correct_scatter_shebang (self , scatter_file ):
187
+ def correct_scatter_shebang (self , scatter_file , base_path = curdir ):
186
188
"""Correct the shebang at the top of a scatter file.
187
189
188
190
Positional arguments:
@@ -196,16 +198,19 @@ def correct_scatter_shebang(self, scatter_file):
196
198
"""
197
199
with open (scatter_file , "rb" ) as input :
198
200
lines = input .readlines ()
199
- if (lines [0 ].startswith (self .SHEBANG ) or
200
- not lines [0 ].startswith ("#!" )):
201
+ if (lines [0 ].startswith (self .SHEBANG ) or
202
+ not lines [0 ].startswith ("#!" )):
201
203
return scatter_file
202
204
else :
203
205
new_scatter = join (self .build_dir , ".link_script.sct" )
206
+ self .SHEBANG += " -I %s" % relpath (dirname (scatter_file ),
207
+ base_path )
204
208
if self .need_update (new_scatter , [scatter_file ]):
205
209
with open (new_scatter , "wb" ) as out :
206
210
out .write (self .SHEBANG )
207
211
out .write ("\n " )
208
212
out .write ("" .join (lines [1 :]))
213
+
209
214
return new_scatter
210
215
211
216
@hook_tool
@@ -310,15 +315,19 @@ def __init__(self, target, *args, **kwargs):
310
315
if target .core .lower ().endswith ("fd" ):
311
316
self .flags ['common' ].append ("-mcpu=%s" % target .core .lower ()[:- 2 ])
312
317
self .flags ['ld' ].append ("--cpu=%s" % target .core .lower ()[:- 2 ])
318
+ self .SHEBANG += " -mcpu=%s" % target .core .lower ()[:- 2 ]
313
319
elif target .core .lower ().endswith ("f" ):
314
320
self .flags ['common' ].append ("-mcpu=%s" % target .core .lower ()[:- 1 ])
315
321
self .flags ['ld' ].append ("--cpu=%s" % target .core .lower ()[:- 1 ])
322
+ self .SHEBANG += " -mcpu=%s" % target .core .lower ()[:- 1 ]
316
323
elif target .core .lower ().endswith ("ns" ):
317
324
self .flags ['common' ].append ("-mcpu=%s" % target .core .lower ()[:- 3 ])
318
325
self .flags ['ld' ].append ("--cpu=%s" % target .core .lower ()[:- 3 ])
326
+ self .SHEBANG += " -mcpu=%s" % target .core .lower ()[:- 3 ]
319
327
else :
320
328
self .flags ['common' ].append ("-mcpu=%s" % target .core .lower ())
321
329
self .flags ['ld' ].append ("--cpu=%s" % target .core .lower ())
330
+ self .SHEBANG += " -mcpu=%s" % target .core .lower ()
322
331
323
332
if target .core == "Cortex-M4F" :
324
333
self .flags ['common' ].append ("-mfpu=fpv4-sp-d16" )
@@ -356,7 +365,6 @@ def __init__(self, target, *args, **kwargs):
356
365
self .ar = [join (TOOLCHAIN_PATHS ["ARMC6" ], "armar" )]
357
366
self .elf2bin = join (TOOLCHAIN_PATHS ["ARMC6" ], "fromelf" )
358
367
359
-
360
368
def parse_dependencies (self , dep_path ):
361
369
return mbedToolchain .parse_dependencies (self , dep_path )
362
370
0 commit comments