@@ -252,6 +252,8 @@ class mbedToolchain:
252
252
253
253
MBED_CONFIG_FILE_NAME = "mbed_config.h"
254
254
255
+ PROFILE_FILE_NAME = ".profile"
256
+
255
257
__metaclass__ = ABCMeta
256
258
257
259
profile_template = {'common' :[], 'c' :[], 'cxx' :[], 'asm' :[], 'ld' :[]}
@@ -798,6 +800,7 @@ def compile_sources(self, resources, inc_dirs=None):
798
800
799
801
# Generate configuration header (this will update self.build_all if needed)
800
802
self .get_config_header ()
803
+ self .dump_build_profile ()
801
804
802
805
# Sort compile queue for consistency
803
806
files_to_compile .sort ()
@@ -911,13 +914,19 @@ def compile_command(self, source, object, includes):
911
914
deps = []
912
915
config_file = ([self .config .app_config_location ]
913
916
if self .config .app_config_location else [])
914
- if len (deps ) == 0 or self .need_update (object , deps + config_file ):
917
+ deps .append (config_file )
918
+ if ext == '.cpp' or self .COMPILE_C_AS_CPP :
919
+ deps .append (join (self .build_dir , self .PROFILE_FILE_NAME + "-cxx" ))
920
+ else :
921
+ deps .append (join (self .build_dir , self .PROFILE_FILE_NAME + "-c" ))
922
+ if len (deps ) == 0 or self .need_update (object , deps ):
915
923
if ext == '.cpp' or self .COMPILE_C_AS_CPP :
916
924
return self .compile_cpp (source , object , includes )
917
925
else :
918
926
return self .compile_c (source , object , includes )
919
927
elif ext == '.s' :
920
928
deps = [source ]
929
+ deps .append (join (self .build_dir , self .PROFILE_FILE_NAME + "-asm" ))
921
930
if self .need_update (object , deps ):
922
931
return self .assemble (source , object , includes )
923
932
else :
@@ -1012,8 +1021,9 @@ def link_program(self, r, tmp_path, name):
1012
1021
r .objects = sorted (set (r .objects ))
1013
1022
config_file = ([self .config .app_config_location ]
1014
1023
if self .config .app_config_location else [])
1015
- if self .need_update (elf , r .objects + r .libraries + [r .linker_script ] +
1016
- config_file ):
1024
+ dependencies = r .objects + r .libraries + [r .linker_script , config_file ]
1025
+ dependencies .append (join (self .build_dir , self .PROFILE_FILE_NAME + "-ld" ))
1026
+ if self .need_update (elf , dependencies ):
1017
1027
needed_update = True
1018
1028
self .progress ("link" , name )
1019
1029
self .link (elf , r .objects , r .libraries , r .lib_dirs , r .linker_script )
@@ -1161,6 +1171,22 @@ def get_config_header(self):
1161
1171
self .config_processed = True
1162
1172
return self .config_file
1163
1173
1174
+ def dump_build_profile (self ):
1175
+ """Dump the current build profile and macros into the `.profile` file
1176
+ in the build directory"""
1177
+ for key in ["cxx" , "c" , "asm" , "ld" ]:
1178
+ to_dump = (str (self .flags [key ]) + str (sorted (self .macros )))
1179
+ if key in ["cxx" , "c" ]:
1180
+ to_dump += str (self .flags ['common' ])
1181
+ where = join (self .build_dir , self .PROFILE_FILE_NAME + "-" + key )
1182
+ self ._overwrite_when_not_equal (where , to_dump )
1183
+
1184
+ @staticmethod
1185
+ def _overwrite_when_not_equal (filename , content ):
1186
+ if not exists (filename ) or content != open (filename ).read ():
1187
+ with open (filename , "wb" ) as out :
1188
+ out .write (content )
1189
+
1164
1190
@staticmethod
1165
1191
def generic_check_executable (tool_key , executable_name , levels_up ,
1166
1192
nested_dir = None ):
0 commit comments