00001
00002
00003
00004
00005
00006
00007
00008
00009
00011
00012
00013
00014 #include "wx/wxprec.h"
00015
00016 #ifdef __BORLANDC__
00017 #pragma hdrstop
00018 #endif
00019
00020 #ifndef WX_PRECOMP
00021 #include "wx/wx.h"
00022 #endif
00023
00024
00025 #include "wx/config.h"
00026
00027 #include "wxp/packagecmd.h"
00028 #include "wxp/compiler.h"
00029 #include "wxp/wxp.h"
00030
00031
00032
00033 wxPackageCompilerFormat wxCompilerSettings::s_defaultFormat = wxPCF_INVALID;
00034 wxPathList wxCompilerSettings::s_paths[wxPCF_MAX][wxPCPT_MAX];
00035
00036
00037
00038
00039
00040 wxString wxPackageCompilerFormatName[] =
00041 {
00042 _T("borland"),
00043 _T("msvc"),
00044 _T("watcom"),
00045 _T("mingw"),
00046 _T("msys"),
00047
00048 _T("gnu"),
00049 _T("autoconf")
00050 };
00051
00052 wxString wxPackageCMakeFormatName[] =
00053 {
00054 _T("Borland Makefiles"),
00055 _T("NMake Makefiles"),
00056 _T("Wactom WMake"),
00057 _T("MinGW Makefiles"),
00058 _T("MSYS Makefiles"),
00059
00060 _T("Unix Makefiles"),
00061 _T("NOTSUPPORTED")
00062 };
00063
00064 wxString wxPackageMakeName[] =
00065 {
00066 wxT("make.exe"),
00067 wxT("nmake.exe"),
00068 wxT("wmake.exe"),
00069 wxT("mingw32-make.exe"),
00070 wxT("make"),
00071
00072
00073 wxT("make"),
00074 wxT("make")
00075 };
00076
00077 wxString wxPackageCompilerPathTypeName[] =
00078 {
00079 wxT("bin"),
00080 wxT("include"),
00081 wxT("lib")
00082 };
00083
00084
00085
00086
00087 wxString wxBakefileMakefileExtName[] =
00088 {
00089 wxT("bcc"),
00090 wxT("vc"),
00091 wxT("wat"),
00092 wxT("mingw"),
00093 wxT(""),
00094
00095 wxT(""),
00096 wxT("")
00097 };
00098
00099
00100 #define wxPBST_ALL (wxPBST_BAKEFILE|wxPBST_CMAKE|wxPBST_SCONS)
00101
00102
00103
00104
00105
00106
00107 int s_nBuildSystemTypeMask[wxPCF_MAX] =
00108 {
00109 wxPBST_ALL,
00110 wxPBST_ALL,
00111 wxPBST_BAKEFILE|wxPBST_CMAKE,
00112 wxPBST_ALL,
00113 wxPBST_CMAKE,
00114 wxPBST_ALL,
00115 wxPBST_BAKEFILE
00116 };
00117
00118 #undef wxPBST_ALL
00119
00120
00121 long s_nPlatformMask[wxPCF_MAX] =
00122 {
00123 wxOS_WINDOWS,
00124 wxOS_WINDOWS,
00125 wxOS_WINDOWS,
00126 wxOS_WINDOWS,
00127 wxOS_WINDOWS,
00128 wxOS_UNIX,
00129 wxOS_UNIX
00130 };
00131
00132
00133
00134
00135
00136
00137
00138 wxIMPLEMENT_STRING2COMBINEABLE_ENUM(PackageCompilerFormat, wxPCF_MAX)
00139 wxIMPLEMENT_STRING2COMBINEABLE_ENUM(PackageBuildSystemType, wxPBST_MAX)
00140 wxIMPLEMENT_STRING2ENUM(PackageCompilerPathType, wxPCPT_MAX)
00141
00142
00143
00144
00145 bool wxIsCompilerFormatSupportedBy(wxPackageCompilerFormat fmt,
00146 wxPackageBuildSystemType buildsys)
00147 {
00148 wxASSERT(fmt != wxPCF_INVALID);
00149 return (wxGetBuildSystemsSupportingCompilerFormat(fmt) & buildsys) != 0;
00150 }
00151
00152 int wxGetBuildSystemsSupportingCompilerFormat(wxPackageCompilerFormat fmt)
00153 {
00154 wxASSERT(fmt != wxPCF_INVALID);
00155 return s_nBuildSystemTypeMask[wxPackageCompilerFormat2Idx(fmt)];
00156 }
00157
00158 bool wxIsCompilerFormatSupportedByThisPlatform(wxPackageCompilerFormat fmt)
00159 {
00160 wxASSERT(fmt != wxPCF_INVALID);
00161 wxPlatformInfo current;
00162
00163 long osmask = s_nPlatformMask[wxPackageCompilerFormat2Idx(fmt)];
00164 return (osmask & current.GetOperatingSystemId()) != 0;
00165 }
00166
00167 wxString wxPackageCompilerFormat2BakefileFormatName(wxPackageCompilerFormat f)
00168 {
00169
00170 return wxPackageCompilerFormat2String(f);
00171 }
00172
00173 wxString wxPackageCompilerFormat2CMakeFormatName(wxPackageCompilerFormat f)
00174 {
00175
00176 return wxPackageCMakeFormatName[wxPackageCompilerFormat2Idx(f)];
00177 }
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188 bool wxCompilerSettings::IsValidPathList(wxPackageCompilerFormat fmt,
00189 const wxPathList &pl)
00190 {
00191 wxArrayString arr = GetRequiredToolsList(fmt);
00192
00193
00194 for (size_t i=0; i < arr.GetCount(); i++)
00195 {
00196 wxString str = arr[i];
00197 if (!str.IsEmpty() && pl.FindAbsoluteValidPath(str).IsEmpty())
00198 return false;
00199 }
00200
00201 return true;
00202 }
00203
00204 void wxCompilerSettings::UpdateEnvVar(const wxString &name, wxPackageCompilerPathType t)
00205 {
00206 wxString paths;
00207 for (size_t j=0; j<GetCompilerPaths(t).GetCount(); j++)
00208 paths += GetCompilerPaths(t).Item(j) + wxT(";");
00209 if (!paths.IsEmpty() && paths.Last() == wxT(';'))
00210 paths.RemoveLast();
00211
00212 wxString value = paths, oldvalue;
00213 if (wxGetEnv(name, &oldvalue))
00214 value += wxT(";") + oldvalue;
00215 wxSetEnv(name, value);
00216 }
00217
00218 void wxCompilerSettings::UpdateEnvVars()
00219 {
00220 UpdateEnvVar(wxT("PATH"), wxPCPT_BIN);
00221 UpdateEnvVar(wxT("INCLUDE"), wxPCPT_INCLUDE);
00222 UpdateEnvVar(wxT("LIB"), wxPCPT_LIB);
00223
00224
00225 UpdateEnvVar(wxT("LIBPATH"), wxPCPT_LIB);
00226 }
00227
00228 wxStringHashMap wxCompilerSettings::GetSubstitutionHashMap(wxPackageBuildSystemType t) const
00229 {
00230 wxStringHashMap ret;
00231 if (s_selFormat == wxPCF_INVALID)
00232 return ret;
00233
00234 size_t n = wxPackageCompilerFormat2Idx(s_selFormat);
00235 bool needExe = (wxPlatformInfo().GetOperatingSystemId() & wxOS_WINDOWS) != 0;
00236
00237 ret[wxT("make")] = wxPackageMakeName[n];
00238 ret[wxT("cmake")] = needExe ? wxT("cmake.exe") : wxT("cmake");
00239 ret[wxT("scons")] = needExe ? wxT("scons.exe") : wxT("scons");
00240
00241
00242 ret[wxT("format-bakefile")] = wxPackageCompilerFormat2BakefileFormatName(s_selFormat);
00243 ret[wxT("format-cmake")] = wxPackageCompilerFormat2CMakeFormatName(s_selFormat);
00244
00245
00246 switch (t)
00247 {
00248 case wxPBST_BAKEFILE:
00249 ret[wxT("makefileext"] = wxBakefileMakefileExtName[n]);
00250 break;
00251
00252 default:
00253 break;
00254 }
00255
00256
00257 wxStringHashMap opts(GetOptionsWithDefaults(t));
00258 for( wxStringHashMap::iterator it = opts.begin(); it != opts.end(); ++it )
00259 {
00260 wxString key = it->first, value = it->second;
00261 ret[key + wxT("-default")] = value;
00262 }
00263
00264 return ret;
00265 }
00266
00267
00268 bool wxCompilerSettings::LoadGlobals(wxConfigBase *p, const wxString &path)
00269 {
00270 wxString defformat =
00271 #if defined(__WXMSW__)
00272 wxT("msvc");
00273 #elif defined(__UNIX__)
00274 wxT("gnu");
00275 #endif
00276
00277
00278 wxString fmtstr = p->Read(path + wxT("/CompilerFormats/DefaultFormat"), defformat);
00279 SetDefaultFormat(wxString2PackageCompilerFormat(fmtstr));
00280
00281
00282 for (size_t i=0; i < wxPCF_MAX; i++)
00283 {
00284 for (size_t j=0; j < wxPCPT_MAX; j++)
00285 {
00286 wxString str =
00287 path + wxT("/CompilerPaths/") +
00288 wxPackageCompilerPathType2String((wxPackageCompilerPathType)j) + wxT("/") +
00289 wxPackageCompilerFormat2String(wxIdx2PackageCompilerFormat(i));
00290
00291
00292
00293 s_paths[i][j].Add(wxStringTokenize(p->Read(str, wxEmptyString), wxT(",")));
00294 }
00295 }
00296
00297 return true;
00298 }
00299
00300 bool wxCompilerSettings::Load(wxConfigBase *p, const wxString &path)
00301 {
00302
00303 wxString fmtstr = p->Read(path + wxT("/CompilerFormats/SelectedFormat"), wxT("msvc"));
00304 SetSelFormat(wxString2PackageCompilerFormat(fmtstr));
00305
00306 return true;
00307 }
00308
00309
00310 void wxCompilerSettings::SaveGlobals(wxConfigBase *p, const wxString &path)
00311 {
00312 p->Write(path + wxT("/CompilerFormats/DefaultFormat"),
00313 wxPackageCompilerFormat2String(GetDefaultFormat()));
00314
00315
00316 for (size_t i=0; i < wxPCF_MAX; i++)
00317 {
00318 for (size_t k=0; k < wxPCPT_MAX; k++)
00319 {
00320 wxString str =
00321 path + wxT("/CompilerPaths/") +
00322 wxPackageCompilerPathType2String((wxPackageCompilerPathType)k) + wxT("/") +
00323 wxPackageCompilerFormat2String(wxIdx2PackageCompilerFormat(i));
00324
00325 p->Write(str, wxArray2String(s_paths[i][k]));
00326 }
00327 }
00328 }
00329
00330 void wxCompilerSettings::Save(wxConfigBase *p, const wxString &path) const
00331 {
00332
00333 wxString fmt(wxPackageCompilerFormat2String(s_selFormat));
00334 p->Write(path + wxT("/CompilerFormats/SelectedFormat"), fmt);
00335 }
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347 wxArrayString wxCompilerSettings::GetRequiredToolsList(wxPackageCompilerFormat fmt)
00348 {
00349 wxArrayString ret;
00350
00351 switch (fmt)
00352 {
00353 case wxPCF_BORLAND:
00354 ret.Add(wxT("bcc32.exe"));
00355 ret.Add(wxT("make.exe"));
00356 ret.Add(wxT("ilink32.exe"));
00357 ret.Add(wxT("tlib.exe"));
00358 break;
00359
00360 case wxPCF_MSVC:
00361 ret.Add(wxT("cl.exe"));
00362 ret.Add(wxT("rc.exe"));
00363 ret.Add(wxT("nmake.exe"));
00364 ret.Add(wxT("mspdb71.dll"));
00365 break;
00366
00367 case wxPCF_WATCOM:
00368 ret.Add(wxT("wmake.exe"));
00369 ret.Add(wxT("wpp386.exe"));
00370 ret.Add(wxT("wcc386.exe"));
00371 ret.Add(wxT("wlink.exe"));
00372 ret.Add(wxT("wrc.exe"));
00373 break;
00374
00375 case wxPCF_MINGW:
00376 ret.Add(wxT("g++.exe"));
00377 ret.Add(wxT("gcc.exe"));
00378 ret.Add(wxT("mingw32-make.exe"));
00379 ret.Add(wxT("ld.exe"));
00380 ret.Add(wxT("windres.exe"));
00381 break;
00382
00383 case wxPCF_MSYS:
00384
00385 break;
00386
00387 case wxPCF_GNUMAKEFILE:
00388 ret.Add(wxT("make"));
00389 ret.Add(wxT("gcc"));
00390 ret.Add(wxT("g++"));
00391 ret.Add(wxT("ar"));
00392 break;
00393
00394 case wxPCF_AUTOCONF:
00395
00396
00397 break;
00398
00399 default:
00400 wxFAIL;
00401 }
00402
00403 return ret;
00404 }
00405
00406 wxStringHashMap wxCompilerSettings::GetOptionsWithDefaults(wxPackageBuildSystemType bs) const
00407 {
00408 wxStringHashMap h;
00409
00410 switch (bs)
00411 {
00412 case wxPBST_BAKEFILE:
00413 h[wxT("CFLAGS")] = wxEmptyString;
00414 h[wxT("CXXFLAGS")] = wxEmptyString;
00415 h[wxT("CPPFLAGS")] = wxEmptyString;
00416 h[wxT("LDFLAGS")] = wxEmptyString;
00417 switch (s_selFormat)
00418 {
00419 case wxPCF_BORLAND:
00420 h[wxT("CC")] = wxT("bcc32.exe");
00421 h[wxT("CXX")] = wxT("bcc32.exe");
00422 h[wxT("CPPFLAGS")] = wxT("-a8 -g0");
00423 break;
00424 case wxPCF_MSVC:
00425 h[wxT("CC")] = wxT("cl.exe");
00426 h[wxT("CXX")] = wxT("cl.exe");
00427 break;
00428 case wxPCF_WATCOM:
00429 h[wxT("CC")] = wxT("wcc386.exe");
00430 h[wxT("CXX")] = wxT("wpp386.exe");
00431 break;
00432 case wxPCF_MINGW:
00433 h[wxT("CC")] = wxT("gcc.exe");
00434 h[wxT("CXX")] = wxT("g++.exe");
00435 break;
00436 case wxPCF_GNUMAKEFILE:
00437 h[wxT("CC")] = wxT("gcc");
00438 h[wxT("CXX")] = wxT("g++");
00439 break;
00440 case wxPCF_AUTOCONF:
00441
00442
00443 h[wxT("CC")] = wxEmptyString;
00444 h[wxT("CXX")] = wxEmptyString;
00445 break;
00446
00447 default:
00448 wxFAIL;
00449 break;
00450 }
00451 break;
00452
00453 case wxPBST_CMAKE:
00454 h[wxT("CMAKE_C_FLAGS")] = wxEmptyString;
00455 h[wxT("CMAKE_CXX_FLAGS")] = wxEmptyString;
00456 h[wxT("CMAKE_MODULE_LINKER_FLAGS")] = wxEmptyString;
00457 h[wxT("CMAKE_SHARED_LINKER_FLAGS")] = wxEmptyString;
00458 h[wxT("CMAKE_EXE_LINKER_FLAGS")] = wxEmptyString;
00459 switch (s_selFormat)
00460 {
00461 case wxPCF_BORLAND:
00462 h[wxT("CMAKE_C_COMPILER")] = wxT("bcc32.exe");
00463 h[wxT("CMAKE_CXX_COMPILER")] = wxT("bcc32.exe");
00464 break;
00465 case wxPCF_MSVC:
00466 h[wxT("CMAKE_C_COMPILER")] = wxT("cl.exe");
00467 h[wxT("CMAKE_CXX_COMPILER")] = wxT("cl.exe");
00468 break;
00469
00470 default:
00471
00472 break;
00473 }
00474 break;
00475
00476 case wxPBST_SCONS:
00477
00478 break;
00479
00480 default:
00481 wxFAIL;
00482 break;
00483 }
00484
00485 return h;
00486 }
00487