Permalink
Browse files

A-line: Force-delete .a files to avoid corruption

Always delete a unix static library before running `ar rcs`, to prevent the
case of conflicting object code that can cause link errors or even spurious
failures at runtime.
  • Loading branch information...
1 parent 08ff91c commit 5eef5720dfe6ce05f9b4f5270adec028525e2323 @jjuran committed Apr 30, 2012
Showing with 35 additions and 0 deletions.
  1. +35 −0 lamp/jTools/A-line/A-line/Link.cc
View
35 lamp/jTools/A-line/A-line/Link.cc
@@ -242,10 +242,45 @@ namespace tool
void Make();
};
+ static bool is_dot_a( const plus::string& s )
+ {
+ const size_t size = s.size();
+
+ if ( size > 2 )
+ {
+ const char* data = s.data();
+
+ return data[ size - 2 ] == '.' && data[ size - 1 ] == 'a';
+ }
+
+ return false;
+ }
+
void LinkingTask::Make()
{
plus::string output_filename = p7::basename( OutputPath() );
+ #ifndef __RELIX__
+
+ /*
+ Delete unix static library files before linking, since `ar rcs`
+ always appends and never replaces, and there's no option for it to
+ do that.
+
+ Don't delete Metrowerks' files (ending in ".lib"), however, since
+ it doesn't have this problem.
+
+ In MacRelix-hosted builds, only Metrowerks is targeted, so don't
+ even check.
+ */
+
+ if ( is_dot_a( output_filename ) )
+ {
+ unlink( OutputPath().c_str() );
+ }
+
+ #endif
+
ExecuteCommand( shared_from_this(), its_caption + output_filename, get_command(), get_diagnostics_file_path().c_str() );
}

0 comments on commit 5eef572

Please sign in to comment.