13 #include <sys/utime.h>
20 #include "exception.h"
25 #define EXEPOSTFIX ".exe"
31 #define EXEPREFIX "./"
53 class AutomaticDependency
;
60 XMLElement
*node
, *head
;
64 std::vector
<Module
*> modules
;
65 std::vector
<Include
*> includes
;
66 std::vector
<Define
*> defines
;
67 std::vector
<LinkerFlag
*> linkerFlags
;
68 std::vector
<Property
*> properties
;
71 Project ( const std::string
& filename
);
73 void WriteConfigurationFile ();
74 void ExecuteInvocations ();
75 void ProcessXML ( const std::string
& path
);
76 Module
* LocateModule ( const std::string
& name
);
77 const Module
* LocateModule ( const std::string
& name
) const;
79 const Property
* LookupProperty ( const std::string
& name
) const;
80 void SetConfigurationOption ( char* s
,
82 std::string
* alternativeName
);
83 void SetConfigurationOption ( char* s
,
85 void WriteIfChanged ( char* outbuf
,
86 std::string filename
);
88 void ProcessXMLSubElement ( const XMLElement
& e
,
89 const std::string
& path
,
92 // disable copy semantics
93 Project ( const Project
& );
94 Project
& operator = ( const Project
& );
120 const Project
& project
;
121 const XMLElement
& node
;
123 std::string extension
;
124 std::string entrypoint
;
127 ImportLibrary
* importLibrary
;
129 std::vector
<File
*> files
;
130 std::vector
<Library
*> libraries
;
131 std::vector
<Include
*> includes
;
132 std::vector
<Define
*> defines
;
133 std::vector
<Invoke
*> invocations
;
134 std::vector
<Dependency
*> dependencies
;
135 std::vector
<If
*> ifs
;
136 std::vector
<CompilerFlag
*> compilerFlags
;
137 std::vector
<LinkerFlag
*> linkerFlags
;
139 Module ( const Project
& project
,
140 const XMLElement
& moduleNode
,
141 const std::string
& modulePath
);
143 ModuleType
GetModuleType ( const std::string
& location
,
144 const XMLAttribute
& attribute
);
145 bool HasImportLibrary () const;
146 std::string
GetTargetName () const;
147 std::string
GetDependencyPath () const;
148 std::string
GetBasePath () const;
149 std::string
GetPath () const;
150 std::string
GetPathWithPrefix ( const std::string
& prefix
) const;
151 std::string
GetTargets () const;
152 std::string
GetInvocationTarget ( const int index
) const;
153 bool HasFileWithExtensions ( const std::string
& extension1
,
154 const std::string
& extension2
) const;
155 void InvokeModule () const;
158 std::string
GetDefaultModuleExtension () const;
159 std::string
GetDefaultModuleEntrypoint () const;
160 void ProcessXMLSubElement ( const XMLElement
& e
,
161 const std::string
& path
,
169 const Project
& project
;
170 const Module
* module
;
171 const XMLElement
& node
;
172 std::string directory
;
173 std::string basePath
;
175 Include ( const Project
& project
,
176 const XMLElement
& includeNode
);
177 Include ( const Project
& project
,
178 const Module
* module
,
179 const XMLElement
& includeNode
);
190 const Project
& project
;
191 const Module
* module
;
192 const XMLElement
& node
;
196 Define ( const Project
& project
,
197 const XMLElement
& defineNode
);
198 Define ( const Project
& project
,
199 const Module
* module
,
200 const XMLElement
& defineNode
);
214 File ( const std::string
& _name
, bool _first
);
223 const XMLElement
& node
;
224 const Module
& module
;
227 Library ( const XMLElement
& _node
,
228 const Module
& _module
,
229 const std::string
& _name
);
238 const XMLElement
& node
;
239 const Module
& module
;
240 const Module
* invokeModule
;
241 std::vector
<InvokeFile
*> input
;
242 std::vector
<InvokeFile
*> output
;
244 Invoke ( const XMLElement
& _node
,
245 const Module
& _module
);
248 std::string
GetTargets () const;
249 std::string
GetParameters () const;
251 void ProcessXMLSubElement ( const XMLElement
& e
);
252 void ProcessXMLSubElementInput ( const XMLElement
& e
);
253 void ProcessXMLSubElementOutput ( const XMLElement
& e
);
260 const XMLElement
& node
;
262 std::string switches
;
264 InvokeFile ( const XMLElement
& _node
,
265 const std::string
& _name
);
274 const XMLElement
& node
;
275 const Module
& module
;
276 const Module
* dependencyModule
;
278 Dependency ( const XMLElement
& _node
,
279 const Module
& _module
);
288 const XMLElement
& node
;
289 const Module
& module
;
290 std::string basename
;
291 std::string definition
;
293 ImportLibrary ( const XMLElement
& _node
,
294 const Module
& module
);
303 const XMLElement
& node
;
304 const Project
& project
;
305 const Module
* module
;
306 std::string property
, value
;
307 std::vector
<File
*> files
;
308 std::vector
<Include
*> includes
;
309 std::vector
<Define
*> defines
;
310 std::vector
<Property
*> properties
;
311 std::vector
<If
*> ifs
;
313 If ( const XMLElement
& node_
,
314 const Project
& project_
,
315 const Module
* module_
);
325 const Project
& project
;
326 const Module
* module
;
327 const XMLElement
& node
;
330 CompilerFlag ( const Project
& project
,
331 const XMLElement
& compilerFlagNode
);
332 CompilerFlag ( const Project
& project
,
333 const Module
* module
,
334 const XMLElement
& compilerFlagNode
);
345 const Project
& project
;
346 const Module
* module
;
347 const XMLElement
& node
;
350 LinkerFlag ( const Project
& project
,
351 const XMLElement
& linkerFlagNode
);
352 LinkerFlag ( const Project
& project
,
353 const Module
* module
,
354 const XMLElement
& linkerFlagNode
);
365 const XMLElement
& node
;
366 const Project
& project
;
367 const Module
* module
;
368 std::string name
, value
;
370 Property ( const XMLElement
& node_
,
371 const Project
& project_
,
372 const Module
* module_
);
381 SourceFile ( AutomaticDependency
* automaticDependency
,
383 const std::string
& filename
,
385 bool isNonAutomaticDependency
);
386 SourceFile
* ParseFile ( const std::string
& normalizedFilename
);
388 std::string
Location () const;
389 std::vector
<SourceFile
*> files
;
390 AutomaticDependency
* automaticDependency
;
392 std::string filename
;
393 std::string filenamePart
;
394 std::string directoryPart
;
395 std::vector
<SourceFile
*> parents
; /* List of files, this file is included from */
396 bool isNonAutomaticDependency
;
397 std::string cachedDependencies
;
398 time_t lastWriteTime
;
399 time_t youngestLastWriteTime
; /* Youngest last write time of this file and all children */
400 SourceFile
* youngestFile
;
402 void GetDirectoryAndFilenameParts ();
405 void SkipWhitespace ();
406 bool ReadInclude ( std::string
& filename
,
408 bool IsIncludedFrom ( const std::string
& normalizedFilename
);
409 SourceFile
* GetParentSourceFile ();
410 bool CanProcessFile ( const std::string
& extension
);
411 bool IsParentOf ( const SourceFile
* parent
,
412 const SourceFile
* child
);
419 class AutomaticDependency
421 friend class SourceFileTest
;
423 const Project
& project
;
425 AutomaticDependency ( const Project
& project
);
426 ~AutomaticDependency ();
428 std::string
GetFilename ( const std::string
& filename
);
429 bool LocateIncludedFile ( const std::string
& directory
,
430 const std::string
& includedFilename
,
431 std::string
& resolvedFilename
);
432 bool LocateIncludedFile ( SourceFile
* sourceFile
,
434 const std::string
& includedFilename
,
436 std::string
& resolvedFilename
);
437 SourceFile
* RetrieveFromCacheOrParse ( Module
& module
,
438 const std::string
& filename
,
439 SourceFile
* parentSourceFile
);
440 SourceFile
* RetrieveFromCache ( const std::string
& filename
);
441 void CheckAutomaticDependencies ();
442 void CheckAutomaticDependenciesForFile ( SourceFile
* sourceFile
);
444 void ProcessModule ( Module
& module
);
445 void ProcessFile ( Module
& module
,
447 std::map
<std::string
, SourceFile
*> sourcefile_map
;
452 FixSeparator ( const std::string
& s
);
455 GetExtension ( const std::string
& filename
);
458 GetDirectory ( const std::string
& filename
);
461 NormalizeFilename ( const std::string
& filename
);
463 #endif /* __RBUILD_H */