4848Rtt_Root = ''
4949Env = None
5050
51+ if not hasattr (rtconfig , 'CXXFLAGS' ) and hasattr (rtconfig , 'CFLAGS' ):
52+ rtconfig .CXXFLAGS = rtconfig .CFLAGS
53+
54+ def _path_variants (path ):
55+ variants = set ()
56+ if not path :
57+ return variants
58+
59+ normalized = path .replace ('\\ ' , '/' ).rstrip ('/' )
60+ variants .add (normalized )
61+ variants .add (normalized + '/' )
62+ variants .add (normalized .replace ('/' , '\\ ' ))
63+ variants .add ((normalized + '/' ).replace ('/' , '\\ ' ))
64+
65+ return variants
66+
67+ def _split_exec_path (exec_path ):
68+ normalized = exec_path .replace ('\\ ' , '/' ).rstrip ('/' )
69+ lower = normalized .lower ()
70+ for suffix in ('/arm/armclang/bin' , '/arm/armcc/bin' , '/arm/bin40' , '/arm/bin' , '/bin' ):
71+ if lower .endswith (suffix ):
72+ return normalized [:- len (suffix )], normalized [- len (suffix ):]
73+
74+ return normalized , ''
75+
76+ def _replace_exec_path (value , old_path , new_path ):
77+ if not isinstance (value , str ):
78+ return value
79+
80+ result = value
81+ normalized_new_path = new_path .replace ('\\ ' , '/' ).rstrip ('/' )
82+ for old in sorted (_path_variants (old_path ), key = len , reverse = True ):
83+ replacement = normalized_new_path .replace ('/' , '\\ ' ) if '\\ ' in old else normalized_new_path
84+ if old .endswith (('/' , '\\ ' )):
85+ replacement += old [- 1 ]
86+ result = result .replace (old , replacement )
87+
88+ return result
89+
90+ def _apply_exec_path_override (env , exec_path ):
91+ old_exec_path = getattr (rtconfig , 'EXEC_PATH' , '' )
92+ old_root , suffix = _split_exec_path (old_exec_path )
93+ new_root , new_suffix = _split_exec_path (exec_path )
94+ new_exec_path = new_root + (new_suffix or suffix )
95+
96+ if old_root :
97+ for name in ('CFLAGS' , 'CXXFLAGS' , 'AFLAGS' , 'LFLAGS' ,
98+ 'M_CFLAGS' , 'M_CXXFLAGS' , 'M_LFLAGS' ):
99+ if hasattr (rtconfig , name ):
100+ setattr (rtconfig , name , _replace_exec_path (getattr (rtconfig , name ), old_root , new_root ))
101+
102+ rtconfig .EXEC_PATH = new_exec_path
103+ for key , name in (('CC' , 'CC' ), ('CXX' , 'CXX' ), ('AS' , 'AS' ), ('AR' , 'AR' ),
104+ ('LINK' , 'LINK' ), ('CFLAGS' , 'CFLAGS' ),
105+ ('CXXFLAGS' , 'CXXFLAGS' ), ('ASFLAGS' , 'AFLAGS' ),
106+ ('LINKFLAGS' , 'LFLAGS' )):
107+ if hasattr (rtconfig , name ):
108+ env [key ] = getattr (rtconfig , name )
109+
110+ def _normalize_armclang_flags_for_host (env ):
111+ if rtconfig .PLATFORM == 'armclang' and env ['PLATFORM' ] != 'win32' :
112+ for name in ('LFLAGS' , 'M_LFLAGS' ):
113+ if hasattr (rtconfig , name ):
114+ setattr (rtconfig , name , getattr (rtconfig , name ).replace ('\\ ' , '/' ))
115+
116+ if hasattr (rtconfig , 'LFLAGS' ):
117+ env ['LINKFLAGS' ] = rtconfig .LFLAGS
118+
51119def _as_unicode (value ):
52120 try :
53121 unicode
@@ -208,6 +276,9 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [
208276 os .environ ['RTT_EXEC_PATH' ] = exec_path
209277
210278 utils .ReloadModule (rtconfig ) # update environment variables to rtconfig.py
279+ if exec_path :
280+ _apply_exec_path_override (env , exec_path )
281+ _normalize_armclang_flags_for_host (env )
211282
212283 # some env variables have loaded in Environment() of SConstruct before re-load rtconfig.py;
213284 # after update rtconfig.py's variables, those env variables need to synchronize
@@ -219,8 +290,6 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [
219290 env ['LINK' ] = rtconfig .LINK
220291 if exec_path :
221292 env .PrependENVPath ('PATH' , rtconfig .EXEC_PATH )
222- env ['ASCOM' ]= env ['ASPPCOM' ]
223-
224293 if GetOption ('strict-compiling' ):
225294 STRICT_FLAGS = ''
226295 if rtconfig .PLATFORM in ['gcc' ]:
@@ -241,8 +310,16 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [
241310 env ['LIBLINKPREFIX' ] = ''
242311 env ['LIBLINKSUFFIX' ] = '.lib'
243312 env ['LIBDIRPREFIX' ] = '--userlibpath '
313+ if rtconfig .PLATFORM == 'armclang' and rtconfig .AS == 'armasm' :
314+ env ['ASCOM' ] = '$AS $ASFLAGS -o $TARGET $SOURCES'
315+ env ['ASPPCOM' ] = env ['ASCOM' ]
316+ else :
317+ env ['ASCOM' ] = env ['ASPPCOM' ]
318+
319+ else :
320+ env ['ASCOM' ] = env ['ASPPCOM' ]
244321
245- elif rtconfig .PLATFORM == 'iccarm' :
322+ if rtconfig .PLATFORM == 'iccarm' :
246323 env ['LIBPREFIX' ] = ''
247324 env ['LIBSUFFIX' ] = '.a'
248325 env ['LIBLINKPREFIX' ] = ''
0 commit comments