Try this patch. (I am not sure what the equivalent Linux command is to only try to delete a file if it exists, so someone else will have to change that.)
Index: src/plugins/compilergcc/directcommands.cpp
===================================================================
--- src/plugins/compilergcc/directcommands.cpp (revision 8417)
+++ src/plugins/compilergcc/directcommands.cpp (working copy)
@@ -736,6 +736,13 @@
break;
}
wxString compilerCmd = compiler->GetCommand(ct);
+ if (ct == ctLinkStaticCmd) // static libraries should be deleted before recreation
+ {
+ if (platform::windows)
+ compilerCmd.Prepend(wxT("cmd /c if exist $static_output del $static_output\n"));
+ else
+ compilerCmd.Prepend(wxT("rm $static_output\n"));
+ }
compiler->GenerateCommandLine(compilerCmd,
target,
0,
Why don't you simply use wxRemoveFile?
Because the delete command won't be executed just before the ar command, probably.
Yes; so, for example, if the build is aborted, the previous library will not have been prematurely deleted.
But does the direct commands support executing two commands put in a single command and separated by \n?
Yes; directcommands.cpp line 79:
void DirectCommands::AddCommandsToArray(const wxString& cmds, wxArrayString& array, bool isWaitCmd, bool isLinkCmd)
{
wxString cmd = cmds;
while (!cmd.IsEmpty())
{
int idx = cmd.Find(_T("\n"));
wxString cmdpart = idx != -1 ? cmd.Left(idx) : cmd;
cmdpart.Trim(false);
cmdpart.Trim(true);
if (!cmdpart.IsEmpty())
{
if (isWaitCmd)
array.Add(wxString(COMPILER_WAIT));
if (isLinkCmd)
array.Add(wxString(COMPILER_WAIT_LINK));
array.Add(cmdpart);
}
if (idx == -1)
break;
cmd.Remove(0, idx + 1);
}
}
Well, Mac says (http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man1/rm.1.html) it will work, but I do not have access to a Mac to test it.
Using -f on non-Windows will prevent from waiting for a prompt if it failed. Also, I believe this is the correct way to only try to delete if the file exists.
Index: src/plugins/compilergcc/directcommands.cpp
===================================================================
--- src/plugins/compilergcc/directcommands.cpp (revision 8428)
+++ src/plugins/compilergcc/directcommands.cpp (working copy)
@@ -733,6 +733,13 @@
break;
}
wxString compilerCmd = compiler->GetCommand(ct);
+ if (ct == ctLinkStaticCmd) // static libraries should be deleted before recreation
+ {
+ if (platform::windows)
+ compilerCmd.Prepend(wxT("cmd /c if exist $static_output del $static_output\n"));
+ else
+ compilerCmd.Prepend(wxT("if [ -f $static_output ]; then rm -f $static_output; fi\n"));
+ }
compiler->GenerateCommandLine(compilerCmd,
target,
0,
Alternatively,
if [ -w $static_output ]; then rm -f $static_output; fi
could be used to only try to delete if write access is available on the file (under non-Windows).
Bash, I think (sorry, I am still relatively new to the Linux world, so I am not sure).
I forgot Linux has the option to run under different shells; maybe the most portable option in this situation would be just
IIRC, it is a sh script: bash prefer the use of double '[' so it would have been if [[ -w $static_output ]]; then rm -f $static_output; fi
Also, to write "cleaner" code (I think bash is shell compatible, but shell is not bash compatible... need to check. Anyway, I do not know if csh or zsh have compatibility with other shells so...), you could think about using the command test instead of it's shortcut ( "[...]" ) and to finish, use the && operator:
test -w $static_output && rm -f $static_output
This results in, at least, faster code ("&&" is faster than "if" said a teacher of mine, and result as an "if" because if first expression is false, the second is not evaluated, like in C and C++. Anyway, I do not really think that it is important here) and as && is probably also in csh (C-shell, so I guess our usual operators works there too ;) ) maybe a more UNIX portable code too.
About the test, I am not sure it is really useful: "man rm" said this for the "-f" option: "Do not prompt for confirmation. Do not write diagnostic messages or modify the exit status in the case of nonexistent operands. Any previous occurrences of the -i option shall be ignored." so if the use of the test is simply to verify that you can delete... just delete, effect will be identical.
But I would not say everything I said is certain: I am still considering myself as a child with linux scripting.