Imported Upstream version 2.8.9
[platform/upstream/cmake.git] / Source / cmGlobalUnixMakefileGenerator3.h
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 #ifndef cmGlobalUnixMakefileGenerator3_h
13 #define cmGlobalUnixMakefileGenerator3_h
14
15 #include "cmGlobalGenerator.h"
16
17 class cmGeneratedFileStream;
18 class cmMakefileTargetGenerator;
19 class cmLocalUnixMakefileGenerator3;
20
21 /** \class cmGlobalUnixMakefileGenerator3
22  * \brief Write a Unix makefiles.
23  *
24  * cmGlobalUnixMakefileGenerator3 manages UNIX build process for a tree
25
26
27  The basic approach of this generator is to produce Makefiles that will all
28  be run with the current working directory set to the Home Output
29  directory. The one exception to this is the subdirectory Makefiles which are
30  created as a convenience and just cd up to the Home Output directory and
31  invoke the main Makefiles.
32
33  The make process starts with Makefile. Makefile should only contain the
34  targets the user is likely to invoke directly from a make command line. No
35  internal targets should be in this file. Makefile2 contains the internal
36  targets that are required to make the process work.
37
38  Makefile2 in turn will recursively make targets in the correct order. Each
39  target has its own directory \<target\>.dir and its own makefile build.make in
40  that directory. Also in that directory is a couple makefiles per source file
41  used by the target. Typically these are named source.obj.build.make and
42  source.obj.build.depend.make. The source.obj.build.make contains the rules
43  for building, cleaning, and computing dependencies for the given source
44  file. The build.depend.make contains additional dependencies that were
45  computed during dependency scanning. An additional file called
46  source.obj.depend is used as a marker to indicate when dependencies must be
47  rescanned.
48
49  Rules for custom commands follow the same model as rules for source files.
50
51  */
52
53 class cmGlobalUnixMakefileGenerator3 : public cmGlobalGenerator
54 {
55 public:
56   cmGlobalUnixMakefileGenerator3();
57   static cmGlobalGenerator* New() {
58     return new cmGlobalUnixMakefileGenerator3; }
59
60   ///! Get the name for the generator.
61   virtual const char* GetName() const {
62     return cmGlobalUnixMakefileGenerator3::GetActualName();}
63   static const char* GetActualName() {return "Unix Makefiles";}
64
65   /** Get the documentation entry for this generator.  */
66   virtual void GetDocumentation(cmDocumentationEntry& entry) const;
67
68   ///! Create a local generator appropriate to this Global Generator3
69   virtual cmLocalGenerator *CreateLocalGenerator();
70
71   /**
72    * Try to determine system infomation such as shared library
73    * extension, pthreads, byte order etc.
74    */
75   virtual void EnableLanguage(std::vector<std::string>const& languages,
76                               cmMakefile *, bool optional);
77
78   /**
79    * Generate the all required files for building this project/tree. This
80    * basically creates a series of LocalGenerators for each directory and
81    * requests that they Generate.
82    */
83   virtual void Generate();
84
85
86   void WriteMainCMakefileLanguageRules(cmGeneratedFileStream& cmakefileStream,
87                                        std::vector<cmLocalGenerator *> &);
88
89   // write out the help rule listing the valid targets
90   void WriteHelpRule(std::ostream& ruleFileStream,
91                      cmLocalUnixMakefileGenerator3 *);
92
93   // write the top level target rules
94   void WriteConvenienceRules(std::ostream& ruleFileStream,
95                              std::set<cmStdString> &emitted);
96
97   /** Get the command to use for a target that has no rule.  This is
98       used for multiple output dependencies and for cmake_force.  */
99   std::string GetEmptyRuleHackCommand() { return this->EmptyRuleHackCommand; }
100
101   /** Get the fake dependency to use when a rule has no real commands
102       or dependencies.  */
103   std::string GetEmptyRuleHackDepends() { return this->EmptyRuleHackDepends; }
104
105   // change the build command for speed
106   virtual std::string GenerateBuildCommand
107   (const char* makeProgram,
108    const char *projectName, const char* additionalOptions,
109    const char *targetName,
110    const char* config, bool ignoreErrors, bool fast);
111
112   /** Record per-target progress information.  */
113   void RecordTargetProgress(cmMakefileTargetGenerator* tg);
114
115   void AddCXXCompileCommand(const std::string &sourceFile,
116                             const std::string &workingDirectory,
117                             const std::string &compileCommand);
118
119 protected:
120   void WriteMainMakefile2();
121   void WriteMainCMakefile();
122
123   void WriteConvenienceRules2(std::ostream& ruleFileStream,
124                               cmLocalUnixMakefileGenerator3*);
125
126   void WriteDirectoryRule2(std::ostream& ruleFileStream,
127                            cmLocalUnixMakefileGenerator3* lg,
128                            const char* pass, bool check_all,
129                            bool check_relink);
130   void WriteDirectoryRules2(std::ostream& ruleFileStream,
131                             cmLocalUnixMakefileGenerator3* lg);
132
133   void AppendGlobalTargetDepends(std::vector<std::string>& depends,
134                                  cmTarget& target);
135
136   // does this generator need a requires step for any of its targets
137   bool NeedRequiresStep(cmTarget const&);
138
139   // Target name hooks for superclass.
140   const char* GetAllTargetName()           const { return "all"; }
141   const char* GetInstallTargetName()       const { return "install"; }
142   const char* GetInstallLocalTargetName()  const { return "install/local"; }
143   const char* GetInstallStripTargetName()  const { return "install/strip"; }
144   const char* GetPreinstallTargetName()    const { return "preinstall"; }
145   const char* GetTestTargetName()          const { return "test"; }
146   const char* GetPackageTargetName()       const { return "package"; }
147   const char* GetPackageSourceTargetName() const { return "package_source"; }
148   const char* GetEditCacheTargetName()     const { return "edit_cache"; }
149   const char* GetRebuildCacheTargetName()  const { return "rebuild_cache"; }
150   const char* GetCleanTargetName()         const { return "clean"; }
151
152   virtual bool CheckALLOW_DUPLICATE_CUSTOM_TARGETS() { return true; }
153
154   // Some make programs (Borland) do not keep a rule if there are no
155   // dependencies or commands.  This is a problem for creating rules
156   // that might not do anything but might have other dependencies
157   // added later.  If non-empty this variable holds a fake dependency
158   // that can be added.
159   std::string EmptyRuleHackDepends;
160
161   // Some make programs (Watcom) do not like rules with no commands.
162   // If non-empty this variable holds a bogus command that may be put
163   // in the rule to satisfy the make program.
164   std::string EmptyRuleHackCommand;
165
166   // Store per-target progress counters.
167   struct TargetProgress
168   {
169     TargetProgress(): NumberOfActions(0) {}
170     unsigned long NumberOfActions;
171     std::string VariableFile;
172     std::vector<unsigned long> Marks;
173     void WriteProgressVariables(unsigned long total, unsigned long& current);
174   };
175   struct ProgressMapCompare { bool operator()(cmTarget*,cmTarget*) const; };
176   typedef std::map<cmTarget*, TargetProgress,
177                    ProgressMapCompare> ProgressMapType;
178   ProgressMapType ProgressMap;
179
180   size_t CountProgressMarksInTarget(cmTarget* target,
181                                     std::set<cmTarget*>& emitted);
182   size_t CountProgressMarksInAll(cmLocalUnixMakefileGenerator3* lg);
183
184   cmGeneratedFileStream *CommandDatabase;
185 private:
186   virtual void ComputeTargetObjects(cmGeneratorTarget* gt) const;
187 };
188
189 #endif