Code::Blocks  SVN r11506
compilerGNUFortran.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of the Code::Blocks IDE and licensed under the GNU General Public License, version 3
3  * http://www.gnu.org/licenses/gpl-3.0.html
4  *
5  */
6 
7 #include <sdk.h>
8 #include <prep.h>
9 #include "compilerGNUFortran.h"
10 #include <wx/intl.h>
11 #include <wx/regex.h>
12 #include <wx/config.h>
13 #include <wx/fileconf.h>
14 #include <wx/msgdlg.h>
15 #include "manager.h"
16 #include "logmanager.h"
17 
18 #include <configmanager.h>
19 
20 #ifdef __WXMSW__
21  #include <wx/msw/registry.h>
22 #endif
23 
25  : Compiler(_("GNU Fortran Compiler"), _T("gfortran"))
26 {
27  m_Weight = 88;
28  m_MultiLineMessages = true;
29  Reset();
30 }
31 
33 {
34  //dtor
35 }
36 
38 {
39  return (new CompilerGNUFortran(*this));
40 }
41 
43 {
44  // try to find MinGW in environment variable PATH first
45  wxString pathValues;
46  wxGetEnv(_T("PATH"), &pathValues);
47  if (!pathValues.IsEmpty())
48  {
49  wxString sep = platform::windows ? _T(";") : _T(":");
50  wxChar pathSep = platform::windows ? _T('\\') : _T('/');
51  wxArrayString pathArray = GetArrayFromString(pathValues, sep);
52  for (size_t i = 0; i < pathArray.GetCount(); ++i)
53  {
54  if (wxFileExists(pathArray[i] + pathSep + m_Programs.C))
55  {
56  if (pathArray[i].AfterLast(pathSep).IsSameAs(_T("bin")))
57  {
58  m_MasterPath = pathArray[i].BeforeLast(pathSep);
59  return adrDetected;
60  }
61  }
62  }
63  }
64 
66  if (platform::windows)
67  {
68  // look first if MinGW was installed with Code::Blocks (new in beta6)
70  if (!wxFileExists(m_MasterPath + sep + _T("bin") + sep + m_Programs.C))
71  // if that didn't do it, look under C::B\MinGW, too (new in 08.02)
72  m_MasterPath += sep + _T("MinGW");
73  if (!wxFileExists(m_MasterPath + sep + _T("bin") + sep + m_Programs.C))
74  {
75  // no... search for MinGW installation dir
76  wxString windir = wxGetOSDirectory();
77  wxFileConfig ini(_T(""), _T(""), windir + _T("/MinGW.ini"), _T(""), wxCONFIG_USE_LOCAL_FILE | wxCONFIG_USE_NO_ESCAPE_CHARACTERS);
78  m_MasterPath = ini.Read(_T("/InstallSettings/InstallPath"), _T("C:\\MinGW"));
79  if (!wxFileExists(m_MasterPath + sep + _T("bin") + sep + m_Programs.C))
80  {
81 #ifdef __WXMSW__ // for wxRegKey
82  // not found...
83  // look for dev-cpp installation
84  wxRegKey key; // defaults to HKCR
85  key.SetName(_T("HKEY_LOCAL_MACHINE\\Software\\Dev-C++"));
86  if (key.Exists() && key.Open(wxRegKey::Read))
87  {
88  // found; read it
89  key.QueryValue(_T("Install_Dir"), m_MasterPath);
90  }
91  else
92  {
93  // installed by inno-setup
94  // HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Minimalist GNU for Windows 4.1_is1
95  wxString name;
96  long index;
97  key.SetName(_T("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall"));
98  //key.SetName("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion");
99  bool ok = key.GetFirstKey(name, index);
100  while (ok && !name.StartsWith(_T("Minimalist GNU for Windows")))
101  {
102  ok = key.GetNextKey(name, index);
103  }
104  if (ok)
105  {
106  name = key.GetName() + _T("\\") + name;
107  key.SetName(name);
108  if (key.Exists() && key.Open(wxRegKey::Read))
109  key.QueryValue(_T("InstallLocation"), m_MasterPath);
110  }
111  }
112 #endif
113  }
114  }
115  else
116  m_Programs.MAKE = _T("make.exe"); // we distribute "make" not "mingw32-make"
117  }
118  else
119  m_MasterPath = _T("/usr");
120 
122  // don't add lib/include dirs. GCC knows where its files are located
123 
124  //SetVersionString();
125  return ret;
126 }
127 
wxString GetName(bool bShortPrefix=true) const
DLLIMPORT wxArrayString GetArrayFromString(const wxString &text, const wxString &separator=DEFAULT_ARRAY_SEP, bool trimSpaces=true)
Definition: globals.cpp:134
bool wxGetEnv(const wxString &var, wxString *value)
bool Read(const wxString &key, wxString *str) const
bool wxFileExists(const wxString &filename)
bool GetFirstKey(wxString &strKeyName, long &lIndex)
bool m_MultiLineMessages
Definition: compiler.h:423
virtual void Reset()
Reset settings to defaults.
Definition: compiler.cpp:157
#define _T(string)
bool QueryValue(const wxString &szValue, wxString &strValue, bool raw) const
CompilerPrograms m_Programs
Definition: compiler.h:412
AutoDetectResult
Definition: compiler.h:190
wxUSE_UNICODE_dependent wxChar
wxString MAKE
Definition: compiler.h:204
static const wxString sep
static wxUniChar GetPathSeparator(wxPathFormat format=wxPATH_NATIVE)
wxString wxGetOSDirectory()
const wxString & _(const wxString &string)
Abstract base class for compilers.
Definition: compiler.h:274
bool IsEmpty() const
wxString C
Definition: compiler.h:199
static wxString GetExecutableFolder()
virtual Compiler * CreateCopy()
Implement this in new compilers, to return a new copy.
bool GetNextKey(wxString &strKeyName, long &lIndex) const
wxString m_MasterPath
Definition: compiler.h:409
bool Exists() const
virtual AutoDetectResult AutoDetectInstallationDir()
Try to auto-detect the compiler&#39;s installation directory.
bool StartsWith(const wxString &prefix, wxString *rest=NULL) const
bool Open(AccessMode mode=Write)
size_t GetCount() const
int m_Weight
Definition: compiler.h:422
void SetName(const wxString &strKey)