packaging: Initial packaging
[platform/upstream/cmake.git] / Source / cmGlobalMSYSMakefileGenerator.cxx
1 /*============================================================================
2   CMake - Cross Platform Makefile Generator
3   Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
4
5   Distributed under the OSI-approved BSD License (the "License");
6   see accompanying file Copyright.txt for details.
7
8   This software is distributed WITHOUT ANY WARRANTY; without even the
9   implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10   See the License for more information.
11 ============================================================================*/
12 #include "cmGlobalMSYSMakefileGenerator.h"
13 #include "cmLocalUnixMakefileGenerator3.h"
14 #include "cmMakefile.h"
15 #include "cmake.h"
16
17 cmGlobalMSYSMakefileGenerator::cmGlobalMSYSMakefileGenerator()
18 {
19   this->FindMakeProgramFile = "CMakeMSYSFindMake.cmake";
20   this->ForceUnixPaths = true;
21   this->ToolSupportsColor = true;
22   this->UseLinkScript = false;
23 }
24
25 std::string
26 cmGlobalMSYSMakefileGenerator::FindMinGW(std::string const& makeloc)
27 {
28   std::string fstab = makeloc;
29   fstab += "/../etc/fstab";
30   std::ifstream fin(fstab.c_str());
31   std::string path;
32   std::string mount;
33   std::string mingwBin;
34   while(fin)
35     {
36     fin >> path;
37     fin >> mount;
38     if(mount == "/mingw")
39       {
40       mingwBin = path;
41       mingwBin += "/bin";
42       }
43     }
44   return mingwBin;
45 }
46
47 void cmGlobalMSYSMakefileGenerator
48 ::EnableLanguage(std::vector<std::string>const& l,
49                  cmMakefile *mf,
50                  bool optional)
51 {
52   this->FindMakeProgram(mf);
53   std::string makeProgram = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM");
54   std::vector<std::string> locations;
55   std::string makeloc = cmSystemTools::GetProgramPath(makeProgram.c_str());
56   locations.push_back(this->FindMinGW(makeloc));
57   locations.push_back(makeloc);
58   locations.push_back("/mingw/bin");
59   locations.push_back("c:/mingw/bin");
60   std::string tgcc = cmSystemTools::FindProgram("gcc", locations);
61   std::string gcc = "gcc.exe";
62   if(tgcc.size())
63     {
64     gcc = tgcc;
65     }
66   std::string tgxx = cmSystemTools::FindProgram("g++", locations);
67   std::string gxx = "g++.exe";
68   if(tgxx.size())
69     {
70     gxx = tgxx;
71     }
72   std::string trc = cmSystemTools::FindProgram("windres", locations);
73   std::string rc = "windres.exe";
74   if(trc.size())
75     {
76     rc = trc;
77     }
78   mf->AddDefinition("MSYS", "1");
79   mf->AddDefinition("CMAKE_GENERATOR_CC", gcc.c_str());
80   mf->AddDefinition("CMAKE_GENERATOR_CXX", gxx.c_str());
81   mf->AddDefinition("CMAKE_GENERATOR_RC", rc.c_str());
82   this->cmGlobalUnixMakefileGenerator3::EnableLanguage(l, mf, optional);
83
84   if(!mf->IsSet("CMAKE_AR") &&
85       !this->CMakeInstance->GetIsInTryCompile() &&
86       !(1==l.size() && l[0]=="NONE"))
87     {
88     cmSystemTools::Error
89       ("CMAKE_AR was not found, please set to archive program. ",
90        mf->GetDefinition("CMAKE_AR"));
91     }
92 }
93
94 ///! Create a local generator appropriate to this Global Generator
95 cmLocalGenerator *cmGlobalMSYSMakefileGenerator::CreateLocalGenerator()
96 {
97   cmLocalUnixMakefileGenerator3* lg = new cmLocalUnixMakefileGenerator3;
98   lg->SetWindowsShell(false);
99   lg->SetMSYSShell(true);
100   lg->SetGlobalGenerator(this);
101   lg->SetIgnoreLibPrefix(true);
102   lg->SetPassMakeflags(false);
103   lg->SetUnixCD(true);
104   return lg;
105 }
106
107 //----------------------------------------------------------------------------
108 void cmGlobalMSYSMakefileGenerator
109 ::GetDocumentation(cmDocumentationEntry& entry)
110 {
111   entry.Name = cmGlobalMSYSMakefileGenerator::GetActualName();
112   entry.Brief = "Generates MSYS makefiles.";
113   entry.Full = "The makefiles use /bin/sh as the shell.  "
114     "They require msys to be installed on the machine.";
115 }