@@ -1074,65 +1074,12 @@ private void compileLibrary(UserLibrary lib, List<File> includeFolders)
10741074 // Compile the library with .a linkage if a flag was set in library.properties
10751075 if (lib .alinkage ()){
10761076
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 );
11281079
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 );
11361083 }
11371084
11381085 // no alinkage, old, default .o file linkage
@@ -1171,39 +1118,17 @@ private void compileFilesInFolder(File buildFolder, File srcFolder, List<File> i
11711118 objectFiles .addAll (objects );
11721119 }
11731120
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" );
11801124
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 , coreFolder , true ,
12011126 includeFolders );
12021127
12031128 // See if the .a file is already uptodate
12041129 if (afile .exists ()) {
12051130 boolean changed = false ;
1206- for (File file : coreObjectFiles ) {
1131+ for (File file : aObjectFiles ) {
12071132 if (file .lastModified () > afile .lastModified ()) {
12081133 changed = true ;
12091134 break ;
@@ -1219,15 +1144,15 @@ void compileCore()
12191144 if (!changed ) {
12201145 if (verbose )
12211146 System .out .println (I18n .format (tr ("Using previously compiled file: {0}" ), afile .getPath ()));
1222- return ;
1147+ return afile ;
12231148 }
12241149 }
12251150
12261151 // Delete the .a file, to prevent any previous code from lingering
12271152 afile .delete ();
12281153
12291154 try {
1230- for (File file : coreObjectFiles ) {
1155+ for (File file : aObjectFiles ) {
12311156
12321157 PreferencesMap dict = new PreferencesMap (prefs );
12331158 dict .put ("ide_version" , "" + BaseNoGui .REVISION );
@@ -1248,6 +1173,35 @@ void compileCore()
12481173 afile .delete ();
12491174 throw e ;
12501175 }
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 );
12511205 }
12521206
12531207 // 4. link it all together into the .elf file
0 commit comments