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