Imported Upstream version 2.8.12.2
[platform/upstream/cmake.git] / Source / cmLocalUnixMakefileGenerator3.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 cmLocalUnixMakefileGenerator3_h
13 #define cmLocalUnixMakefileGenerator3_h
14
15 #include "cmLocalGenerator.h"
16
17 // for cmDepends::DependencyVector
18 #include "cmDepends.h"
19
20 class cmCustomCommand;
21 class cmDependInformation;
22 class cmDepends;
23 class cmMakefileTargetGenerator;
24 class cmTarget;
25 class cmSourceFile;
26
27 /** \class cmLocalUnixMakefileGenerator3
28  * \brief Write a LocalUnix makefiles.
29  *
30  * cmLocalUnixMakefileGenerator3 produces a LocalUnix makefile from its
31  * member Makefile.
32  */
33 class cmLocalUnixMakefileGenerator3 : public cmLocalGenerator
34 {
35 public:
36   cmLocalUnixMakefileGenerator3();
37   virtual ~cmLocalUnixMakefileGenerator3();
38
39   /**
40    * Process the CMakeLists files for this directory to fill in the
41    * Makefile ivar
42    */
43   virtual void Configure();
44
45   /**
46    * Generate the makefile for this directory.
47    */
48   virtual void Generate();
49
50
51   // this returns the relative path between the HomeOutputDirectory and this
52   // local generators StartOutputDirectory
53   const std::string &GetHomeRelativeOutputPath();
54
55   // Write out a make rule
56   void WriteMakeRule(std::ostream& os,
57                      const char* comment,
58                      const char* target,
59                      const std::vector<std::string>& depends,
60                      const std::vector<std::string>& commands,
61                      bool symbolic,
62                      bool in_help = false);
63
64   // write the main variables used by the makefiles
65   void WriteMakeVariables(std::ostream& makefileStream);
66
67   /**
68    * If true, then explicitly pass MAKEFLAGS on the make all target for makes
69    * that do not use environment variables.
70    *
71    */
72   void SetPassMakeflags(bool s){this->PassMakeflags = s;}
73   bool GetPassMakeflags() { return this->PassMakeflags; }
74
75   /**
76    * Set the flag used to keep the make program silent.
77    */
78   void SetMakeSilentFlag(const char* s) { this->MakeSilentFlag = s; }
79   std::string &GetMakeSilentFlag() { return this->MakeSilentFlag; }
80
81   /**
82    * Set to true if the shell being used is the windows shell.
83    * This controls if statements in the makefile and the SHELL variable.
84    * The default is false.
85    */
86   void SetWindowsShell(bool v)  {this->WindowsShell = v;}
87
88   /**
89    * Set to true if the make tool being used is Watcom WMake.
90    */
91   void SetWatcomWMake(bool v)  {this->WatcomWMake = v;}
92
93   /**
94    * Set to true if the make tool being used is MinGW Make.
95    */
96   void SetMinGWMake(bool v)  {this->MinGWMake = v;}
97
98   /**
99    * Set to true if the make tool being used is NMake.
100    */
101   void SetNMake(bool v)  {this->NMake = v;}
102
103   /**
104    * Set to true if the shell being used is the MSYS shell.
105    * This controls if statements in the makefile and the SHELL variable.
106    * The default is false.
107    */
108   void SetMSYSShell(bool v)  {this->MSYSShell = v;}
109
110   /**
111    * If set to true, then NULL is set to nil for non Windows_NT.
112    * This uses make syntax used by nmake and borland.
113    * The default is false.
114    */
115   void SetDefineWindowsNULL(bool v)  {this->DefineWindowsNULL = v;}
116
117   /**
118    * If set to true, cd dir && command is used to
119    * run commands in a different directory.
120    */
121   void SetUnixCD(bool v)  {this->UnixCD = v;}
122
123   /**
124    * Set Support Verbose Variable.  If true, then .SILENT will
125    * be not end with :  i.e. .SILENT: or .SILENT
126    */
127   void SetSilentNoColon(bool v)  {this->SilentNoColon = v;}
128
129   /**
130    * Set the string used to include one makefile into another default
131    * is include.
132    */
133   void SetIncludeDirective(const char* s) { this->IncludeDirective = s; }
134   const char *GetIncludeDirective() { return this->IncludeDirective.c_str(); }
135
136   /**
137    * Set max makefile variable size, default is 0 which means unlimited.
138    */
139   void SetMakefileVariableSize(int s) { this->MakefileVariableSize = s; }
140
141   /**
142    * If ignore lib prefix is true, then do not strip lib from the name
143    * of a library.
144    */
145   void SetIgnoreLibPrefix(bool s) { this->IgnoreLibPrefix = s; }
146
147   /**
148    * Set whether passing a make target on a command line requires an
149    * extra level of escapes.
150    */
151   void SetMakeCommandEscapeTargetTwice(bool b)
152     { this->MakeCommandEscapeTargetTwice = b; }
153
154   /**
155    * Set whether the Borland curly brace command line hack should be
156    * applied.
157    */
158   void SetBorlandMakeCurlyHack(bool b)
159     { this->BorlandMakeCurlyHack = b; }
160
161   // used in writing out Cmake files such as WriteDirectoryInformation
162   static void WriteCMakeArgument(std::ostream& os, const char* s);
163
164   /** creates the common disclaimer text at the top of each makefile */
165   void WriteDisclaimer(std::ostream& os);
166
167   // write a  comment line #====... in the stream
168   void WriteDivider(std::ostream& os);
169
170   /** used to create a recursive make call */
171   std::string GetRecursiveMakeCall(const char *makefile, const char* tgt);
172
173   // append flags to a string
174   virtual void AppendFlags(std::string& flags, const char* newFlags);
175
176   // append an echo command
177   enum EchoColor { EchoNormal, EchoDepend, EchoBuild, EchoLink,
178                    EchoGenerate, EchoGlobal };
179   void AppendEcho(std::vector<std::string>& commands, const char* text,
180                   EchoColor color = EchoNormal);
181
182   /** Get whether the makefile is to have color.  */
183   bool GetColorMakefile() const { return this->ColorMakefile; }
184
185   virtual std::string GetTargetDirectory(cmTarget const& target) const;
186
187     // create a command that cds to the start dir then runs the commands
188   void CreateCDCommand(std::vector<std::string>& commands,
189                        const char *targetDir,
190                        cmLocalGenerator::RelativeRoot returnDir);
191
192   static std::string ConvertToQuotedOutputPath(const char* p);
193
194   std::string CreateMakeVariable(const char* sin, const char* s2in);
195
196   /** Called from command-line hook to bring dependencies up to date
197       for a target.  */
198   virtual bool UpdateDependencies(const char* tgtInfo,
199                                   bool verbose, bool color);
200
201   /** Called from command-line hook to clear dependencies.  */
202   virtual void ClearDependencies(cmMakefile* mf, bool verbose);
203
204   /** write some extra rules such as make test etc */
205   void WriteSpecialTargetsTop(std::ostream& makefileStream);
206   void WriteSpecialTargetsBottom(std::ostream& makefileStream);
207
208   std::string GetRelativeTargetDirectory(cmTarget const& target);
209
210   // File pairs for implicit dependency scanning.  The key of the map
211   // is the depender and the value is the explicit dependee.
212   struct ImplicitDependFileMap:
213     public std::map<cmStdString, cmDepends::DependencyVector> {};
214   struct ImplicitDependLanguageMap:
215     public std::map<cmStdString, ImplicitDependFileMap> {};
216   struct ImplicitDependTargetMap:
217     public std::map<cmStdString, ImplicitDependLanguageMap> {};
218   ImplicitDependLanguageMap const& GetImplicitDepends(cmTarget const& tgt);
219
220   void AddImplicitDepends(cmTarget const& tgt, const char* lang,
221                           const char* obj, const char* src);
222
223   void AppendGlobalTargetDepends(std::vector<std::string>& depends,
224                                  cmTarget& target);
225
226   // write the target rules for the local Makefile into the stream
227   void WriteLocalAllRules(std::ostream& ruleFileStream);
228
229   void AddLocalObjectFile(cmTarget* target, cmSourceFile* sf,
230                           std::string objNoTargetDir,
231                           bool hasSourceExtension);
232
233   std::vector<cmStdString> const& GetLocalHelp() { return this->LocalHelp; }
234
235   /** Get whether to create rules to generate preprocessed and
236       assembly sources.  This could be converted to a variable lookup
237       later.  */
238   bool GetCreatePreprocessedSourceRules()
239     {
240     return !this->SkipPreprocessedSourceRules;
241     }
242   bool GetCreateAssemblySourceRules()
243     {
244     return !this->SkipAssemblySourceRules;
245     }
246
247   // Fill the vector with the target names for the object files,
248   // preprocessed files and assembly files. Currently only used by the
249   // Eclipse generator.
250   void GetIndividualFileTargets(std::vector<std::string>& targets);
251
252 protected:
253   void WriteLocalMakefile();
254
255
256   // write the target rules for the local Makefile into the stream
257   void WriteLocalMakefileTargets(std::ostream& ruleFileStream,
258                                  std::set<cmStdString> &emitted);
259
260   // this method Writes the Directory information files
261   void WriteDirectoryInformationFile();
262
263
264   // write the depend info
265   void WriteDependLanguageInfo(std::ostream& cmakefileStream, cmTarget &tgt);
266
267   // write the local help rule
268   void WriteHelpRule(std::ostream& ruleFileStream);
269
270   // this converts a file name that is relative to the StartOuputDirectory
271   // into a full path
272   std::string ConvertToFullPath(const std::string& localPath);
273
274
275   void WriteConvenienceRule(std::ostream& ruleFileStream,
276                             const char* realTarget,
277                             const char* helpTarget);
278
279   void WriteTargetDependRule(std::ostream& ruleFileStream,
280                              cmTarget& target);
281   void WriteTargetCleanRule(std::ostream& ruleFileStream,
282                             cmTarget& target,
283                             const std::vector<std::string>& files);
284   void WriteTargetRequiresRule(std::ostream& ruleFileStream,
285                                cmTarget& target,
286                                const std::vector<std::string>& objects);
287
288   void AppendRuleDepend(std::vector<std::string>& depends,
289                         const char* ruleFileName);
290   void AppendRuleDepends(std::vector<std::string>& depends,
291                          std::vector<std::string> const& ruleFiles);
292   void AppendCustomDepends(std::vector<std::string>& depends,
293                            const std::vector<cmCustomCommand>& ccs);
294   void AppendCustomDepend(std::vector<std::string>& depends,
295                           const cmCustomCommand& cc);
296   void AppendCustomCommands(std::vector<std::string>& commands,
297                             const std::vector<cmCustomCommand>& ccs,
298                             cmTarget* target,
299                             cmLocalGenerator::RelativeRoot relative =
300                             cmLocalGenerator::HOME_OUTPUT);
301   void AppendCustomCommand(std::vector<std::string>& commands,
302                            const cmCustomCommand& cc,
303                            cmTarget* target,
304                            bool echo_comment=false,
305                            cmLocalGenerator::RelativeRoot relative =
306                            cmLocalGenerator::HOME_OUTPUT,
307                            std::ostream* content = 0);
308   void AppendCleanCommand(std::vector<std::string>& commands,
309                           const std::vector<std::string>& files,
310                           cmTarget& target, const char* filename =0);
311
312   // Helper methods for dependeny updates.
313   bool ScanDependencies(const char* targetDir,
314                 std::map<std::string, cmDepends::DependencyVector>& validDeps);
315   void CheckMultipleOutputs(bool verbose);
316
317 private:
318   std::string ConvertShellCommand(std::string const& cmd, RelativeRoot root);
319   std::string MakeLauncher(const cmCustomCommand& cc, cmTarget* target,
320                            RelativeRoot relative);
321
322   friend class cmMakefileTargetGenerator;
323   friend class cmMakefileExecutableTargetGenerator;
324   friend class cmMakefileLibraryTargetGenerator;
325   friend class cmMakefileUtilityTargetGenerator;
326   friend class cmGlobalUnixMakefileGenerator3;
327
328   ImplicitDependTargetMap ImplicitDepends;
329
330   //==========================================================================
331   // Configuration settings.
332   int MakefileVariableSize;
333   std::string IncludeDirective;
334   std::string MakeSilentFlag;
335   std::string ConfigurationName;
336   bool DefineWindowsNULL;
337   bool UnixCD;
338   bool PassMakeflags;
339   bool SilentNoColon;
340   bool MakeCommandEscapeTargetTwice;
341   bool BorlandMakeCurlyHack;
342   //==========================================================================
343
344   std::string HomeRelativeOutputPath;
345
346   /* Copy the setting of CMAKE_COLOR_MAKEFILE from the makefile at the
347      beginning of generation to avoid many duplicate lookups.  */
348   bool ColorMakefile;
349
350   /* Copy the setting of CMAKE_SKIP_PREPROCESSED_SOURCE_RULES and
351      CMAKE_SKIP_ASSEMBLY_SOURCE_RULES at the beginning of generation to
352      avoid many duplicate lookups.  */
353   bool SkipPreprocessedSourceRules;
354   bool SkipAssemblySourceRules;
355
356   struct LocalObjectEntry
357   {
358     cmTarget* Target;
359     std::string Language;
360     LocalObjectEntry(): Target(0), Language() {}
361     LocalObjectEntry(cmTarget* t, const char* lang):
362       Target(t), Language(lang) {}
363   };
364   struct LocalObjectInfo: public std::vector<LocalObjectEntry>
365   {
366     bool HasSourceExtension;
367     bool HasPreprocessRule;
368     bool HasAssembleRule;
369     LocalObjectInfo():HasSourceExtension(false), HasPreprocessRule(false),
370                       HasAssembleRule(false) {}
371   };
372   std::map<cmStdString, LocalObjectInfo> LocalObjectFiles;
373   void WriteObjectConvenienceRule(std::ostream& ruleFileStream,
374                                   const char* comment, const char* output,
375                                   LocalObjectInfo const& info);
376
377   std::vector<cmStdString> LocalHelp;
378
379   /* does the work for each target */
380   std::map<cmStdString, cmStdString> MakeVariableMap;
381   std::map<cmStdString, cmStdString> ShortMakeVariableMap;
382 };
383
384 #endif