This is my patch that requires minor SDK header file changes to enum type AutoDetectResult in Compiler.h.
Tim S.
Index: src/plugins/compilergcc/compilerCYGWIN.cpp
===================================================================
--- src/plugins/compilergcc/compilerCYGWIN.cpp (revision 7711)
+++ src/plugins/compilergcc/compilerCYGWIN.cpp (working copy)
@@ -35,9 +35,11 @@
{
CompilerMINGW::Reset();
- m_Programs.C = _T("gcc.exe");
- m_Programs.CPP = _T("g++.exe");
- m_Programs.LD = _T("g++.exe");
+ // NOTE: Cygwin's gcc.exe is a file link and
+ // is not a good default name for running via cmd.exe
+ m_Programs.C = _T("gcc-3.exe");
+ m_Programs.CPP = _T("g++-3.exe");
+ m_Programs.LD = _T("g++-3.exe");
m_Programs.DBG = _T("gdb.exe");
m_Programs.LIB = _T("ar.exe");
m_Programs.WINDRES = _T("windres.exe");
@@ -48,24 +50,87 @@
m_Options.AddOption(_("Do not use cygwin specific functionality"), _T("-mno-cygwin"), _("General"));
}
+bool isNormalFileNotSymlink(const wxString& filename){
+ if (wxFileExists(filename)){
+ wxFile aFile(filename);
+ if (aFile.IsOpened()){
+ char buffer[10]={0};
+ aFile.Read(buffer,10);
+ if (memcmp("!<symlink>", buffer, 10) != 0){
+ return true;
+ }
+ }
+ }
+ return false;
+}
+
AutoDetectResult CompilerCYGWIN::AutoDetectInstallationDir()
{
- m_MasterPath = _T("C:\\Cygwin"); // just a guess
+ AutoDetectResult ret = adrGuessed;
+ wxString tempMasterPath = _T("C:\\Cygwin"); // just a guess
+ m_MasterPath = tempMasterPath;
+ bool validInstallationDir = false;
// look in registry for Cygwin
wxRegKey key; // defaults to HKCR
- key.SetName(_T("HKEY_LOCAL_MACHINE\\Software\\Cygnus Solutions\\Cygwin\\mounts v2\\/"));
+ key.SetName(_T("HKEY_LOCAL_MACHINE\\Software\\Cygwin\\setup"));
if (key.Exists() && key.Open(wxRegKey::Read))
{
- // found; read it
- key.QueryValue(_T("native"), m_MasterPath);
+ // found CygWin version 1.7 or newer; read it
+ key.QueryValue(_T("rootdir"), tempMasterPath);
+ if (wxDirExists(
+ tempMasterPath + wxFILE_SEP_PATH +
+ _T("bin"))
+ ){
+ validInstallationDir = true;
+ }
}
- AutoDetectResult ret = wxFileExists(m_MasterPath + wxFILE_SEP_PATH +
- _T("bin") + wxFILE_SEP_PATH +
- m_Programs.C)
- ? adrDetected
- : adrGuessed;
+ if (!validInstallationDir){
+ key.SetName(_T("HKEY_LOCAL_MACHINE\\Software\\Cygnus Solutions\\Cygwin\\mounts v2\\/"));
+ if (key.Exists() && key.Open(wxRegKey::Read))
+ {
+ // found CygWin version 1.5 or older; read it
+ key.QueryValue(_T("native"), tempMasterPath);
+ if (wxDirExists(
+ tempMasterPath + wxFILE_SEP_PATH +
+ _T("bin")
+ )
+ ){
+ validInstallationDir = true;
+ }
+ }
+ }
+
+ if (validInstallationDir){
+ wxString cProgramDir = tempMasterPath + wxFILE_SEP_PATH +
+ _T("bin") + wxFILE_SEP_PATH;
+ wxString cProgramFullname = cProgramDir + m_Programs.C;
+ if (isNormalFileNotSymlink(cProgramFullname)){
+ m_MasterPath = tempMasterPath;
+ ret = adrDetected;
+ } else {
+ if (isNormalFileNotSymlink(cProgramDir + _T("gcc-4.exe"))){
+ m_Programs.C = _T("gcc-4.exe");
+ m_Programs.CPP = _T("g++-4.exe");
+ m_Programs.LD = _T("g++-4.exe");
+ m_MasterPath = tempMasterPath;
+ ret = adrDetectedToolChain;
+ } else if (isNormalFileNotSymlink(cProgramDir + _T("gcc-3.exe"))){
+ m_Programs.C = _T("gcc-3.exe");
+ m_Programs.CPP = _T("g++-3.exe");
+ m_Programs.LD = _T("g++-3.exe");
+ m_MasterPath = tempMasterPath;
+ ret = adrDetectedToolChain;
+ }
+ }
+ }
+
+ if (validInstallationDir && ret == adrGuessed){
+ m_MasterPath = tempMasterPath;
+ ret = adrDetectedDir;
+ }
+
return ret;
}
Index: src/plugins/compilergcc/compileroptionsdlg.cpp
===================================================================
--- src/plugins/compilergcc/compileroptionsdlg.cpp (revision 7711)
+++ src/plugins/compilergcc/compileroptionsdlg.cpp (working copy)
@@ -1299,6 +1299,37 @@
switch (compiler->AutoDetectInstallationDir())
{
+ case adrDetectedDir:
+ {
+ wxString msg;
+ msg.Printf(_("Auto-detected \"%s\";but, failed to find a valid C-Compiler\nin installation path of \"%s\"\n"
+ "Do you want to use this installation directory?"),
+ #if wxCHECK_VERSION(2, 9, 0)
+ compiler->GetName().wx_str(), compiler->GetMasterPath().wx_str());
+ #else
+ compiler->GetName().c_str(), compiler->GetMasterPath().c_str());
+ #endif
+ if (cbMessageBox(msg, _("Confirmation"), wxICON_QUESTION | wxYES_NO) == wxID_NO)
+ {
+ compiler->SetMasterPath(backup);
+ compiler->SetExtraPaths(ExtraPathsBackup);
+ }
+ }
+ break;
+
+ case adrDetectedToolChain:
+ {
+ wxString msg;
+ #if wxCHECK_VERSION(2, 9, 0)
+ msg.Printf(_("Auto-detected \"%s\"\nwith different C-Compiler filename \nin installation path of \"%s\""), compiler->GetName().wx_str(), compiler->GetMasterPath().wx_str());
+ #else
+ msg.Printf(_("Auto-detected \"%s\"\nwith different C-Compiler filename \nin installation path of \"%s\""), compiler->GetName().c_str(), compiler->GetMasterPath().c_str());
+ #endif
+ cbMessageBox(msg);
+ DoFillCompilerPrograms();
+ }
+ break;
+
case adrDetected:
{
wxString msg;
Index: src/include/compiler.h
===================================================================
--- src/include/compiler.h (revision 7711)
+++ src/include/compiler.h (working copy)
@@ -142,7 +142,9 @@
enum AutoDetectResult
{
adrDetected,
- adrGuessed
+ adrGuessed,
+ adrDetectedDir,
+ adrDetectedToolChain
};
/// Struct to keep programs