Code::Blocks  SVN r11506
compilerG95.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 "compilerG95.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(_("G95 Fortran Compiler"), _T("g95"))
26 {
27  m_Weight = 92;
28  Reset();
29 }
30 
32 {
33  //dtor
34 }
35 
37 {
38  return (new CompilerG95(*this));
39 }
40 
42 {
43  // try to find MinGW in environment variable PATH first
44  wxString pathValues;
45  wxGetEnv(_T("PATH"), &pathValues);
46  if (!pathValues.IsEmpty())
47  {
48  wxString sep = platform::windows ? _T(";") : _T(":");
49  wxChar pathSep = platform::windows ? _T('\\') : _T('/');
50  wxArrayString pathArray = GetArrayFromString(pathValues, sep);
51  for (size_t i = 0; i < pathArray.GetCount(); ++i)
52  {
53  if (wxFileExists(pathArray[i] + pathSep + m_Programs.C))
54  {
55  if (pathArray[i].AfterLast(pathSep).IsSameAs(_T("bin")))
56  {
57  m_MasterPath = pathArray[i].BeforeLast(pathSep);
58  return adrDetected;
59  }
60  }
61  }
62  }
63 
65  if (platform::windows)
66  {
67  // look first if MinGW was installed with Code::Blocks (new in beta6)
69  if (!wxFileExists(m_MasterPath + sep + _T("bin") + sep + m_Programs.C))
70  // if that didn't do it, look under C::B\MinGW, too (new in 08.02)
71  m_MasterPath += sep + _T("MinGW");
72  if (!wxFileExists(m_MasterPath + sep + _T("bin") + sep + m_Programs.C))
73  {
74  // no... search for MinGW installation dir
75  wxString windir = wxGetOSDirectory();
76  wxFileConfig ini(_T(""), _T(""), windir + _T("/MinGW.ini"), _T(""), wxCONFIG_USE_LOCAL_FILE | wxCONFIG_USE_NO_ESCAPE_CHARACTERS);
77  m_MasterPath = ini.Read(_T("/InstallSettings/InstallPath"), _T("C:\\MinGW"));
78  if (!wxFileExists(m_MasterPath + sep + _T("bin") + sep + m_Programs.C))
79  {
80 #ifdef __WXMSW__ // for wxRegKey
81  // not found...
82  // look for dev-cpp installation
83  wxRegKey key; // defaults to HKCR
84  key.SetName(_T("HKEY_LOCAL_MACHINE\\Software\\Dev-C++"));
85  if (key.Exists() && key.Open(wxRegKey::Read))
86  {
87  // found; read it
88  key.QueryValue(_T("Install_Dir"), m_MasterPath);
89  }
90  else
91  {
92  // installed by inno-setup
93  // HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Minimalist GNU for Windows 4.1_is1
94  wxString name;
95  long index;
96  key.SetName(_T("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall"));
97  //key.SetName("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion");
98  bool ok = key.GetFirstKey(name, index);
99  while (ok && !name.StartsWith(_T("Minimalist GNU for Windows")))
100  {
101  ok = key.GetNextKey(name, index);
102  }
103  if (ok)
104  {
105  name = key.GetName() + _T("\\") + name;
106  key.SetName(name);
107  if (key.Exists() && key.Open(wxRegKey::Read))
108  key.QueryValue(_T("InstallLocation"), m_MasterPath);
109  }
110  }
111 #endif
112  }
113  }
114  else
115  m_Programs.MAKE = _T("make.exe"); // we distribute "make" not "mingw32-make"
116  }
117  else
118  m_MasterPath = _T("/usr");
119 
121  // don't add lib/include dirs. GCC knows where its files are located
122 
124  return ret;
125 }
126 
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)
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
virtual ~CompilerG95()
Definition: compilerG95.cpp:31
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()
bool GetNextKey(wxString &strKeyName, long &lIndex) const
wxString m_MasterPath
Definition: compiler.h:409
bool Exists() const
virtual Compiler * CreateCopy()
Implement this in new compilers, to return a new copy.
Definition: compilerG95.cpp:36
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)
virtual void SetVersionString()
Set the compiler version string.
Definition: compiler.h:362
virtual AutoDetectResult AutoDetectInstallationDir()
Try to auto-detect the compiler&#39;s installation directory.
Definition: compilerG95.cpp:41