@@ -1074,65 +1074,12 @@ private void compileLibrary(UserLibrary lib, List<File> includeFolders)
1074
1074
// Compile the library with .a linkage if a flag was set in library.properties
1075
1075
if (lib .alinkage ()){
1076
1076
1077
- File afile = new File (libBuildFolder , lib .getName () + ".a" );
1078
-
1079
- createFolder (libBuildFolder );
1080
- List <File > libraryObjectFiles = compileFiles (libBuildFolder , libFolder , true , includeFolders );
1081
-
1082
- // See if the .a file is already uptodate
1083
- if (afile .exists ()) {
1084
- boolean changed = false ;
1085
- for (File file : libraryObjectFiles ) {
1086
- if (file .lastModified () > afile .lastModified ()) {
1087
- changed = true ;
1088
- break ;
1089
- }
1090
- }
1091
-
1092
- // If none of the object files is newer than the .a file, don't
1093
- // bother rebuilding the .a file. There is a small corner case
1094
- // here: If a source file was removed, but no other source file
1095
- // was modified, this will not rebuild core.a even when it
1096
- // should. It's hard to fix and not a realistic case, so it
1097
- // shouldn't be a problem.
1098
- if (!changed ) {
1099
- if (verbose )
1100
- System .out .println (I18n .format (tr ("Using previously compiled file: {0}" ), afile .getPath ()));
1101
-
1102
- // this is no longer an object file, but will be added anyways.
1103
- objectFiles .add (afile );
1104
- return ;
1105
- }
1106
- }
1107
-
1108
- // Delete the .a file, to prevent any previous code from lingering
1109
- afile .delete ();
1110
-
1111
- try {
1112
- for (File file : libraryObjectFiles ) {
1113
- PreferencesMap dict = new PreferencesMap (prefs );
1114
- dict .put ("ide_version" , "" + BaseNoGui .REVISION );
1115
- dict .put ("archive_file" , afile .getName ());
1116
- dict .put ("object_file" , file .getAbsolutePath ());
1117
- dict .put ("build.path" , libBuildFolder .getAbsolutePath ());
1118
-
1119
- String [] cmdArray ;
1120
- String cmd = prefs .getOrExcept ("recipe.ar.pattern" );
1121
- try {
1122
- cmdArray = StringReplacer .formatAndSplit (cmd , dict , true );
1123
- } catch (Exception e ) {
1124
- throw new RunnerException (e );
1125
- }
1126
- execAsynchronously (cmdArray );
1127
- }
1077
+ createFolder (libBuildFolder );
1078
+ File afile = compileThroughAFile (libBuildFolder , libFolder , lib .getName (), includeFolders );
1128
1079
1129
- } catch (RunnerException e ) {
1130
- afile .delete ();
1131
- throw e ;
1132
- }
1133
-
1134
- // this is no longer an object file, but will be added anyways.
1135
- objectFiles .add (afile );
1080
+ // This is not a .o object file, but a .a file with all .o files inside.
1081
+ // This way libraries can be optimized better, similar as the core files.
1082
+ objectFiles .add (afile );
1136
1083
}
1137
1084
1138
1085
// no alinkage, old, default .o file linkage
@@ -1171,39 +1118,17 @@ private void compileFilesInFolder(File buildFolder, File srcFolder, List<File> i
1171
1118
objectFiles .addAll (objects );
1172
1119
}
1173
1120
1174
- // 3. compile the core, outputting .o files to <buildPath> and then
1175
- // collecting them into the core.a library file.
1176
- // Also compiles the variant (if it supplies actual source files),
1177
- // which are included in the link directly (not through core.a)
1178
- void compileCore ()
1179
- throws RunnerException , PreferencesMapException {
1121
+ private File compileThroughAFile (File buildFolder , File srcFolder , String name , List <File > includeFolders )
1122
+ throws RunnerException , PreferencesMapException {
1123
+ File afile = new File (buildFolder , name + ".a" );
1180
1124
1181
- File coreFolder = prefs .getFile ("build.core.path" );
1182
- File variantFolder = prefs .getFile ("build.variant.path" );
1183
- File buildFolder = new File (prefs .getFile ("build.path" ), "core" );
1184
- if (!buildFolder .exists () && !buildFolder .mkdirs ()) {
1185
- throw new RunnerException ("Unable to create folder " + buildFolder );
1186
- }
1187
-
1188
- List <File > includeFolders = new ArrayList <File >();
1189
- includeFolders .add (coreFolder ); // include core path only
1190
- if (variantFolder != null )
1191
- includeFolders .add (variantFolder );
1192
-
1193
-
1194
- if (variantFolder != null )
1195
- objectFiles .addAll (compileFiles (buildFolder , variantFolder , true ,
1196
- includeFolders ));
1197
-
1198
- File afile = new File (buildFolder , "core.a" );
1199
-
1200
- List <File > coreObjectFiles = compileFiles (buildFolder , coreFolder , true ,
1125
+ List <File > aObjectFiles = compileFiles (buildFolder , srcFolder , true ,
1201
1126
includeFolders );
1202
1127
1203
1128
// See if the .a file is already uptodate
1204
1129
if (afile .exists ()) {
1205
1130
boolean changed = false ;
1206
- for (File file : coreObjectFiles ) {
1131
+ for (File file : aObjectFiles ) {
1207
1132
if (file .lastModified () > afile .lastModified ()) {
1208
1133
changed = true ;
1209
1134
break ;
@@ -1219,15 +1144,15 @@ void compileCore()
1219
1144
if (!changed ) {
1220
1145
if (verbose )
1221
1146
System .out .println (I18n .format (tr ("Using previously compiled file: {0}" ), afile .getPath ()));
1222
- return ;
1147
+ return afile ;
1223
1148
}
1224
1149
}
1225
1150
1226
1151
// Delete the .a file, to prevent any previous code from lingering
1227
1152
afile .delete ();
1228
1153
1229
1154
try {
1230
- for (File file : coreObjectFiles ) {
1155
+ for (File file : aObjectFiles ) {
1231
1156
1232
1157
PreferencesMap dict = new PreferencesMap (prefs );
1233
1158
dict .put ("ide_version" , "" + BaseNoGui .REVISION );
@@ -1248,6 +1173,35 @@ void compileCore()
1248
1173
afile .delete ();
1249
1174
throw e ;
1250
1175
}
1176
+
1177
+ return afile ;
1178
+ }
1179
+
1180
+ // 3. compile the core, outputting .o files to <buildPath> and then
1181
+ // collecting them into the core.a library file.
1182
+ // Also compiles the variant (if it supplies actual source files),
1183
+ // which are included in the link directly (not through core.a)
1184
+ void compileCore ()
1185
+ throws RunnerException , PreferencesMapException {
1186
+
1187
+ File coreFolder = prefs .getFile ("build.core.path" );
1188
+ File variantFolder = prefs .getFile ("build.variant.path" );
1189
+ File buildFolder = new File (prefs .getFile ("build.path" ), "core" );
1190
+ if (!buildFolder .exists () && !buildFolder .mkdirs ()) {
1191
+ throw new RunnerException ("Unable to create folder " + buildFolder );
1192
+ }
1193
+
1194
+ List <File > includeFolders = new ArrayList <File >();
1195
+ includeFolders .add (coreFolder ); // include core path only
1196
+ if (variantFolder != null )
1197
+ includeFolders .add (variantFolder );
1198
+
1199
+
1200
+ if (variantFolder != null )
1201
+ objectFiles .addAll (compileFiles (buildFolder , variantFolder , true ,
1202
+ includeFolders ));
1203
+
1204
+ compileThroughAFile (buildFolder , coreFolder , "core" , includeFolders );
1251
1205
}
1252
1206
1253
1207
// 4. link it all together into the .elf file
0 commit comments